cart.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. <template>
  2. <view>
  3. <view class="page">
  4. <block v-for="(item, index) in pageList" :key="index">
  5. <!-- 普通产品 -->
  6. <view class="cart" v-if="item.list.length > 0">
  7. <view class="dian dflex">
  8. <image
  9. :src="item.isActive ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'"
  10. class="check"
  11. :data-merchantId="item.merchantId"
  12. :data-index="index"
  13. @tap="checkProduct"
  14. ></image>
  15. <view class="flex" v-if="item.isTimely == 0">{{ item.merchantName }}</view>
  16. <view class="flex" v-if="item.isTimely == 1">{{ item.merchantName }}及时达</view>
  17. </view>
  18. <view class="list">
  19. <block v-for="(item, idx) in item.list" :key="idx">
  20. <view class="li">
  21. <view class="checkbox" :data-index="index" :data-idx="idx" :data-store="item.store" @tap="checkProduct">
  22. <image :src="item.isActive ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'" class="check"></image>
  23. </view>
  24. <view class="info dflex flex">
  25. <view class="cimgs" @tap="toDetail" :data-id="item.productId">
  26. <image :src="item.pic" mode="aspectFit" class="cimg"></image>
  27. <image src="/static/pages/images/jishida.png" class="type" v-if="item.isTimely == 1"></image>
  28. <view class="gys" v-if="item.isTimely == 2">不支持自提</view>
  29. <!-- <view class="gys" wx:if="{{item.store<=0||item.isInvalid}}">{{item.store<=0?'已售罄':item.isInvalid?'已下架':''}}</view> -->
  30. </view>
  31. <view class="zhinfo">
  32. <view :class="'zhtit ' + (item.store <= 0 || item.isInvalid ? 'color999' : '')" @tap="toDetail" :data-id="item.productId">
  33. {{ item.title }}
  34. </view>
  35. <view class="color999" v-if="item.store <= 0 || item.isInvalid">{{ item.store <= 0 ? '已售罄' : item.isInvalid ? '已下架' : '' }}</view>
  36. <view v-if="item.baseModelList" class="guigecontent">
  37. 规格:
  38. <text v-for="(itemGuige, index) in item.baseModelList" class="guige" :decode="true" :key="index">{{ itemGuige.value }}&nbsp;</text>
  39. </view>
  40. <view class="jiage">
  41. <view class="integral">
  42. <text class="intnum">{{ item.integral }}积分</text>
  43. <text class="money">+¥{{ item.price }}</text>
  44. </view>
  45. <view class="num">
  46. <view class="jian" @tap="jianQuantity" :data-index="index" :data-idx="idx">-</view>
  47. <input class="nums" :value="item.quantity" type="number" @input="getNum" @blur="minNum" :data-index="index" :data-idx="idx" />
  48. <view class="jian" @tap="jiaQuantity" :data-index="index" :data-idx="idx">+</view>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. </block>
  55. </view>
  56. </view>
  57. </block>
  58. </view>
  59. <block v-if="ishow">
  60. <view class="nodata_cart">
  61. <image src="/static/pages/images/null.png"></image>
  62. <view>购物车是空的</view>
  63. <navigator url="/integralshop/index/index" open-type="reLaunch">去逛逛</navigator>
  64. </view>
  65. <view class="cai pdlr20">
  66. <view class="cai-tit dflex">
  67. <image src="/static/pages/images/cai_bg1.png"></image>
  68. 猜您喜欢
  69. <image src="/static/pages/images/cai_bg2.png"></image>
  70. </view>
  71. <view class="tabcon dflex">
  72. <block v-for="(item, index) in likeList" :key="index">
  73. <view class="li">
  74. <view class="jsdimgs" @tap="toDetail" :data-id="item.id">
  75. <image :src="item.pic + '?x-oss-process=style/w375'" mode="aspectFit" class="jsdpro"></image>
  76. <image src="/static/pages/images/jishida.png" v-if="item.isTimely === 1" class="jsdimg"></image>
  77. </view>
  78. <view class="jsdinfo">
  79. <view class="proname" @tap="toDetail" :data-id="item.id">{{ item.title }}</view>
  80. <view class="operate dflex">
  81. <view class="price proprice">
  82. <text>{{ item.salePrice }}</text>
  83. <text class="del">¥{{ item.marketPrice }}</text>
  84. </view>
  85. <view class="add-cart">
  86. <view class="nums dflex" v-if="item.count > 0">
  87. <image src="/static/pages/images/jian.png"></image>
  88. <view class="num">{{ item.count }}</view>
  89. <image src="/static/pages/images/jia1.png"></image>
  90. </view>
  91. <image src="/static/pages/images/jia.png" @tap="addShopCart" :data-id="item.id" :data-skuid="item.skuId" :data-index="index" v-else></image>
  92. </view>
  93. </view>
  94. </view>
  95. </view>
  96. </block>
  97. </view>
  98. </view>
  99. </block>
  100. <view class="bot" :style="'bottom:' + (bottomBlankHeignt + 115) + 'rpx'" v-if="pageList.length > 0">
  101. <view class="botl">
  102. <view class="dflex flex">
  103. <view class="all" data-index="-1" @tap="checkProduct">
  104. <image :src="isAll ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'" class="check"></image>
  105. 全选
  106. </view>
  107. <view class="heji flex" v-if="!isEdit">
  108. 总计:
  109. <text>{{ integral }}积分+¥{{ money }}</text>
  110. </view>
  111. </view>
  112. <view class="editc">
  113. <text class="edit" @tap="edit">{{ isEdit ? '完成' : '编辑' }}</text>
  114. </view>
  115. </view>
  116. <view class="jiesuan" @tap="deleteCart" v-if="isEdit">删除({{ count }})</view>
  117. <view class="jiesuan" @tap="Settlement" v-else>去结算({{ count }})</view>
  118. </view>
  119. <view class="placeholder-view" :style="'height:' + (bottomBlankHeignt + 115) + 'rpx'"></view>
  120. <foot channel="cart" product-type="2" :isUpdate="isUpdate"></foot>
  121. </view>
  122. </template>
  123. <script>
  124. const app = getApp();
  125. const req = require('../../utils/request.js');
  126. import foot from '../../components/integral-nav/index';
  127. export default {
  128. data() {
  129. return {
  130. bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
  131. form: {},
  132. pageList: [],
  133. page: 1,
  134. likeList: [],
  135. isLoad: true,
  136. isLikeLoad: true,
  137. isAll: false,
  138. isJsdAll: false,
  139. isCgAll: false,
  140. money: 0.0,
  141. count: 0,
  142. isEdit: false,
  143. isUpdate: false,
  144. // 是否更新消息
  145. merchant: {},
  146. integral: 0,
  147. shopName: '',
  148. ishow: false
  149. };
  150. },
  151. components: {
  152. foot
  153. },
  154. props: {},
  155. onLoad(options) {
  156. this.query = options;
  157. // console.log(options);
  158. this.getLikeList();
  159. },
  160. onShow: function() {
  161. let _ts = this;
  162. _ts.setData({
  163. isUpdate: !_ts.isUpdate
  164. }); // if (req.getStorage("MERCHANT").isDefault != 1) {
  165. // req.getRequest('/api/merchant/getMerchantList', {}, res => {
  166. // res = res.filter(it => it.isDefault == 1)
  167. // console.log(res)
  168. // this.data.merchant = res[0]
  169. // })
  170. // } else {
  171. this.merchant = req.getStorage('MERCHANT'); // }
  172. this.isLoad = true;
  173. this.setData({
  174. count: 0,
  175. money: 0,
  176. integral: 0,
  177. isAll: false,
  178. shopName: this.merchant.title,
  179. isEdit: false
  180. });
  181. this.getList();
  182. },
  183. onHide() {
  184. // this.query.integralshop=0
  185. // this.setData({integralshop:false})
  186. },
  187. methods: {
  188. toDetail(e) {
  189. let id = e.currentTarget.dataset.id;
  190. app.globalData.openPage('integralshop/detail/detail?id=' + id);
  191. },
  192. addShopCart(e) {
  193. let skuId = e.currentTarget.dataset.skuid;
  194. let id = e.currentTarget.dataset.id;
  195. let params = {
  196. skuId: skuId,
  197. quantity: 1,
  198. productId: id
  199. };
  200. if (this.merchant) {
  201. params.merchantId = this.merchant.id;
  202. }
  203. req.postRequest('/api/purchase/cart', params, res => {
  204. req.msg('加入购物车成功');
  205. this.setData({
  206. isUpdate: !this.isUpdate
  207. });
  208. this.isLoad = true;
  209. this.getList();
  210. });
  211. },
  212. getList() {
  213. let isShowLoading = false;
  214. if (this.form.page == 1 && !isShowLoading) {
  215. req.loadIng('加载中');
  216. isShowLoading = true;
  217. }
  218. if (!this.isLoad) return false;
  219. this.isLoad = false;
  220. let that = this;
  221. let newList = [];
  222. this.form.purchaseType = 2;
  223. // console.log(this.form);
  224. req.getRequest('/api/purchase/list', this.form, data => {
  225. let params = []; // 1及时达产品
  226. params.push({
  227. isTimely: 1,
  228. isActive: false,
  229. list: data.filter(it => it.isTimely == 1)
  230. }); // 0常规产品
  231. params.push({
  232. isTimely: 0,
  233. list: data.filter(it => it.isTimely == 0 || it.isTimely == 2)
  234. }); // 常规产品
  235. params[1].list.forEach(el => {
  236. if (el.merchantId == '' || el.merchantId == null) {
  237. let merchant = this.merchant; // let merchant = req.getStorage('MERCHANT');
  238. el.merchantId = merchant.id;
  239. el.merchantName = merchant.title;
  240. }
  241. if (newList.length == 0) {
  242. newList.push({
  243. merchantId: el.merchantId,
  244. merchantName: el.merchantName,
  245. isTimely: 0,
  246. isActive: false,
  247. list: [el]
  248. });
  249. } else {
  250. let res = newList.some(item => {
  251. if (item.merchantId == el.merchantId) {
  252. item.list.push(el);
  253. return true;
  254. }
  255. });
  256. if (!res) {
  257. newList.push({
  258. merchantId: el.merchantId,
  259. isTimely: 0,
  260. merchantName: el.merchantName,
  261. isActive: false,
  262. list: [el]
  263. });
  264. }
  265. }
  266. });
  267. // console.log(newList);
  268. let jsd = [];
  269. params[0].list.forEach(el => {
  270. if (el.merchantId == '' || el.merchantId == null) {
  271. // console.log(el); // let merchant = req.getStorage('MERCHANT');
  272. let merchant = this.merchant;
  273. el.merchantId = merchant.id;
  274. el.merchantName = merchant.title;
  275. }
  276. if (jsd.length == 0) {
  277. jsd.push({
  278. merchantId: el.merchantId,
  279. merchantName: el.merchantName,
  280. isTimely: 1,
  281. isActive: false,
  282. list: [el]
  283. });
  284. } else {
  285. let res = jsd.some(item => {
  286. if (item.merchantId == el.merchantId) {
  287. item.list.push(el);
  288. return true;
  289. }
  290. });
  291. if (!res) {
  292. jsd.push({
  293. merchantId: el.merchantId,
  294. isTimely: 1,
  295. merchantName: el.merchantName,
  296. isActive: false,
  297. list: [el]
  298. });
  299. }
  300. }
  301. }); // console.log(newList,jsd)
  302. newList = newList.concat(jsd);
  303. // console.log(newList); // newList.forEach(el => {
  304. // if (el.merchantId == '' || el.merchantName == '' || el.merchantName == null || el.merchantId == null) {
  305. // let merchant = req.getStorage('MERCHANT');
  306. // el.merchantId = merchant.id
  307. // el.merchantName = merchant.title
  308. // el.list.forEach(item => {
  309. // item.merchantId = merchant.id
  310. // item.merchantName = merchant.title
  311. // if (item.merchantId == el.merchantId) {
  312. // console.log(el)
  313. // // item.list.push(el.list)
  314. // // return true
  315. // }
  316. // })
  317. // console.log(el)
  318. // }
  319. // })
  320. that.setData({
  321. pageList: newList
  322. });
  323. if (this.pageList <= 0) {
  324. that.setData({
  325. ishow: true
  326. });
  327. } else {
  328. that.setData({
  329. ishow: false
  330. });
  331. }
  332. if (isShowLoading) {
  333. uni.hideLoading();
  334. isShowLoading = false;
  335. }
  336. });
  337. },
  338. checkProduct(event) {
  339. // debugger
  340. //选择商品
  341. const that = this;
  342. const index = event.currentTarget.dataset.index;
  343. const idx = event.currentTarget.dataset.idx;
  344. const store = event.currentTarget.dataset.store;
  345. const merchantId = event.currentTarget.dataset.merchantid;
  346. let d = {};
  347. if (idx == undefined) {
  348. // console.log("进行全选和店铺全选");
  349. if (index == -1) {
  350. // 全选
  351. // console.log("全选");
  352. const isAll = that.isAll;
  353. for (let i = 0, len = that.pageList.length; i < len; i++) {
  354. for (let j = 0, len = that.pageList[i].list.length; j < len; j++) {
  355. if (!this.isEdit) {
  356. if (this.pageList[i].list[j].store <= 0) return req.msg(this.pageList[i].list[j].title + '商品已售罄');
  357. if (this.pageList[i].list[j].isInvalid) return req.msg(this.pageList[i].list[j].title + '商品已下架或失效');
  358. }
  359. if (!that.pageList[i].list[j].isInvalid) {
  360. d['pageList[' + i + '].list[' + j + '].isActive'] = !isAll;
  361. d['pageList[' + i + '].isActive'] = !isAll;
  362. }
  363. }
  364. }
  365. d['isAll'] = !isAll;
  366. } else {
  367. for (let i = 0, len = this.pageList[index].list.length; i < len; i++) {
  368. if (!this.isEdit) {
  369. if (this.pageList[index].list[i].store <= 0) return req.msg(this.pageList[index].list[i].title + '商品已售罄');
  370. if (this.pageList[index].list[i].isInvalid) return req.msg(this.pageList[index].list[i].title + '商品已下架或失效');
  371. }
  372. if (!this.pageList[index].list[i].isInvalid) {
  373. d['pageList[' + index + '].list[' + i + '].isActive'] = !this.pageList[index].isActive;
  374. d['pageList[' + index + '].isActive'] = !this.pageList[index].isActive;
  375. } // d['isJsd']=index
  376. }
  377. } // if (this.data.index == index) {
  378. // isJsdAll = this.data.isJsdAll
  379. // }else{
  380. // isJsdAll=false
  381. // }
  382. } else {
  383. // 单选
  384. // console.log("单选");
  385. if (!this.isEdit) {
  386. if (this.pageList[index].list[idx].store <= 0) return req.msg(this.pageList[index].list[idx].title + '商品已售罄');
  387. if (this.pageList[index].list[idx].isInvalid) return req.msg(this.pageList[index].list[idx].title + '商品已下架或失效');
  388. }
  389. d['pageList[' + index + '].list[' + idx + '].isActive'] = !this.pageList[index].list[idx].isActive;
  390. }
  391. // console.log(d);
  392. this.setData(d);
  393. if (index != -1) {
  394. this.merchantCheckProduct(index, idx);
  395. }
  396. this.CalculationMoney(index);
  397. },
  398. // 判断店铺的商品是否全部选择
  399. merchantCheckProduct(index, idx) {
  400. let d = {}; // debugger
  401. if (this.pageList[index].list.filter(it => it.isActive).length == this.pageList[index].list.length) {
  402. if (this.pageList.filter(it => it.isActive).length == this.pageList.length) {
  403. d['isAll'] = true;
  404. }
  405. d['pageList[' + index + '].isActive'] = true;
  406. } else {
  407. d['pageList[' + index + '].isActive'] = false;
  408. d['isAll'] = false;
  409. }
  410. this.setData(d);
  411. },
  412. adjustmentQuantity(id, quantity, skuId, success) {
  413. req.postRequest(
  414. '/api/purchase/quantity',
  415. {
  416. id: id,
  417. skuId: skuId,
  418. quantity: quantity
  419. },
  420. () => {
  421. this.setData({
  422. isUpdate: !this.isUpdate
  423. });
  424. success.call(this);
  425. }
  426. );
  427. },
  428. jianQuantity(event) {
  429. const index = event.currentTarget.dataset.index;
  430. const idx = event.currentTarget.dataset.idx;
  431. const page = this.pageList[index].list[idx];
  432. if (page.store <= 0) return req.msg(page.title + '已售罄');
  433. if (page.isInvalid) return req.msg('商品已下架或失效');
  434. if (page.quantity <= 1) return false;
  435. const q = parseInt(page.quantity) - 1;
  436. let that = this;
  437. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  438. let d = {};
  439. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  440. that.setData(d);
  441. if (page.isActive) that.CalculationMoney();
  442. });
  443. },
  444. jiaQuantity(event) {
  445. const index = event.currentTarget.dataset.index;
  446. const idx = event.currentTarget.dataset.idx;
  447. const page = this.pageList[index].list[idx];
  448. if (page.store <= 0) return req.msg(page.title + '已售罄');
  449. if (page.isInvalid) return req.msg('商品已下架或失效');
  450. let q = parseInt(page.quantity) + 1;
  451. if (page.maxBuy > 0) {
  452. console.log(page, q, '===========================');
  453. if (q > page.maxBuy) return req.msg('非常的抱歉,本产品最多可购买' + page.maxBuy);
  454. else {
  455. q = parseInt(page.quantity) + 1;
  456. }
  457. }
  458. let that = this;
  459. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  460. let d = {};
  461. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  462. that.setData(d);
  463. if (page.isActive) that.CalculationMoney();
  464. });
  465. },
  466. // 获取输入的值
  467. getNum(event) {
  468. const index = event.currentTarget.dataset.index;
  469. const idx = event.currentTarget.dataset.idx;
  470. const page = this.pageList[index].list[idx];
  471. if (page.store <= 0) return req.msg(page.title + '已售罄');
  472. if (page.isInvalid) return req.msg('商品已下架或失效');
  473. let q = event.detail.value;
  474. if (page.maxBuy > 0) {
  475. if (q > page.maxBuy) {
  476. req.msg('非常的抱歉,本产品最多可购买' + page.maxBuy);
  477. q = page.maxBuy;
  478. } else {
  479. q = event.detail.value;
  480. }
  481. }
  482. let d = {};
  483. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  484. this.setData(d);
  485. if (page.isActive) this.CalculationMoney(); // let that = this;
  486. // console.log(q)
  487. // if(q!=''){
  488. // this.adjustmentQuantity(page.id, q, page.skuId, () => {
  489. // let d = {};
  490. // d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  491. // that.setData(d);
  492. // if (page.isActive) that.CalculationMoney();
  493. // })
  494. // }
  495. },
  496. minNum(event) {
  497. const index = event.currentTarget.dataset.index;
  498. const idx = event.currentTarget.dataset.idx;
  499. const page = this.pageList[index].list[idx];
  500. let that = this;
  501. if (event.detail.value == '') {
  502. let q = 1;
  503. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  504. let d = {};
  505. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  506. that.setData(d);
  507. if (page.isActive) that.CalculationMoney();
  508. });
  509. } else {
  510. let q = parseInt(event.detail.value);
  511. if (q > page.store) {
  512. req.msg('非常的抱歉,本产品库存量剩余' + page.store);
  513. q = page.store;
  514. }
  515. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  516. let d = {};
  517. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  518. that.setData(d);
  519. if (page.isActive) that.CalculationMoney();
  520. });
  521. }
  522. },
  523. deleteCart(event) {
  524. //删除购物车数据
  525. // const index = event.currentTarget.dataset.index;
  526. // const page = this.data.pageList[index];
  527. const page = this.pageList;
  528. let ids = [];
  529. page.map(item => {
  530. item.list.map(it => {
  531. if (it.isActive) ids.push(it.id);
  532. });
  533. });
  534. if (!ids || ids.length == 0) return req.msg('请选择删除项');
  535. let that = this;
  536. req.msgConfirm('确定删除该商品', () => {
  537. req.postRequest(
  538. '/api/purchase/deletes',
  539. {
  540. ids: ids.join(',')
  541. },
  542. () => {
  543. let data = [];
  544. for (let i = 0, len = that.pageList.length; i < len; i++) {
  545. data.push({
  546. merchantId: that.pageList[i].merchantId,
  547. merchantName: that.pageList[i].merchantName,
  548. isTimely: that.pageList[i].isTimely,
  549. list: that.pageList[i].list.filter(it => !it.isActive)
  550. });
  551. }
  552. data = data.filter(res => res.list.length != 0);
  553. if (data.length <= 0) {
  554. that.setData({
  555. ishow: true,
  556. isAll: false
  557. });
  558. } else {
  559. that.setData({
  560. ishow: false
  561. });
  562. }
  563. that.setData({
  564. pageList: data,
  565. count: 0,
  566. money: 0
  567. });
  568. this.setData({
  569. isUpdate: !this.isUpdate
  570. }); // if (page.isActive) that.CalculationMoney();
  571. }
  572. );
  573. });
  574. },
  575. CalculationMoney(index) {
  576. //计算商品总价格
  577. let arr = [];
  578. let jsdMoney = 0;
  579. let money = 0;
  580. let integral = 0;
  581. this.pageList.forEach(el => {
  582. arr.push(el.list.filter(it => it.isActive).length);
  583. el.list
  584. .filter(it => it.isActive)
  585. .forEach(lst => {
  586. jsdMoney += lst.quantity * lst.price;
  587. integral += lst.quantity * lst.integral;
  588. });
  589. });
  590. var count = arr.reduce(function(prev, cur) {
  591. return prev + cur;
  592. }, 0);
  593. money = Number(jsdMoney);
  594. this.setData({
  595. count: count,
  596. money: parseFloat(money).toFixed(2),
  597. integral: integral
  598. });
  599. },
  600. Settlement() {
  601. // debugger
  602. const page = this.pageList;
  603. const ids = [];
  604. // console.log(page);
  605. page.map(item => {
  606. item.list.map(it => {
  607. if (it.isActive) ids.push(it.id);
  608. });
  609. });
  610. if (ids.length == 0) return req.msg('未选择结算商品');
  611. const timely = [];
  612. const noTimely = [];
  613. const merchantList = [];
  614. const timelyList = [];
  615. page.map(item => {
  616. item.list.map(it => {
  617. if (it.isActive && it.isTimely === 1) timely.push(it);
  618. if (it.isActive && (it.isTimely === 0 || it.isTimely === 2)) noTimely.push(it);
  619. });
  620. }); // 常规产品
  621. noTimely.forEach(el => {
  622. if (merchantList.length == 0) {
  623. merchantList.push({
  624. merchantId: el.merchantId,
  625. merchantName: el.merchantName,
  626. isTimely: 0,
  627. isActive: false,
  628. list: [el]
  629. });
  630. } else {
  631. let res = merchantList.some(item => {
  632. if (item.merchantId == el.merchantId) {
  633. item.list.push(el);
  634. return true;
  635. }
  636. });
  637. if (!res) {
  638. merchantList.push({
  639. merchantId: el.merchantId,
  640. isTimely: 0,
  641. merchantName: el.merchantName,
  642. isActive: false,
  643. list: [el]
  644. });
  645. }
  646. }
  647. }); // 及时达
  648. timely.forEach(el => {
  649. if (timelyList.length == 0) {
  650. timelyList.push({
  651. merchantId: el.merchantId,
  652. merchantName: el.merchantName,
  653. isTimely: 1,
  654. isActive: false,
  655. list: [el]
  656. });
  657. } else {
  658. let res = timelyList.some(item => {
  659. if (item.merchantId == el.merchantId) {
  660. item.list.push(el);
  661. return true;
  662. }
  663. });
  664. if (!res) {
  665. timelyList.push({
  666. merchantId: el.merchantId,
  667. isTimely: 1,
  668. merchantName: el.merchantName,
  669. isActive: false,
  670. list: [el]
  671. });
  672. }
  673. }
  674. }); // const timely = this.data.pageList.filter(it => it.isActive && it.isTimely === 1);
  675. // const noTimely = this.data.pageList.filter(it => it.isActive && it.isTimely === 0);
  676. // console.log(merchantList, timelyList, timely, noTimely); // 海外购产品
  677. let hwg = noTimely.filter(it => it.isOtc == 5);
  678. if (timely.length > 0 && noTimely.length > 0) return req.alertMsg('及时达商品和非及时达商品不能一起下单');
  679. if (merchantList.length >= 2 || timelyList.length >= 2) return req.alertMsg('门店与门店之间不能一起下单'); //判断是否及时达订单
  680. let redirect = 'product/subOrder/subOrder?ids=' + ids.join(',');
  681. let orderType = 1;
  682. let merchantId = '';
  683. if (merchantList.length > 0) {
  684. merchantId = merchantList[0].merchantId;
  685. } // if (timely.length > 0) orderType = 5, merchantId = timelyList[0].merchantId;
  686. // if (hwg.length > 0) orderType = 10
  687. orderType = 11;
  688. redirect += '&orderType=' + orderType + '&merchantId=' + merchantId;
  689. app.globalData.openPage(redirect);
  690. },
  691. edit() {
  692. this.setData({
  693. isEdit: !this.isEdit
  694. });
  695. },
  696. getLikeList() {
  697. //Recommend
  698. if (!this.isLikeLoad) return false;
  699. this.isLikeLoad = false;
  700. let that = this;
  701. req.getRequest(
  702. '/api/product/list',
  703. {
  704. page: that.page,
  705. limit: 10,
  706. attr: 'sell_well'
  707. },
  708. res => {
  709. if (res && res.length >= 10) that.isLikeLoad = true;
  710. if (that.page > 1) res = that.likeList.concat(res);
  711. that.setData({
  712. likeList: res
  713. });
  714. }
  715. );
  716. }
  717. }
  718. };
  719. </script>
  720. <style>
  721. @import './cart.css';
  722. </style>