cart.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  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="picUrlss+'null.png'"></image>
  62. <view>购物车是空的</view>
  63. <navigator url="/integralshop/index/index" open-type="redirect">去逛逛</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. picUrlss: req.public.picUrls,
  131. bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
  132. form: {},
  133. pageList: [],
  134. page: 1,
  135. likeList: [],
  136. isLoad: true,
  137. isLikeLoad: true,
  138. isAll: false,
  139. isJsdAll: false,
  140. isCgAll: false,
  141. money: 0.0,
  142. count: 0,
  143. isEdit: false,
  144. isUpdate: false,
  145. // 是否更新消息
  146. merchant: {},
  147. integral: 0,
  148. shopName: '',
  149. ishow: false
  150. };
  151. },
  152. components: {
  153. foot
  154. },
  155. props: {},
  156. onLoad(options) {
  157. this.query = options;
  158. // console.log(options);
  159. this.getLikeList();
  160. },
  161. onShow: function() {
  162. let _ts = this;
  163. _ts.setData({
  164. isUpdate: !_ts.isUpdate
  165. }); // if (req.getStorage("MERCHANT").isDefault != 1) {
  166. // req.getRequest('/api/merchant/getMerchantList', {}, res => {
  167. // res = res.filter(it => it.isDefault == 1)
  168. // console.log(res)
  169. // this.data.merchant = res[0]
  170. // })
  171. // } else {
  172. this.merchant = req.getStorage('MERCHANT'); // }
  173. this.isLoad = true;
  174. this.setData({
  175. count: 0,
  176. money: 0,
  177. integral: 0,
  178. isAll: false,
  179. shopName: this.merchant.title,
  180. isEdit: false
  181. });
  182. this.getList();
  183. },
  184. onHide() {
  185. // this.query.integralshop=0
  186. // this.setData({integralshop:false})
  187. },
  188. methods: {
  189. toDetail(e) {
  190. let id = e.currentTarget.dataset.id;
  191. app.globalData.openPage('integralshop/detail/detail?id=' + id);
  192. },
  193. addShopCart(e) {
  194. let skuId = e.currentTarget.dataset.skuid;
  195. let id = e.currentTarget.dataset.id;
  196. let params = {
  197. skuId: skuId,
  198. quantity: 1,
  199. productId: id
  200. };
  201. if (this.merchant) {
  202. params.merchantId = this.merchant.id;
  203. }
  204. req.postRequest('/api/purchase/cart', params, res => {
  205. req.msg('加入购物车成功');
  206. this.setData({
  207. isUpdate: !this.isUpdate
  208. });
  209. this.isLoad = true;
  210. this.getList();
  211. });
  212. },
  213. getList() {
  214. let isShowLoading = false;
  215. if (this.form.page == 1 && !isShowLoading) {
  216. req.loadIng('加载中');
  217. isShowLoading = true;
  218. }
  219. if (!this.isLoad) return false;
  220. this.isLoad = false;
  221. let that = this;
  222. let newList = [];
  223. this.form.purchaseType = 2;
  224. // console.log(this.form);
  225. req.getRequest('/api/purchase/list', this.form, data => {
  226. let params = []; // 1及时达产品
  227. params.push({
  228. isTimely: 1,
  229. isActive: false,
  230. list: data.filter(it => it.isTimely == 1)
  231. }); // 0常规产品
  232. params.push({
  233. isTimely: 0,
  234. list: data.filter(it => it.isTimely == 0 || it.isTimely == 2)
  235. }); // 常规产品
  236. params[1].list.forEach(el => {
  237. if (el.merchantId == '' || el.merchantId == null) {
  238. let merchant = this.merchant; // let merchant = req.getStorage('MERCHANT');
  239. el.merchantId = merchant.id;
  240. el.merchantName = merchant.title;
  241. }
  242. if (newList.length == 0) {
  243. newList.push({
  244. merchantId: el.merchantId,
  245. merchantName: el.merchantName,
  246. isTimely: 0,
  247. isActive: false,
  248. list: [el]
  249. });
  250. } else {
  251. let res = newList.some(item => {
  252. if (item.merchantId == el.merchantId) {
  253. item.list.push(el);
  254. return true;
  255. }
  256. });
  257. if (!res) {
  258. newList.push({
  259. merchantId: el.merchantId,
  260. isTimely: 0,
  261. merchantName: el.merchantName,
  262. isActive: false,
  263. list: [el]
  264. });
  265. }
  266. }
  267. });
  268. // console.log(newList);
  269. let jsd = [];
  270. params[0].list.forEach(el => {
  271. if (el.merchantId == '' || el.merchantId == null) {
  272. // console.log(el); // let merchant = req.getStorage('MERCHANT');
  273. let merchant = this.merchant;
  274. el.merchantId = merchant.id;
  275. el.merchantName = merchant.title;
  276. }
  277. if (jsd.length == 0) {
  278. jsd.push({
  279. merchantId: el.merchantId,
  280. merchantName: el.merchantName,
  281. isTimely: 1,
  282. isActive: false,
  283. list: [el]
  284. });
  285. } else {
  286. let res = jsd.some(item => {
  287. if (item.merchantId == el.merchantId) {
  288. item.list.push(el);
  289. return true;
  290. }
  291. });
  292. if (!res) {
  293. jsd.push({
  294. merchantId: el.merchantId,
  295. isTimely: 1,
  296. merchantName: el.merchantName,
  297. isActive: false,
  298. list: [el]
  299. });
  300. }
  301. }
  302. }); // console.log(newList,jsd)
  303. newList = newList.concat(jsd);
  304. // console.log(newList); // newList.forEach(el => {
  305. // if (el.merchantId == '' || el.merchantName == '' || el.merchantName == null || el.merchantId == null) {
  306. // let merchant = req.getStorage('MERCHANT');
  307. // el.merchantId = merchant.id
  308. // el.merchantName = merchant.title
  309. // el.list.forEach(item => {
  310. // item.merchantId = merchant.id
  311. // item.merchantName = merchant.title
  312. // if (item.merchantId == el.merchantId) {
  313. // console.log(el)
  314. // // item.list.push(el.list)
  315. // // return true
  316. // }
  317. // })
  318. // console.log(el)
  319. // }
  320. // })
  321. that.setData({
  322. pageList: newList
  323. });
  324. if (this.pageList <= 0) {
  325. that.setData({
  326. ishow: true
  327. });
  328. } else {
  329. that.setData({
  330. ishow: false
  331. });
  332. }
  333. if (isShowLoading) {
  334. uni.hideLoading();
  335. isShowLoading = false;
  336. }
  337. });
  338. },
  339. checkProduct(event) {
  340. // debugger
  341. //选择商品
  342. const that = this;
  343. const index = event.currentTarget.dataset.index;
  344. const idx = event.currentTarget.dataset.idx;
  345. const store = event.currentTarget.dataset.store;
  346. const merchantId = event.currentTarget.dataset.merchantid;
  347. let d = {};
  348. if (idx == undefined) {
  349. // console.log("进行全选和店铺全选");
  350. if (index == -1) {
  351. // 全选
  352. // console.log("全选");
  353. const isAll = that.isAll;
  354. for (let i = 0, len = that.pageList.length; i < len; i++) {
  355. for (let j = 0, len = that.pageList[i].list.length; j < len; j++) {
  356. if (!this.isEdit) {
  357. if (this.pageList[i].list[j].store <= 0) return req.msg(this.pageList[i].list[j].title + '商品已售罄');
  358. if (this.pageList[i].list[j].isInvalid) return req.msg(this.pageList[i].list[j].title + '商品已下架或失效');
  359. }
  360. if (!that.pageList[i].list[j].isInvalid) {
  361. d['pageList[' + i + '].list[' + j + '].isActive'] = !isAll;
  362. d['pageList[' + i + '].isActive'] = !isAll;
  363. }
  364. }
  365. }
  366. d['isAll'] = !isAll;
  367. } else {
  368. for (let i = 0, len = this.pageList[index].list.length; i < len; i++) {
  369. if (!this.isEdit) {
  370. if (this.pageList[index].list[i].store <= 0) return req.msg(this.pageList[index].list[i].title + '商品已售罄');
  371. if (this.pageList[index].list[i].isInvalid) return req.msg(this.pageList[index].list[i].title + '商品已下架或失效');
  372. }
  373. if (!this.pageList[index].list[i].isInvalid) {
  374. d['pageList[' + index + '].list[' + i + '].isActive'] = !this.pageList[index].isActive;
  375. d['pageList[' + index + '].isActive'] = !this.pageList[index].isActive;
  376. } // d['isJsd']=index
  377. }
  378. } // if (this.data.index == index) {
  379. // isJsdAll = this.data.isJsdAll
  380. // }else{
  381. // isJsdAll=false
  382. // }
  383. } else {
  384. // 单选
  385. // console.log("单选");
  386. if (!this.isEdit) {
  387. if (this.pageList[index].list[idx].store <= 0) return req.msg(this.pageList[index].list[idx].title + '商品已售罄');
  388. if (this.pageList[index].list[idx].isInvalid) return req.msg(this.pageList[index].list[idx].title + '商品已下架或失效');
  389. }
  390. d['pageList[' + index + '].list[' + idx + '].isActive'] = !this.pageList[index].list[idx].isActive;
  391. }
  392. // console.log(d);
  393. this.setData(d);
  394. if (index != -1) {
  395. this.merchantCheckProduct(index, idx);
  396. }
  397. this.CalculationMoney(index);
  398. },
  399. // 判断店铺的商品是否全部选择
  400. merchantCheckProduct(index, idx) {
  401. let d = {}; // debugger
  402. if (this.pageList[index].list.filter(it => it.isActive).length == this.pageList[index].list.length) {
  403. if (this.pageList.filter(it => it.isActive).length == this.pageList.length) {
  404. d['isAll'] = true;
  405. }
  406. d['pageList[' + index + '].isActive'] = true;
  407. } else {
  408. d['pageList[' + index + '].isActive'] = false;
  409. d['isAll'] = false;
  410. }
  411. this.setData(d);
  412. },
  413. adjustmentQuantity(id, quantity, skuId, success) {
  414. req.postRequest(
  415. '/api/purchase/quantity',
  416. {
  417. id: id,
  418. skuId: skuId,
  419. quantity: quantity
  420. },
  421. () => {
  422. this.setData({
  423. isUpdate: !this.isUpdate
  424. });
  425. success.call(this);
  426. }
  427. );
  428. },
  429. jianQuantity(event) {
  430. const index = event.currentTarget.dataset.index;
  431. const idx = event.currentTarget.dataset.idx;
  432. const page = this.pageList[index].list[idx];
  433. if (page.store <= 0) return req.msg(page.title + '已售罄');
  434. if (page.isInvalid) return req.msg('商品已下架或失效');
  435. if (page.quantity <= 1) return false;
  436. const q = parseInt(page.quantity) - 1;
  437. let that = this;
  438. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  439. let d = {};
  440. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  441. that.setData(d);
  442. if (page.isActive) that.CalculationMoney();
  443. });
  444. },
  445. jiaQuantity(event) {
  446. const index = event.currentTarget.dataset.index;
  447. const idx = event.currentTarget.dataset.idx;
  448. const page = this.pageList[index].list[idx];
  449. if (page.store <= 0) return req.msg(page.title + '已售罄');
  450. if (page.isInvalid) return req.msg('商品已下架或失效');
  451. let q = parseInt(page.quantity) + 1;
  452. if (page.maxBuy > 0) {
  453. console.log(page, q, '===========================');
  454. if (q > page.maxBuy) return req.msg('非常的抱歉,本产品最多可购买' + page.maxBuy);
  455. else {
  456. q = parseInt(page.quantity) + 1;
  457. }
  458. }
  459. let that = this;
  460. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  461. let d = {};
  462. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  463. that.setData(d);
  464. if (page.isActive) that.CalculationMoney();
  465. });
  466. },
  467. // 获取输入的值
  468. getNum(event) {
  469. const index = event.currentTarget.dataset.index;
  470. const idx = event.currentTarget.dataset.idx;
  471. const page = this.pageList[index].list[idx];
  472. if (page.store <= 0) return req.msg(page.title + '已售罄');
  473. if (page.isInvalid) return req.msg('商品已下架或失效');
  474. let q = event.detail.value;
  475. if (page.maxBuy > 0) {
  476. if (q > page.maxBuy) {
  477. req.msg('非常的抱歉,本产品最多可购买' + page.maxBuy);
  478. q = page.maxBuy;
  479. } else {
  480. q = event.detail.value;
  481. }
  482. }
  483. let d = {};
  484. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  485. this.setData(d);
  486. if (page.isActive) this.CalculationMoney(); // let that = this;
  487. // console.log(q)
  488. // if(q!=''){
  489. // this.adjustmentQuantity(page.id, q, page.skuId, () => {
  490. // let d = {};
  491. // d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  492. // that.setData(d);
  493. // if (page.isActive) that.CalculationMoney();
  494. // })
  495. // }
  496. },
  497. minNum(event) {
  498. const index = event.currentTarget.dataset.index;
  499. const idx = event.currentTarget.dataset.idx;
  500. const page = this.pageList[index].list[idx];
  501. let that = this;
  502. if (event.detail.value == '') {
  503. let q = 1;
  504. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  505. let d = {};
  506. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  507. that.setData(d);
  508. if (page.isActive) that.CalculationMoney();
  509. });
  510. } else {
  511. let q = parseInt(event.detail.value);
  512. if (q > page.store) {
  513. req.msg('非常的抱歉,本产品库存量剩余' + page.store);
  514. q = page.store;
  515. }
  516. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  517. let d = {};
  518. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  519. that.setData(d);
  520. if (page.isActive) that.CalculationMoney();
  521. });
  522. }
  523. },
  524. deleteCart(event) {
  525. //删除购物车数据
  526. // const index = event.currentTarget.dataset.index;
  527. // const page = this.data.pageList[index];
  528. const page = this.pageList;
  529. let ids = [];
  530. page.map(item => {
  531. item.list.map(it => {
  532. if (it.isActive) ids.push(it.id);
  533. });
  534. });
  535. if (!ids || ids.length == 0) return req.msg('请选择删除项');
  536. let that = this;
  537. req.msgConfirm('确定删除该商品', () => {
  538. req.postRequest(
  539. '/api/purchase/deletes',
  540. {
  541. ids: ids.join(',')
  542. },
  543. () => {
  544. let data = [];
  545. for (let i = 0, len = that.pageList.length; i < len; i++) {
  546. data.push({
  547. merchantId: that.pageList[i].merchantId,
  548. merchantName: that.pageList[i].merchantName,
  549. isTimely: that.pageList[i].isTimely,
  550. list: that.pageList[i].list.filter(it => !it.isActive)
  551. });
  552. }
  553. data = data.filter(res => res.list.length != 0);
  554. if (data.length <= 0) {
  555. that.setData({
  556. ishow: true,
  557. isAll: false
  558. });
  559. } else {
  560. that.setData({
  561. ishow: false
  562. });
  563. }
  564. that.setData({
  565. pageList: data,
  566. count: 0,
  567. money: 0
  568. });
  569. this.setData({
  570. isUpdate: !this.isUpdate
  571. }); // if (page.isActive) that.CalculationMoney();
  572. }
  573. );
  574. });
  575. },
  576. CalculationMoney(index) {
  577. //计算商品总价格
  578. let arr = [];
  579. let jsdMoney = 0;
  580. let money = 0;
  581. let integral = 0;
  582. this.pageList.forEach(el => {
  583. arr.push(el.list.filter(it => it.isActive).length);
  584. el.list
  585. .filter(it => it.isActive)
  586. .forEach(lst => {
  587. jsdMoney += lst.quantity * lst.price;
  588. integral += lst.quantity * lst.integral;
  589. });
  590. });
  591. var count = arr.reduce(function(prev, cur) {
  592. return prev + cur;
  593. }, 0);
  594. money = Number(jsdMoney);
  595. this.setData({
  596. count: count,
  597. money: parseFloat(money).toFixed(2),
  598. integral: integral
  599. });
  600. },
  601. Settlement() {
  602. // debugger
  603. const page = this.pageList;
  604. const ids = [];
  605. // console.log(page);
  606. page.map(item => {
  607. item.list.map(it => {
  608. if (it.isActive) ids.push(it.id);
  609. });
  610. });
  611. if (ids.length == 0) return req.msg('未选择结算商品');
  612. const timely = [];
  613. const noTimely = [];
  614. const merchantList = [];
  615. const timelyList = [];
  616. page.map(item => {
  617. item.list.map(it => {
  618. if (it.isActive && it.isTimely === 1) timely.push(it);
  619. if (it.isActive && (it.isTimely === 0 || it.isTimely === 2)) noTimely.push(it);
  620. });
  621. }); // 常规产品
  622. noTimely.forEach(el => {
  623. if (merchantList.length == 0) {
  624. merchantList.push({
  625. merchantId: el.merchantId,
  626. merchantName: el.merchantName,
  627. isTimely: 0,
  628. isActive: false,
  629. list: [el]
  630. });
  631. } else {
  632. let res = merchantList.some(item => {
  633. if (item.merchantId == el.merchantId) {
  634. item.list.push(el);
  635. return true;
  636. }
  637. });
  638. if (!res) {
  639. merchantList.push({
  640. merchantId: el.merchantId,
  641. isTimely: 0,
  642. merchantName: el.merchantName,
  643. isActive: false,
  644. list: [el]
  645. });
  646. }
  647. }
  648. }); // 及时达
  649. timely.forEach(el => {
  650. if (timelyList.length == 0) {
  651. timelyList.push({
  652. merchantId: el.merchantId,
  653. merchantName: el.merchantName,
  654. isTimely: 1,
  655. isActive: false,
  656. list: [el]
  657. });
  658. } else {
  659. let res = timelyList.some(item => {
  660. if (item.merchantId == el.merchantId) {
  661. item.list.push(el);
  662. return true;
  663. }
  664. });
  665. if (!res) {
  666. timelyList.push({
  667. merchantId: el.merchantId,
  668. isTimely: 1,
  669. merchantName: el.merchantName,
  670. isActive: false,
  671. list: [el]
  672. });
  673. }
  674. }
  675. }); // const timely = this.data.pageList.filter(it => it.isActive && it.isTimely === 1);
  676. // const noTimely = this.data.pageList.filter(it => it.isActive && it.isTimely === 0);
  677. // console.log(merchantList, timelyList, timely, noTimely); // 海外购产品
  678. let hwg = noTimely.filter(it => it.isOtc == 5);
  679. if (timely.length > 0 && noTimely.length > 0) return req.alertMsg('及时达商品和非及时达商品不能一起下单');
  680. if (merchantList.length >= 2 || timelyList.length >= 2) return req.alertMsg('门店与门店之间不能一起下单'); //判断是否及时达订单
  681. let redirect = 'product/subOrder/subOrder?ids=' + ids.join(',');
  682. let orderType = 1;
  683. let merchantId = '';
  684. if (merchantList.length > 0) {
  685. merchantId = merchantList[0].merchantId;
  686. } // if (timely.length > 0) orderType = 5, merchantId = timelyList[0].merchantId;
  687. // if (hwg.length > 0) orderType = 10
  688. orderType = 11;
  689. redirect += '&orderType=' + orderType + '&merchantId=' + merchantId;
  690. app.globalData.openPage(redirect);
  691. },
  692. edit() {
  693. this.setData({
  694. isEdit: !this.isEdit
  695. });
  696. },
  697. getLikeList() {
  698. //Recommend
  699. if (!this.isLikeLoad) return false;
  700. this.isLikeLoad = false;
  701. let that = this;
  702. req.getRequest(
  703. '/api/product/list',
  704. {
  705. page: that.page,
  706. limit: 10,
  707. attr: 'sell_well'
  708. },
  709. res => {
  710. if (res && res.length >= 10) that.isLikeLoad = true;
  711. if (that.page > 1) res = that.likeList.concat(res);
  712. that.setData({
  713. likeList: res
  714. });
  715. }
  716. );
  717. }
  718. }
  719. };
  720. </script>
  721. <style>
  722. @import './cart.css';
  723. </style>