order_addcart.vue 36 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315
  1. <template>
  2. <view :style="colorStyle">
  3. <view class='shoppingCart copy-data' v-if="canShow">
  4. <view class='labelNav acea-row row-around row-middle'>
  5. <view class='item'><text class='iconfont icon-xuanzhong'></text>{{$t(`100%正品保证`)}}</view>
  6. <view class='item'><text class='iconfont icon-xuanzhong'></text>{{$t(`所有商品精挑细选`)}}</view>
  7. <view class='item'><text class='iconfont icon-xuanzhong'></text>{{$t(`售后无忧`)}}</view>
  8. </view>
  9. <view class='nav acea-row row-between-wrapper'>
  10. <view>{{$t(`购物数量`)}} <text class='num font-num'>{{cartCount}}</text></view>
  11. <view v-if="cartList.valid.length > 0 || cartList.invalid.length > 0"
  12. class='administrate acea-row row-center-wrapper' @click='manage'>
  13. {{ footerswitch ? $t(`管理`) : $t(`取消`)}}
  14. </view>
  15. </view>
  16. <view v-if="(cartList.valid.length > 0 || cartList.invalid.length > 0) && canShow ">
  17. <view class='list'>
  18. <checkbox-group @change="checkboxChange">
  19. <block v-for="(item,index) in cartList.valid" :key="index">
  20. <view class='item acea-row row-between-wrapper'>
  21. <!-- #ifndef MP -->
  22. <checkbox :value="(item.id).toString()" :checked="item.checked"
  23. :disabled="!item.attrStatus && footerswitch" />
  24. <!-- <checkbox :value="(item.id).toString()" :checked="item.checked" :disabled="item.attrStatus?false:true" /> -->
  25. <!-- #endif -->
  26. <!-- #ifdef MP -->
  27. <checkbox :value="item.id" :checked="item.checked"
  28. :disabled="!item.attrStatus && footerswitch" />
  29. <!-- #endif -->
  30. <navigator :url='"/pages/goods_details/index?id="+item.product_id' hover-class='none'
  31. class='picTxt acea-row row-between-wrapper'>
  32. <view class='pictrue'>
  33. <image v-if="item.productInfo.attrInfo" :src='item.productInfo.attrInfo.image'>
  34. </image>
  35. <image v-else :src='item.productInfo.image'></image>
  36. </view>
  37. <view class='text'>
  38. <view class='line2' :class="item.attrStatus?'':'reColor'">
  39. {{item.productInfo.store_name}}
  40. </view>
  41. <view class='infor line1' v-if="item.productInfo.attrInfo">
  42. {{$t(`属性`)}}:{{item.productInfo.attrInfo.suk}}
  43. </view>
  44. <view class='money' v-if="item.attrStatus">{{$t(`¥`)}}{{item.truePrice}}</view>
  45. <view class="reElection acea-row row-between-wrapper" v-else>
  46. <view class="title">{{$t(`请重新选择商品规格`)}}</view>
  47. <view class="reBnt cart-color acea-row row-center-wrapper"
  48. @click.stop="reElection(item)">{{$t(`重选`)}}</view>
  49. </view>
  50. </view>
  51. <view class='carnum acea-row row-center-wrapper' v-if="item.attrStatus">
  52. <view class="reduce" :class="item.numSub ? 'on' : ''"
  53. @click.stop='subCart(index)'>-</view>
  54. <!-- <view class='num'>{{item.cart_num}}</view> -->
  55. <view class="num">
  56. <input type="number" v-model="item.cart_num" @click.stop
  57. @input="iptCartNum(index)" @blur="blurInput(index)" />
  58. </view>
  59. <view class="plus" :class="item.numAdd ? 'on' : ''"
  60. @click.stop='addCart(index)'>+</view>
  61. </view>
  62. </navigator>
  63. </view>
  64. </block>
  65. </checkbox-group>
  66. </view>
  67. <view class='invalidGoods' v-if="cartList.invalid.length > 0">
  68. <view class='goodsNav acea-row row-between-wrapper'>
  69. <view @click='goodsOpen'><text class='iconfont'
  70. :class='goodsHidden==true?"icon-xiangxia":"icon-xiangshang"'></text>{{$t(`失效商品`)}}
  71. </view>
  72. <view class='del' @click='unsetCart'><text class='iconfont icon-shanchu1'></text>{{$t(`清空`)}}
  73. </view>
  74. </view>
  75. <view class='goodsList' :hidden='goodsHidden'>
  76. <block v-for="(item,index) in cartList.invalid" :key='index'>
  77. <view class='item acea-row row-between-wrapper'>
  78. <view class='invalid'>{{$t(`失效`)}}</view>
  79. <view class='pictrue'>
  80. <image v-if="item.productInfo.attrInfo" :src='item.productInfo.attrInfo.image'>
  81. </image>
  82. <image v-else :src='item.productInfo.image'></image>
  83. </view>
  84. <view class='text acea-row row-column-between'>
  85. <view class='line1 name'>{{item.productInfo.store_name}}</view>
  86. <view class='infor line1' v-if="item.productInfo.attrInfo">
  87. {{$t(`属性`)}}:{{item.productInfo.attrInfo.suk}}
  88. </view>
  89. <view class='acea-row row-between-wrapper'>
  90. <!-- <view>¥{{item.truePrice}}</view> -->
  91. <view class='end'>{{$t(`该商品已失效`)}}</view>
  92. </view>
  93. </view>
  94. </view>
  95. </block>
  96. </view>
  97. </view>
  98. <!-- <view class='loadingicon acea-row row-center-wrapper' v-if="cartList.valid.length&&!loadend">
  99. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  100. </view> -->
  101. <view class='loadingicon acea-row row-center-wrapper' v-if="cartList.invalid.length&&loadend">
  102. <text class='loading iconfont icon-jiazai'
  103. :hidden='loadingInvalid==false'></text>{{loadTitleInvalid}}
  104. </view>
  105. </view>
  106. <view class='noCart' v-if="cartList.valid.length == 0 && cartList.invalid.length == 0 && canShow">
  107. <view class='emptyBox'>
  108. <image :src="imgHost + '/statics/images/no-thing.png'"></image>
  109. <view class="tips">{{$t(`暂无商品`)}}</view>
  110. </view>
  111. <recommend v-if="hostProduct.length" :hostProduct='hostProduct'></recommend>
  112. </view>
  113. <view style='height:120rpx;color: #F5F5F5;'></view>
  114. <view class='footer acea-row row-between-wrapper' v-if="cartList.valid.length > 0 && canShow"
  115. :class="is_diy && is_diy_set? 'on' : ''">
  116. <view>
  117. <checkbox-group @change="checkboxAllChange">
  118. <checkbox value="all" :checked="!!isAllSelect" />
  119. <text class='checkAll'>{{$t(`全选`)}}({{selectValue.length}})</text>
  120. </checkbox-group>
  121. </view>
  122. <view class='money acea-row row-middle' v-if="footerswitch==true">
  123. <text class='font-color'>{{$t(`¥`)}}{{selectCountPrice}}</text>
  124. <form @submit="subOrder">
  125. <button class='placeOrder bg-color' formType="submit">{{$t(`立即下单`)}}</button>
  126. </form>
  127. </view>
  128. <view class='button acea-row row-middle' v-else>
  129. <form @submit="subCollect">
  130. <button class='bnt cart-color' formType="submit">{{$t(`收藏`)}}</button>
  131. </form>
  132. <form @submit="subDel">
  133. <button class='bnt' formType="submit">{{$t(`删除`)}}</button>
  134. </form>
  135. </view>
  136. </view>
  137. </view>
  138. <productWindow :attr="attr" :isShow='1' :iSplus='1' :iScart='1' @myevent="onMyEvent" @ChangeAttr="ChangeAttr"
  139. @ChangeCartNum="ChangeCartNum" @attrVal="attrVal" @iptCartNum="iptCartNum" @goCat="reGoCat"
  140. id='product-window'></productWindow>
  141. <!-- #ifdef MP -->
  142. <!-- <authorize :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize> -->
  143. <!-- #endif -->
  144. <!-- <view class="uni-p-b-96"></view> -->
  145. <view class="uni-p-b-98"></view>
  146. <!-- <pageFooter :countNum="cartCount"></pageFooter> -->
  147. <tabBar v-if="!is_diy" :pagePath="'/pages/order_addcart/order_addcart'"></tabBar>
  148. <pageFooter v-else></pageFooter>
  149. </view>
  150. </template>
  151. <script>
  152. // #ifdef APP-PLUS
  153. let sysHeight = uni.getSystemInfoSync().statusBarHeight + 'px';
  154. // #endif
  155. // #ifndef APP-PLUS
  156. let sysHeight = 0
  157. // #endif
  158. import {
  159. getCartList,
  160. getCartCounts,
  161. changeCartNum,
  162. cartDel,
  163. getResetCart
  164. } from '@/api/order.js';
  165. import {
  166. getProductHot,
  167. collectAll,
  168. getProductDetail
  169. } from '@/api/store.js';
  170. import {
  171. toLogin
  172. } from '@/libs/login.js';
  173. import tabBar from "@/pages/index/visualization/components/tabBar.vue"
  174. import {
  175. mapGetters
  176. } from "vuex";
  177. import recommend from '@/components/recommend';
  178. import productWindow from '@/components/productWindow';
  179. // #ifdef MP
  180. import authorize from '@/components/Authorize';
  181. // #endif
  182. import pageFooter from '@/components/pageFooter/index.vue'
  183. import colors from "@/mixins/color";
  184. import {
  185. HTTP_REQUEST_URL
  186. } from '@/config/app';
  187. export default {
  188. components: {
  189. pageFooter,
  190. recommend,
  191. productWindow,
  192. tabBar,
  193. // #ifdef MP
  194. authorize
  195. // #endif
  196. },
  197. mixins: [colors],
  198. data() {
  199. return {
  200. imgHost: HTTP_REQUEST_URL,
  201. is_diy: uni.getStorageSync('is_diy'),
  202. canShow: false,
  203. cartCount: 0,
  204. goodsHidden: true,
  205. footerswitch: true,
  206. hostProduct: [],
  207. cartList: {
  208. valid: [],
  209. invalid: []
  210. },
  211. isAllSelect: false, //全选
  212. selectValue: [], //选中的数据
  213. selectCountPrice: 0.00,
  214. isAuto: false, //没有授权的不会自动授权
  215. isShowAuth: false, //是否隐藏授权
  216. hotScroll: false,
  217. hotPage: 1,
  218. hotLimit: 10,
  219. loading: false,
  220. loadend: false,
  221. loadTitle: this.$t(`我也是有底线的`), //提示语
  222. page: 1,
  223. limit: 20,
  224. loadingInvalid: false,
  225. loadendInvalid: false,
  226. loadTitleInvalid: this.$t(`加载更多`), //提示语
  227. pageInvalid: 1,
  228. limitInvalid: 20,
  229. attr: {
  230. cartAttr: false,
  231. productAttr: [],
  232. productSelect: {}
  233. },
  234. productValue: [], //系统属性
  235. storeInfo: {},
  236. attrValue: '', //已选属性
  237. attrTxt: this.$t(`请选择`), //属性页面提示
  238. cartId: 0,
  239. product_id: 0,
  240. sysHeight: sysHeight,
  241. newData: {},
  242. activeRouter: '',
  243. is_diy_set: false,
  244. adding: false
  245. };
  246. },
  247. computed: mapGetters(['isLogin']),
  248. onLoad(options) {
  249. uni.hideTabBar()
  250. let that = this;
  251. let routes = getCurrentPages(); // 获取当前打开过的页面路由数组
  252. let curRoute = routes[routes.length - 1].route //获取当前页面路由
  253. this.activeRouter = '/' + curRoute
  254. },
  255. onShow() {
  256. if (!this.isLogin) toLogin();
  257. this.canShow = false
  258. if (this.isLogin == true) {
  259. this.hotPage = 1;
  260. this.hostProduct = []
  261. this.hotScroll = false
  262. this.getHostProduct();
  263. this.loadend = false;
  264. this.page = 1;
  265. this.cartList.valid = [];
  266. this.getCartList(1);
  267. this.loadendInvalid = false;
  268. this.pageInvalid = 1;
  269. this.cartList.invalid = [];
  270. this.getInvalidList();
  271. // this.getCartNum();
  272. this.goodsHidden = true;
  273. this.footerswitch = true;
  274. this.hostProduct = [];
  275. this.hotScroll = false;
  276. this.hotPage = 1;
  277. this.hotLimit = 10;
  278. this.cartList = {
  279. valid: [],
  280. invalid: []
  281. },
  282. this.isAllSelect = false; //全选
  283. this.selectValue = []; //选中的数据
  284. this.selectCountPrice = 0.00;
  285. this.cartCount = 0;
  286. this.isShowAuth = false;
  287. };
  288. },
  289. methods: {
  290. // 授权关闭
  291. authColse: function(e) {
  292. this.isShowAuth = e;
  293. },
  294. // 修改购物车
  295. reGoCat: function() {
  296. let that = this,
  297. productSelect = that.productValue[this.attrValue];
  298. //如果有属性,没有选择,提示用户选择
  299. if (
  300. that.attr.productAttr.length &&
  301. productSelect === undefined
  302. )
  303. return that.$util.Tips({
  304. title: that.$t(`产品库存不足,请选择其它`)
  305. });
  306. let q = {
  307. id: that.cartId,
  308. product_id: that.product_id,
  309. num: that.attr.productSelect.cart_num,
  310. unique: that.attr.productSelect !== undefined ?
  311. that.attr.productSelect.unique : ""
  312. };
  313. getResetCart(q)
  314. .then(function(res) {
  315. that.attr.cartAttr = false;
  316. that.$util.Tips({
  317. title: that.$t(`添加购物车成功`),
  318. success: () => {
  319. that.loadend = false;
  320. that.page = 1;
  321. that.cartList.valid = [];
  322. that.getCartList();
  323. that.getCartNum();
  324. }
  325. });
  326. })
  327. .catch(res => {
  328. return that.$util.Tips({
  329. title: res.msg
  330. });
  331. });
  332. },
  333. onMyEvent: function() {
  334. this.$set(this.attr, 'cartAttr', false);
  335. },
  336. reElection: function(item) {
  337. this.getGoodsDetails(item)
  338. },
  339. /**
  340. * 获取产品详情
  341. *
  342. */
  343. getGoodsDetails: function(item) {
  344. uni.showLoading({
  345. title: this.$t(`加载中`),
  346. mask: true
  347. });
  348. let that = this;
  349. that.cartId = item.id;
  350. that.product_id = item.product_id;
  351. getProductDetail(item.product_id).then(res => {
  352. uni.hideLoading();
  353. that.attr.cartAttr = true;
  354. let storeInfo = res.data.storeInfo;
  355. that.$set(that, 'storeInfo', storeInfo);
  356. that.$set(that.attr, 'productAttr', res.data.productAttr);
  357. that.$set(that, 'productValue', res.data.productValue);
  358. that.DefaultSelect();
  359. }).catch(err => {
  360. uni.hideLoading();
  361. })
  362. },
  363. /**
  364. * 属性变动赋值
  365. *
  366. */
  367. ChangeAttr: function(res) {
  368. let productSelect = this.productValue[res];
  369. if (productSelect && productSelect.stock > 0) {
  370. this.$set(this.attr.productSelect, "image", productSelect.image);
  371. this.$set(this.attr.productSelect, "price", productSelect.price);
  372. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  373. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  374. this.$set(this.attr.productSelect, "cart_num", 1);
  375. this.$set(this, "attrValue", res);
  376. this.$set(this, "attrTxt", this.$t(`已选择`));
  377. } else {
  378. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  379. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  380. this.$set(this.attr.productSelect, "stock", 0);
  381. this.$set(this.attr.productSelect, "unique", "");
  382. this.$set(this.attr.productSelect, "cart_num", 0);
  383. this.$set(this, "attrValue", "");
  384. this.$set(this, "attrTxt", this.$t(`请选择`));
  385. }
  386. },
  387. /**
  388. * 默认选中属性
  389. *
  390. */
  391. DefaultSelect: function() {
  392. let productAttr = this.attr.productAttr;
  393. let value = [];
  394. for (var key in this.productValue) {
  395. if (this.productValue[key].stock > 0) {
  396. value = this.attr.productAttr.length ? key.split(",") : [];
  397. break;
  398. }
  399. }
  400. for (let i = 0; i < productAttr.length; i++) {
  401. this.$set(productAttr[i], "index", value[i]);
  402. }
  403. //sort();排序函数:数字-英文-汉字;
  404. let productSelect = this.productValue[value.sort().join(",")];
  405. if (productSelect && productAttr.length) {
  406. this.$set(
  407. this.attr.productSelect,
  408. "store_name",
  409. this.storeInfo.store_name
  410. );
  411. this.$set(this.attr.productSelect, "image", productSelect.image);
  412. this.$set(this.attr.productSelect, "price", productSelect.price);
  413. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  414. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  415. this.$set(this.attr.productSelect, "cart_num", 1);
  416. this.$set(this, "attrValue", value.sort().join(","));
  417. this.$set(this, "attrTxt", this.$t(`已选择`));
  418. } else if (!productSelect && productAttr.length) {
  419. this.$set(
  420. this.attr.productSelect,
  421. "store_name",
  422. this.storeInfo.store_name
  423. );
  424. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  425. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  426. this.$set(this.attr.productSelect, "stock", 0);
  427. this.$set(this.attr.productSelect, "unique", "");
  428. this.$set(this.attr.productSelect, "cart_num", 0);
  429. this.$set(this, "attrValue", "");
  430. this.$set(this, "attrTxt", this.$t(`请选择`));
  431. } else if (!productSelect && !productAttr.length) {
  432. this.$set(
  433. this.attr.productSelect,
  434. "store_name",
  435. this.storeInfo.store_name
  436. );
  437. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  438. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  439. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  440. this.$set(
  441. this.attr.productSelect,
  442. "unique",
  443. this.storeInfo.unique || ""
  444. );
  445. this.$set(this.attr.productSelect, "cart_num", 1);
  446. this.$set(this, "attrValue", "");
  447. this.$set(this, "attrTxt", this.$t(`请选择`));
  448. }
  449. },
  450. attrVal(val) {
  451. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val
  452. .indexn]);
  453. },
  454. /**
  455. * 购物车数量加和数量减
  456. *
  457. */
  458. ChangeCartNum: function(changeValue) {
  459. //changeValue:是否 加|减
  460. //获取当前变动属性
  461. let productSelect = this.productValue[this.attrValue];
  462. //如果没有属性,赋值给商品默认库存
  463. if (productSelect === undefined && !this.attr.productAttr.length)
  464. productSelect = this.attr.productSelect;
  465. //无属性值即库存为0;不存在加减;
  466. if (productSelect === undefined) return;
  467. let stock = productSelect.stock || 0;
  468. let num = this.attr.productSelect;
  469. if (changeValue) {
  470. num.cart_num++;
  471. if (num.cart_num > stock) {
  472. this.$set(this.attr.productSelect, "cart_num", stock ? stock : 1);
  473. this.$set(this, "cart_num", stock ? stock : 1);
  474. }
  475. } else {
  476. num.cart_num--;
  477. if (num.cart_num < 1) {
  478. this.$set(this.attr.productSelect, "cart_num", 1);
  479. this.$set(this, "cart_num", 1);
  480. }
  481. }
  482. },
  483. /**
  484. * 购物车手动填写
  485. *
  486. */
  487. iptCartNum: function(e) {
  488. this.$set(this.attr.productSelect, 'cart_num', e);
  489. },
  490. subDel: function(event) {
  491. let that = this,
  492. selectValue = that.selectValue;
  493. if (selectValue.length > 0)
  494. cartDel(selectValue).then(res => {
  495. that.loadend = false;
  496. that.page = 1;
  497. that.cartList.valid = [];
  498. that.getCartList();
  499. that.getCartNum();
  500. });
  501. else
  502. return that.$util.Tips({
  503. title: that.$t(`请选择产品`)
  504. });
  505. },
  506. getSelectValueProductId: function() {
  507. let that = this;
  508. let validList = that.cartList.valid;
  509. let selectValue = that.selectValue;
  510. let productId = [];
  511. if (selectValue.length > 0) {
  512. for (let index in validList) {
  513. if (that.inArray(validList[index].id, selectValue)) {
  514. productId.push(validList[index].product_id);
  515. }
  516. }
  517. };
  518. return productId;
  519. },
  520. subCollect: function(event) {
  521. let that = this,
  522. selectValue = that.selectValue;
  523. if (selectValue.length > 0) {
  524. let selectValueProductId = that.getSelectValueProductId();
  525. collectAll(that.getSelectValueProductId().join(',')).then(res => {
  526. return that.$util.Tips({
  527. title: res.msg,
  528. icon: 'success'
  529. });
  530. }).catch(err => {
  531. return that.$util.Tips({
  532. title: err
  533. });
  534. });
  535. } else {
  536. return that.$util.Tips({
  537. title: that.$t(`请选择产品`)
  538. });
  539. }
  540. },
  541. subOrder(event) {
  542. let that = this,
  543. selectValue = that.selectValue;
  544. if (selectValue.length > 0) {
  545. uni.navigateTo({
  546. url: '/pages/goods/order_confirm/index?cartId=' + selectValue.join(',')
  547. });
  548. } else {
  549. return that.$util.Tips({
  550. title: that.$t(`请选择产品`)
  551. });
  552. }
  553. },
  554. checkboxAllChange: function(event) {
  555. let value = event.detail.value;
  556. if (value.length > 0) {
  557. this.setAllSelectValue(1)
  558. } else {
  559. this.setAllSelectValue(0)
  560. }
  561. },
  562. setAllSelectValue: function(status) {
  563. let that = this;
  564. let selectValue = [];
  565. let valid = that.cartList.valid;
  566. if (valid.length > 0) {
  567. let newValid = valid.map(item => {
  568. if (status) {
  569. if (that.footerswitch) {
  570. if (item.attrStatus) {
  571. item.checked = true;
  572. selectValue.push(item.id);
  573. } else {
  574. item.checked = false;
  575. }
  576. } else {
  577. item.checked = true;
  578. selectValue.push(item.id);
  579. }
  580. that.isAllSelect = true;
  581. } else {
  582. item.checked = false;
  583. that.isAllSelect = false;
  584. }
  585. return item;
  586. });
  587. that.$set(that.cartList, 'valid', newValid);
  588. that.selectValue = selectValue;
  589. that.switchSelect();
  590. }
  591. },
  592. checkboxChange: function(event) {
  593. let that = this;
  594. let value = event.detail.value;
  595. let valid = that.cartList.valid;
  596. let arr1 = [];
  597. let arr2 = [];
  598. let arr3 = [];
  599. let newValid = valid.map(item => {
  600. if (that.inArray(item.id, value)) {
  601. if (that.footerswitch) {
  602. if (item.attrStatus) {
  603. item.checked = true;
  604. arr1.push(item);
  605. } else {
  606. item.checked = false;
  607. }
  608. } else {
  609. item.checked = true;
  610. arr1.push(item);
  611. }
  612. } else {
  613. item.checked = false;
  614. arr2.push(item);
  615. }
  616. return item;
  617. });
  618. if (that.footerswitch) {
  619. arr3 = arr2.filter(item => !item.attrStatus);
  620. }
  621. // for (let index in valid) {
  622. // if (that.inArray(valid[index].id, value)){
  623. // if(valid[index].attrStatus){
  624. // valid[index].checked = true;
  625. // }else{
  626. // valid[index].checked = false;
  627. // }
  628. // } else {
  629. // valid[index].checked = false;
  630. // }
  631. // }
  632. that.$set(that.cartList, 'valid', newValid);
  633. // let newArr = that.cartList.valid.filter(item => item.attrStatus);
  634. that.isAllSelect = newValid.length === arr1.length + arr3.length;
  635. that.selectValue = value;
  636. that.switchSelect();
  637. },
  638. inArray: function(search, array) {
  639. for (let i in array) {
  640. if (array[i] == search) {
  641. return true;
  642. }
  643. }
  644. return false;
  645. },
  646. switchSelect: function() {
  647. let that = this;
  648. let validList = that.cartList.valid;
  649. let selectValue = that.selectValue;
  650. let selectCountPrice = 0.00;
  651. if (selectValue.length < 1) {
  652. that.selectCountPrice = selectCountPrice;
  653. } else {
  654. for (let index in validList) {
  655. if (that.inArray(validList[index].id, selectValue)) {
  656. selectCountPrice = that.$util.$h.Add(selectCountPrice, that.$util.$h.Mul(validList[index]
  657. .cart_num, validList[
  658. index].truePrice))
  659. }
  660. }
  661. that.selectCountPrice = selectCountPrice;
  662. }
  663. },
  664. /**
  665. * 购物车手动填写
  666. *
  667. */
  668. iptCartNum: function(index) {
  669. let item = this.cartList.valid[index];
  670. if (item.cart_num) {
  671. this.setCartNum(item.id, item.cart_num);
  672. }
  673. this.switchSelect();
  674. },
  675. blurInput: function(index) {
  676. let item = this.cartList.valid[index];
  677. if (!item.cart_num) {
  678. item.cart_num = 1;
  679. this.$set(this.cartList, 'valid', this.cartList.valid)
  680. }
  681. },
  682. subCart: function(index) {
  683. let that = this;
  684. let status = false;
  685. let item = that.cartList.valid[index];
  686. item.cart_num = Number(item.cart_num) - 1;
  687. if (item.cart_num < 1) status = true;
  688. if (item.cart_num <= 1) {
  689. item.cart_num = 1;
  690. item.numSub = true;
  691. } else {
  692. item.numSub = false;
  693. item.numAdd = false;
  694. }
  695. if (false == status) {
  696. that.setCartNum(item.id, item.cart_num, function(data) {
  697. that.cartList.valid[index] = item;
  698. that.getCartNum();
  699. that.switchSelect();
  700. }, () => {
  701. item.cart_num = Number(item.cart_num) + 1
  702. })
  703. }
  704. },
  705. addCart: function(index) {
  706. let that = this;
  707. if (this.adding) return
  708. let item = that.cartList.valid[index];
  709. item.cart_num = Number(item.cart_num) + 1
  710. let productInfo = item.productInfo;
  711. if (productInfo.hasOwnProperty('attrInfo') && item.cart_num >= item.productInfo.attrInfo.stock) {
  712. item.cart_num = item.productInfo.attrInfo.stock;
  713. item.numAdd = true;
  714. item.numSub = false;
  715. } else {
  716. item.numAdd = false;
  717. item.numSub = false;
  718. }
  719. that.setCartNum(item.id, item.cart_num, (data) => {
  720. that.cartList.valid[index] = item;
  721. that.getCartNum();
  722. that.switchSelect();
  723. }, () => {
  724. item.cart_num = Number(item.cart_num) - 1
  725. })
  726. },
  727. setCartNum(cartId, cartNum, successCallback, errorCallback) {
  728. let that = this;
  729. changeCartNum(cartId, cartNum).then(res => {
  730. successCallback && successCallback(res.data);
  731. }).catch(err => {
  732. errorCallback && errorCallback()
  733. return that.$util.Tips({
  734. title: err
  735. });
  736. })
  737. },
  738. getCartNum: function() {
  739. let that = this;
  740. getCartCounts().then(res => {
  741. that.cartCount = res.data.count;
  742. this.adding = false
  743. this.$store.commit('indexData/setCartNum', res.data.count > 99 ? '..' : res.data.count)
  744. if (res.data.count > 0) {
  745. wx.setTabBarBadge({
  746. index: 2,
  747. text: res.data.count + ''
  748. })
  749. } else {
  750. wx.hideTabBarRedDot({
  751. index: 2
  752. })
  753. }
  754. });
  755. },
  756. getCartData(data) {
  757. return new Promise((resolve, reject) => {
  758. getCartList(data).then((res) => {
  759. resolve(res.data);
  760. }).catch((err) => {
  761. this.loading = false;
  762. this.canShow = true
  763. this.$util.Tips({
  764. title: err
  765. });
  766. })
  767. });
  768. },
  769. async getCartList(init) {
  770. uni.showLoading({
  771. title: this.$t(`加载中`),
  772. mask: true
  773. });
  774. let that = this;
  775. let data = {
  776. page: that.page,
  777. limit: that.limit,
  778. status: 1
  779. }
  780. getCartCounts().then(async c => {
  781. that.cartCount = c.data.count;
  782. if (init) {
  783. this.adding = false
  784. this.$store.commit('indexData/setCartNum', c.data.count > 99 ? '..' : c.data
  785. .count)
  786. if (c.data.count > 0) {
  787. wx.setTabBarBadge({
  788. index: 2,
  789. text: c.data.count + ''
  790. })
  791. } else {
  792. wx.hideTabBarRedDot({
  793. index: 2
  794. })
  795. }
  796. }
  797. for (let i = 0; i < Math.ceil(c.data.ids.length / that.limit); i++) {
  798. let cartList = await this.getCartData(data)
  799. data.page = data.page + 1;
  800. let valid = cartList.valid
  801. let validList = that.$util.SplitArray(valid, that.cartList.valid);
  802. let numSub = [{
  803. numSub: true
  804. }, {
  805. numSub: false
  806. }];
  807. let numAdd = [{
  808. numAdd: true
  809. }, {
  810. numAdd: false
  811. }],
  812. selectValue = [];
  813. if (validList.length > 0) {
  814. for (let index in validList) {
  815. if (validList[index].cart_num == 1) {
  816. validList[index].numSub = true;
  817. } else {
  818. validList[index].numSub = false;
  819. }
  820. let productInfo = validList[index].productInfo;
  821. if (productInfo.hasOwnProperty('attrInfo') && validList[index].cart_num ==
  822. validList[index].productInfo.attrInfo
  823. .stock) {
  824. validList[index].numAdd = true;
  825. } else if (validList[index].cart_num == validList[index].productInfo
  826. .stock) {
  827. validList[index].numAdd = true;
  828. } else {
  829. validList[index].numAdd = false;
  830. }
  831. if (validList[index].attrStatus) {
  832. validList[index].checked = true;
  833. selectValue.push(validList[index].id);
  834. } else {
  835. validList[index].checked = false;
  836. }
  837. }
  838. }
  839. that.$set(that.cartList, 'valid', validList);
  840. // that.goodsHidden = cartList.valid.length <= 0 ? false : true;
  841. that.selectValue = selectValue;
  842. let newArr = validList.filter(item => item.attrStatus);
  843. that.isAllSelect = newArr.length == selectValue.length && newArr.length;
  844. that.switchSelect();
  845. }
  846. that.loading = false;
  847. this.canShow = true
  848. uni.hideLoading();
  849. });
  850. },
  851. getInvalidList: function() {
  852. let that = this;
  853. if (this.loadendInvalid) return false;
  854. if (this.loadingInvalid) return false;
  855. let data = {
  856. page: that.pageInvalid,
  857. limit: that.limitInvalid,
  858. status: 0
  859. }
  860. getCartList(data).then(res => {
  861. let cartList = res.data,
  862. invalid = cartList.invalid,
  863. loadendInvalid = invalid.length < that.limitInvalid;
  864. let invalidList = that.$util.SplitArray(invalid, that.cartList.invalid);
  865. that.$set(that.cartList, 'invalid', invalidList);
  866. that.loadendInvalid = loadendInvalid;
  867. that.loadTitleInvalid = loadendInvalid ? that.$t(`我也是有底线的`) : that.$t(`加载更多`);
  868. that.pageInvalid = that.pageInvalid + 1;
  869. that.loadingInvalid = false;
  870. }).catch(res => {
  871. that.loadingInvalid = false;
  872. that.loadTitleInvalid = that.$t(`加载更多`);
  873. })
  874. },
  875. getHostProduct: function() {
  876. let that = this;
  877. if (that.hotScroll) return
  878. getProductHot(
  879. that.hotPage,
  880. that.hotLimit,
  881. ).then(res => {
  882. that.hotPage++
  883. that.hotScroll = res.data.length < that.hotLimit
  884. that.hostProduct = that.hostProduct.concat(res.data)
  885. });
  886. },
  887. goodsOpen: function() {
  888. let that = this;
  889. that.goodsHidden = !that.goodsHidden;
  890. },
  891. goRouter(item) {
  892. var pages = getCurrentPages();
  893. var page = (pages[pages.length - 1]).$page.fullPath;
  894. if (item.link == page) return
  895. uni.switchTab({
  896. url: item.link,
  897. fail(err) {
  898. uni.redirectTo({
  899. url: item.link
  900. })
  901. }
  902. })
  903. },
  904. manage: function() {
  905. let that = this;
  906. that.footerswitch = !that.footerswitch;
  907. let arr1 = [];
  908. let arr2 = [];
  909. let newValid = that.cartList.valid.map(item => {
  910. if (that.footerswitch) {
  911. if (item.attrStatus) {
  912. if (item.checked) {
  913. arr1.push(item.id);
  914. }
  915. } else {
  916. item.checked = false;
  917. arr2.push(item);
  918. }
  919. } else {
  920. if (item.checked) {
  921. arr1.push(item.id);
  922. }
  923. }
  924. return item;
  925. });
  926. that.cartList.valid = newValid;
  927. if (that.footerswitch) {
  928. that.isAllSelect = newValid.length === arr1.length + arr2.length;
  929. } else {
  930. that.isAllSelect = newValid.length === arr1.length;
  931. }
  932. that.selectValue = arr1;
  933. that.switchSelect();
  934. },
  935. unsetCart: function() {
  936. let that = this,
  937. ids = [];
  938. for (let i = 0, len = that.cartList.invalid.length; i < len; i++) {
  939. ids.push(that.cartList.invalid[i].id);
  940. }
  941. cartDel(ids).then(res => {
  942. that.$util.Tips({
  943. title: that.$t(`清除成功`)
  944. });
  945. that.$set(that.cartList, 'invalid', []);
  946. that.getCartNum();
  947. }).catch(res => {
  948. });
  949. }
  950. },
  951. onReachBottom() {
  952. let that = this;
  953. if (that.loadend) {
  954. that.getInvalidList();
  955. }
  956. if (that.cartList.valid.length == 0 && that.cartList.invalid.length == 0) {
  957. that.getHostProduct();
  958. }
  959. },
  960. // 滚动监听
  961. onPageScroll(e) {
  962. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  963. uni.$emit('scroll');
  964. },
  965. }
  966. </script>
  967. <style scoped lang="scss">
  968. .shoppingCart {
  969. /* #ifdef H5 */
  970. // padding-bottom: 0;
  971. // padding-bottom: constant(safe-area-inset-bottom);
  972. // padding-bottom: env(safe-area-inset-bottom);
  973. /* #endif */
  974. }
  975. .shoppingCart .labelNav {
  976. height: 76rpx;
  977. padding: 0 30rpx;
  978. font-size: 22rpx;
  979. color: #8c8c8c;
  980. position: fixed;
  981. left: 0;
  982. width: 100%;
  983. box-sizing: border-box;
  984. background-color: #f5f5f5;
  985. z-index: 5;
  986. top: 0;
  987. }
  988. .shoppingCart .labelNav .item .iconfont {
  989. font-size: 25rpx;
  990. margin-right: 10rpx;
  991. }
  992. .shoppingCart .nav {
  993. width: 100%;
  994. height: 80rpx;
  995. background-color: #fff;
  996. padding: 0 30rpx;
  997. box-sizing: border-box;
  998. font-size: 28rpx;
  999. color: #282828;
  1000. position: fixed;
  1001. left: 0;
  1002. z-index: 5;
  1003. top: 76rpx;
  1004. }
  1005. .shoppingCart .nav .num {
  1006. margin-left: 12rpx;
  1007. }
  1008. .shoppingCart .nav .administrate {
  1009. font-size: 26rpx;
  1010. color: #282828;
  1011. width: 110rpx;
  1012. height: 46rpx;
  1013. border-radius: 6rpx;
  1014. border: 1px solid #a4a4a4;
  1015. }
  1016. .shoppingCart .noCart {
  1017. margin-top: 171rpx;
  1018. background-color: #fff;
  1019. padding-top: 0.1rpx;
  1020. }
  1021. .shoppingCart .noCart .pictrue {
  1022. width: 414rpx;
  1023. height: 336rpx;
  1024. margin: 78rpx auto 56rpx auto;
  1025. }
  1026. .shoppingCart .noCart .pictrue image {
  1027. width: 100%;
  1028. height: 100%;
  1029. }
  1030. .shoppingCart .list {
  1031. margin-top: 171rpx;
  1032. }
  1033. .shoppingCart .list .item {
  1034. padding: 25rpx 30rpx;
  1035. background-color: #fff;
  1036. margin-bottom: 15rpx;
  1037. }
  1038. .shoppingCart .list .item .picTxt {
  1039. width: 627rpx;
  1040. position: relative;
  1041. }
  1042. .shoppingCart .list .item .picTxt .pictrue {
  1043. width: 160rpx;
  1044. height: 160rpx;
  1045. }
  1046. .shoppingCart .list .item .picTxt .pictrue image {
  1047. width: 100%;
  1048. height: 100%;
  1049. border-radius: 6rpx;
  1050. }
  1051. .shoppingCart .list .item .picTxt .text {
  1052. width: 444rpx;
  1053. font-size: 28rpx;
  1054. color: #282828;
  1055. }
  1056. .shoppingCart .list .item .picTxt .text .reColor {
  1057. color: #999;
  1058. }
  1059. .shoppingCart .list .item .picTxt .text .reElection {
  1060. margin-top: 20rpx;
  1061. }
  1062. .shoppingCart .list .item .picTxt .text .reElection .title {
  1063. font-size: 24rpx;
  1064. }
  1065. .shoppingCart .list .item .picTxt .text .reElection .reBnt {
  1066. // width: 120rpx;
  1067. padding: 0 10rpx;
  1068. // height: 46rpx;
  1069. margin-top: 6rpx;
  1070. border-radius: 23rpx;
  1071. font-size: 26rpx;
  1072. }
  1073. .shoppingCart .list .item .picTxt .text .infor {
  1074. font-size: 24rpx;
  1075. color: #868686;
  1076. margin-top: 16rpx;
  1077. }
  1078. .shoppingCart .list .item .picTxt .text .money {
  1079. font-size: 32rpx;
  1080. color: var(--view-theme);
  1081. margin-top: 28rpx;
  1082. }
  1083. .shoppingCart .list .item .picTxt .carnum {
  1084. height: 47rpx;
  1085. position: absolute;
  1086. bottom: 0rpx;
  1087. right: 0;
  1088. }
  1089. .shoppingCart .list .item .picTxt .carnum view {
  1090. border: 1rpx solid #a4a4a4;
  1091. width: 66rpx;
  1092. text-align: center;
  1093. height: 100%;
  1094. line-height: 40rpx;
  1095. font-size: 28rpx;
  1096. color: #a4a4a4;
  1097. }
  1098. .shoppingCart .list .item .picTxt .carnum .reduce {
  1099. border-right: 0;
  1100. border-radius: 3rpx 0 0 3rpx;
  1101. }
  1102. .shoppingCart .list .item .picTxt .carnum .reduce.on {
  1103. border-color: #e3e3e3;
  1104. color: #dedede;
  1105. }
  1106. .shoppingCart .list .item .picTxt .carnum .plus {
  1107. border-left: 0;
  1108. border-radius: 0 3rpx 3rpx 0;
  1109. }
  1110. .shoppingCart .list .item .picTxt .carnum .plus.on {
  1111. border-color: #e3e3e3;
  1112. color: #dedede;
  1113. }
  1114. .shoppingCart .list .item .picTxt .carnum .num {
  1115. color: #282828;
  1116. }
  1117. .shoppingCart .invalidGoods {
  1118. background-color: #fff;
  1119. }
  1120. .shoppingCart .invalidGoods .goodsNav {
  1121. width: 100%;
  1122. height: 66rpx;
  1123. padding: 0 30rpx;
  1124. box-sizing: border-box;
  1125. font-size: 28rpx;
  1126. color: #282828;
  1127. }
  1128. .shoppingCart .invalidGoods .goodsNav .iconfont {
  1129. color: #424242;
  1130. font-size: 28rpx;
  1131. margin-right: 17rpx;
  1132. }
  1133. .shoppingCart .invalidGoods .goodsNav .del {
  1134. font-size: 26rpx;
  1135. color: #999;
  1136. }
  1137. .shoppingCart .invalidGoods .goodsNav .del .icon-shanchu1 {
  1138. color: #999;
  1139. font-size: 33rpx;
  1140. vertical-align: -2rpx;
  1141. margin-right: 8rpx;
  1142. }
  1143. .shoppingCart .invalidGoods .goodsList .item {
  1144. padding: 20rpx 30rpx;
  1145. border-top: 1rpx solid #f5f5f5;
  1146. }
  1147. .shoppingCart .invalidGoods .goodsList .item .invalid {
  1148. font-size: 22rpx;
  1149. color: #fff;
  1150. width: 70rpx;
  1151. height: 36rpx;
  1152. background-color: #aaa;
  1153. border-radius: 3rpx;
  1154. text-align: center;
  1155. line-height: 36rpx;
  1156. }
  1157. .shoppingCart .invalidGoods .goodsList .item .pictrue {
  1158. width: 140rpx;
  1159. height: 140rpx;
  1160. }
  1161. .shoppingCart .invalidGoods .goodsList .item .pictrue image {
  1162. width: 100%;
  1163. height: 100%;
  1164. border-radius: 6rpx;
  1165. }
  1166. .shoppingCart .invalidGoods .goodsList .item .text {
  1167. width: 433rpx;
  1168. font-size: 28rpx;
  1169. color: #999;
  1170. height: 140rpx;
  1171. }
  1172. .shoppingCart .invalidGoods .goodsList .item .text .name {
  1173. width: 100%;
  1174. }
  1175. .shoppingCart .invalidGoods .goodsList .item .text .infor {
  1176. font-size: 24rpx;
  1177. }
  1178. .shoppingCart .invalidGoods .goodsList .item .text .end {
  1179. font-size: 26rpx;
  1180. color: #bbb;
  1181. }
  1182. .shoppingCart .footer {
  1183. z-index: 999;
  1184. width: 100%;
  1185. height: 96rpx;
  1186. background-color: rgba(255, 255, 255, 0.85);
  1187. backdrop-filter: blur(10px);
  1188. position: fixed;
  1189. padding: 0 30rpx;
  1190. box-sizing: border-box;
  1191. border-top: 1rpx solid #eee;
  1192. bottom: 98rpx;
  1193. bottom: calc(98rpx + constant(safe-area-inset-bottom)); ///兼容 IOS<11.2/
  1194. bottom: calc(98rpx + env(safe-area-inset-bottom)); ///兼容 IOS>11.2/
  1195. }
  1196. .shoppingCart .footer.on {
  1197. // #ifndef H5
  1198. bottom: 0rpx;
  1199. // #endif
  1200. }
  1201. .shoppingCart .footer .checkAll {
  1202. font-size: 28rpx;
  1203. color: #282828;
  1204. margin-left: 16rpx;
  1205. }
  1206. // .shoppingCart .footer checkbox .wx-checkbox-input{background-color:#fafafa;}
  1207. .shoppingCart .footer .money {
  1208. font-size: 30rpx;
  1209. }
  1210. .shoppingCart .footer .placeOrder {
  1211. color: #fff;
  1212. font-size: 30rpx;
  1213. width: 226rpx;
  1214. height: 70rpx;
  1215. border-radius: 50rpx;
  1216. text-align: center;
  1217. line-height: 70rpx;
  1218. margin-left: 22rpx;
  1219. }
  1220. .shoppingCart .footer .button .bnt {
  1221. font-size: 28rpx;
  1222. color: #999;
  1223. border-radius: 50rpx;
  1224. border: 1px solid #999;
  1225. width: 160rpx;
  1226. height: 60rpx;
  1227. text-align: center;
  1228. line-height: 60rpx;
  1229. }
  1230. .shoppingCart .footer .button form~form {
  1231. margin-left: 17rpx;
  1232. }
  1233. .uni-p-b-96 {
  1234. height: 96rpx;
  1235. }
  1236. .uni-p-b-98 {
  1237. height: 100rpx;
  1238. /* 兼容 IOS<11.2 */
  1239. height: calc(100rpx + constant(safe-area-inset-bottom));
  1240. /* 兼容 IOS>11.2 */
  1241. height: calc(100rpx + env(safe-area-inset-bottom));
  1242. }
  1243. .emptyBox {
  1244. text-align: center;
  1245. padding: 80rpx 0;
  1246. .tips {
  1247. color: #aaa;
  1248. font-size: 26rpx;
  1249. }
  1250. image {
  1251. width: 414rpx;
  1252. height: 304rpx;
  1253. }
  1254. }
  1255. </style>