cart.vue 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452
  1. <template>
  2. <view class="cartPage" :style="[mainStyle]">
  3. <!-- <view :class="'top-fixed' + (skinNotColor ? ' not-color' : '')" :style="'height: '+ systems.barHeight + 'rpx;'">
  4. <view :class="'bgcolor' + (isTop == 1 ? ' opacity' : '')" :style="'height:' + systems.barHeight + 'rpx'">
  5. </view>
  6. <view class="top-fixed-c"
  7. :style="'height: '+ systems.navigationHeight + 'rpx;margin-top:' + systems.ktxStatusHeight + 'rpx;'">
  8. <navigator v-if="backBtn" url="" hover-class="none" open-type="navigateBack" class="back">
  9. <image :src="picUrlss+'back_black.png'"></image>
  10. </navigator>
  11. <view class="top-title tover"
  12. :style="'line-height: '+ systems.navigationHeight + 'rpx;'+(backBtn?'':'padding-left:30rpx;')">购物车
  13. </view>
  14. </view>
  15. </view>
  16. <view :style="'height: '+ systems.barHeight + 'rpx;'"></view> -->
  17. <view class="page">
  18. <block v-for="(items, index) in pageList" :key="index">
  19. <!-- 普通产品 -->
  20. <view class="cart" v-if="items.list.length > 0">
  21. <view class="dian dflex">
  22. <image :src="items.isActive ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'"
  23. class="check" :data-merchantId="items.merchantId" :data-index="index" @tap="checkProduct">
  24. </image>
  25. <view class="flex dflex top" v-if="items.isTimely == 0">
  26. <view class="merchantName">{{ items.shopName ? items.shopName : items.merchantName }}</view>
  27. <block v-if="!isEdit">
  28. <block v-if="about.Min_Order_Money && items.merchantMoney > 0">
  29. <view class="dflex">
  30. <view class="tbg">还差{{ items.merchantMoney }}元下单</view>
  31. <!-- <navigator class="tbg dflex gocou" url="/pages/index/index" open-type="switchTab">去凑单<image src="/pages/images/more.png" class="more"></image></navigator> -->
  32. <view class=" dflex gocou" @tap="goindex">
  33. 去凑单
  34. <image src="/static/pages/images/more.png" class="more"></image>
  35. </view>
  36. </view>
  37. </block>
  38. <block v-else>
  39. <view class="dflex" v-if="about.Express_Fee > 0">
  40. <view class="tbg" v-if="items.freeShipping > 0">还差{{ items.freeShipping }}元包邮
  41. </view>
  42. <view v-if="items.freeShipping > 0" class=" dflex gocou" @tap="goindex">
  43. 去凑单
  44. <image src="/static/pages/images/more.png" class="more"></image>
  45. </view>
  46. <view v-else class="tbg">已免运费</view>
  47. <!-- <view>{{item.freeShipping }}</view> -->
  48. </view>
  49. </block>
  50. </block>
  51. </view>
  52. <view class="flex" v-if="items.isTimely == 1">
  53. {{ items.shopName ? items.shopName : items.merchantName }}及时达</view>
  54. </view>
  55. <view class="list">
  56. <block v-for="(item, idx) in items.list" :key="idx">
  57. <view class="li">
  58. <view class="checkbox" :data-index="index" :data-idx="idx" :data-store="item.store"
  59. @tap="checkProduct">
  60. <image
  61. :src="item.isActive ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'"
  62. class="check"></image>
  63. </view>
  64. <view class="info dflex flex">
  65. <view class="cimgs" @tap="toDetail" :data-id="item.productId"
  66. :data-merchant="item.merchantId" :data-type="item.activityType"
  67. :data-actid="item.activityProductId">
  68. <image :src="item.pic + '?x-oss-process=style/w160'" class="cimg"></image>
  69. <image src="/static/pages/images/jishida.png" class="type"
  70. v-if="item.isJs && !item.activityType"></image>
  71. <image src="/static/pages/images/tuangou.png" class="type"
  72. v-if="item.activityType == 1"></image>
  73. <image src="/static/pages/images/seckill.png" class="type"
  74. v-if="item.activityType == 2"></image>
  75. <image src="/static/pages/images/newbornZone.png" class="type"
  76. v-if="item.activityType == 4"></image>
  77. <view class="gys" v-if="item.store <= 0">已售罄</view>
  78. <view class="gys" v-else-if="item.isInvalid">已下架</view>
  79. <view class="gys" v-else-if="item.activityState === 1">活动进行中</view>
  80. <view class="gys" v-else-if="item.activityState === 0">活动已结束</view>
  81. <!-- <view class="gys" wx:if="{{item.store<=0||item.isInvalid}}">{{item.store<=0?'已售罄':item.isInvalid?'已下架':''}}</view> -->
  82. </view>
  83. <view class="zhinfo">
  84. <view :class="'zhtit ' + (item.store <= 0 || item.isInvalid ? 'color999' : '')"
  85. @tap="toDetail" :data-id="item.productId" :data-merchant="item.merchantId"
  86. :data-type="item.activityType" :data-actid="item.activityProductId">
  87. {{ item.title }}
  88. </view>
  89. <view v-if="item.baseModelList" class="guigecontent">
  90. 规格:
  91. <text v-for="(itemGuige, index) in item.baseModelList" class="guige"
  92. :decode="true" :key="index">{{ itemGuige.value }}&nbsp;</text>
  93. </view>
  94. <view class="jiage"
  95. :style="item.baseModelList || item.activityState === 0 || item.store <= 0 || item.isInvalid ? 'margin-top: 14rpx;' : ''">
  96. <view class="zhjia" @tap="toDetail" :data-id="item.productId"
  97. :data-merchant="item.merchantId" :data-actid="item.activityProductId"
  98. v-if="!integralshop">
  99. <text>¥</text>
  100. {{ item.price }}
  101. </view>
  102. <view class="integral" v-if="integralshop">
  103. <text class="intnum">{{ item.integral }}积分</text>
  104. <text class="money">+¥{{ item.price }}</text>
  105. </view>
  106. <view class="num">
  107. <view class="jian" @tap="jianQuantity" :data-index="index"
  108. :data-idx="idx">-</view>
  109. <input class="nums" :value="item.quantity" type="number" @input="getNum"
  110. @blur="minNum" :data-index="index" :data-idx="idx" />
  111. <view class="jian" @tap="jiaQuantity" :data-index="index"
  112. :data-idx="idx">+</view>
  113. </view>
  114. </view>
  115. <view class="tabe dflex">
  116. <text v-if="item.productForm == 1" v-for="(it, index) in item.tabe"
  117. :key="index">{{ it }}</text>
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. </block>
  123. </view>
  124. </view>
  125. </block>
  126. </view>
  127. <block v-if="ishow">
  128. <view class="nodata_cart">
  129. <image :src="picUrlss+'null.png'"></image>
  130. <view>购物车是空的</view>
  131. <navigator open-type="navigateBack">去逛逛</navigator>
  132. </view>
  133. <view class="cai pdlr20" v-if="likeList.length > 0">
  134. <view class="cai-tit dflex">
  135. <image src="/static/pages/images/cai_bg1.png"></image>
  136. 猜您喜欢
  137. <image src="/static/pages/images/cai_bg2.png"></image>
  138. </view>
  139. <view class="tabcon dflex">
  140. <block v-for="(item, index) in likeList" :key="index">
  141. <view class="li">
  142. <view class="jsdimgs" @tap="toDetail" :data-id="item.id">
  143. <image :src="item.pic + '?x-oss-process=style/w210'" mode="aspectFit" class="jsdpro">
  144. </image>
  145. <image src="/static/pages/images/jishida.png" v-if="item.isJs" class="jsdimg"></image>
  146. </view>
  147. <view class="jsdinfo">
  148. <view class="proname" @tap="toDetail" :data-id="item.id">{{ item.title }}</view>
  149. <view class="operate dflex">
  150. <view class="price proprice">
  151. <text>{{ item.salePrice }}</text>
  152. <text class="vip"
  153. v-if="about.show_membership_price == 1 && item.actualPrice < item.salePrice">
  154. <text class="sale">VIP</text>
  155. <text class="members">{{ item.actualPrice }}</text>
  156. </text>
  157. <text class="vip"
  158. v-if="about.show_membership_price == 1 && item.membersPrice < item.salePrice">
  159. <text class="sale">VIP</text>
  160. <text class="members">{{ item.membersPrice }}</text>
  161. </text>
  162. <text class="del"
  163. v-if="about.show_membership_price != 1">¥{{ item.marketPrice }}</text>
  164. </view>
  165. <view class="add-cart">
  166. <view class="nums dflex" v-if="item.count > 0">
  167. <image src="/static/pages/images/jian.png"></image>
  168. <view class="num">{{ item.count }}</view>
  169. <image src="/static/pages/images/jia1.png"></image>
  170. </view>
  171. <image src="/static/pages/images/jia.png" @tap="addShopCart" :data-id="item.id"
  172. :data-skuid="item.skuId" :data-index="index" :data-state="item.state"
  173. v-else></image>
  174. </view>
  175. </view>
  176. </view>
  177. </view>
  178. </block>
  179. </view>
  180. </view>
  181. </block>
  182. <view @click="jumpLogin()" hover-class="none" class="cart-login" v-if="!isLogin">请点击登录,查看购物车</view>
  183. <view class="bot savepadding" :style="'bottom:'+(isSwitchTab ? '115':'-1')+'rpx;'" v-if="pageList.length > 0">
  184. <view class="botl">
  185. <view class="dflex flex">
  186. <view class="all" data-index="-1" @tap="checkProduct">
  187. <image :src="isAll ? '/static/pages/images/gou_h.png' : '/static/pages/images/gou.png'"
  188. class="check"></image>
  189. 全选
  190. </view>
  191. <view class="heji flex" v-if="!isEdit && !integralshop">
  192. 总计:
  193. <text>¥{{ money }}</text>
  194. </view>
  195. <view class="heji flex" v-if="!isEdit && integralshop">
  196. 总计:
  197. <text>{{ integral }}积分+¥{{ money }}</text>
  198. </view>
  199. </view>
  200. <view class="editc">
  201. <text class="edit" @tap="edit">{{ isEdit ? '完成' : '编辑' }}</text>
  202. </view>
  203. </view>
  204. <view class="jiesuan" @tap="deleteCart" v-if="isEdit">删除({{ count }})</view>
  205. <view class="jiesuan" @tap="Settlement" v-else>去结算({{ count }})</view>
  206. </view>
  207. <foot channel="cart" :isUpdate="isUpdate" v-if="isSwitchTab"></foot>
  208. <!-- #ifdef MP-WEIXIN -->
  209. <update-userinfo :update-info="isUpdateInfo" :update-mobile="isUpdateMobile" v-if="isShowUpdate"
  210. @closeUpdate="closeUpdate" @updateInfo="updateInfo" @updateMobile="updateMobile"></update-userinfo>
  211. <!-- #endif -->
  212. </view>
  213. </template>
  214. <script>
  215. const app = getApp();
  216. const req = require('../../utils/request.js');
  217. let commodity = [];
  218. let merchantArr = [];
  219. let deliverWay = [];
  220. let ativityType = [];
  221. import foot from '../../components/nav-bar/index';
  222. export default {
  223. components: {
  224. foot
  225. },
  226. data() {
  227. return {
  228. mainStyle: app.globalData.mainStyle,
  229. picUrlss: req.public.picUrls,
  230. bottomBlankHeignt: app.globalData.isIPhoneX ? 68 : 0,
  231. systems: {},
  232. isTop: 0,
  233. query: {},
  234. form: {},
  235. pageList: [],
  236. page: 1,
  237. likeList: [],
  238. isLoad: true,
  239. isLikeLoad: true,
  240. isAll: false,
  241. isJsdAll: false,
  242. isCgAll: false,
  243. money: 0.0,
  244. count: 0,
  245. isEdit: false,
  246. isUpdate: false,
  247. // 是否更新消息
  248. merchant: {},
  249. integral: 0,
  250. integralshop: false,
  251. shopName: '',
  252. show_membership_price: 0,
  253. ishow: false,
  254. header: req.header,
  255. isLogin: false,
  256. about: {},
  257. isShowUpdate: false, //是否显示更新信息弹窗
  258. isUpdateInfo: false, //更新用户信息
  259. isUpdateMobile: false, //绑定手机号
  260. isSwitchTab: false, //是否是tab
  261. backBtn: false
  262. };
  263. },
  264. props: {},
  265. async onLoad(options) {
  266. console.log('cart onLoad')
  267. let pages = getCurrentPages();
  268. var prevPage = pages[pages.length - 2];
  269. if (prevPage) {
  270. this.backBtn = true
  271. }
  272. // 如果是tab页面不往下执行跳转tab缓存页面
  273. await this.getConfig().then(async res => {
  274. if (req.isTabPage('cart', this.about.solution_name)) {
  275. req.toTabBar('cart', options)
  276. return false
  277. } else {
  278. this.onLoadPage(options)
  279. }
  280. });
  281. },
  282. onShow: async function() {
  283. let _ts = this;
  284. let userInfo = req.getStorage('userInfo');
  285. if (userInfo) _ts.isLogin = true;
  286. // #ifdef MP-WEIXIN
  287. uni.hideHomeButton();
  288. // #endif
  289. // 如果是tab页面不往下执行跳转tab缓存页面
  290. await this.getConfig().then(async res => {
  291. if (req.isTabPage('cart', this.about.solution_name)) {
  292. return false
  293. } else {
  294. this.onShowPage()
  295. }
  296. });
  297. },
  298. onHide() {
  299. this.query.integralshop = 0;
  300. this.setData({
  301. integralshop: false
  302. });
  303. },
  304. methods: {
  305. jumpLogin() {
  306. req.isLogins(true);
  307. },
  308. onLoadPage(options) {
  309. console.log("--------options", options)
  310. this.query = options;
  311. if (options.integralshop == 1) {
  312. this.setData({
  313. integralshop: true
  314. });
  315. }
  316. // console.log(options);
  317. this.getLikeList();
  318. },
  319. onShowPage: function() {
  320. let _ts = this;
  321. let userInfo = req.getStorage('userInfo');
  322. if (userInfo) _ts.isLogin = true;
  323. this.getConfig();
  324. _ts.setData({
  325. isUpdate: !_ts.isUpdate
  326. });
  327. //用户选择的门店
  328. if (req.getStorage('MERCHANT') != '') {
  329. this.merchant = req.getStorage('MERCHANT');
  330. }
  331. this.isLoad = true;
  332. this.setData({
  333. count: 0,
  334. money: 0,
  335. shopName: this.merchant.title,
  336. isEdit: false
  337. });
  338. if (_ts.isLogin) {
  339. this.getList();
  340. }
  341. },
  342. toDetail(e) {
  343. // console.log(e, "123132456")
  344. let id = e.currentTarget.dataset.id;
  345. let merchantId = e.currentTarget.dataset.merchant;
  346. let actId = e.currentTarget.dataset.actid;
  347. let url = 'product/detail/detail?id=' + id;
  348. let type = e.currentTarget.dataset.type;
  349. if (!type) {
  350. if (merchantId) {
  351. app.globalData.openPage(url + '&merchantId=' + merchantId);
  352. } else {
  353. app.globalData.openPage('product/detail/detail?id=' + id);
  354. }
  355. } else if (type == 1) {
  356. app.globalData.openPage('product/groupDetail/groupDetail?acid=' + actId + '&id=' + id +
  357. '&merchantId=' + merchantId);
  358. } else if (type == 2) {
  359. app.globalData.openPage('activity/seckillDetails/seckillDetails?acid=' + actId + '&id=' + id +
  360. '&merchantId=' + merchantId);
  361. } else if (type == 4) {
  362. app.globalData.openPage('activity/newbornDetails/newbornDetails?acid=' + actId + '&id=' + id +
  363. '&merchantId=' + merchantId);
  364. }
  365. },
  366. getConfig() {
  367. var _this = this;
  368. return new Promise((resolve, reject) => {
  369. req.getRequest('/api/config', {}, function(res) {
  370. if (res && res.show_membership_price == 1) {
  371. _this.setData({
  372. show_membership_price: 1
  373. });
  374. }
  375. if (res) {
  376. _this.setData({
  377. about: res
  378. });
  379. }
  380. if (req.isTabPage('cart', _this.about.solution_name)) {
  381. _this.isSwitchTab = true;
  382. }
  383. resolve(res);
  384. });
  385. });
  386. },
  387. addShopCart(e) {
  388. let state = e.currentTarget.dataset.state;
  389. let skuId = e.currentTarget.dataset.skuid;
  390. let id = e.currentTarget.dataset.id;
  391. let params = {
  392. skuId: skuId,
  393. quantity: 1,
  394. productId: id
  395. };
  396. if (this.merchant) {
  397. params.merchantId = this.merchant.id;
  398. }
  399. req.postRequest('/api/purchase/cart', params, res => {
  400. req.msg('加入购物车成功');
  401. this.setData({
  402. isUpdate: !this.isUpdate
  403. });
  404. this.isLoad = true;
  405. this.getList();
  406. });
  407. },
  408. getList() {
  409. let isShowLoading = false;
  410. if (this.form.page == 1 && !isShowLoading) {
  411. req.loadIng('加载中');
  412. isShowLoading = true;
  413. }
  414. this.isLoad = false;
  415. let that = this;
  416. let newList = [];
  417. if (this.query.integralshop == 1) {
  418. this.form.purchaseType = 2;
  419. } else {
  420. this.form.purchaseType = 1;
  421. }
  422. if (this.merchant) {
  423. this.form.merchantId = this.merchant.id;
  424. }
  425. req.getRequest('/api/purchase/list', this.form, data => {
  426. data = data.map(it => {
  427. let arr = ['自提', '邮寄', '同城配送', '自主配送'];
  428. let tabe = [];
  429. let deliverWays = JSON.parse(it.deliverWay);
  430. deliverWays.forEach(it => {
  431. tabe.push(arr[it - 1]);
  432. });
  433. if (it.isOtc == 5) {
  434. (it.tabe = ['邮寄']), (it.deliverWay = '[2]');
  435. } else {
  436. it.tabe = tabe;
  437. }
  438. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  439. return it;
  440. });
  441. // console.log(data);
  442. data = data.map(it => {
  443. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  444. return it;
  445. });
  446. if (this.query.integralshop == 1) {
  447. data = data.filter(it => it.productType == 2);
  448. }
  449. commodity.forEach(it => {
  450. data.forEach(el => {
  451. if (it.id == el.id && !el.isInvalid && it.deliverWay == el
  452. .deliverWay) {
  453. el.isActive = true;
  454. }
  455. });
  456. });
  457. this.setData({
  458. count: commodity.length
  459. });
  460. let params = []; // 1及时达
  461. params.push({
  462. isTimely: 0,
  463. list: data
  464. });
  465. params[0].list.forEach(el => {
  466. if (el.merchantId == '' || el.merchantId == null) {
  467. let merchant = this.merchant; // let merchant = req.getStorage('MERCHANT');
  468. el.merchantId = merchant.id;
  469. el.merchantName = merchant.title;
  470. }
  471. if (newList.length == 0) {
  472. newList.push({
  473. merchantId: el.merchantId,
  474. merchantName: el.merchantName,
  475. isTimely: 0,
  476. isActive: false,
  477. list: [el],
  478. shopId: el.shopId,
  479. shopName: el.shopName,
  480. merchantMoney: this.about.Min_Order_Money ? this.about
  481. .Min_Order_Money : 0,
  482. freeShipping: this.about.Free_Shipping
  483. });
  484. } else {
  485. let res = newList.some(item => {
  486. if (item.merchantId == el.merchantId && item.shopId == el.shopId) {
  487. item.list.push(el);
  488. return true;
  489. }
  490. });
  491. if (!res) {
  492. newList.push({
  493. merchantId: el.merchantId,
  494. isTimely: 0,
  495. merchantName: el.merchantName,
  496. isActive: false,
  497. list: [el],
  498. shopId: el.shopId,
  499. shopName: el.shopName,
  500. merchantMoney: this.about.Min_Order_Money ? this.about
  501. .Min_Order_Money : 0,
  502. freeShipping: this.about.Free_Shipping
  503. });
  504. }
  505. }
  506. });
  507. let jsd = [];
  508. newList = newList.concat(jsd);
  509. let i = 0;
  510. newList.forEach(it => {
  511. let arr = it.list.filter(el => el.isActive);
  512. // console.log(arr, it.list.length);
  513. if (arr.length == it.list.length) {
  514. it.isActive = true;
  515. }
  516. });
  517. let abb = newList.filter(res => res.isActive);
  518. // console.log(abb, newList.length);
  519. if (abb.length == newList.length && abb.length != 0) {
  520. this.setData({
  521. isAll: true
  522. });
  523. } else {
  524. this.setData({
  525. isAll: false
  526. });
  527. }
  528. that.setData({
  529. pageList: newList
  530. });
  531. that.CalculationMoney();
  532. if (this.pageList <= 0) {
  533. that.setData({
  534. ishow: true
  535. });
  536. } else {
  537. that.setData({
  538. ishow: false
  539. });
  540. }
  541. if (isShowLoading) {
  542. uni.hideLoading();
  543. isShowLoading = false;
  544. }
  545. });
  546. },
  547. checkProduct(event) {
  548. // debugger
  549. //选择商品
  550. const that = this;
  551. const index = event.currentTarget.dataset.index;
  552. const idx = event.currentTarget.dataset.idx;
  553. const store = event.currentTarget.dataset.store;
  554. const merchantId = event.currentTarget.dataset.merchantid;
  555. let d = {};
  556. if (idx == undefined) {
  557. // console.log("进行全选和店铺全选");
  558. if (index == -1) {
  559. // 全选
  560. // console.log("全选");
  561. const isAll = that.isAll;
  562. for (let i = 0, len = that.pageList.length; i < len; i++) {
  563. for (let j = 0, len = that.pageList[i].list.length; j < len; j++) {
  564. if (!this.isEdit) {
  565. if (this.pageList[i].list[j].store <= 0) return req.msg(this.pageList[i].list[j]
  566. .title + '商品已售罄');
  567. if (this.pageList[i].list[j].isInvalid) return req.msg(this.pageList[i].list[j].title +
  568. '商品已下架或失效');
  569. if (this.pageList[i].list[j].activityState === 0) return req.msg(this.pageList[i].list[
  570. j].title + '活动已结束');
  571. if (this.pageList.length > 1) return req.msg('门店与门店之间不能一起下单'); // 发货方式判断
  572. if (this.pageList[i].list.every(it => it.ativityType && it.ativityType === this
  573. .pageList[i].list[0].ativityType)) {
  574. return req.msg('活动商品不支持一起下单');
  575. }
  576. // 先存一个选择的发货方式
  577. if (deliverWay.length < 1) {
  578. deliverWay.push(JSON.parse(this.pageList[i].list[j].deliverWay));
  579. }
  580. // 先存一个选择的活动类型
  581. let activityTypes = '';
  582. if (!this.pageList[i].list[j].activityType) {
  583. activityTypes = 99;
  584. } else {
  585. activityTypes = this.pageList[i].list[j].activityType;
  586. }
  587. if (ativityType.length < 1) {
  588. ativityType[0] = activityTypes;
  589. }
  590. let k = 0;
  591. this.getTheSame(deliverWay).forEach(it => {
  592. if (JSON.parse(this.pageList[i].list[j].deliverWay).indexOf(it) == -1) {
  593. this.fou = true;
  594. // console.log("123");
  595. this.CalculationMoney(index);
  596. } else {
  597. ativityType.map(it => {
  598. if (activityTypes != it) {
  599. this.fou = true;
  600. } else {
  601. k++;
  602. this.fou = false;
  603. }
  604. });
  605. }
  606. });
  607. if (k > 0) {
  608. this.fou = false;
  609. }
  610. // console.log(k);
  611. }
  612. if (!that.pageList[i].list[j].isInvalid) {
  613. this.pageList.some(item => {
  614. if (item.merchantId == this.pageList[i].merchantId) {
  615. if (merchantArr.length > 0) {
  616. if (merchantArr[0] != this.pageList[i].merchantId) {
  617. // return false
  618. let res = this.pageList.map(it => {
  619. if (it.isActive) {
  620. it.isActive = !it.isActive;
  621. }
  622. it.merchantMoney = 0;
  623. it.list.map(el => {
  624. if (el.isActive) {
  625. el.isActive = !el.isActive;
  626. return el;
  627. }
  628. });
  629. return it;
  630. });
  631. merchantArr.splice(0, 1, this.pageList[i].merchantId);
  632. this.setData({
  633. pageList: res
  634. });
  635. }
  636. } else {
  637. merchantArr.push(item.merchantId);
  638. }
  639. }
  640. });
  641. }
  642. if (this.fou) {
  643. return req.msg('暂不支持一起下单');
  644. } else {
  645. // console.log("545");
  646. d['pageList[' + i + '].list[' + j + '].isActive'] = !isAll;
  647. d['pageList[' + i + '].isActive'] = !isAll;
  648. }
  649. }
  650. }
  651. d['isAll'] = !isAll;
  652. } else {
  653. for (let i = 0, len = this.pageList[index].list.length; i < len; i++) {
  654. if (!this.isEdit) {
  655. if (this.pageList[index].list[i].store <= 0) return req.msg(this.pageList[index].list[i]
  656. .title + '商品已售罄');
  657. if (this.pageList[index].list[i].isInvalid) return req.msg(this.pageList[index].list[i]
  658. .title + '商品已下架或失效');
  659. if (this.pageList[index].list[i].activityState === 0) return req.msg(this.pageList[index]
  660. .list[i].title + '活动已结束');
  661. // 发货方式判断
  662. // 先存一个选择的发货方式
  663. // 判断是否切换了门店,切换了就清空deliverWay
  664. if (this.pageList[index].merchantId != merchantArr[0]) {
  665. deliverWay = [];
  666. } // 判断deliverWay长度是否小于1,小于1就默认拿当前第一个产品的发货方式存进去
  667. if (deliverWay.length < 1) {
  668. deliverWay.push(JSON.parse(this.pageList[index].list[i].deliverWay));
  669. }
  670. // 先存一个选择的活动类型
  671. let activityTypes = '';
  672. if (!this.pageList[index].list[i].activityType) {
  673. activityTypes = 99;
  674. } else {
  675. activityTypes = this.pageList[index].list[i].activityType;
  676. }
  677. if (ativityType.length < 1) {
  678. ativityType[0] = activityTypes;
  679. }
  680. // 设置j标识
  681. let j =
  682. 0; // this.getTheSame 拿到重复的发货方式 去循环判断点击的发货方式里面存不存在这个共同的发货方式 不存在就提示用户不能一起下单,存在就j++,只要j大于0就说明有共同的发货方式
  683. this.getTheSame(deliverWay).forEach(it => {
  684. if (JSON.parse(this.pageList[index].list[i].deliverWay).indexOf(it) == -1) {
  685. this.fou = true;
  686. this.CalculationMoney(index);
  687. } else {
  688. ativityType.map(it => {
  689. if (activityTypes != it) {
  690. this.fou = true;
  691. } else {
  692. j++;
  693. this.fou = false;
  694. }
  695. });
  696. }
  697. });
  698. if (j > 0) {
  699. this.fou = false;
  700. }
  701. }
  702. if (!this.pageList[index].list[i].isInvalid) {
  703. this.pageList.some(item => {
  704. if (item.merchantId == this.pageList[index].merchantId) {
  705. if (merchantArr.length > 0) {
  706. if (merchantArr[0] != this.pageList[index].merchantId) {
  707. let res = this.pageList.map(it => {
  708. if (it.isActive) {
  709. it.isActive = !it.isActive;
  710. }
  711. it.merchantMoney = 0;
  712. it.list.map(el => {
  713. if (el.isActive) {
  714. el.isActive = !el.isActive;
  715. return el;
  716. }
  717. });
  718. return it;
  719. });
  720. merchantArr.splice(0, 1, this.pageList[index].merchantId);
  721. this.setData({
  722. pageList: res
  723. });
  724. }
  725. } else {
  726. merchantArr.push(item.merchantId);
  727. }
  728. }
  729. });
  730. }
  731. if (this.fou) {
  732. return req.msg('暂不支持一起下单');
  733. } else {
  734. d['pageList[' + index + '].list[' + i + '].isActive'] = !this.pageList[index].isActive;
  735. d['pageList[' + index + '].isActive'] = !this.pageList[index].isActive;
  736. }
  737. }
  738. }
  739. } else {
  740. // 单选
  741. if (!this.isEdit) {
  742. if (this.pageList[index].list[idx].store <= 0) return req.msg(this.pageList[index].list[idx]
  743. .title + '商品已售罄');
  744. if (this.pageList[index].list[idx].isInvalid) return req.msg(this.pageList[index].list[idx].title +
  745. '商品已下架或失效');
  746. if (this.pageList[index].list[idx].activityState === 0) return req.msg(this.pageList[index].list[
  747. idx].title + '活动已结束');
  748. if (deliverWay.length < 1) {
  749. deliverWay.push(JSON.parse(this.pageList[index].list[idx].deliverWay));
  750. }
  751. // 先存一个选择的活动类型
  752. let activityTypes = '';
  753. if (!this.pageList[index].list[idx].activityType) {
  754. activityTypes = 99;
  755. } else {
  756. activityTypes = this.pageList[index].list[idx].activityType;
  757. }
  758. if (ativityType.length < 1) {
  759. ativityType[0] = activityTypes;
  760. }
  761. let i = 0;
  762. // console.log(deliverWay); // this.getTheSame 拿到重复的发货方式 去循环判断点击的发货方式里面存不存在这个共同的发货方式
  763. this.getTheSame(deliverWay).forEach(it => {
  764. if (JSON.parse(this.pageList[index].list[idx].deliverWay).indexOf(it) == -1) {
  765. this.fou = true;
  766. } else {
  767. ativityType.map(it => {
  768. if (activityTypes != it) {
  769. this.fou = true;
  770. } else {
  771. i++;
  772. this.fou = false;
  773. }
  774. });
  775. }
  776. });
  777. if (i > 0) {
  778. this.fou = false;
  779. }
  780. }
  781. // 单独门店的最低消费和包邮计算
  782. this.pageList.some(item => {
  783. if (item.merchantId == this.pageList[index].merchantId) {
  784. if (merchantArr.length > 0) {
  785. if (merchantArr[0] != this.pageList[index].merchantId) {
  786. // return false
  787. let res = this.pageList.map(it => {
  788. if (it.isActive) {
  789. it.isActive = !it.isActive;
  790. } else {
  791. it.merchantMoney = 0;
  792. }
  793. it.list.map(el => {
  794. if (el.isActive) {
  795. el.isActive = !el.isActive;
  796. return el;
  797. }
  798. });
  799. return it;
  800. });
  801. merchantArr.splice(0, 1, this.pageList[index].merchantId);
  802. this.setData({
  803. pageList: res
  804. });
  805. }
  806. } else {
  807. merchantArr.push(item.merchantId);
  808. }
  809. }
  810. });
  811. if (this.fou) {
  812. return req.msg('暂不支持一起下单');
  813. } else {
  814. d['pageList[' + index + '].list[' + idx + '].isActive'] = !this.pageList[index].list[idx].isActive;
  815. }
  816. }
  817. // console.log(d);
  818. this.setData(d);
  819. // console.log(this.pageList);
  820. commodity = [];
  821. this.pageList.forEach(it => {
  822. it.list.forEach(el => {
  823. if (el.isActive) {
  824. commodity.push({
  825. id: el.id,
  826. deliverWay: el.deliverWay
  827. });
  828. }
  829. });
  830. });
  831. if (index != -1) {
  832. this.merchantCheckProduct(index, idx);
  833. }
  834. this.CalculationMoney(index);
  835. },
  836. // 获取重复的配送方式值
  837. getTheSame(arr) {
  838. return arr.reduce(function(a, b) {
  839. return a.filter(function(item) {
  840. return b.includes(item);
  841. });
  842. });
  843. },
  844. // 获取重复的活动类型值
  845. getTheSameType(arr) {
  846. return arr.reduce(function(a, b) {
  847. return a.filter(function(item) {
  848. return b.includes(item);
  849. });
  850. });
  851. },
  852. // 判断店铺的商品是否全部选择
  853. merchantCheckProduct(index, idx) {
  854. let d = {}; // debugger
  855. if (this.pageList[index].list.filter(it => it.isActive).length == this.pageList[index].list.length) {
  856. d['pageList[' + index + '].isActive'] = true;
  857. } else {
  858. d['pageList[' + index + '].isActive'] = false;
  859. d['isAll'] = false;
  860. }
  861. this.setData(d);
  862. if (this.pageList.filter(it => it.isActive).length == this.pageList.length) {
  863. this.setData({
  864. isAll: true
  865. });
  866. }
  867. },
  868. adjustmentQuantity(id, quantity, skuId, success) {
  869. req.postRequest(
  870. '/api/purchase/quantity', {
  871. id: id,
  872. skuId: skuId,
  873. quantity: quantity
  874. },
  875. () => {
  876. this.setData({
  877. isUpdate: !this.isUpdate
  878. });
  879. success.call(this);
  880. }
  881. );
  882. },
  883. jianQuantity(event) {
  884. const index = event.currentTarget.dataset.index;
  885. const idx = event.currentTarget.dataset.idx;
  886. const page = this.pageList[index].list[idx];
  887. if (page.store <= 0) return req.msg(page.title + '已售罄');
  888. if (page.isInvalid) return req.msg('商品已下架或失效');
  889. if (page.activityState === 0) return req.msg('该活动已结束');
  890. if (page.quantity <= 1) return false;
  891. const q = parseInt(page.quantity) - 1;
  892. let that = this;
  893. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  894. let d = {};
  895. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  896. this.getList();
  897. that.setData(d);
  898. // if (page.isActive) that.CalculationMoney();
  899. });
  900. },
  901. jiaQuantity(event) {
  902. const index = event.currentTarget.dataset.index;
  903. const idx = event.currentTarget.dataset.idx;
  904. const page = this.pageList[index].list[idx];
  905. if (page.store <= 0) return req.msg(page.title + '已售罄');
  906. if (page.isInvalid) return req.msg('商品已下架或失效');
  907. if (page.activityState === 0) return req.msg('该活动已结束');
  908. let q = parseInt(page.quantity) + 1;
  909. if (page.maxBuy > 0) {
  910. if (q > page.maxBuy) return req.msg('非常的抱歉,本产品最多可购买' + page.maxBuy);
  911. else {
  912. q = parseInt(page.quantity) + 1;
  913. }
  914. }
  915. let that = this;
  916. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  917. let d = {};
  918. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  919. that.setData(d);
  920. this.getList();
  921. // if (page.isActive) that.CalculationMoney();
  922. });
  923. },
  924. // 获取输入的值
  925. getNum(event) {
  926. const index = event.currentTarget.dataset.index;
  927. const idx = event.currentTarget.dataset.idx;
  928. const page = this.pageList[index].list[idx];
  929. if (page.store <= 0) {
  930. req.msg(page.title + '已售罄');
  931. return 1;
  932. } else if (page.isInvalid) {
  933. req.msg('商品已下架或失效');
  934. return 1;
  935. } else if (page.activityState === 0) {
  936. req.msg('该活动已结束');
  937. return 1;
  938. } else {
  939. let q = event.detail.value;
  940. if (page.maxBuy > 0) {
  941. if (q > page.maxBuy) {
  942. req.msg('非常的抱歉,本产品最多可购买' + page.maxBuy);
  943. q = page.maxBuy;
  944. } else {
  945. q = event.detail.value;
  946. }
  947. }
  948. let d = {};
  949. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  950. this.setData(d);
  951. return q;
  952. }
  953. },
  954. minNum(event) {
  955. const index = event.currentTarget.dataset.index;
  956. const idx = event.currentTarget.dataset.idx;
  957. const page = this.pageList[index].list[idx];
  958. let that = this;
  959. if (page.store <= 0) {
  960. req.msg(page.title + '已售罄');
  961. return 1;
  962. } else if (page.isInvalid) {
  963. req.msg('商品已下架或失效');
  964. return 1;
  965. } else if (page.activityState === 0) {
  966. req.msg('该活动已结束');
  967. return 1;
  968. } else if (event.detail.value == '') {
  969. let q = 1;
  970. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  971. let d = {};
  972. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  973. that.setData(d);
  974. this.getList();
  975. });
  976. } else {
  977. let q = parseInt(event.detail.value);
  978. if (q > page.store) {
  979. req.msg('非常的抱歉,本产品库存量剩余' + page.store);
  980. q = page.store;
  981. }
  982. this.adjustmentQuantity(page.id, q, page.skuId, () => {
  983. let d = {};
  984. d['pageList[' + index + '].list[' + idx + '].quantity'] = q;
  985. that.setData(d);
  986. this.getList();
  987. return q;
  988. });
  989. }
  990. },
  991. deleteCart(event) {
  992. //删除购物车数据
  993. const page = this.pageList;
  994. let ids = [];
  995. page.map(item => {
  996. item.list.map(it => {
  997. if (it.isActive) ids.push(it.id);
  998. });
  999. });
  1000. if (!ids || ids.length == 0) return req.msg('请选择删除项');
  1001. let that = this;
  1002. req.msgConfirm('确定删除该商品', () => {
  1003. req.postRequest(
  1004. '/api/purchase/deletes', {
  1005. ids: ids.join(',')
  1006. },
  1007. () => {
  1008. let data = [];
  1009. for (let i = 0, len = that.pageList.length; i < len; i++) {
  1010. data.push({
  1011. merchantId: that.pageList[i].merchantId,
  1012. merchantName: that.pageList[i].merchantName,
  1013. isTimely: that.pageList[i].isTimely,
  1014. list: that.pageList[i].list.filter(it => !it.isActive)
  1015. });
  1016. }
  1017. data = data.filter(res => res.list.length != 0);
  1018. if (data.length <= 0) {
  1019. that.setData({
  1020. ishow: true,
  1021. isAll: false
  1022. });
  1023. } else {
  1024. that.setData({
  1025. ishow: false
  1026. });
  1027. }
  1028. that.setData({
  1029. pageList: data,
  1030. count: 0,
  1031. money: 0.0
  1032. });
  1033. this.setData({
  1034. isUpdate: !this.isUpdate
  1035. });
  1036. }
  1037. );
  1038. });
  1039. },
  1040. CalculationMoney(index) {
  1041. //计算商品总价格
  1042. let arr = [];
  1043. let jsdMoney = 0;
  1044. let money = 0.0;
  1045. let integral = 0;
  1046. let merchantMoney = 0;
  1047. deliverWay = [];
  1048. this.pageList.forEach(el => {
  1049. if (el.list.filter(it => it.isActive).length < 1) {
  1050. ativityType = [];
  1051. }
  1052. arr.push(el.list.filter(it => it.isActive).length);
  1053. el.list
  1054. .filter(it => it.isActive)
  1055. .forEach(lst => {
  1056. jsdMoney += lst.quantity * lst.price;
  1057. integral += lst.quantity * lst.integral;
  1058. deliverWay.push(JSON.parse(lst.deliverWay));
  1059. });
  1060. });
  1061. let res = this.pageList.map(el => {
  1062. el.merchantMoney = this.about.Min_Order_Money ? this.about.Min_Order_Money : 0;
  1063. if (commodity.length == 0) {
  1064. el.freeShipping = parseFloat(this.about.Free_Shipping - merchantMoney).toFixed(2);
  1065. }
  1066. el.list
  1067. .filter(it => it.isActive)
  1068. .forEach(lst => {
  1069. if (merchantArr[0] == lst.merchantId) {
  1070. merchantMoney += lst.quantity * lst.price;
  1071. el.merchantMoney = parseFloat(this.about.Min_Order_Money - merchantMoney)
  1072. .toFixed(2);
  1073. el.freeShipping = parseFloat(this.about.Free_Shipping - merchantMoney).toFixed(
  1074. 2);
  1075. return lst;
  1076. }
  1077. });
  1078. return el;
  1079. });
  1080. var count = arr.reduce(function(prev, cur) {
  1081. return prev + cur;
  1082. }, 0);
  1083. money = Number(jsdMoney);
  1084. this.setData({
  1085. count: count,
  1086. money: parseFloat(money).toFixed(2),
  1087. integral: integral,
  1088. pageList: res
  1089. });
  1090. },
  1091. /**
  1092. * 判断勾选的产品是否为同一类型的产品(实物/虚拟物+服务):1实物、2虚拟物、3服务;判断是否能下单
  1093. */
  1094. isCheckProOrder() {
  1095. var list = [];
  1096. var productNum = 0; //选择的产品个数
  1097. this.pageList.map(it => {
  1098. it.list.map(itx => {
  1099. if (itx.isActive) {
  1100. productNum++;
  1101. if (itx.productForm == 1) {
  1102. list.push(itx);
  1103. }
  1104. }
  1105. });
  1106. });
  1107. console.log('list====>>>', list);
  1108. if (list.length == 0 || list.length == productNum) {
  1109. return true;
  1110. }
  1111. return false;
  1112. },
  1113. Settlement() {
  1114. // #ifdef MP-WEIXIN
  1115. if (!req.getStorage('userInfo').mobile) {
  1116. this.isShowUpdate = true;
  1117. this.isUpdateMobile = true;
  1118. return false;
  1119. }
  1120. // #endif
  1121. //判断勾选的产品是否为同一类型的产品(实物、虚拟物、服务)
  1122. if (!this.isCheckProOrder()) {
  1123. return req.msg('暂不支持一起下单');
  1124. }
  1125. // debugger
  1126. const page = this.pageList;
  1127. const ids = [];
  1128. // console.log(page);
  1129. page.map(item => {
  1130. item.list.map(it => {
  1131. if (it.isActive) ids.push(it.id);
  1132. });
  1133. });
  1134. if (this.about.Min_Order_Money) {
  1135. if (this.about.Min_Order_Money - this.money > 0) {
  1136. return req.msg('还差' + (parseFloat(this.about.Min_Order_Money).toFixed(2) - parseFloat(this.money)
  1137. .toFixed(2)) + '元下单');
  1138. }
  1139. }
  1140. if (ids.length == 0) return req.msg('未选择结算商品');
  1141. const timely = [];
  1142. const noTimely = [];
  1143. const merchantList = [];
  1144. const timelyList = [];
  1145. const all = [];
  1146. page.map(item => {
  1147. item.list.map(it => {
  1148. //发货方式:自提1,邮寄2,同城配送3,自主配送4;
  1149. if (it.isActive && it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1)
  1150. timely.push(it);
  1151. if ((it.isActive && it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) == -1) ||
  1152. (it.deliverWay == null && it.isActive)) noTimely.push(it);
  1153. if (it.isActive) all.push(it);
  1154. });
  1155. }); // 常规产品
  1156. noTimely.forEach(el => {
  1157. if (merchantList.length == 0) {
  1158. merchantList.push({
  1159. merchantId: el.merchantId,
  1160. merchantName: el.merchantName,
  1161. isTimely: 0,
  1162. isActive: false,
  1163. list: [el],
  1164. shopId: el.shopId,
  1165. shopName: el.shopName
  1166. });
  1167. } else {
  1168. let res = merchantList.some(item => {
  1169. if (item.merchantId == el.merchantId && item.shopId == el.shopId) {
  1170. item.list.push(el);
  1171. return true;
  1172. }
  1173. });
  1174. if (!res) {
  1175. merchantList.push({
  1176. merchantId: el.merchantId,
  1177. isTimely: 0,
  1178. merchantName: el.merchantName,
  1179. isActive: false,
  1180. list: [el],
  1181. shopId: el.shopId,
  1182. shopName: el.shopName
  1183. });
  1184. }
  1185. }
  1186. });
  1187. // 及时达
  1188. timely.forEach(el => {
  1189. if (timelyList.length == 0) {
  1190. timelyList.push({
  1191. merchantId: el.merchantId,
  1192. merchantName: el.merchantName,
  1193. isTimely: 1,
  1194. isActive: false,
  1195. list: [el],
  1196. shopId: el.shopId,
  1197. shopName: el.shopName
  1198. });
  1199. } else {
  1200. let res = timelyList.some(item => {
  1201. if (item.merchantId == el.merchantId && item.shopId == el.shopId) {
  1202. item.list.push(el);
  1203. return true;
  1204. }
  1205. });
  1206. if (!res) {
  1207. timelyList.push({
  1208. merchantId: el.merchantId,
  1209. isTimely: 1,
  1210. merchantName: el.merchantName,
  1211. isActive: false,
  1212. list: [el],
  1213. shopId: el.shopId,
  1214. shopName: el.shopName
  1215. });
  1216. }
  1217. }
  1218. });
  1219. let hwg = noTimely.filter(it => it.isOtc == 5);
  1220. let act = all.filter(it => it.activityType);
  1221. let otc = all.filter(it => !it.activityType);
  1222. let active = [];
  1223. if (act.length > 0) {
  1224. all.forEach(it => {
  1225. if (it.activityType == act[0].activityType) {
  1226. active.push(it);
  1227. }
  1228. });
  1229. }
  1230. if (merchantList.length >= 2 || timelyList.length >= 2) return req.alertMsg('门店与门店之间不能一起下单'); //判断是否及时达订单
  1231. let redirect = 'product/subOrder/subOrder?ids=' + ids.join(',');
  1232. let orderType = 1;
  1233. let merchantId = '';
  1234. let shopId;
  1235. if (req.getStorage('user_merchantId')) {
  1236. merchantId = req.getStorage('user_merchantId');
  1237. } else {
  1238. if (timely.length > 0) merchantId = timelyList[0].merchantId;
  1239. }
  1240. if (active.length > 0 && act.length > 0) {
  1241. if (active.length == all.length) {
  1242. if (act[0].activityType == 1) orderType = 2;
  1243. if (act[0].activityType == 2) orderType = 3;
  1244. if (act[0].activityType == 3) orderType = 4;
  1245. if (act[0].activityType == 4) orderType = 6;
  1246. if (act[0].activityType == 5) orderType = 7;
  1247. } else {
  1248. orderType = 20;
  1249. }
  1250. } else {
  1251. if (timely.length > 0) orderType = 5;
  1252. if (hwg.length > 0) orderType = 10;
  1253. if (act.length > 0 && otc.length > 0) orderType = 20;
  1254. if (this.query.integralshop == 1) orderType = 11;
  1255. }
  1256. if (req.getStorage('user_merchantId')) {
  1257. merchantId = req.getStorage('user_merchantId');
  1258. } else {
  1259. if (merchantList.length > 0) {
  1260. merchantId = merchantList[0].merchantId;
  1261. if (merchantList[0].shopId) {
  1262. shopId = merchantList[0].shopId;
  1263. redirect += '&shopId=' + shopId;
  1264. }
  1265. }
  1266. }
  1267. redirect += '&orderType=' + orderType + '&merchantId=' + merchantId;
  1268. app.globalData.openPage(redirect);
  1269. // console.log(redirect)
  1270. },
  1271. edit() {
  1272. deliverWay = [];
  1273. merchantArr = [];
  1274. commodity = [];
  1275. if (this.isEdit) {
  1276. let res = this.pageList.map(it => {
  1277. it.merchantMoney = this.about.Min_Order_Money ? this.about.Min_Order_Money : 0;
  1278. it.freeShipping = this.about.Free_Shipping ? this.about.Free_Shipping : 0;
  1279. it.list.map(el => {
  1280. el.isActive = false;
  1281. return el;
  1282. });
  1283. it.isActive = false;
  1284. return it;
  1285. });
  1286. // console.log(res);
  1287. this.setData({
  1288. pageList: res,
  1289. isAll: false,
  1290. money: 0.0
  1291. });
  1292. }
  1293. if (!this.isEdit) {
  1294. // console.log(this.fou);
  1295. this.fou = false;
  1296. }
  1297. this.setData({
  1298. isEdit: !this.isEdit
  1299. });
  1300. },
  1301. goindex() {
  1302. uni.reLaunch({
  1303. url: '/pages/service/index'
  1304. })
  1305. },
  1306. getLikeList() {
  1307. //Recommend
  1308. if (!this.isLikeLoad) return false;
  1309. this.isLikeLoad = false;
  1310. let that = this;
  1311. req.getRequest(
  1312. '/api/product/list', {
  1313. page: that.page,
  1314. limit: 10,
  1315. attr: 'sell_well'
  1316. },
  1317. res => {
  1318. if (res && res.length >= 10) that.isLikeLoad = true;
  1319. if (that.page > 1) res = that.likeList.concat(res);
  1320. res = res.map(it => {
  1321. if (it.deliverWay && JSON.parse(it.deliverWay).indexOf(3) != -1) it.isJs = true;
  1322. return it;
  1323. });
  1324. that.setData({
  1325. likeList: res
  1326. });
  1327. }
  1328. );
  1329. },
  1330. closeUpdate() {
  1331. this.isShowUpdate = false;
  1332. },
  1333. updateInfo(e) {
  1334. this.isUpdateInfo = e;
  1335. },
  1336. updateMobile(e) {
  1337. this.isUpdateMobile = e;
  1338. }
  1339. },
  1340. mounted() {
  1341. const systemInfo = uni.getSystemInfoSync();
  1342. // px转换到rpx的比例
  1343. let pxToRpxScale = 750 / systemInfo.windowWidth;
  1344. let systems = {
  1345. ktxStatusHeight: systemInfo.statusBarHeight * pxToRpxScale, // 状态栏的高度
  1346. navigationHeight: 44 * pxToRpxScale // 导航栏的高度
  1347. };
  1348. systems.barHeight = systems.ktxStatusHeight + systems.navigationHeight;
  1349. this.systems = systems;
  1350. },
  1351. onPageScroll: function(e) {
  1352. if (e.scrollTop > this.systems.barHeight) {
  1353. this.isTop = 1;
  1354. } else {
  1355. this.isTop = 0;
  1356. }
  1357. }
  1358. };
  1359. </script>
  1360. <style scoped>
  1361. @import './cart.css';
  1362. </style>