order_addcart.vue 33 KB

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