app-attr.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369
  1. <template>
  2. <view class="app-attr">
  3. <view @click="alert">
  4. <slot name="button"></slot>
  5. </view>
  6. <view class="modal" v-if="display === 'block'" @click="close">
  7. <view class="safe-area-inset-bottom u-attr-fixed">
  8. <view class="content" @tap.native.stop="preventD">
  9. <image src="../../../static/image/icon/close.png" class="close" @click="close"></image>
  10. <view class="first dir-left-nowrap" :class="sign =='wholesale' ? 'no-border' : ''">
  11. <view class="box-grow-0 img" @click="clickImg(attrPic)">
  12. <app-image :img-src="attrPic" width="100%" height="100%"></app-image>
  13. </view>
  14. <view class="info">
  15. <view class="dir-left-nowrap cross-center" :class="priceColor">
  16. <view class="dir-left-nowrap cross-center">
  17. <view class="dir-left-nowrap cross-center" :class="theme+'-m-text ' + theme"
  18. v-if="selectAttr.extra || goods.extra">
  19. <view>{{selectAttr.extra ? selectAttr.extra.value + selectAttr.extra.name :
  20. goods.extra.value + goods.extra.name}}
  21. </view>
  22. <view v-if="!(goods.sign === 'integral_mall' && attrPrice == 0)">+</view>
  23. </view>
  24. <app-price :theme="theme"
  25. v-if="!(goods.sign === 'integral_mall' && attrPrice == 0) && sign != 'wholesale'"
  26. type="text-price-all" :price="attrPrice" :default-price="goods.price">
  27. </app-price>
  28. <app-price :theme="theme" v-if="sign == 'wholesale'" type="text-price-all"
  29. :price="attrPrice"
  30. :max="goods.level_show == 1 ? goods.price_member_max : goods.price_max"
  31. :min="goods.level_show == 1 ? goods.price_member_min : goods.price_min">
  32. </app-price>
  33. </view>
  34. <view v-if="goods.level_show === 1 && (selectAttr || sign == 'wholesale')">
  35. <app-member-mark :theme="themeObject"></app-member-mark>
  36. </view>
  37. </view>
  38. <view class="stock">库存:{{attrNum}}</view>
  39. </view>
  40. </view>
  41. <view class="second" :class="sign =='wholesale' ? 'no-padding' : ''">
  42. <slot name="extra"></slot>
  43. <view class="wholesale" v-if="sign =='wholesale'">
  44. <view class="wholesale-attr-list dir-left-nowrap cross-center"
  45. v-if="index != goods.attr_groups.length -1" v-for="(item, index) in goods.attr_groups"
  46. :key="index">
  47. <view class="wholesale-attr-group t-omit-two">{{item.attr_group_name}}</view>
  48. <scroll-view @scroll="scrollGet($event,index)" :scroll-left="item.scrollLeft"
  49. class="wholesale-attr-item" scroll-x="true">
  50. <view class="attr-name" v-for="(attr, key) in item.attr_list" :key="key"
  51. :class="attr.active ? theme + '-m-back ' + theme : 'attr-background'"
  52. @click="chooseAttr(index,attr)">{{attr.attr_name}}
  53. <view class="attr-number" :style="{'right':`${attr.length + 'rpx'}`}"
  54. :class="theme + '-m-back ' + theme" v-if="index == 0 && attr.number > 0">
  55. {{attr.number}}</view>
  56. </view>
  57. <view class="attr-name attr-background" style="visibility: hidden">占位
  58. </view>
  59. </scroll-view>
  60. <view @click.stop="toBottom(index)" class="right-icon">
  61. <view></view>
  62. <image src="/static/image/icon/right.png"></image>
  63. </view>
  64. </view>
  65. <view class="wholesale-attr-group-list">
  66. <view class="wholesale-attr-group" v-for="(item, index) in goodsAttr" :key="index">
  67. <view class="dir-left-nowrap">
  68. <view class="wholesale-attr-item main-between">
  69. <view class="dir-top-nowrap main-center attr-name t-omit">
  70. <view class="t-omit">
  71. {{item.attr_list[item.attr_list.length - 1].attr_name}}</view>
  72. <view class="attr-price">
  73. ¥{{goods.level_show === 1 ? item.price_member : item.price}}</view>
  74. </view>
  75. <view class="dir-left-nowrap wholesale-number-box cross-center">
  76. <image
  77. :src="item.number <= 0 ? '/static/image/plugins/un-low.png' : '/static/image/plugins/low.png'"
  78. class="block box-grow-0 cross-center main-center"
  79. @click="wholesaleNumberSub(index)">
  80. </image>
  81. <view
  82. class="wholesale-number-input box-grow-0 cross-center main-center">
  83. <app-input height="60" type="number" v-model="item.number"
  84. paddingLeft="0" :center="true" placeholder=" "
  85. @blur="wholesaleNumberBlur(index)" :focus="false" width="88">
  86. </app-input>
  87. </view>
  88. <image
  89. :src="item.number >= item.stock? '/static/image/plugins/un-add.png' : '/static/image/plugins/add.png'"
  90. class="block box-grow-0 cross-center main-center"
  91. @click="wholesaleNumberAdd(index)"></image>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </view>
  97. </view>
  98. <view class="attr-group" v-if="goods.type === 'goods' && sign !='wholesale'"
  99. v-for="(item, index) in newAttrGroupList" :key="index">
  100. <view class="attr-group-name">{{item.attr_group_name}}</view>
  101. <view class="dir-left-wrap">
  102. <view v-for="(attr, key) in item.attr_list" :key="key" class="attr-item"
  103. :class="attr.checked && sign !== 'gift' ? theme + '-m-back active ' + theme : attr.checked && sign === 'gift' ? theme + '-background active' : 'attr-item-default' + (attr.attr_num_0 ? ' attr_num_0' : '')"
  104. @click="storeAttrClick(attr.attr_id, item.attr_group_id)">{{attr.attr_name}}
  105. </view>
  106. </view>
  107. </view>
  108. <view v-if="chooseNumber" class="dir-left-nowrap number-box cross-center">
  109. <view class="box-grow-1">数量</view>
  110. <image
  111. :src="number <= 1 ? '/static/image/icon/can-be-reduced.png' : '/static/image/cart/can-be-reduced.png'"
  112. class="block box-grow-0 cross-center main-center" @click="numberSub">
  113. </image>
  114. <view class="number-input box-grow-0 cross-center main-center">
  115. <app-input type="number" v-model="number" paddingLeft="0" :center="true" placeholder=" "
  116. @blur="numberBlur" :focus="false" width="88"></app-input>
  117. </view>
  118. <image src="/static/image/cart/can-be-added.png"
  119. class="block box-grow-0 cross-center main-center" @click="numberAdd"></image>
  120. </view>
  121. <view class="service"
  122. v-if="service_screen&&service_screen.screenList&&service_screen.screenList.length>0">
  123. <view class="service_title">全优汇服务</view>
  124. <view class="service_item" style="align-items: center;">
  125. <image style="width: 26upx;height:26upx;"
  126. src="https://t12.9026.com/web/statics/icon1/sp.png"> </image>
  127. <view style="flex: 1;">
  128. <view style="float: left;">碎屏险</view>
  129. <view class="slh">{{screenDescription}}</view>
  130. </view>
  131. <view style="color: red;" @click="gotoSpDetail">服务说明
  132. <image style="width: 26upx;height:26upx;"
  133. src="https://t12.9026.com/web/statics/icon1/问号.png"> </image>
  134. </view>
  135. <!-- <view>{{service_screen.screenList.intro}}</view> -->
  136. </view>
  137. <view class="service_value">
  138. <view class="service_block" v-for="(item,index) of service_screen.screenList"
  139. :key="index" :class="{service_block_active:index == serviceId}"
  140. @click="select_service(index)">
  141. {{item.name}} ¥{{item.price}}
  142. </view>
  143. </view>
  144. </view>
  145. </view>
  146. <view v-if="sign =='wholesale'" class="total">已选<text>{{totalNumber}}</text>件
  147. 总计<text>¥{{totalPrice > 0? totalPrice : '0.00'}}</text></view>
  148. <view class="three dir-left-nowrap">
  149. <view class="box-grow-1 main-center cross-center" v-if="cartShow"
  150. :class="sign === 'pick' ? theme + '-m-back ' + 'buy ' + theme : theme === 'b' || theme === 'f' || theme === 'a' ? theme + '-s-back ' + 'buy ' + theme : theme + '-s-back ' + theme+ '-m-text ' + theme"
  151. @click="cart">{{addText}}
  152. </view>
  153. <view v-if="is_show_buy" class="box-grow-1 main-center cross-center buy"
  154. :class="sign !== 'gift' ? theme + '-m-back '+ theme : theme + '-background'" @click="buy">
  155. {{buyText}}
  156. </view>
  157. </view>
  158. </view>
  159. </view>
  160. </view>
  161. </view>
  162. </template>
  163. <script>
  164. import {
  165. mapState,
  166. mapGetters
  167. } from "vuex";
  168. import appPrice from "../../page-component/goods/app-price.vue";
  169. import appImage from "../../basic-component/app-image/app-image.vue";
  170. import appMemberMark from '../../page-component/app-member-mark/app-member-mark.vue';
  171. export default {
  172. name: "app-attr",
  173. components: {
  174. appPrice,
  175. 'app-image': appImage,
  176. appMemberMark
  177. },
  178. props: {
  179. goods: Object,
  180. attrGroupList: Array,
  181. attrCart: {
  182. type: Array,
  183. default () {
  184. return [];
  185. }
  186. },
  187. cartShow: {
  188. type: Boolean,
  189. default () {
  190. return true
  191. }
  192. },
  193. previewUrl: String,
  194. submitUrl: String,
  195. goodsId: {
  196. type: Number,
  197. default () {
  198. return 0
  199. }
  200. },
  201. show: Number,
  202. buyText: {
  203. type: String,
  204. default () {
  205. return '立即购买';
  206. }
  207. },
  208. plugin: {
  209. default: '',
  210. },
  211. theme: {
  212. type: String,
  213. default: 'a',
  214. },
  215. chooseNumber: {
  216. type: Boolean,
  217. default: true,
  218. },
  219. noPay: {
  220. type: Boolean,
  221. default: false,
  222. },
  223. buyClick: {
  224. type: Boolean,
  225. default: false,
  226. },
  227. addText: {
  228. type: String,
  229. default: '加入购物车',
  230. },
  231. is_show_buy: {
  232. type: Boolean,
  233. default: true,
  234. },
  235. sign: {
  236. type: String
  237. },
  238. totalPrice: {
  239. type: String,
  240. default: '0.00',
  241. },
  242. totalNumber: {
  243. type: Number,
  244. default: 0,
  245. },
  246. discount: {
  247. type: Number,
  248. default: 0,
  249. },
  250. wholesaleType: {
  251. type: Number,
  252. default: 0,
  253. }
  254. },
  255. data() {
  256. return {
  257. display: 'none',
  258. number: 1,
  259. selectAttr: null,
  260. newAttrGroupList: null,
  261. pic_url: null,
  262. // 商品批发
  263. activeAttr: [],
  264. goodsAttr: [],
  265. service_screen: null, //碎屏险
  266. service_label: null, //当前对屏对象
  267. serviceId: null, //碎屏险ID
  268. card_id: null,
  269. screenDescription: '',
  270. };
  271. },
  272. watch: {
  273. show() {
  274. if (this.display === 'block') {
  275. this.selectAttr = null;
  276. this.serviceId = null
  277. this.screenDescription = ""
  278. this.service_label = null
  279. this.card_id = null
  280. this.close();
  281. } else if (this.display === 'none') {
  282. this.alert();
  283. }
  284. },
  285. newData: {
  286. handler() {
  287. this.$emit('attr', this.newData)
  288. },
  289. immediate: true,
  290. },
  291. attrGroupList: {
  292. handler() {
  293. this.newAttrGroupList = this.attrGroupList;
  294. if (this.display == 'block') {
  295. this.alert();
  296. }
  297. },
  298. immediate: true
  299. },
  300. goods: {
  301. handler() {
  302. if (this.display == 'block') {
  303. this.alert();
  304. }
  305. },
  306. immediate: true
  307. }
  308. },
  309. mounted() {
  310. if (this.sign == 'wholesale') {
  311. this.pic_url = this.goods.attr_groups[0].attr_list[0].pic_url
  312. if (this.goods.attr_groups.length == 1) {
  313. this.goodsAttr = this.goods.attr;
  314. } else {
  315. for (let item of this.goods.attr_groups) {
  316. let para = {
  317. attr_group_name: '',
  318. attr_group_id: '',
  319. attr_id: '',
  320. attr_name: ''
  321. };
  322. para.attr_group_name = item.attr_group_name
  323. para.attr_group_id = item.attr_group_id
  324. para.attr_id = item.attr_list[0].attr_id
  325. para.attr_name = item.attr_list[0].attr_name
  326. this.activeAttr.push(para)
  327. }
  328. for (let item of this.goods.attr) {
  329. let same = true;
  330. for (let i = 0; i < item.attr_list.length - 1; i++) {
  331. let first = {
  332. attr_group_name: item.attr_list[i].attr_group_name,
  333. attr_group_id: item.attr_list[i].attr_group_id,
  334. attr_id: item.attr_list[i].attr_id,
  335. attr_name: item.attr_list[i].attr_name
  336. }
  337. if (JSON.stringify(first) != JSON.stringify(this.activeAttr[i])) {
  338. same = false;
  339. }
  340. }
  341. if (same) {
  342. this.goodsAttr.push(item)
  343. }
  344. }
  345. }
  346. }
  347. },
  348. methods: {
  349. select_service(index) {
  350. if (this.serviceId == index) {
  351. this.serviceId = null
  352. this.screenDescription = ""
  353. this.service_label = null
  354. this.card_id = null
  355. } else {
  356. this.serviceId = index
  357. this.screenDescription = this.service_screen.screenList[index]['description'] || ''
  358. this.service_label = this.service_screen.screenList[index]
  359. this.card_id = this.service_screen.screenList['card_id']
  360. }
  361. },
  362. alert() {
  363. if (this.attrGroupList.length === 0) {
  364. return;
  365. }
  366. if (this.sign != 'wholesale') {
  367. let attr_group_list = this.attrGroupList;
  368. let attrs = this.goods.attr;
  369. let select_attr = null;
  370. this.number = 1;
  371. if (attr_group_list.length === 1) {
  372. for (let i in attrs) {
  373. for (let j in attr_group_list[0].attr_list) {
  374. if (attr_group_list[0].attr_list[j].attr_id == attrs[i].attr_list[0].attr_id) {
  375. if (attrs[i].stock > 0) {
  376. if (attrs.length === 1) {
  377. attr_group_list[0].attr_list[j].checked = true;
  378. }
  379. attr_group_list[0].attr_list[j].attr_num_0 = false;
  380. this.pic_url = attr_group_list[0].attr_list[j].pic_url;
  381. } else {
  382. this.number = 0;
  383. attr_group_list[0].attr_list[j].checked = false;
  384. attr_group_list[0].attr_list[j].attr_num_0 = true;
  385. }
  386. }
  387. }
  388. }
  389. if (attrs.length === 1) {
  390. select_attr = attrs[0];
  391. this.$emit('attrtap', select_attr);
  392. }
  393. }
  394. this.newAttrGroupList = attr_group_list;
  395. if (this.goods.selectAttr) {
  396. this.selectAttr = this.goods.selectAttr
  397. } else {
  398. this.selectAttr = select_attr;
  399. }
  400. }
  401. // this.getservice()
  402. this.display = 'block';
  403. },
  404. gotoSpDetail() {
  405. uni.navigateTo({
  406. url: "/pages/goods/spDetail"
  407. })
  408. },
  409. getservice(select_val) {
  410. if(select_val.length<=1) return false
  411. this.goods.attr.forEach((item, index) => {
  412. let select_item_list = []
  413. let select_item_value = ''
  414. let attrList = item.attr_list || [];
  415. attrList.forEach((value, key) => {
  416. select_item_value = value.attr_group_id + '-' + value.attr_id
  417. select_item_list.push(select_item_value)
  418. })
  419. if (JSON.stringify(select_val) == JSON.stringify(select_item_list)) {
  420. this.service_screen = item
  421. }
  422. console.log(this.service_screen, "oooooooooooooooo")
  423. })
  424. },
  425. scrollGet(e, index) {
  426. this.goods.attr_groups[index].scrollLeft = e.detail.scrollLeft;
  427. this.$forceUpdate();
  428. },
  429. toBottom(index) {
  430. this.$nextTick().then(() => {
  431. this.goods.attr_groups[index].scrollLeft = 99999;
  432. this.$forceUpdate();
  433. })
  434. },
  435. chooseAttr(index, attrItem) {
  436. let that = this;
  437. for (let attr of that.goods.attr_groups[index].attr_list) {
  438. attr.active = false;
  439. if (attr.attr_id == attrItem.attr_id && attr.attr_name == attrItem.attr_name) {
  440. attr.active = true;
  441. }
  442. }
  443. if (index == 0) {
  444. that.pic_url = attrItem.pic_url;
  445. }
  446. that.activeAttr[index].attr_id = attrItem.attr_id
  447. that.activeAttr[index].attr_name = attrItem.attr_name
  448. that.goodsAttr = [];
  449. for (let item of that.goods.attr) {
  450. let same = true;
  451. for (let i = 0; i < item.attr_list.length - 1; i++) {
  452. let first = {
  453. attr_group_name: item.attr_list[i].attr_group_name,
  454. attr_group_id: item.attr_list[i].attr_group_id,
  455. attr_id: item.attr_list[i].attr_id,
  456. attr_name: item.attr_list[i].attr_name
  457. }
  458. if (JSON.stringify(first) != JSON.stringify(this.activeAttr[i])) {
  459. same = false;
  460. }
  461. }
  462. if (same) {
  463. that.goodsAttr.push(item)
  464. }
  465. }
  466. that.$forceUpdate();
  467. that.count();
  468. },
  469. wholesaleNumberSub(index) {
  470. if (this.goodsAttr[index].number == 0) {
  471. return false;
  472. }
  473. this.goodsAttr[index].number--;
  474. if (this.goods.attr_groups.length == 1) {
  475. this.pic_url = this.goodsAttr[index].pic_url;
  476. }
  477. this.count(index);
  478. },
  479. wholesaleNumberAdd(index) {
  480. if (this.goodsAttr[index].number > this.goodsAttr[index].stock || this.goodsAttr[index].number == this
  481. .goodsAttr[index].stock) {
  482. return false
  483. }
  484. this.goodsAttr[index].number++;
  485. if (this.goods.attr_groups.length == 1) {
  486. this.pic_url = this.goodsAttr[index].pic_url;
  487. }
  488. this.count(index);
  489. },
  490. wholesaleNumberBlur(index) {
  491. if (+this.goodsAttr[index].number > +this.goodsAttr[index].stock) {
  492. this.goodsAttr[index].number = this.goodsAttr[index].stock
  493. }
  494. if (this.goods.attr_groups.length == 1) {
  495. this.pic_url = this.goodsAttr[index].pic_url;
  496. }
  497. this.count(index);
  498. },
  499. count(index) {
  500. let that = this;
  501. this.$emit('attrtap', that.goods, that.goodsAttr);
  502. setTimeout(() => {
  503. that.selectAttr = that.goodsAttr[index]
  504. })
  505. },
  506. close() {
  507. this.display = 'none';
  508. this.$emit('close', false)
  509. },
  510. preventD() {},
  511. storeAttrClick(attr_id, attr_group_id) {
  512. let select_num = []
  513. let attr_group_list = JSON.parse(JSON.stringify(this.newAttrGroupList));
  514. let attrs = this.goods.attr;
  515. let checkedAttr = [];
  516. let attr_cart = this.attrCart;
  517. for (let i in attr_group_list) {
  518. for (let j in attr_group_list[i].attr_list) {
  519. let temp = attr_group_list[i].attr_list[j];
  520. if (parseInt(attr_group_list[i].attr_group_id) == parseInt(attr_group_id)) {
  521. if (parseInt(temp.attr_id) === parseInt(attr_id)) {
  522. if (temp.checked) {
  523. temp.checked = false;
  524. } else {
  525. temp.checked = true;
  526. }
  527. if (temp.attr_num_0) {
  528. return;
  529. }
  530. } else {
  531. temp.checked = false;
  532. }
  533. }
  534. if (temp.checked) {
  535. if (i == 0) {
  536. this.pic_url = attr_group_list[0].attr_list[j].pic_url;
  537. }
  538. checkedAttr.push(attr_group_list[i].attr_group_id + '-' + temp.attr_id);
  539. }
  540. }
  541. }
  542. this.getservice(checkedAttr)
  543. function inArray(val, arr) {
  544. return arr.some(function(v) {
  545. return val == v;
  546. })
  547. }
  548. let attrNum_0 = [];
  549. let select_attr = null;
  550. let number = 1;
  551. for (let i in attrs) {
  552. let arr = [];
  553. let sign = 0;
  554. for (let j in attrs[i].attr_list) {
  555. let param = attrs[i].attr_list[j].attr_group_id + '-' + attrs[i].attr_list[j].attr_id;
  556. if (!inArray(param, checkedAttr)) {
  557. sign += 1;
  558. arr.push(param);
  559. }
  560. }
  561. if (attrs[i].stock == 0 && sign <= 1) {
  562. attrNum_0 = attrNum_0.concat(arr);
  563. }
  564. if (sign == 0) {
  565. if (!select_attr) {
  566. select_attr = {};
  567. }
  568. select_attr = attrs[i];
  569. attr_cart.forEach(item => {
  570. if (item.attr_id == select_attr.id) {
  571. number = item.num;
  572. }
  573. });
  574. if (select_attr.stock <= 0) {
  575. uni.showToast({
  576. title: '库存不足',
  577. icon: 'none'
  578. });
  579. return;
  580. }
  581. if (select_attr.stock <= number) {
  582. number = select_attr.stock;
  583. }
  584. }
  585. }
  586. if (checkedAttr.length == 0) {
  587. select_attr = null;
  588. }
  589. //库存为0的规格添加标识
  590. for (let i in attr_group_list) {
  591. for (let j in attr_group_list[i].attr_list) {
  592. let cAttr = attr_group_list[i].attr_list[j];
  593. let cParam = attr_group_list[i].attr_group_id + '-' + cAttr.attr_id;
  594. if (inArray(cParam, attrNum_0) && !inArray(cParam, checkedAttr)) {
  595. cAttr.attr_num_0 = true;
  596. } else {
  597. cAttr.attr_num_0 = false;
  598. }
  599. }
  600. }
  601. this.newAttrGroupList = attr_group_list;
  602. this.selectAttr = select_attr;
  603. this.number = number;
  604. this.$emit('attrtap', this.selectAttr);
  605. },
  606. numberBlur(number) {
  607. number = parseInt(number.value);
  608. if (number > this.attrNum) {
  609. uni.showToast({
  610. title: '库存不足',
  611. icon: 'none'
  612. });
  613. number = this.attrNum;
  614. }
  615. this.$emit('attrtap', this.selectAttr);
  616. return this.number = number;
  617. },
  618. numberSub() {
  619. let number = this.number;
  620. if (number <= 1) {
  621. return true;
  622. }
  623. number--;
  624. this.number = number;
  625. this.$emit('attrtap', this.selectAttr);
  626. },
  627. numberAdd() {
  628. let number = this.number;
  629. number++;
  630. if (number > this.attrNum) {
  631. uni.showToast({
  632. title: '库存不足',
  633. icon: 'none'
  634. });
  635. this.number = this.attrNum;
  636. return;
  637. }
  638. this.number = number;
  639. this.$emit('attrtap', this.selectAttr);
  640. },
  641. cart() {
  642. if (!this.submit()) {
  643. return false;
  644. }
  645. let select_attr = this.selectAttr;
  646. if (this.goods.sign === 'pick' || this.goods.sign === 'community') {
  647. this.$emit('add', select_attr, this.number);
  648. return;
  649. }
  650. // 普通商品
  651. if (this.goods.type === 'goods') {
  652. if (this.goods.sign === 'miaosha') {
  653. this.$request({
  654. url: this.$api.miaosha.add_cart,
  655. data: {
  656. miaosha_goods_id: select_attr.goods_id,
  657. attr_id: select_attr.id,
  658. num: this.number
  659. },
  660. method: 'post'
  661. }).then(e => {
  662. uni.showToast({
  663. title: e.msg,
  664. type: 'success'
  665. });
  666. this.display = 'none';
  667. this.selectAttr.number = this.number;
  668. this.$emit('selectNumber', this.selectAttr);
  669. }).catch(() => {
  670. this.display = 'none';
  671. });
  672. } else if (this.goods.sign === 'flash_sale') {
  673. this.$request({
  674. url: this.$api.flash_sale.add_cart,
  675. data: {
  676. flash_goods_id: select_attr.goods_id,
  677. attr_id: select_attr.id,
  678. num: this.number
  679. },
  680. method: 'post'
  681. }).then(e => {
  682. uni.showToast({
  683. title: e.msg,
  684. type: 'success'
  685. });
  686. this.display = 'none';
  687. this.selectAttr.number = this.number;
  688. this.$emit('selectNumber', this.selectAttr);
  689. }).catch(() => {
  690. this.display = 'none';
  691. });
  692. } else if (this.goods.sign == 'wholesale') {
  693. if (this.totalNumber < this.goods.wholesaleGoods.rise_num) {
  694. uni.showToast({
  695. title: '至少采购' + this.goods.wholesaleGoods.rise_num + this.goods.unit,
  696. image: '/static/image/plugins/tip.png',
  697. duration: 1000
  698. });
  699. return false
  700. }
  701. let para = [];
  702. for (let item of this.goods.attr) {
  703. if (item.number > 0) {
  704. para.push(item)
  705. }
  706. }
  707. this.$request({
  708. url: this.$api.wholesale.cart,
  709. data: {
  710. attr: JSON.stringify(para)
  711. },
  712. method: 'post'
  713. }).then(response => {
  714. this.display = 'none';
  715. if (response.code === 0) {
  716. for (let item of this.goods.attr) {
  717. item.number = '0'
  718. }
  719. for (let item of this.goodsAttr) {
  720. item.number = '0'
  721. }
  722. this.count();
  723. uni.hideLoading();
  724. uni.showToast({
  725. title: '添加成功',
  726. duration: 1000
  727. });
  728. }
  729. }).catch(response => {
  730. this.display = 'none';
  731. })
  732. } else {
  733. this.$request({
  734. url: this.$api.cart.add,
  735. data: {
  736. goods_id: select_attr.goods_id,
  737. attr: select_attr.id,
  738. num: this.number
  739. },
  740. method: 'post'
  741. }).then(e => {
  742. if (e.code === 0) {
  743. uni.showToast({
  744. title: e.msg,
  745. type: 'success'
  746. });
  747. this.display = 'none';
  748. this.selectAttr.number = this.number;
  749. this.$emit('selectNumber', this.selectAttr);
  750. } else {
  751. uni.showToast({
  752. title: e.msg,
  753. icon: "none",
  754. duration: 2500
  755. });
  756. this.display = 'none';
  757. }
  758. }).catch(() => {
  759. this.display = 'none';
  760. });
  761. }
  762. // 虚拟商品
  763. } else if (this.goods.type === 'ecard') {
  764. uni.showToast({
  765. title: '虚拟商品不允许加入购物车',
  766. icon: 'none'
  767. });
  768. }
  769. },
  770. buy() {
  771. if (this.$user.isLogin() && this.$store.state.user.info) {
  772. let member_level = this.$store.state.user.info.identity.member_level;
  773. if (member_level < this.goods.member_level) {
  774. uni.showModal({
  775. title: "提示",
  776. content: "需达到" + this.goods.member_name + "会员才可购买",
  777. showCancel: true,
  778. buttonText: '升级',
  779. success: (res) => {
  780. if (res.confirm) {
  781. uni.navigateTo({
  782. // url:"/pages/member/index/index",
  783. url: '/pages/member/upgrade/upgrade?level=' + member_level +
  784. '&other=' + this.goods.member_level
  785. })
  786. } else if (res.cancel) {
  787. console.log('用户点击取消');
  788. }
  789. }
  790. })
  791. return;
  792. }
  793. }
  794. if (!this.submit()) return false;
  795. if (this.noPay) {
  796. this.$emit('pay', this.number);
  797. return;
  798. }
  799. if (this.buyClick) {
  800. this.display = 'none';
  801. this.selectAttr.number = this.number;
  802. this.selectAttr.service_label = this.service_label
  803. this.$emit('buyClick', this.selectAttr);
  804. return false;
  805. }
  806. if (this.goods.sign == 'wholesale') {
  807. if (this.totalNumber < this.goods.wholesaleGoods.rise_num) {
  808. uni.showToast({
  809. title: '至少采购' + this.goods.wholesaleGoods.rise_num + this.goods.unit,
  810. image: '/static/image/plugins/tip.png',
  811. duration: 1000
  812. });
  813. return false
  814. }
  815. let para = {};
  816. let mch_list = [{
  817. mch_id: 0,
  818. goods_list: []
  819. }];
  820. for (let item of this.goods.attr) {
  821. if (item.number > 0) {
  822. para = {
  823. id: item.goods_id,
  824. attr: [],
  825. num: item.number,
  826. cat_id: 0,
  827. goods_attr_id: item.id
  828. }
  829. for (let attr of item.attr_list) {
  830. let attrList = {
  831. attr_id: attr.attr_id,
  832. attr_group_id: attr.attr_group_id
  833. }
  834. para.attr.push(attrList)
  835. }
  836. mch_list[0].goods_list.push(para)
  837. }
  838. }
  839. let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
  840. if (this.submitUrl && this.previewUrl) {
  841. url +=
  842. `&preview_url=${encodeURIComponent(this.previewUrl)}&submit_url=${encodeURIComponent(this.submitUrl)}&plugin=${this.plugin}`;
  843. }
  844. uni.navigateTo({
  845. url: url
  846. })
  847. } else {
  848. let goods = this.goods;
  849. let number = this.number;
  850. let select_attr = this.selectAttr;
  851. let goods_attr_id = select_attr.id;
  852. let attr = [];
  853. for (let i in select_attr.attr_list) {
  854. attr.push({
  855. attr_id: select_attr.attr_list[i].attr_id,
  856. attr_group_id: select_attr.attr_list[i].attr_group_id
  857. });
  858. }
  859. let mch_list = [{
  860. mch_id: goods.mch_id ? goods.mch_id : 0,
  861. goods_list: [{
  862. id: this.goodsId ? this.goodsId : goods.id,
  863. attr: attr,
  864. num: number,
  865. cat_id: 0,
  866. goods_attr_id: goods_attr_id
  867. }]
  868. }];
  869. let url = `/pages/order-submit/order-submit?mch_list=${JSON.stringify(mch_list)}`;
  870. if (this.submitUrl && this.previewUrl) {
  871. url +=
  872. `&preview_url=${encodeURIComponent(this.previewUrl)}&submit_url=${encodeURIComponent(this.submitUrl)}&plugin=${this.plugin}`;
  873. }
  874. uni.navigateTo({
  875. url: url
  876. })
  877. }
  878. },
  879. submit() {
  880. let select_attr = this.selectAttr;
  881. if (this.goods.sign === 'wholesale') {
  882. return true;
  883. }
  884. if (!select_attr) {
  885. uni.showToast({
  886. title: '请先选规格',
  887. icon: 'none'
  888. });
  889. return false;
  890. }
  891. if (select_attr.stock <= 0) {
  892. uni.showToast({
  893. title: '库存不足',
  894. icon: 'none'
  895. });
  896. return false;
  897. }
  898. if (this.number <= 0) {
  899. uni.showToast({
  900. title: '数量不能为0',
  901. icon: 'none'
  902. });
  903. return false;
  904. }
  905. if (!this.goods) {
  906. return false;
  907. }
  908. return true;
  909. },
  910. clickImg(src) {
  911. uni.previewImage({
  912. current: 0,
  913. urls: [src]
  914. });
  915. },
  916. },
  917. computed: {
  918. ...mapState({
  919. gConfig: state => state.gConfig,
  920. }),
  921. attrPic() {
  922. if (this.pic_url) {
  923. return this.pic_url;
  924. } else if (this.goods) {
  925. return this.goods.cover_pic;
  926. } else {
  927. return ``;
  928. }
  929. },
  930. priceColor() {
  931. if (this.goods && this.goods.level_show === 1) {
  932. return `member`;
  933. } else {
  934. return this.theme + '-color';
  935. }
  936. },
  937. attrNum() {
  938. if (this.selectAttr) {
  939. return this.selectAttr.stock;
  940. } else if (this.goods) {
  941. return this.goods.goods_num;
  942. } else {
  943. return 0;
  944. }
  945. },
  946. attrPrice() {
  947. if (this.selectAttr) {
  948. let price;
  949. if (this.goods.level_show === 1) {
  950. price = this.selectAttr.price_member
  951. } else {
  952. price = this.selectAttr.price;
  953. }
  954. if (this.sign == 'wholesale') {
  955. if (this.selectAttr.number == 0) {
  956. return 'undefined'
  957. }
  958. if (this.wholesaleType == 0) {
  959. price = (price * (this.discount / 10)).toFixed(2);
  960. return price
  961. } else {
  962. price = (price - this.discount).toFixed(2);
  963. return price
  964. }
  965. } else {
  966. return price
  967. }
  968. } else if (this.sign == 'wholesale') {
  969. return 'undefined';
  970. } else if (this.goods) {
  971. if (this.goods.hasOwnProperty('price_min')) {
  972. return this.goods.price_min;
  973. } else {
  974. return this.goods.price;
  975. }
  976. } else {
  977. return 0;
  978. }
  979. },
  980. newData() {
  981. const {
  982. number,
  983. display,
  984. selectAttr
  985. } = this;
  986. return {
  987. number,
  988. display,
  989. selectAttr
  990. }
  991. },
  992. themeObject: function() {
  993. return {
  994. back: this.theme + '-m-back ' + this.theme,
  995. theme: this.theme,
  996. color: this.theme + '-m-text ' + this.theme,
  997. sBack: this.theme + '-s-back ' + this.theme
  998. }
  999. },
  1000. ...mapGetters('iPhoneX', {
  1001. boolEmpty: 'getBoolEmpty'
  1002. })
  1003. }
  1004. }
  1005. </script>
  1006. <style scoped lang="scss">
  1007. .app-attr {
  1008. background-color: #ffffff;
  1009. .modal {
  1010. background-color: rgba(0, 0, 0, 0.5);
  1011. position: fixed;
  1012. top: 0;
  1013. left: 0;
  1014. width: 100%;
  1015. height: 100%;
  1016. z-index: 1603;
  1017. }
  1018. .content {
  1019. width: 100%;
  1020. background-color: #ffffff;
  1021. border-radius: #{16rpx} #{16rpx} 0 0;
  1022. .close {
  1023. width: #{30rpx};
  1024. height: #{30rpx};
  1025. position: absolute;
  1026. right: #{24rpx};
  1027. top: #{24rpx};
  1028. background-color: #ffffff;
  1029. }
  1030. .first {
  1031. margin: 0 #{24rpx};
  1032. border-bottom: #{1rpx} solid #e2e2e2;
  1033. &.no-border {
  1034. border-bottom: 0;
  1035. }
  1036. .img {
  1037. width: #{200rpx};
  1038. height: #{200rpx};
  1039. border: #{4rpx} solid #ffffff;
  1040. border-radius: #{8rpx};
  1041. margin-top: #{-64rpx};
  1042. display: block;
  1043. }
  1044. .info {
  1045. margin: #{36rpx} 0 #{26rpx} #{24rpx};
  1046. font-size: $uni-font-size-import-two;
  1047. line-height: 1;
  1048. .stock {
  1049. font-size: $uni-font-size-weak-one;
  1050. color: $uni-general-color-two;
  1051. margin-top: #{18rpx};
  1052. }
  1053. view {
  1054. &:first-child {
  1055. margin-right: #{12rpx};
  1056. }
  1057. }
  1058. .member {
  1059. color: #f39800;
  1060. }
  1061. }
  1062. }
  1063. .second {
  1064. max-height: #{650rpx};
  1065. overflow-y: auto;
  1066. overflow-x: hidden;
  1067. padding: #{4rpx} #{24rpx};
  1068. font-size: $uni-font-size-general-two;
  1069. &.no-padding {
  1070. padding: 0;
  1071. }
  1072. .attr-group {
  1073. padding: #{32rpx} 0;
  1074. border-bottom: #{1rpx} solid #e2e2e2;
  1075. .attr-group-name {
  1076. color: $uni-general-color-one;
  1077. margin-bottom: #{20rpx};
  1078. }
  1079. .attr-item {
  1080. margin-right: #{20rpx};
  1081. padding: #{15rpx 24rpx};
  1082. border-radius: #{8rpx};
  1083. margin-bottom: #{20rpx};
  1084. &.attr-item-default {
  1085. background-color: #f2f2f2;
  1086. color: $uni-important-color-black;
  1087. }
  1088. &.active {
  1089. color: #ffffff;
  1090. }
  1091. &.attr_num_0 {
  1092. color: #cdcdcd;
  1093. background-color: #f7f7f7;
  1094. }
  1095. }
  1096. }
  1097. .number-box {
  1098. color: $uni-general-color-one;
  1099. height: #{124rpx};
  1100. .block {
  1101. width: #{60rpx};
  1102. height: #{60rpx};
  1103. margin: 0 #{4rpx};
  1104. &.disabled {
  1105. background-color: #fbfbfb;
  1106. color: $uni-general-color-two;
  1107. }
  1108. }
  1109. .number-input {
  1110. width: #{88rpx};
  1111. height: #{60rpx};
  1112. color: $uni-important-color-black;
  1113. font-size: $uni-font-size-general-one;
  1114. background-color: $uni-weak-color-two;
  1115. }
  1116. }
  1117. }
  1118. .three {
  1119. height: #{110rpx};
  1120. width: 100%;
  1121. font-size: $uni-font-size-general-one;
  1122. }
  1123. }
  1124. }
  1125. .buy {
  1126. color: #ffffff;
  1127. }
  1128. .wholesale {
  1129. .wholesale-attr-list {
  1130. height: 88rpx;
  1131. margin: 0 24rpx;
  1132. border-bottom: 1rpx solid #e2e2e2;
  1133. position: relative;
  1134. &:first-of-type {
  1135. border-top: 1rpx solid #e2e2e2;
  1136. }
  1137. .wholesale-attr-group {
  1138. max-width: 200rpx;
  1139. flex-shrink: 0;
  1140. margin-right: 4rpx;
  1141. font-size: 20rpx;
  1142. color: #666666;
  1143. }
  1144. .right-icon {
  1145. position: absolute;
  1146. right: -24rpx;
  1147. top: 0;
  1148. height: 84rpx;
  1149. padding-left: 10rpx;
  1150. width: 50rpx;
  1151. z-index: 10000;
  1152. background-color: #fff;
  1153. view {
  1154. height: 40rpx;
  1155. width: 3rpx;
  1156. background-color: #e2e2e2;
  1157. position: absolute;
  1158. left: 0;
  1159. top: 24rpx;
  1160. }
  1161. image {
  1162. margin-top: 33rpx;
  1163. height: 22rpx;
  1164. width: 16rpx;
  1165. }
  1166. }
  1167. .wholesale-attr-item {
  1168. height: 100%;
  1169. white-space: nowrap;
  1170. .attr-name {
  1171. margin-top: 16rpx;
  1172. color: #fff;
  1173. padding: 0 22rpx;
  1174. height: 56rpx;
  1175. line-height: 56rpx;
  1176. border-radius: 8rpx;
  1177. font-size: 26rpx;
  1178. margin-left: 20rpx;
  1179. display: inline-block;
  1180. position: relative;
  1181. .attr-number {
  1182. color: #fff;
  1183. position: absolute;
  1184. top: -15rpx;
  1185. height: 30rpx;
  1186. line-height: 26rpx;
  1187. border: 2rpx solid #fff;
  1188. padding: 0 10rpx;
  1189. border-radius: 15rpx;
  1190. font-size: 20rpx;
  1191. z-index: 100;
  1192. }
  1193. &.attr-background {
  1194. background-color: #f2f2f2;
  1195. color: #353535;
  1196. }
  1197. }
  1198. }
  1199. }
  1200. .wholesale-attr-group-list {
  1201. margin-top: 20rpx;
  1202. .wholesale-attr-group {
  1203. margin-bottom: 20rpx;
  1204. .wholesale-attr-item {
  1205. padding: 20rpx;
  1206. background-color: #f7f7f7;
  1207. width: 100%;
  1208. .attr-name {
  1209. width: 60%;
  1210. .attr-price {
  1211. color: #999999;
  1212. font-size: 24rpx;
  1213. }
  1214. }
  1215. .wholesale-number-box {
  1216. color: $uni-general-color-one;
  1217. .block {
  1218. width: #{60rpx};
  1219. height: #{60rpx};
  1220. margin: 0 #{4rpx};
  1221. &.disabled {
  1222. background-color: #fbfbfb;
  1223. color: $uni-general-color-two;
  1224. }
  1225. }
  1226. .wholesale-number-input {
  1227. width: #{88rpx};
  1228. height: #{60rpx};
  1229. color: $uni-important-color-black;
  1230. font-size: $uni-font-size-general-one;
  1231. background-color: #fff;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }
  1238. .total {
  1239. width: 100%;
  1240. height: 80rpx;
  1241. line-height: 80rpx;
  1242. text-align: right;
  1243. padding: 0 24rpx;
  1244. color: #353535;
  1245. font-size: 28rpx;
  1246. border-top: 1rpx solid #e2e2e2;
  1247. text {
  1248. color: #ff4544;
  1249. }
  1250. }
  1251. .u-attr-fixed {
  1252. position: fixed;
  1253. bottom: 0;
  1254. left: 0;
  1255. width: 100%;
  1256. background-color: #ffffff;
  1257. }
  1258. .service{
  1259. margin-bottom: 20rpx;
  1260. }
  1261. .service_title {
  1262. padding-top: 10px;
  1263. margin: 14px 10px 10px;
  1264. font-weight: 700;
  1265. font-size: 13px;
  1266. }
  1267. .service_item {
  1268. margin: 14px 0px 0px;
  1269. font-size: 26rpx;
  1270. color: #666;
  1271. display: flex;
  1272. justify-content: space-between;
  1273. }
  1274. .service_value {
  1275. display: flex;
  1276. flex-wrap: wrap;
  1277. padding: 0px 10px;
  1278. }
  1279. .service_block {
  1280. min-width: 46%;
  1281. height: 28px;
  1282. line-height: 26px;
  1283. border: 1px solid #f5f5f5;
  1284. border-radius: 16px;
  1285. text-align: center;
  1286. margin-right: 10px;
  1287. margin-top: 10px;
  1288. font-size: 12px;
  1289. background-color: #f5f5f5;
  1290. position: relative;
  1291. }
  1292. .service_block_active {
  1293. color: #f21c1c;
  1294. border: 1px solid #f21c1c;
  1295. }
  1296. .slh {
  1297. margin-left: 5upx;
  1298. overflow: hidden;
  1299. text-overflow: ellipsis;
  1300. width: 460upx;
  1301. white-space: nowrap;
  1302. float: left;
  1303. /* display: -webkit-box;
  1304. -webkit-line-clamp: 1;
  1305. -webkit-box-orient: vertical; */
  1306. }
  1307. </style>