order_addcart.vue 35 KB

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