cart.vue 47 KB

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