shopping-cart.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. <template>
  2. <view class="cartbox">
  3. <view class="topEditOpar" v-if="goodsList.length>0">
  4. <!-- <view class="">
  5. 有心仪的宝贝,快去下单吧~
  6. </view> -->
  7. <view class="text opartxt" @click="isEdit = !isEdit">
  8. {{isEdit?'完成':'管理'}}
  9. </view>
  10. </view>
  11. <NoData v-if="finish&&goodsList.length<1"></NoData>
  12. <view class="scrollbox" v-else>
  13. <!-- 购物车列表 -->
  14. <view class="cart-list">
  15. <view class="item" v-for="(goods, index) in goodsList" :key="index">
  16. <u-icon class="delIcon" name="trash" color="#999" @click.stop="delCartGoods(goods.id,index)"></u-icon>
  17. <view class="left">
  18. <u-checkbox shape="circle" active-color="#ed3f14" icon-size="16" :disabled="goods.status==2&&!isEdit"
  19. v-model="goods.checked"></u-checkbox>
  20. </view>
  21. <view class="right" @click.stop="goGoodsDetail(goods.goods_id)">
  22. <view class="chuo" v-if="goods.status==2">
  23. 已下架
  24. </view>
  25. <view class="img">
  26. <image :src="goods.goods.cover" mode=""></image>
  27. </view>
  28. <view class="info">
  29. <view class="title">{{ goods.goods.title }}</view>
  30. <!-- <view class="sku">{{ goods.difference }}</view> -->
  31. <u-tag :text="goods.difference" type="info" />
  32. <view class="operate">
  33. <view class="price">
  34. <text>¥</text>
  35. <text>{{ goods.amount }}</text>
  36. </view>
  37. <view class="num">
  38. <u-number-box v-model="goods.nums" :min="1" :max="5" :disabled-input="true"
  39. @minus="e=>changeNums(e,goods.id)" @plus="e=>changeNums(e,goods.id)"></u-number-box>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. </view>
  47. <!-- 底部按钮 -->
  48. <view class="bottom_opar" v-if="isEdit">
  49. <view class="check">
  50. <u-checkbox shape="circle" active-color="#ed3f14" icon-size="16" v-model="checkAllStauts"
  51. @change="checkAllGoods">全选</u-checkbox>
  52. <!-- <text>全选</text> -->
  53. </view>
  54. <view class="right">
  55. <view class="soldOutBtn" v-if="isJiesuanBtn">
  56. 删除
  57. </view>
  58. <view class="buyBtn" v-else @click="delCarts">
  59. 删除({{ goodsList.filter(item => item.checked).length }})
  60. </view>
  61. </view>
  62. </view>
  63. <view class="bottom_opar" v-else>
  64. <view class="check">
  65. <u-checkbox shape="circle" active-color="#ed3f14" icon-size="16" v-model="checkAllStauts"
  66. @change="checkAllGoods">全选</u-checkbox>
  67. <!-- <text>全选</text> -->
  68. </view>
  69. <view class="right">
  70. <view class="price">
  71. <text>合计:</text>
  72. <text>¥</text>
  73. <text>{{ parseFloat(totalPrice).toFixed(2) }}</text>
  74. </view>
  75. <!-- <u-button type="primary" :disabled="isJiesuanBtn" @click="goPayResult">
  76. 去结算({{ goodsList.filter(item => item.checked).length }})
  77. </u-button> -->
  78. <view class="soldOutBtn" v-if="isJiesuanBtn">
  79. 去结算
  80. </view>
  81. <view class="buyBtn" v-else @click="goPayResult">
  82. 去结算({{ goodsList.filter(item => item.checked).length }})
  83. </view>
  84. </view>
  85. </view>
  86. </view>
  87. </template>
  88. <script>
  89. var _self;
  90. export default {
  91. data() {
  92. return {
  93. isEdit:false,
  94. // showJiesuan:false,
  95. showRecommend: false, //是否显示推荐商品
  96. loading: false,
  97. page: 1,
  98. finish: false,
  99. totalPrice: 0,
  100. checkAllStauts: false,
  101. goodsList: [],
  102. isBiangeng: false,
  103. pullDown: false,
  104. };
  105. },
  106. computed: {
  107. checkAll() {
  108. let newList = this.goodsList;
  109. if(!this.isEdit){
  110. // 编辑状态
  111. newList = this.goodsList.filter(item=>item.status==1)
  112. }
  113. this.totalPrice = 0;
  114. if (newList.length < 1) {
  115. this.checkAllStauts = false;
  116. return;
  117. }
  118. newList.map(item => (item.checked ? (this.totalPrice += Number(item.amount) * item.nums) : 0));
  119. if (newList.filter(item => item.checked).length == newList.length) {
  120. this.checkAllStauts = true;
  121. } else {
  122. this.checkAllStauts = false;
  123. }
  124. },
  125. canBuyGoods(){
  126. return this.goodsList.filter(item=>item.status==1)
  127. },
  128. isJiesuanBtn() {
  129. return this.goodsList.filter(item => item.checked).length <= 0;
  130. },
  131. },
  132. onLoad() {
  133. _self = this;
  134. },
  135. onPullDownRefresh() {
  136. this.pullDown = true;
  137. this.reData();
  138. },
  139. onShow() {
  140. this.reData();
  141. },
  142. onReachBottom() {
  143. console.log('滚动到底部')
  144. // this.getData();
  145. this.getCartList();
  146. },
  147. methods: {
  148. reData(){
  149. this.finish = false;
  150. this.loading = false;
  151. this.page = 1;
  152. this.getCartList();
  153. },
  154. // 批量删除
  155. delCarts(){
  156. let selItems = this.goodsList.filter(item => item.checked);
  157. if(selItems.length>0){
  158. let ids = selItems.map(e=>e.id);
  159. _self.delCartGoods(ids.toString());
  160. }
  161. },
  162. // 删除
  163. delCartGoods(id, index) {
  164. console.log('>>>>>', id);
  165. uni.showModal({
  166. title: '提示',
  167. content: '确认要删除选择的商品吗?',
  168. success: function(res) {
  169. if (res.confirm) {
  170. _self.$u.api.delCartGoodsAjax(id).then(({code, data,msg}) => {
  171. if (code == 1) {
  172. _self.$u.toast(msg)
  173. if(_self.isEdit){
  174. _self.reData();
  175. return;
  176. }
  177. if(index||index==0){
  178. _self.goodsList.splice(index, 1);
  179. }
  180. }
  181. }).catch(() => {})
  182. }
  183. }
  184. });
  185. },
  186. changeNums(e, id) {
  187. uni.showLoading();
  188. this.$u.api.updateCartNumsAjax({
  189. cart_id: id,
  190. nums: e.value
  191. }).then(({
  192. code,
  193. data
  194. }) => {
  195. console.log(code, data)
  196. uni.hideLoading();
  197. }).catch(() => {
  198. uni.hideLoading();
  199. })
  200. },
  201. checkAllGoods() {
  202. if (this.checkAllStauts) {
  203. this.goodsList.forEach(item => (item.checked = false));
  204. } else {
  205. this.goodsList.forEach(item => (item.checked = true));
  206. }
  207. this.$forceUpdate();
  208. },
  209. goGoodsDetail(id) {
  210. uni.navigateTo({
  211. url: '/pages-mall/pages/goods/detail?goodsId=' + id
  212. });
  213. },
  214. goPayResult() {
  215. // goodsList.filter(item => item.checked).length<=0
  216. let orderInfos = [];
  217. let cartIds = [];
  218. _self.goodsList.forEach(e => {
  219. if (e.checked) {
  220. cartIds.push(e.id);
  221. orderInfos.push({
  222. id: e.goods_id,
  223. cover: e.goods.cover,
  224. isbn: '',
  225. price_selling: e.amount,
  226. publish: '',
  227. title: e.goods.title,
  228. nums: e.nums,
  229. selectdSku: {
  230. id: e.sku_id,
  231. difference: e.difference,
  232. price_selling: e.amount,
  233. },
  234. })
  235. }
  236. })
  237. console.log(orderInfos);
  238. uni.navigateTo({
  239. url: '/pages-mall/pages/order/submit?cartIds=' + cartIds.toString() + '&orderInfo=' + encodeURIComponent(
  240. JSON.stringify(orderInfos))
  241. });
  242. },
  243. getCartList() {
  244. if (this.finish) return false;
  245. if (this.loading) return false;
  246. this.loading = true;
  247. this.$u.api.getCartListAjax().then(({
  248. code,
  249. data
  250. }) => {
  251. if (this.pullDown) {
  252. uni.stopPullDownRefresh();
  253. this.pullDown = false;
  254. }
  255. this.isBiangeng = true;
  256. console.log(code, data)
  257. this.loading = false;
  258. let returnData = data.data;
  259. if (code == 1) {
  260. if (data.last_page <= data.current_page) {
  261. this.finish = true;
  262. }
  263. returnData.forEach(e => {
  264. e.checked = false;
  265. })
  266. if (data.current_page == 1) {
  267. this.goodsList = returnData;
  268. } else {
  269. this.goodsList = this.goodsList.concat(returnData);
  270. }
  271. this.page++;
  272. console.log(this.goodsList);
  273. } else {
  274. this.finish = true;
  275. }
  276. }).catch(() => {
  277. this.loading = false;
  278. this.finish = true;
  279. })
  280. },
  281. // nextPage(e){
  282. // if(this.finish){
  283. // /* 已滚动到底部,不继续加载 */
  284. // return false;
  285. // }
  286. // console.log(e);
  287. // this.page++;
  288. // this.getUserCouponList();
  289. // },
  290. }
  291. };
  292. </script>
  293. <style lang="scss" scoped>
  294. .topOpar{
  295. height: 80rpx;
  296. text-align: right;
  297. background-color: $app-theme-light-color;
  298. display: flex;
  299. align-items: center;
  300. justify-content: space-between;
  301. padding: 0 30rpx;
  302. margin-bottom: 20rpx;
  303. }
  304. .cartbox {
  305. height: 100vh;
  306. background: $app-theme-bg-gray-color;
  307. padding-top: 20rpx;
  308. }
  309. .scrollbox {
  310. // height: 100%;
  311. padding-bottom: 100rpx;
  312. box-sizing: border-box;
  313. }
  314. /deep/.u-icon {
  315. display: flex !important;
  316. }
  317. .delIcon {
  318. position: absolute;
  319. top: 10rpx;
  320. right: 10rpx;
  321. }
  322. .cart-list {
  323. .item {
  324. display: flex;
  325. align-items: center;
  326. background-color: $app-theme-bg-color;
  327. padding: 30rpx 24rpx 30rpx 24rpx;
  328. border-bottom: 1rpx solid $app-theme-border-color;
  329. position: relative;
  330. .left {
  331. display: flex;
  332. align-items: center;
  333. width: 46rpx;
  334. }
  335. .right {
  336. width: calc(100% - 46rpx);
  337. display: flex;
  338. align-items: center;
  339. position: relative;
  340. .img {
  341. width: 160rpx;
  342. height: 160rpx;
  343. margin-right: 20rpx;
  344. image {
  345. width: 100%;
  346. height: 100%;
  347. }
  348. }
  349. .info {
  350. width: 418rpx;
  351. .title {
  352. font-size: 28rpx;
  353. font-family: PingFang-SC-Regular, PingFang-SC;
  354. font-weight: 400;
  355. color: $app-theme-text-black-color;
  356. padding-bottom: 16rpx;
  357. }
  358. .sku {
  359. font-size: 22rpx;
  360. font-family: PingFang-SC-Regular, PingFang-SC;
  361. font-weight: 400;
  362. background: $app-theme-bg-gray-color;
  363. border-radius: 2px;
  364. color: $app-theme-card-gray-deep-color;
  365. padding: 4rpx 16rpx;
  366. }
  367. .operate {
  368. padding-top: 30rpx;
  369. display: flex;
  370. align-items: center;
  371. justify-content: space-between;
  372. .price {
  373. text:nth-child(1) {
  374. font-size: 24rpx;
  375. font-family: PingFangSC-Medium, PingFang SC;
  376. font-weight: 500;
  377. color: $app-theme-text-money-color;
  378. }
  379. text:nth-child(2) {
  380. font-size: 36rpx;
  381. font-family: PingFangSC-Regular, PingFang SC;
  382. font-weight: 400;
  383. color: $app-theme-text-money-color;
  384. }
  385. }
  386. .num {}
  387. }
  388. }
  389. }
  390. }
  391. }
  392. .bottom_opar {
  393. position: fixed;
  394. bottom: 0;
  395. left: 0;
  396. width: 100%;
  397. background-color: $app-theme-bg-color;
  398. height: 100rpx;
  399. z-index: $app-zIndex-fixed;
  400. display: flex;
  401. justify-content: space-between;
  402. align-items: center;
  403. .check {
  404. padding-left: 30rpx;
  405. display: flex;
  406. align-items: center;
  407. text {
  408. font-size: 28rpx;
  409. font-weight: 400;
  410. color: $app-theme-text-black-color;
  411. }
  412. }
  413. .right {
  414. display: flex;
  415. align-items: center;
  416. .price {
  417. margin-right: 54rpx;
  418. text:nth-child(1) {
  419. font-size: 28rpx;
  420. font-family: PingFangSC-Regular, PingFang SC;
  421. font-weight: 400;
  422. color: $app-theme-text-black-color;
  423. }
  424. text:nth-child(2) {
  425. font-size: 24rpx;
  426. font-family: PingFangSC-Medium, PingFang SC;
  427. font-weight: 500;
  428. color: $app-theme-text-money-color;
  429. }
  430. text:nth-child(3) {
  431. font-size: 36rpx;
  432. font-family: PingFangSC-Regular, PingFang SC;
  433. font-weight: 400;
  434. color: $app-theme-text-money-color;
  435. }
  436. }
  437. }
  438. }
  439. .topEditOpar{
  440. display: flex;
  441. padding: 10rpx 20rpx;
  442. display: flex;
  443. align-items: center;
  444. justify-content: space-between;
  445. text-align: center;
  446. .text{
  447. flex: 1;
  448. text-align: right;
  449. font-weight: bold;
  450. font-size: 32rpx;
  451. }
  452. .opartxt{
  453. color: $app-theme-deep-color;
  454. }
  455. }
  456. .chuo{
  457. position: absolute;
  458. width: 90rpx;
  459. height: 90rpx;
  460. border-radius: 50%;
  461. color: #fff;
  462. display: flex;
  463. align-items: center;
  464. justify-content: center;
  465. background-color: rgba(0, 0, 0, .5);
  466. top: 40rpx;
  467. left: 40rpx;
  468. transform: rotate(30deg);
  469. font-size: 24rpx;
  470. }
  471. </style>