order_addcart.vue 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170
  1. <template>
  2. <view :style="viewColor">
  3. <view class='shoppingCart'>
  4. <view class='labelNav acea-row row-around row-middle'>
  5. <view class='item'><text class='iconfont icon-xuanzhong'></text>100%正品保证</view>
  6. <view class='item'><text class='iconfont icon-xuanzhong'></text>所有商品精挑细选</view>
  7. <view class='item'><text class='iconfont icon-xuanzhong'></text>售后无忧</view>
  8. </view>
  9. <view class='nav acea-row row-between-wrapper'>
  10. <view>购物数量 <text class='num t-color'>{{cartTotalCount}}</text></view>
  11. <view v-if="cartList.valid.length > 0 || cartList.invalid.length > 0" class='administrate acea-row row-center-wrapper'
  12. @click='manage'>{{ footerswitch ? '管理' : '取消'}}</view>
  13. </view>
  14. <view v-if="cartList.valid.length > 0 || cartList.invalid.length > 0">
  15. <view class='list'>
  16. <block v-for="(item,index) in cartList.valid" :key="index">
  17. <view class='item acea-row row-between-wrapper'>
  18. <view class="store-title">
  19. <view class="checkbox" @click="storeAllCheck(item,index)">
  20. <text v-if="!item.allCheck" class="iconfont icon-weixuanzhong"></text>
  21. <text v-else class="iconfont icon-xuanzhong1"></text>
  22. </view>
  23. <navigator :url="hide_mer_status == 0 ? '/pages/store/index?id='+item.mer_id : '#'" class="info">
  24. <text class="iconfont icon-shangjiadingdan"></text>
  25. <view class="name">{{item.mer_name}}</view>
  26. <text class="iconfont icon-xiangyou"></text>
  27. </navigator>
  28. <view class="coupon-btn" v-if="item.hasCoupon>0" @click="giveCoupon(item)">优惠券</view>
  29. </view>
  30. <navigator v-for="goods in item.list" :key="goods.cart_id" :url='"/pages/goods_details/index?id="+goods.product.product_id'
  31. hover-class='none' class='picTxt acea-row'>
  32. <view class="checkbox" @click.stop="goodsCheck(goods,index)">
  33. <text v-if="!goods.check" class="iconfont icon-weixuanzhong"></text>
  34. <text v-else class="iconfont icon-xuanzhong1"></text>
  35. </view>
  36. <view class='pictrue'>
  37. <image :src='(goods.productAttr && goods.productAttr.image) || goods.product.image'></image>
  38. <!-- <image v-else :src='item.productInfo.image'></image> -->
  39. </view>
  40. <view class='text'>
  41. <view class='line1'>{{goods.product.store_name}}</view>
  42. <view class='infor line1' v-if="goods.productAttr.sku" @click.stop='changeCart(goods)'>
  43. {{goods.productAttr.sku}}
  44. <text class="iconfont icon-xiala1"></text>
  45. </view>
  46. <view class='money'>¥{{goods.productAttr.price}}</view>
  47. </view>
  48. <view class='carnum acea-row row-center-wrapper'>
  49. <view class="reduce" :class="goods.numSub ? 'on' : ''" @click.stop='subCart(goods)'>-</view>
  50. <view class='num'>{{goods.cart_num}}</view>
  51. <view class="plus" :class="goods.numAdd ? 'on' : ''" @click.stop='addCart(goods)'>+</view>
  52. </view>
  53. </navigator>
  54. </view>
  55. </block>
  56. </view>
  57. <view class='invalidGoods' v-if="cartList.invalid.length > 0">
  58. <view class='goodsNav acea-row row-between-wrapper'>
  59. <view @click='goodsOpen'><text class='iconfont' :class='goodsHidden==true?"icon-xiangxia":"icon-xiangshang"'></text>失效商品</view>
  60. <view class='del' @click='unsetCart'><text class='iconfont icon-shanchu1'></text>清空</view>
  61. </view>
  62. <view class='goodsList' :hidden='goodsHidden'>
  63. <block v-for="(item,index) in cartList.invalid" :key='index'>
  64. <navigator :url="'/pages/goods_details/index?id='+item.product_id" class='item acea-row row-between-wrapper' hover-class='none'>
  65. <view class='invalid'>失效</view>
  66. <view class='pictrue'>
  67. <image :src='(item.productAttr && item.productAttr.image) || item.product.image'></image>
  68. </view>
  69. <view class='text acea-row row-column-between'>
  70. <view class='line1 name'>{{item.product.store_name}}</view>
  71. <!-- <view class='infor line1' v-if="item.productInfo.attrInfo">属性:{{item.productInfo.attrInfo.suk}}</view> -->
  72. <view class='acea-row row-between-wrapper'>
  73. <!-- <view>¥{{item.truePrice}}</view> -->
  74. <view class='end'>该商品已失效</view>
  75. </view>
  76. </view>
  77. </navigator>
  78. </block>
  79. </view>
  80. </view>
  81. </view>
  82. <view class='noCart' v-if="recommend" :style="{marginTop:cartList.invalid.length ==0 && cartList.invalid.length ==0?'170rpx':'' }">
  83. <view class='pictrue'>
  84. <image src='http://ygs.hqgjsmc.com/baseimg/noCart.png'></image>
  85. <view>暂无商品,去添加点什么吧</view>
  86. </view>
  87. <recommend :hostProduct='hostProduct' :isLogin="isLogin"></recommend>
  88. <view class='loadingicon acea-row row-center-wrapper' v-if="hostProduct.length>5">
  89. <text class='loading iconfont icon-jiazai' :hidden='loading==false'></text>{{loadTitle}}
  90. </view>
  91. </view>
  92. <view class='footer acea-row row-between-wrapper' v-if="cartList.valid.length > 0">
  93. <view>
  94. <view class="allcheckbox" @click.stop="checkboxAllChange">
  95. <text v-if="!isAllSelect" class="iconfont icon-weixuanzhong"></text>
  96. <text v-else class="iconfont icon-xuanzhong1"></text>
  97. 全选 ({{cartCount}})
  98. </view>
  99. </view>
  100. <view class='money acea-row row-middle' v-if="footerswitch==true">
  101. <text class='t-color'>¥{{selectCountPrice}}</text>
  102. <form @submit="subOrder" report-submit='true'>
  103. <button class='placeOrder' formType="submit">立即下单</button>
  104. </form>
  105. </view>
  106. <view class='button acea-row row-middle' v-else>
  107. <form @submit="subCollect" report-submit='true'>
  108. <button class='bnt bt-color' formType="submit">收藏</button>
  109. </form>
  110. <form @submit="subDel" report-submit='true'>
  111. <button class='bnt' formType="submit">删除</button>
  112. </form>
  113. </view>
  114. </view>
  115. </view>
  116. <!-- 优惠券弹窗 -->
  117. <block v-if="coupon.coupon">
  118. <couponListWindow
  119. :coupon='coupon'
  120. @ChangCouponsClone="ChangCouponsClone"
  121. @ChangCouponsUseState="ChangCouponsUseState"
  122. ></couponListWindow>
  123. </block>
  124. <!-- 组件 -->
  125. <addcartWindow :attr="attr" :isShow='1' :iSplus='1' :destri='1' @myevent="onMyEvent" @ChangeAttr="ChangeAttr" @goCat="goCat" @attrVal="attrVal" id='product-window'></addcartWindow>
  126. <authorize :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse" @onLoadFun="onLoadFun"></authorize>
  127. </view>
  128. </template>
  129. <script>
  130. // +----------------------------------------------------------------------
  131. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  132. // +----------------------------------------------------------------------
  133. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  134. // +----------------------------------------------------------------------
  135. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  136. // +----------------------------------------------------------------------
  137. // | Author: CRMEB Team <admin@crmeb.com>
  138. // +----------------------------------------------------------------------
  139. import couponListWindow from '@/components/couponListWindow';
  140. import addcartWindow from '@/components/addcartWindow';
  141. import {
  142. getCartList,
  143. getCartCounts,
  144. changeCartNum,
  145. cartDel
  146. } from '@/api/order.js';
  147. import {
  148. getCoupons,
  149. getShopCoupons
  150. } from '@/api/api.js';
  151. import {
  152. getProductHot,
  153. collectAll
  154. } from '@/api/store.js';
  155. import {
  156. mapGetters
  157. } from "vuex";
  158. import recommend from '@/components/recommend';
  159. import authorize from '@/components/Authorize';
  160. import { configMap } from '@/utils';
  161. const app = getApp();
  162. export default {
  163. components: {
  164. recommend,
  165. couponListWindow,
  166. addcartWindow,
  167. authorize
  168. },
  169. data() {
  170. return {
  171. loading: false, //是否加载中
  172. loadend: false, //是否加载完毕
  173. loadTitle: '加载更多', //提示语
  174. cartCount: 0,
  175. goodsHidden: true,
  176. footerswitch: true,
  177. hostProduct: [],
  178. cartList: {
  179. valid: [],
  180. invalid: []
  181. },
  182. isAllSelect: false, //全选
  183. selectValue: [], //选中的数据
  184. selectCountPrice: 0.00,
  185. isAuto: false, //没有授权的不会自动授权
  186. isShowAuth: false, //是否隐藏授权
  187. hotScroll: false,
  188. hotPage: 1,
  189. hotLimit: 10,
  190. //属性是否打开
  191. coupon: {
  192. 'coupon': false,
  193. list: [],
  194. },
  195. // 购物车总数
  196. cartTotalCount:0,
  197. recommend: false,
  198. productValue: [], //系统属性
  199. attr: {
  200. cartAttr: false,
  201. productAttr: [],
  202. productSelect: {}
  203. },
  204. isOpen: false, //是否打开属性组件
  205. source: '',
  206. attrValue: '', //已选属性
  207. uniqueValue: "",
  208. newVal: {},
  209. goods: {},
  210. currSku: '',
  211. };
  212. },
  213. computed: configMap({hide_mer_status: 1}, mapGetters(['isLogin','viewColor'])),
  214. onReady(){
  215. },
  216. mounted: function() {
  217. },
  218. onLoad: function(options) {
  219. this.getHostProduct();
  220. },
  221. onShow: function() {
  222. uni.showTabBar();
  223. if (this.isLogin == true) {
  224. this.getCartList();
  225. this.getCartNum();
  226. this.goodsHidden = true;
  227. this.footerswitch = true;
  228. this.isAllSelect = false; //全选
  229. this.selectValue = []; //选中的数据
  230. this.isShowAuth = false;
  231. uni.setStorage({
  232. key:'invoice_Data',
  233. data:{},
  234. success: function(){
  235. }
  236. })
  237. }else{
  238. setTimeout(() =>{
  239. this.isAuto = true;
  240. this.isShowAuth = true
  241. }, 300);
  242. }
  243. },
  244. methods: {
  245. // 授权关闭
  246. authColse: function(e) {
  247. console.log(e,'authColse')
  248. this.isShowAuth = e;
  249. },
  250. onLoadFun(){
  251. this.isShowAuth = false;
  252. },
  253. // 删除
  254. subDel: function(event) {
  255. let that = this
  256. let type_id = []
  257. this.cartList.valid.forEach(el=>{
  258. el.list.forEach(goods=>{
  259. if(goods.check){
  260. type_id.push(goods.cart_id)
  261. }
  262. })
  263. })
  264. if(type_id.length == 0){
  265. return that.$util.Tips({
  266. title: '请选择产品'
  267. });
  268. }else{
  269. cartDel({
  270. cart_id:type_id,
  271. }).then(res=>{
  272. this.getCartList();
  273. this.getCartNum();
  274. return that.$util.Tips({
  275. title: res.message,
  276. icon: 'success'
  277. });
  278. }).catch(err => {
  279. return that.$util.Tips({
  280. title: err
  281. });
  282. });
  283. }
  284. },
  285. // 收藏
  286. subCollect: function(event) {
  287. let that = this
  288. let type_id = []
  289. this.cartList.valid.forEach(el=>{
  290. el.list.forEach(goods=>{
  291. if(goods.check){
  292. type_id.push(goods.product.product_id)
  293. }
  294. })
  295. })
  296. if(type_id.length == 0){
  297. return that.$util.Tips({
  298. title: '请选择产品'
  299. });
  300. }else{
  301. collectAll({
  302. type_id:type_id,
  303. type:1
  304. }).then(res=>{
  305. return that.$util.Tips({
  306. title: res.message,
  307. icon: 'success'
  308. });
  309. }).catch(err => {
  310. return that.$util.Tips({
  311. title: err
  312. });
  313. });
  314. }
  315. },
  316. onMyEvent: function() {
  317. this.$set(this.attr, 'cartAttr', false);
  318. this.$set(this, 'isOpen', false);
  319. },
  320. /*
  321. * 更改商品属性
  322. */
  323. changeCart: function(goods) {
  324. let that = this;
  325. that.goods = goods;
  326. that.$set(that.attr, 'productAttr', goods.attr);
  327. console.log(this.attr)
  328. const sku = {}
  329. that.attrValue = goods.productAttr.sku
  330. goods.attrValue.forEach((itemn)=>{
  331. sku[itemn.sku] = itemn;
  332. })
  333. that.$set(that, 'productValue',sku);
  334. let productSelect = sku[that.attrValue];
  335. //打开属性
  336. that.isOpen = that.attr.cartAttr = true;
  337. that.DefaultSelect(goods)
  338. },
  339. /**
  340. * 默认选中属性
  341. *
  342. */
  343. DefaultSelect: function(goods) {
  344. let productAttr = this.attr.productAttr;
  345. let value = [];
  346. let arr = []
  347. console.log(arr, 'arr')
  348. if(this.currSku){
  349. value = [this.currSku]
  350. }else{
  351. for (var key in this.productValue) {
  352. if (this.productValue[key].stock > 0) {
  353. value = this.attr.productAttr.length ? key.split(",") : [];
  354. break;
  355. }
  356. }
  357. }
  358. for (let i = 0; i < productAttr.length; i++) {
  359. this.$set(productAttr[i], "index", value[i]);
  360. }
  361. let productSelect = this.productValue[value.join(",")];
  362. if (productSelect && productAttr.length) {
  363. this.$set(
  364. this.attr.productSelect,
  365. "store_name",
  366. goods.product.store_name
  367. );
  368. this.$set(this.attr.productSelect, "image", productSelect.image ? productSelect.image : this.storeInfo.image);
  369. this.$set(this.attr.productSelect, "price", productSelect.price);
  370. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  371. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  372. this.$set(this, "uniqueValue", productSelect.unique);
  373. this.$set(this, "attrValue", value.join(","));
  374. this.$set(this, "attrTxt", "已选择");
  375. if (productSelect.stock == 0) {
  376. this.$set(this.attr.productSelect, "cart_num", 0);
  377. } else {
  378. this.$set(this.attr.productSelect, "cart_num", 1);
  379. }
  380. } else if (!productSelect && productAttr.length) {
  381. this.$set(
  382. this.attr.productSelect,
  383. "store_name",
  384. goods.product.store_name
  385. );
  386. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  387. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  388. this.$set(this.attr.productSelect, "stock", 0);
  389. this.$set(this.attr.productSelect, "unique", "");
  390. this.$set(this, "uniqueValue", "");
  391. this.$set(this.attr.productSelect, "cart_num", 0);
  392. this.$set(this, "attrValue", "");
  393. this.$set(this, "attrTxt", "请选择");
  394. } else if (!productSelect && !productAttr.length) {
  395. this.$set(
  396. this.attr.productSelect,
  397. "store_name",
  398. goods.product.store_name
  399. );
  400. this.$set(this.attr.productSelect, "image", this.storeInfo.image);
  401. this.$set(this.attr.productSelect, "price", this.storeInfo.price);
  402. this.$set(this.attr.productSelect, "stock", this.storeInfo.stock);
  403. this.$set(this.attr.productSelect, "unique", this.storeInfo.unique || "");
  404. this.$set(this, "uniqueValue", this.storeInfo.unique || "");
  405. this.$set(this.attr.productSelect, "cart_num", 1);
  406. this.$set(this, "attrValue", "");
  407. this.$set(this, "attrTxt", "请选择");
  408. } else if (productSelect && !productAttr.length) {
  409. this.$set(this.attr.productSelect, "store_name", this.storeInfo.store_name);
  410. this.$set(this.attr.productSelect, "image", productSelect.image);
  411. this.$set(this.attr.productSelect, "price", productSelect.price);
  412. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  413. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  414. this.$set(this, "uniqueValue", productSelect.unique);
  415. this.$set(this, "attrValue", value.join(","));
  416. this.$set(this, "attrTxt", "已选择");
  417. if (productSelect.stock == 0) {
  418. this.$set(this.attr.productSelect, "cart_num", 0);
  419. } else {
  420. this.$set(this.attr.productSelect, "cart_num", 1);
  421. }
  422. }
  423. this.goCart(productSelect);
  424. },
  425. goCart(productSelect){
  426. let that = this;
  427. //如果有属性,没有选择,提示用户选择
  428. if (
  429. that.attr.productAttr.length &&
  430. that.isOpen === true &&
  431. productSelect.stock == 0
  432. )
  433. return that.$util.Tips({
  434. title: "产品库存不足,请选择其它"
  435. });
  436. if (that.attr.productSelect.cart_num == 0) {
  437. return that.$util.Tips({
  438. title: '购买个数不能为0!'
  439. })
  440. }
  441. },
  442. attrVal(val) {
  443. this.$set(this.attr.productAttr[val.indexw], 'index', this.attr.productAttr[val.indexw].attr_values[val.indexn]);
  444. },
  445. /**
  446. * 属性变动赋值
  447. *
  448. */
  449. ChangeAttr: function(res) {
  450. let productSelect = this.productValue[res];
  451. this.currSku = res;
  452. this.newVal = this.productValue[res];
  453. if(productSelect)this.$set(this, "uniqueValue", productSelect.unique);
  454. if (productSelect && productSelect.stock > 0) {
  455. this.$set(this.attr.productSelect, "image", productSelect.image ? productSelect.image : this.storeInfo.image);
  456. this.$set(this.attr.productSelect, "price", productSelect.price);
  457. this.$set(this.attr.productSelect, "stock", productSelect.stock);
  458. this.$set(this.attr.productSelect, "unique", productSelect.unique);
  459. this.$set(this, "uniqueValue", productSelect.unique);
  460. this.$set(this.attr.productSelect, "cart_num", 1);
  461. this.$set(this, "attrValue", res);
  462. }
  463. else {
  464. this.$set(this.attr.productSelect, "image", productSelect.image);
  465. this.$set(this.attr.productSelect, "price", productSelect.price);
  466. this.$set(this.attr.productSelect, "stock", 0);
  467. this.$set(this.attr.productSelect, "unique", "");
  468. this.$set(this.attr.productSelect, "cart_num", 0);
  469. this.$set(this, "attrValue", "");
  470. }
  471. },
  472. // 立即下单
  473. subOrder: function(event) {
  474. let selectValue = []
  475. this.cartList.valid.forEach(el=>{
  476. el.list.forEach(goods=>{
  477. if(goods.check){
  478. selectValue.push(goods.cart_id)
  479. }
  480. })
  481. })
  482. if (selectValue.length > 0) {
  483. uni.navigateTo({
  484. url: '/pages/users/order_confirm/index?cartId=' + selectValue.join(',')
  485. });
  486. } else {
  487. return that.$util.Tips({
  488. title: '请选择产品'
  489. });
  490. }
  491. },
  492. // 购物车增加
  493. addCart: function(goods, index) {
  494. let that = this;
  495. changeCartNum(goods.cart_id, {
  496. cart_num: goods.cart_num + 1
  497. }).then(res => {
  498. goods.cart_num = Number(goods.cart_num) + 1
  499. that.cartTotalCount = Number(that.cartTotalCount) + 1;
  500. if (goods.hasOwnProperty('productAttr') && goods.cart_num > goods.productAttr.stock) {
  501. goods.cart_num = goods.productAttr.stock;
  502. goods.numAdd = true;
  503. goods.numSub = false;
  504. return
  505. } else {
  506. goods.numAdd = false;
  507. goods.numSub = false;
  508. }
  509. this.cartAllCheck('goodsCheck')
  510. }).catch(error => {
  511. that.$util.Tips({
  512. title: error
  513. });
  514. // goods.cart_num = Number(goods.cart_num) - 1
  515. })
  516. },
  517. goCat: function() {
  518. let that = this;
  519. changeCartNum(that.goods.cart_id, {
  520. cart_num: that.goods.cart_num,
  521. product_attr_unique: that.newVal.unique
  522. }).then(res => {
  523. if (that.goods.hasOwnProperty('productAttr') && that.goods.cart_num > that.goods.productAttr.stock) {
  524. that.goods.cart_num = that.goods.productAttr.stock;
  525. that.goods.numAdd = true;
  526. that.goods.numSub = false;
  527. return
  528. } else {
  529. that.goods.numAdd = false;
  530. that.goods.numSub = false;
  531. }
  532. that.onMyEvent();
  533. that.getCartList(true);
  534. that.isAllSelect = false
  535. }).catch(error => {
  536. that.$util.Tips({
  537. title: error
  538. });
  539. // goods.cart_num = Number(goods.cart_num) - 1
  540. })
  541. },
  542. // 购物车递减
  543. subCart(goods) {
  544. let status = false;
  545. if (goods.cart_num < 1) status = true;
  546. if (goods.cart_num <= 1) {
  547. goods.cart_num = 1;
  548. goods.numSub = true;
  549. status = true;
  550. } else {
  551. // goods.cart_num = Number(goods.cart_num) - 1
  552. // this.cartTotalCount = Number(this.cartTotalCount) - 1;
  553. if (false == status) {
  554. changeCartNum(goods.cart_id, {
  555. cart_num: Number(goods.cart_num) - 1
  556. }).then(res => {
  557. goods.numSub = false;
  558. goods.numAdd = false;
  559. if(goods.cart_num <= 1){
  560. goods.numSub = true;
  561. }
  562. goods.cart_num = Number(goods.cart_num) - 1
  563. this.cartTotalCount = Number(this.cartTotalCount) - 1;
  564. this.cartAllCheck('goodsCheck')
  565. }).catch(error => {
  566. this.$util.Tips({
  567. title: error
  568. });
  569. })
  570. }
  571. }
  572. },
  573. getCartNum: function() {
  574. let that = this;
  575. getCartCounts().then(res => {
  576. console.log(res);
  577. that.cartTotalCount = res.data[0].count || 0;
  578. });
  579. },
  580. // 购物车列表
  581. getCartList: function(isChange) {
  582. let that = this;
  583. getCartList().then(res => {
  584. res.data.list.forEach((item, index) => {
  585. item.allCheck = true
  586. item.list.forEach((goods, j) => {
  587. goods.check = true
  588. if (goods.cart_num == 1) {
  589. goods.numSub = true;
  590. } else {
  591. goods.numSub = false;
  592. }
  593. if (goods.cart_num == goods.productAttr.stock) {
  594. goods.numAdd = true;
  595. } else {
  596. goods.numAdd = false;
  597. }
  598. })
  599. })
  600. this.cartList.valid = res.data.list
  601. this.cartList.invalid = res.data.fail
  602. if(res.data.list.length == 0 && res.data.list.length == 0){
  603. this.recommend = true;
  604. if(!this.hostProduct.length){
  605. this.getHostProduct();
  606. }
  607. }else{
  608. this.recommend = false
  609. }
  610. const sku = {}
  611. this.checkboxAllChange()
  612. });
  613. },
  614. // 商铺全选
  615. storeAllCheck(item, index) {
  616. // 店铺取消
  617. if (item.allCheck) {
  618. item.allCheck = false
  619. item.list.forEach((el, index) => {
  620. el.check = false
  621. })
  622. } else {
  623. item.allCheck = true
  624. item.list.forEach((el, index) => {
  625. el.check = true
  626. })
  627. }
  628. this.cartAllCheck('goodsCheck')
  629. },
  630. // 商品选中
  631. goodsCheck(goods) {
  632. goods.check = !goods.check
  633. // console.log(parentIndex,'parentIndex')
  634. this.cartAllCheck('goodsCheck')
  635. },
  636. // 全选判断
  637. cartAllCheck(type) {
  638. let allArr = [];
  639. let totalMoney = 0
  640. let totalNum = 0
  641. this.cartList.valid.forEach((el, index) => {
  642. if (type == 'goodsCheck') {
  643. let tempArr = el.list.filter(goods => {
  644. return goods.check == true
  645. })
  646. if (el.list.length == tempArr.length) {
  647. el.allCheck = true
  648. allArr.push(el)
  649. } else {
  650. el.allCheck = false
  651. }
  652. } else {
  653. el.list.forEach((goods) => {
  654. goods.check = this.isAllSelect
  655. })
  656. el.allCheck = this.isAllSelect
  657. if (el.allCheck) allArr.push(el)
  658. }
  659. // 总金额 //总数
  660. el.list.forEach(e => {
  661. if (e.check) {
  662. totalMoney = this.$util.$h.Add(totalMoney, this.$util.$h.Mul(e.productAttr.price, e.cart_num))
  663. totalNum += e.cart_num
  664. }
  665. })
  666. })
  667. this.cartCount = totalNum
  668. this.selectCountPrice = totalMoney
  669. // 全选
  670. this.isAllSelect = allArr.length == this.cartList.valid.length ? true : false
  671. },
  672. // 购物车全选
  673. checkboxAllChange() {
  674. this.isAllSelect = !this.isAllSelect
  675. this.cartAllCheck('cartCheck')
  676. },
  677. // 推荐列表
  678. getHostProduct: function() {
  679. let that = this;
  680. if (that.loadend) return;
  681. if (that.hotScroll) return;
  682. that.loading = true;
  683. that.loadTitle = "加载更多";
  684. getProductHot(
  685. that.hotPage,
  686. that.hotLimit,
  687. ).then(res => {
  688. let list = res.data.list || [];
  689. that.hotPage++
  690. that.hotScroll = res.data.list.length < that.hotLimit
  691. that.hostProduct = that.hostProduct.concat(res.data.list)
  692. that.loading = false;
  693. that.loadTitle = that.hotScroll ? "我也是有底线的" : '加载更多';
  694. });
  695. },
  696. // 失效商品展开
  697. goodsOpen: function() {
  698. let that = this;
  699. that.goodsHidden = !that.goodsHidden;
  700. },
  701. // 管理
  702. manage: function() {
  703. let that = this;
  704. that.footerswitch = !that.footerswitch;
  705. },
  706. // 清空
  707. unsetCart: function() {
  708. let that = this,
  709. ids = [];
  710. for (let i = 0, len = that.cartList.invalid.length; i < len; i++) {
  711. ids.push(that.cartList.invalid[i].cart_id);
  712. }
  713. cartDel({
  714. cart_id:ids
  715. }).then(res => {
  716. that.$util.Tips({
  717. title: '清除成功'
  718. });
  719. that.$set(that.cartList, 'invalid', []);
  720. }).catch(res => {
  721. });
  722. },
  723. // 店铺优惠券
  724. giveCoupon(item){
  725. let that = this;
  726. let goodsArr = []
  727. let couponList = [];
  728. let activeList = [];
  729. let ids = []
  730. item.list.map(el=>{
  731. ids.push(el.product_id)
  732. })
  733. uni.showLoading({
  734. title: '加载中...',
  735. mask: true
  736. });
  737. getCoupons({
  738. ids:ids.join(',')
  739. }).then(res => {
  740. goodsArr = res.data
  741. getShopCoupons(item.mer_id).then(({data})=>{
  742. uni.hideTabBar();
  743. uni.hideLoading();
  744. couponList = goodsArr.concat(data)
  745. this.$set(this.coupon, 'list', couponList);
  746. this.$set(this.coupon, 'coupon', true);
  747. }).catch(error=>{
  748. uni.showTabBar();
  749. })
  750. });
  751. },
  752. ChangCouponsClone: function() {
  753. uni.showTabBar();
  754. this.$set(this.coupon, 'coupon', false)
  755. },
  756. ChangCouponsUseState(index) {
  757. uni.showTabBar();
  758. let that = this;
  759. that.coupon.list[index].issue = true;
  760. console.log(that.coupon.list[index])
  761. // that.$set(that.coupon, 'list', that.coupon.list);
  762. // that.$set(that.coupon, 'coupon', false);
  763. },
  764. },
  765. onReachBottom() {
  766. this.recommend && this.getHostProduct();
  767. },
  768. // 滚动监听
  769. onPageScroll(e) {
  770. // 传入scrollTop值并触发所有easy-loadimage组件下的滚动监听事件
  771. uni.$emit('scroll');
  772. }
  773. }
  774. </script>
  775. <style scoped lang="scss">
  776. .shoppingCart .labelNav {
  777. height: 76rpx;
  778. padding: 0 30rpx;
  779. font-size: 22rpx;
  780. color: #8c8c8c;
  781. position: fixed;
  782. left: 0;
  783. width: 100%;
  784. box-sizing: border-box;
  785. background-color: #f5f5f5;
  786. z-index: 5;
  787. top: 0;
  788. }
  789. .icon-xiala1{
  790. display: inline-block;
  791. transform: rotate(180deg);
  792. font-size: 14rpx;
  793. padding: 0 5rpx;
  794. }
  795. .shoppingCart .labelNav .item .iconfont {
  796. font-size: 25rpx;
  797. margin-right: 10rpx;
  798. }
  799. .t-color {
  800. color: var(--view-theme);
  801. }
  802. .shoppingCart {
  803. margin-bottom: 100rpx;
  804. }
  805. .shoppingCart .nav {
  806. width: 100%;
  807. height: 80rpx;
  808. background-color: #fff;
  809. padding: 0 30rpx;
  810. box-sizing: border-box;
  811. font-size: 28rpx;
  812. color: #282828;
  813. position: fixed;
  814. left: 0;
  815. z-index: 5;
  816. top: 76rpx;
  817. }
  818. .shoppingCart .nav .administrate {
  819. font-size: 26rpx;
  820. color: #282828;
  821. width: 110rpx;
  822. height: 46rpx;
  823. border-radius: 6rpx;
  824. border: 1px solid #868686;
  825. }
  826. .shoppingCart .noCart {
  827. margin-top: 20rpx;
  828. margin-bottom: 20rpx;
  829. background-color: #fff;
  830. padding-top: 0.1rpx;
  831. }
  832. .shoppingCart .noCart .pictrue {
  833. text-align: center;
  834. margin: 78rpx auto 56rpx auto;
  835. }
  836. .shoppingCart .noCart .pictrue image {
  837. width: 414rpx;
  838. height: 305rpx;
  839. }
  840. .shoppingCart .noCart .pictrue view{
  841. color: #999;
  842. }
  843. .shoppingCart .list {
  844. margin: 171rpx 0 20rpx;
  845. }
  846. .shoppingCart .list .item {
  847. background-color: #fff;
  848. margin-bottom: 15rpx;
  849. .store-title {
  850. display: flex;
  851. align-items: center;
  852. width: 100%;
  853. padding: 0 30rpx;
  854. height: 85rpx;
  855. border-bottom: 1px solid #f0f0f0;
  856. .checkbox {
  857. width: 60rpx;
  858. .iconfont {
  859. font-size: 40rpx;
  860. color: #CCCCCC;
  861. }
  862. .icon-xuanzhong1 {
  863. color: var(--view-theme);
  864. }
  865. }
  866. .info {
  867. flex: 1;
  868. display: flex;
  869. align-items: center;
  870. .iconfont {
  871. font-size: 36rpx;
  872. }
  873. .name {
  874. margin: 0 0 0 10rpx;
  875. font-size: 28rpx;
  876. color: #282828;
  877. font-weight: bold;
  878. }
  879. .icon-xiangyou {
  880. margin-top: 6rpx;
  881. font-size: 22rpx;
  882. color: #999;
  883. }
  884. }
  885. .coupon-btn {
  886. color: var(--view-theme);
  887. font-size: 22rpx;
  888. width: 100rpx;
  889. line-height: 36rpx;
  890. background: var(--view-minorColor);
  891. border-radius: 18rpx;
  892. text-align: center;
  893. }
  894. }
  895. }
  896. .shoppingCart .list .item .picTxt {
  897. width: 100%;
  898. padding: 25rpx 30rpx;
  899. position: relative;
  900. align-items: center;
  901. border-bottom: 1px solid #f0f0f0;
  902. .checkbox {
  903. width: 60rpx;
  904. .iconfont {
  905. font-size: 40rpx;
  906. color: #CCCCCC;
  907. }
  908. .icon-xuanzhong1 {
  909. color: var(--view-theme);
  910. }
  911. }
  912. }
  913. .shoppingCart .list .item .picTxt .pictrue {
  914. width: 160rpx;
  915. height: 160rpx;
  916. }
  917. .shoppingCart .list .item .picTxt .pictrue image {
  918. width: 100%;
  919. height: 100%;
  920. border-radius: 6rpx;
  921. }
  922. .shoppingCart .list .item .picTxt .text {
  923. width: 444rpx;
  924. margin-left: 20rpx;
  925. font-size: 28rpx;
  926. color: #282828;
  927. }
  928. .shoppingCart .list .item .picTxt .text .infor {
  929. display: inline-block;
  930. padding: 6rpx;
  931. border-radius: 4rpx;
  932. font-size: 24rpx;
  933. color: #868686;
  934. margin-top: 16rpx;
  935. background-color: #F5F5F5;
  936. max-width: 460rpx;
  937. }
  938. .shoppingCart .list .item .picTxt .text .money {
  939. font-size: 32rpx;
  940. color: #282828;
  941. margin-top: 28rpx;
  942. }
  943. .shoppingCart .list .item .picTxt .carnum {
  944. height: 47rpx;
  945. position: absolute;
  946. bottom: 30rpx;
  947. right: 30rpx;
  948. }
  949. .shoppingCart .list .item .picTxt .carnum view {
  950. border: 1rpx solid #a4a4a4;
  951. min-width: 66rpx;
  952. text-align: center;
  953. height: 100%;
  954. line-height: 46rpx;
  955. font-size: 28rpx;
  956. color: #a4a4a4;
  957. }
  958. .shoppingCart .list .item .picTxt .carnum .reduce {
  959. border-right: 0;
  960. border-radius: 3rpx 0 0 3rpx;
  961. }
  962. .shoppingCart .list .item .picTxt .carnum .reduce.on {
  963. border-color: #e3e3e3;
  964. color: #dedede;
  965. }
  966. .shoppingCart .list .item .picTxt .carnum .plus {
  967. border-left: 0;
  968. border-radius: 0 3rpx 3rpx 0;
  969. }
  970. .shoppingCart .list .item .picTxt .carnum .num {
  971. color: #282828;
  972. }
  973. .shoppingCart .invalidGoods {
  974. background-color: #fff;
  975. }
  976. .shoppingCart .invalidGoods .goodsNav {
  977. width: 100%;
  978. height: 66rpx;
  979. padding: 0 30rpx;
  980. box-sizing: border-box;
  981. font-size: 28rpx;
  982. color: #282828;
  983. }
  984. .shoppingCart .invalidGoods .goodsNav .iconfont {
  985. color: #424242;
  986. font-size: 28rpx;
  987. margin-right: 17rpx;
  988. }
  989. .shoppingCart .invalidGoods .goodsNav .del {
  990. font-size: 26rpx;
  991. color: #999;
  992. }
  993. .shoppingCart .invalidGoods .goodsNav .del .icon-shanchu1 {
  994. color: #999;
  995. font-size: 33rpx;
  996. vertical-align: -2rpx;
  997. margin-right: 8rpx;
  998. }
  999. .shoppingCart .invalidGoods .goodsList .item {
  1000. padding: 20rpx 30rpx;
  1001. border-top: 1rpx solid #f5f5f5;
  1002. }
  1003. .shoppingCart .invalidGoods .goodsList .item .invalid {
  1004. font-size: 22rpx;
  1005. color: #fff;
  1006. width: 70rpx;
  1007. height: 36rpx;
  1008. background-color: #aaa;
  1009. border-radius: 3rpx;
  1010. text-align: center;
  1011. line-height: 36rpx;
  1012. }
  1013. .shoppingCart .invalidGoods .goodsList .item .pictrue {
  1014. width: 140rpx;
  1015. height: 140rpx;
  1016. }
  1017. .shoppingCart .invalidGoods .goodsList .item .pictrue image {
  1018. width: 100%;
  1019. height: 100%;
  1020. border-radius: 6rpx;
  1021. }
  1022. .shoppingCart .invalidGoods .goodsList .item .text {
  1023. width: 433rpx;
  1024. font-size: 28rpx;
  1025. color: #999;
  1026. height: 140rpx;
  1027. }
  1028. .shoppingCart .invalidGoods .goodsList .item .text .name {
  1029. width: 100%;
  1030. }
  1031. .shoppingCart .invalidGoods .goodsList .item .text .infor {
  1032. font-size: 24rpx;
  1033. }
  1034. .shoppingCart .invalidGoods .goodsList .item .text .end {
  1035. font-size: 26rpx;
  1036. color: #bbb;
  1037. }
  1038. .shoppingCart .footer {
  1039. z-index: 9;
  1040. width: 100%;
  1041. height: 96rpx;
  1042. background-color: #fafafa;
  1043. position: fixed;
  1044. padding: 0 30rpx;
  1045. box-sizing: border-box;
  1046. border-top: 1rpx solid #eee;
  1047. bottom: var(--window-bottom);
  1048. }
  1049. .shoppingCart .footer .checkAll {
  1050. font-size: 28rpx;
  1051. color: #282828;
  1052. margin-left: 16rpx;
  1053. }
  1054. .shoppingCart .footer .money {
  1055. font-size: 30rpx;
  1056. }
  1057. .shoppingCart .footer .placeOrder {
  1058. color: #fff;
  1059. font-size: 30rpx;
  1060. width: 226rpx;
  1061. height: 70rpx;
  1062. border-radius: 50rpx;
  1063. text-align: center;
  1064. line-height: 70rpx;
  1065. margin-left: 22rpx;
  1066. background-color: var(--view-theme);
  1067. }
  1068. .shoppingCart .footer .button .bnt {
  1069. font-size: 28rpx;
  1070. color: #999;
  1071. border-radius: 50rpx;
  1072. border: 1px solid #999;
  1073. width: 160rpx;
  1074. height: 60rpx;
  1075. text-align: center;
  1076. line-height: 60rpx;
  1077. &.bt-color {
  1078. color: var(--view-theme);
  1079. border: 1rpx solid var(--view-theme);
  1080. }
  1081. }
  1082. .shoppingCart .footer .button form~form {
  1083. margin-left: 17rpx;
  1084. }
  1085. .allcheckbox {
  1086. display: flex;
  1087. align-items: center;
  1088. width: 260rpx;
  1089. .iconfont {
  1090. margin-right: 20rpx;
  1091. font-size: 40rpx;
  1092. color: #CCCCCC;
  1093. }
  1094. .icon-xuanzhong1 {
  1095. color: var(--view-theme);
  1096. }
  1097. }
  1098. </style>
  1099. <style>
  1100. @supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)){
  1101. .shoppingCart .footer{
  1102. bottom: calc(var(--window-bottom) + constant(safe-area-inset-bottom));
  1103. bottom: calc(var(--window-bottom) + env(safe-area-inset-bottom));
  1104. }
  1105. }
  1106. </style>