cart.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. <template>
  2. <!-- 购物车 -->
  3. <view>
  4. <u-navbar :safeAreaInsetTop="true" :placeholder="true">
  5. <view class="u-nav-slot" slot="left">
  6. <view class="">
  7. <text class="shopcart">{{ i18n.Shopping }}</text>
  8. <text class="sum">({{ goodsNum }})</text>
  9. </view>
  10. </view>
  11. <view class="u-nav-slot" slot="right">
  12. <view class="u-flex">
  13. <text @click="admin" v-if="success">{{ i18n.manage }}</text>
  14. <text @click="admin" v-else>{{ i18n.complete }}</text>
  15. <view class="" style="width: 200rpx"></view>
  16. </view>
  17. </view>
  18. </u-navbar>
  19. <u-checkbox-group
  20. v-model="checkboxValue1"
  21. placement="column"
  22. @change="checkboxChange"
  23. >
  24. <view class="box" v-for="(item, idx) in goodsList" :key="idx">
  25. <view class="item">
  26. <view class="shopname u-flex">
  27. <image
  28. src="/static/mine/354.png"
  29. class="circle"
  30. mode="scaleToFill"
  31. @click="shopSelectAll(item.goods)"
  32. v-if="shop(item.goods)"
  33. />
  34. <image
  35. src="/static/mine/353.png"
  36. class="circle"
  37. mode="scaleToFill"
  38. @click="shopSelectAll(item.goods)"
  39. v-else
  40. />
  41. <image
  42. :src="item.image"
  43. style="width: 28rpx; height: 28rpx"
  44. mode=""
  45. ></image>
  46. <text>{{ item.merchant_name }}</text>
  47. <image
  48. src="/static/express/next1.png"
  49. style="width: 32rpx; height: 32rpx"
  50. mode=""
  51. ></image>
  52. </view>
  53. <u-swipe-action>
  54. <view
  55. class="u-flex"
  56. style="margin-top: 30rpx; width: 100%"
  57. v-for="(chid, index) in item.goods"
  58. :key="index"
  59. >
  60. <u-swipe-action-item :options="options2">
  61. <!-- <view class="" style="position: absolute;top: 0;left: 0;width: 100%;height: 100%;z-index: 100;background-color: rgba(255, 255, 255, 0.5);"></view> -->
  62. <u-checkbox
  63. shape="circle"
  64. :customStyle="{ marginBottom: '8px' }"
  65. :name="chid.cart.merchant_goods_id"
  66. activeColor="#F83224"
  67. >
  68. </u-checkbox>
  69. <view
  70. class=""
  71. style="position: relative; width: 172rpx; height: 172rpx"
  72. >
  73. <image
  74. :src="chid.image"
  75. style="width: 172rpx; height: 172rpx"
  76. mode=""
  77. >
  78. </image>
  79. <!-- <view class="sold">
  80. 商品下架
  81. </view> -->
  82. </view>
  83. <view class="good" style="flex: 1">
  84. <view class="goodname">{{ chid.name_cn }}</view>
  85. <view class="goods" v-if="chid.sku_item.length > 0">{{
  86. chid.sku_item[0].item
  87. }}</view>
  88. <view class="" style="margin-top: 21rpx">
  89. <view
  90. class="goodtab"
  91. v-for="itemLabel in chid.label_arr"
  92. :key="itemLabel.id"
  93. >{{ itemLabel.name_cn }}</view
  94. >
  95. </view>
  96. <view
  97. class="u-flex u-row-between"
  98. style="width: 100%; margin-top: 20rpx"
  99. >
  100. <view class="" v-if="chid.sku_item.length > 0">
  101. <text class="money">¥</text>
  102. <text class="money" style="font-size: 30rpx">{{
  103. chid.sku_item[0].price.split(".")[0]
  104. }}</text>
  105. <text class="money"
  106. >.{{ chid.sku_item[0].price.split(".")[1] }}</text
  107. >
  108. <text class="weight"
  109. >{{ chid.sku_item[0].weight }}kg</text
  110. >
  111. </view>
  112. <view class="aaaaaa">
  113. <!-- <view class="delect" v-if='dele'>{{i18n.delete}}</view> -->
  114. <view class="" v-if="num == chid.cart.id && success">
  115. <!-- <u-number-box v-model="value" @change="valChange"></u-number-box> -->
  116. <u-number-box
  117. v-model="chid.cart.goods_num"
  118. @change="addOrReduce"
  119. >
  120. <view slot="minus" class="minus">
  121. <u-icon
  122. name="minus"
  123. color="#B5B5B5"
  124. size="12"
  125. ></u-icon>
  126. </view>
  127. <text
  128. slot="input"
  129. style="
  130. width: 50px;
  131. text-align: center;
  132. font-size: 20rpx;
  133. "
  134. class="input"
  135. >{{ chid.cart.goods_num }}</text
  136. >
  137. <view slot="plus" class="plus">
  138. <u-icon
  139. name="plus"
  140. color="#B5B5B5"
  141. size="12"
  142. ></u-icon>
  143. </view>
  144. </u-number-box>
  145. </view>
  146. <view
  147. class="num"
  148. v-if="num != chid.cart.id && success"
  149. @click="num = chid.cart.id"
  150. >
  151. x{{ chid.cart.goods_num }}
  152. </view>
  153. </view>
  154. <view v-if="success == false" class="icon">
  155. <u-icon name="trash" color="#fff" size="20"></u-icon>
  156. </view>
  157. </view>
  158. </view>
  159. </u-swipe-action-item>
  160. </view>
  161. </u-swipe-action>
  162. </view>
  163. </view>
  164. </u-checkbox-group>
  165. <view class="" style="height: 260rpx"></view>
  166. <kj-tabbar
  167. ref="tabbar1"
  168. :value1="3"
  169. @allSelect="allSelect"
  170. :goodsWeight="goodsWeight"
  171. :goodsPrice="goodsPrice"
  172. ></kj-tabbar>
  173. </view>
  174. </template>
  175. <script>
  176. export default {
  177. data() {
  178. return {
  179. dele: true,
  180. success: true,
  181. shopitem: -1,
  182. checkboxValue1: [], //商品数组
  183. value: 0,
  184. all: [], //全选数组
  185. goodsList: [],
  186. selectall: -1,
  187. goodsNum: 0,
  188. num: false,
  189. goodsWeight: 0, //商品重量
  190. goodsPrice: 0, //商品价格
  191. options2: [
  192. {
  193. text: "移入关注",
  194. style: {
  195. backgroundColor: "#FFB115",
  196. },
  197. },
  198. {
  199. text: "删除",
  200. style: {
  201. backgroundColor: "#F83224",
  202. },
  203. },
  204. ],
  205. tabarheight: "",
  206. };
  207. },
  208. computed: {
  209. i18n() {
  210. return this.$t("index");
  211. },
  212. },
  213. onLoad() {
  214. const systemInfo = wx.getSystemInfoSync();
  215. const tab =
  216. systemInfo.screenHeight -
  217. systemInfo.safeArea.bottom +
  218. systemInfo.statusBarHeight;
  219. this.tabarheight = tab;
  220. },
  221. methods: {
  222. shop(value) {
  223. let num = 0;
  224. value.map((item) => {
  225. if (this.checkboxValue1.indexOf(item.cart.merchant_goods_id) >= 0) {
  226. num++;
  227. }
  228. });
  229. return num;
  230. },
  231. addOrReduce(n) {
  232. uni.$u.http
  233. .post(`/api/cart/num/${this.num}`, { goods_num: n.value, type: "" })
  234. .then((res) => {
  235. console.log(res);
  236. });
  237. },
  238. //店铺商品全选
  239. shopSelectAll(value) {
  240. //先判断存放选中的数组有没有选中的数据
  241. if (this.checkboxValue1.length == 0) {
  242. //没有数据则直接将选中店铺中的商品存入数组
  243. value.map((item) => {
  244. this.checkboxValue1.push(item.cart.merchant_goods_id);
  245. });
  246. } else {
  247. if (this.shop(value) > 0 && this.shop(value) == value.length) {
  248. value.map((item) => {
  249. //先判断选中的商品数组中该店铺商品是否已被选中,已被选中则取消选中,未被选中则推入选中状态
  250. if (this.checkboxValue1.indexOf(item.cart.merchant_goods_id) >= 0) {
  251. this.checkboxValue1.splice(
  252. this.checkboxValue1.indexOf(item.cart.merchant_goods_id),
  253. 1
  254. );
  255. }
  256. });
  257. } else if (
  258. (this.shop(value) > 0 && this.shop(value) != value.length) ||
  259. this.shop(value) == 0
  260. ) {
  261. value.map((item) => {
  262. //先判断选中的商品数组中该店铺商品是否已被选中,已被选中则取消选中,未被选中则推入选中状态
  263. if (
  264. this.checkboxValue1.indexOf(item.cart.merchant_goods_id) == -1
  265. ) {
  266. this.checkboxValue1.push(item.cart.merchant_goods_id);
  267. }
  268. });
  269. }
  270. }
  271. if (this.checkboxValue1.length == this.goodsNum) {
  272. this.$refs.tabbar1.cancelAll();
  273. } else {
  274. this.$refs.tabbar1.cancelAll("取消");
  275. }
  276. this.shop(value);
  277. },
  278. admin() {
  279. this.success = !this.success;
  280. },
  281. valChange(e) {
  282. console.log("当前值为: " + e.value);
  283. },
  284. //全选
  285. checkAll(e) {
  286. console.log("all", e);
  287. },
  288. checkboxChange(n) {
  289. this.goodsWeight = 0;
  290. this.goodsPrice = 0;
  291. this.checkboxValue1 = n;
  292. this.goodsList.map((item) => {
  293. item.goods.map((items) => {
  294. if (n.indexOf(items.id) > -1) {
  295. this.goodsWeight += items.sku_item[0].weight;
  296. this.goodsPrice += Number(items.sku_item[0].price);
  297. }
  298. });
  299. });
  300. //判断是否全部选中
  301. if (this.checkboxValue1.length == this.goodsNum && this.goodsNum != 0) {
  302. this.$refs.tabbar1.cancelAll();
  303. } else if (this.checkboxValue1.length < this.goodsNum) {
  304. this.$refs.tabbar1.cancelAll("取消");
  305. }
  306. },
  307. //购物车全选
  308. allSelect() {
  309. const all = this.$refs.tabbar1.cancelAll("全选");
  310. if (this.checkboxValue1.length == this.goodsNum && all.length == 0) {
  311. return;
  312. }
  313. console.log(this.checkboxValue1.length, this.goodsNum);
  314. console.log(this.checkboxValue1, this.goodsNum);
  315. //判断是否已经全选,如已全选,则取消全选
  316. if (this.checkboxValue1.length == this.goodsNum) {
  317. this.checkboxValue1 = [];
  318. this.goodsPrice = 0;
  319. this.goodsWeight = 0;
  320. } else {
  321. this.goodsList.map((item) => {
  322. item.goods.map((items) => {
  323. //判断是否有商品已被选中
  324. if (
  325. this.checkboxValue1.indexOf(items.cart.merchant_goods_id) == -1
  326. ) {
  327. this.checkboxValue1.push(items.cart.merchant_goods_id);
  328. this.goodsWeight += items.sku_item[0].weight;
  329. this.goodsPrice += Number(items.sku_item[0].price);
  330. }
  331. });
  332. });
  333. }
  334. },
  335. //获取购物车数据
  336. getShopCarList() {
  337. uni.$u.http.get(`/api/cart`).then((res) => {
  338. this.goodsList = res.data;
  339. //循环店铺,获取购物车商品数量
  340. this.goodsList.map((item) => {
  341. this.goodsNum += item.goods.length;
  342. });
  343. });
  344. },
  345. },
  346. mounted() {
  347. this.getShopCarList();
  348. },
  349. };
  350. </script>
  351. <style lang="scss" scoped>
  352. .sold {
  353. width: 108rpx;
  354. height: 36rpx;
  355. background: rgba(0, 0, 0, 0.4);
  356. border-radius: 18rpx;
  357. // padding: 0 14rpx;
  358. text-align: center;
  359. box-sizing: border-box;
  360. line-height: 36rpx;
  361. font-family: PingFangSC, PingFang SC;
  362. font-weight: 400;
  363. font-size: 20rpx;
  364. color: #ffffff;
  365. font-style: normal;
  366. position: absolute;
  367. top: 50%;
  368. left: 50%;
  369. margin-top: -18rpx;
  370. margin-left: -54rpx;
  371. }
  372. .delect {
  373. // width: 68rpx;
  374. height: 44rpx;
  375. line-height: 44rpx;
  376. border-radius: 22rpx;
  377. border: 1rpx solid #ff1515;
  378. padding: 0 14rpx;
  379. box-sizing: border-box;
  380. font-family: PingFangSC, PingFang SC;
  381. font-weight: 400;
  382. font-size: 20rpx;
  383. color: #ff1515;
  384. text-align: center;
  385. font-style: normal;
  386. }
  387. .allweight {
  388. font-family: PingFangSC, PingFang SC;
  389. font-weight: 400;
  390. font-size: 22rpx;
  391. color: #333333;
  392. line-height: 32rpx;
  393. text-align: left;
  394. font-style: normal;
  395. }
  396. .sum {
  397. font-family: PingFangSC, PingFang SC;
  398. font-weight: 400;
  399. font-size: 22rpx;
  400. color: #333333;
  401. line-height: 32rpx;
  402. text-align: left;
  403. font-style: normal;
  404. }
  405. .summon {
  406. font-family: JDZhengHT, JDZhengHT;
  407. font-weight: 400;
  408. font-size: 24rpx;
  409. color: #ff1515;
  410. line-height: 30rpx;
  411. text-align: left;
  412. font-style: normal;
  413. }
  414. .settle {
  415. width: 176rpx;
  416. height: 68rpx;
  417. background: #f83224;
  418. border-radius: 38rpx;
  419. font-family: PingFangSC, PingFang SC;
  420. font-weight: 500;
  421. font-size: 28rpx;
  422. color: #ffffff;
  423. line-height: 68rpx;
  424. text-align: center;
  425. font-style: normal;
  426. margin-left: 20rpx;
  427. }
  428. .icon {
  429. width: 40rpx;
  430. height: 40rpx;
  431. background: #f83224;
  432. border-radius: 12rpx;
  433. display: flex;
  434. justify-content: center;
  435. align-items: center;
  436. }
  437. .dle {
  438. width: 136rpx;
  439. height: 60rpx;
  440. border-radius: 38rpx;
  441. border: 1rpx solid #979797;
  442. font-family: PingFangSC, PingFang SC;
  443. font-weight: 400;
  444. font-size: 26rpx;
  445. color: #333333;
  446. line-height: 60rpx;
  447. text-align: center;
  448. font-style: normal;
  449. }
  450. ::v-deep .u-swipe-action-item__content {
  451. flex-direction: row !important;
  452. }
  453. ::v-deep .u-swipe-action-item {
  454. width: 100% !important;
  455. }
  456. ::v-deep .u-swipe-action-item__right {
  457. top: 2rpx !important;
  458. right: 2rpx !important;
  459. bottom: 2rpx !important;
  460. }
  461. .bottom {
  462. width: 750rpx;
  463. height: 100rpx;
  464. background: #ffffff;
  465. padding: 0 24rpx;
  466. box-sizing: border-box;
  467. }
  468. .num {
  469. width: 40rpx;
  470. height: 40rpx;
  471. border-radius: 20rpx;
  472. border: 1rpx solid rgba(151, 151, 151, 0.4);
  473. font-family: HarmonyOS_Sans;
  474. font-size: 20rpx;
  475. color: #222222;
  476. line-height: 40rpx;
  477. text-align: center;
  478. font-style: normal;
  479. }
  480. .box {
  481. padding: 0rpx 24rpx 20rpx;
  482. margin-top: 20rpx;
  483. box-sizing: border-box;
  484. .item {
  485. padding: 36rpx 20rpx;
  486. box-sizing: border-box;
  487. width: 702rpx;
  488. // height: 556rpx;
  489. background: #ffffff;
  490. border-radius: 16rpx;
  491. .money {
  492. font-family: HarmonyOS_Sans_Medium;
  493. font-size: 20rpx;
  494. color: #ff1515;
  495. line-height: 26rpx;
  496. text-align: left;
  497. font-style: normal;
  498. }
  499. .weight {
  500. font-family: SFPro, SFPro;
  501. font-weight: 400;
  502. font-size: 20rpx;
  503. color: #333333;
  504. line-height: 24rpx;
  505. text-align: left;
  506. font-style: normal;
  507. margin-left: 12rpx;
  508. }
  509. .goodtab {
  510. // width: 96rpx;
  511. height: 32rpx;
  512. border-radius: 4rpx;
  513. border: 1rpx solid #ff1515;
  514. padding: 2rpx 8rpx;
  515. box-sizing: border-box;
  516. text-align: center;
  517. line-height: 32rpx;
  518. display: inline;
  519. font-family: PingFangSC, PingFang SC;
  520. font-weight: 400;
  521. font-size: 20rpx;
  522. color: #ff1515;
  523. line-height: 28rpx;
  524. text-align: left;
  525. font-style: normal;
  526. margin-right: 6rpx;
  527. }
  528. .goods {
  529. // width: 284rpx;
  530. height: 40rpx;
  531. background: #f4f4f4;
  532. border-radius: 8rpx;
  533. display: inline;
  534. text-align: center;
  535. line-height: 40rpx;
  536. margin-top: 20rpx;
  537. padding: 6rpx 12rpx;
  538. box-sizing: border-box;
  539. font-family: PingFangSC, PingFang SC;
  540. font-weight: 400;
  541. font-size: 20rpx;
  542. color: #555555;
  543. line-height: 28rpx;
  544. text-align: left;
  545. font-style: normal;
  546. }
  547. .goodname {
  548. font-family: PingFangSC, PingFang SC;
  549. font-weight: 500;
  550. font-size: 28rpx;
  551. color: #333333;
  552. line-height: 40rpx;
  553. text-align: left;
  554. font-style: normal;
  555. }
  556. .shopname {
  557. font-family: PingFangSC, PingFang SC;
  558. font-weight: 500;
  559. font-size: 26rpx;
  560. color: #333333;
  561. line-height: 36rpx;
  562. text-align: left;
  563. font-style: normal;
  564. .circle {
  565. width: 32rpx;
  566. height: 32rpx;
  567. margin-right: 10rpx;
  568. }
  569. }
  570. }
  571. }
  572. .shopcart {
  573. font-family: PingFangSC, PingFang SC;
  574. font-weight: 500;
  575. font-size: 36rpx;
  576. color: #222222;
  577. line-height: 50rpx;
  578. text-align: right;
  579. font-style: normal;
  580. }
  581. .sum {
  582. font-family: HarmonyOS_Sans;
  583. font-size: 22rpx;
  584. color: #333333;
  585. line-height: 32rpx;
  586. text-align: left;
  587. font-style: normal;
  588. }
  589. </style>