app-attr.vue 33 KB

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