shopModel.vue 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  1. <template>
  2. <view class="cart_list">
  3. <template v-if="list.length">
  4. <view class="list_wrapper" v-for="(item, index) in list" :key="index">
  5. <view class="cart_wrapper">
  6. <view class="checkout">
  7. <up-checkbox-group
  8. :modelValue="isTrue"
  9. activeColor="var(--black)"
  10. shape="circle"
  11. labelSize="14"
  12. labelColor="#676969"
  13. iconSize="16"
  14. @change="
  15. checkedChanges(item.seller_id, item.seller_id, true, $event)
  16. "
  17. >
  18. <up-checkbox :name="item.seller_id" />
  19. </up-checkbox-group>
  20. </view>
  21. <view class="img">
  22. <image
  23. :src="`../../static/shop/icon_${item.channel}.png`"
  24. class="cart_icon"
  25. ></image>
  26. </view>
  27. <view class="cart_name">{{ item.seller_name }}</view>
  28. </view>
  29. <view class="cart_cont">
  30. <view class="cont_list" v-for="(val, num) in item.goods" :key="num">
  31. <view class="checkout">
  32. <up-checkbox-group
  33. activeColor="var(--black)"
  34. shape="circle"
  35. labelSize="14"
  36. labelColor="#676969"
  37. iconSize="16"
  38. :modelValue="isItemTrue"
  39. @change="checkedChanges(val.seller_id, val.id, false)"
  40. >
  41. <up-checkbox :name="val.id" />
  42. </up-checkbox-group>
  43. </view>
  44. <view class="img">
  45. <image :src="val.pic_url" class="list_icon"></image>
  46. </view>
  47. <view class="goods_info">
  48. <view class="info_name">{{ val.title }}</view>
  49. <view class="info_desc">{{ val.sku_desc }}</view>
  50. <view class="info_price">
  51. <view class="unit_price">
  52. <text>{{ symbol.symbol }}</text>
  53. <text>{{ Moneyhtml(val.price) }}</text>
  54. </view>
  55. <view class="unit_num">
  56. <up-number-box
  57. v-model="val.total"
  58. :min="0"
  59. @change="(newVal) => totalChange(newVal, val)"
  60. ></up-number-box>
  61. </view>
  62. </view>
  63. </view>
  64. </view>
  65. </view>
  66. </view>
  67. </template>
  68. <view class="no_data" v-else>
  69. <image class="img" mode="widthFix" src="@/static/no_data.png"></image>
  70. <trans _t="无数据" class="tips" />
  71. </view>
  72. </view>
  73. </template>
  74. <script setup>
  75. import { ref, computed } from "vue";
  76. import { useSystemStore, useShopStore } from "@/store";
  77. import { SHOP_EDIT_CART, SHOP_CART_DEL } from "@/api";
  78. import { Moneyhtml, Toast } from "@/utils";
  79. const props = defineProps({
  80. list: {
  81. type: Array,
  82. default: () => [],
  83. },
  84. isFree: {
  85. type: Number,
  86. default: 0,
  87. },
  88. });
  89. const emit = defineEmits(["getIds"]);
  90. const ids = ref({});
  91. const useSystem = useSystemStore();
  92. const useShop = useShopStore();
  93. const symbol = computed(() => useSystem.getSymbol);
  94. const allObj = computed(() => {
  95. let result = props.list.reduce((acc, item) => {
  96. acc[item.seller_id] = item.goods.map((good) => good.id);
  97. return acc;
  98. }, {});
  99. return result;
  100. });
  101. const isTrue = computed(() => {
  102. let arr = findDifferentKeys(allObj.value, ids.value);
  103. return arr;
  104. });
  105. const isItemTrue = computed(() => {
  106. let arr = Object.values(ids.value);
  107. let arr1 = Object.values(allObj.value);
  108. let new_arr = arr.flat(1);
  109. let new_arr1 = arr1.flat(1);
  110. let flag = new_arr1.every((value) => new_arr.includes(value));
  111. emit("getIds", ids.value, flag);
  112. return new_arr;
  113. });
  114. const findDifferentKeys = (obj1, obj2) => {
  115. let result = [];
  116. for (let key in obj2) {
  117. if (obj1.hasOwnProperty(key)) {
  118. const isSubset = obj1[key].every((value) => obj2[key].includes(value));
  119. if (isSubset) {
  120. result.push(key);
  121. }
  122. }
  123. }
  124. return result;
  125. };
  126. const checkedChanges = (e, id, flag, e_new) => {
  127. const results = JSON.parse(JSON.stringify(ids.value));
  128. let arr = results[e] || [];
  129. if (flag) {
  130. results[e] = e_new[0] ? JSON.parse(JSON.stringify(allObj.value))[e] : [];
  131. ids.value = results;
  132. return;
  133. }
  134. if (!arr) {
  135. arr = [];
  136. }
  137. const effectiveId = flag ? id : id;
  138. let findIndex = arr.findIndex((item) => item == effectiveId);
  139. if (findIndex == -1 && !flag) {
  140. arr.push(effectiveId);
  141. } else {
  142. arr = arr.filter((item) => item != effectiveId);
  143. }
  144. results[e] = arr;
  145. ids.value = results;
  146. };
  147. const allStatus = (flag) => {
  148. let objs = JSON.parse(JSON.stringify(allObj.value));
  149. ids.value = flag ? objs : {};
  150. };
  151. const totalChange = async (total, item) => {
  152. try {
  153. let para = {
  154. id: item.id,
  155. total: total.value,
  156. };
  157. if (total.value) {
  158. await SHOP_EDIT_CART(para);
  159. } else {
  160. await SHOP_CART_DEL(item.id);
  161. }
  162. useShop.setCartList(props.isFree);
  163. } catch (error) {
  164. Toast(error.msg);
  165. }
  166. };
  167. defineExpose({
  168. allStatus,
  169. });
  170. </script>
  171. <style lang="less" scoped>
  172. @import url("@/style.less");
  173. .cart_list {
  174. padding-bottom: 60rpx;
  175. .list_wrapper {
  176. background-color: var(--light);
  177. .flex();
  178. flex-direction: column;
  179. gap: 24rpx;
  180. margin-bottom: 24rpx;
  181. padding: 24rpx;
  182. .cart_wrapper {
  183. .ver();
  184. .cart_icon {
  185. width: 48rpx;
  186. height: 48rpx;
  187. display: block;
  188. margin-left: 24rpx;
  189. }
  190. .cart_name {
  191. .size(28rpx);
  192. font-weight: 700;
  193. color: var(--text);
  194. margin-left: 24rpx;
  195. }
  196. }
  197. .cart_cont {
  198. .flex();
  199. flex-direction: column;
  200. gap: 24rpx;
  201. .cont_list {
  202. .flex();
  203. column-gap: 16rpx;
  204. .checkout {
  205. flex: 1;
  206. }
  207. .img {
  208. width: 128rpx;
  209. height: 128rpx;
  210. .list_icon {
  211. flex: 0 1 auto;
  212. max-width: 100%;
  213. height: 100%;
  214. border-radius: 16rpx;
  215. }
  216. }
  217. .goods_info {
  218. .size(24rpx);
  219. .info_name {
  220. font-weight: 700;
  221. color: var(--text);
  222. line-height: 48rpx;
  223. }
  224. .info_desc {
  225. color: var(--text-01);
  226. font-weight: 400;
  227. line-height: 40rpx;
  228. margin-top: 8rpx;
  229. }
  230. .info_price {
  231. .flex_position(space-between);
  232. margin-top: 16rpx;
  233. .unit_price {
  234. .size(36rpx);
  235. color: var(--red);
  236. font-weight: 700;
  237. line-height: 60rpx;
  238. .ver();
  239. column-gap: 8rpx;
  240. }
  241. .unit_num {
  242. display: flex;
  243. background-color: var(--bg);
  244. border-radius: 8rpx;
  245. color: var(--red);
  246. .size(24rpx);
  247. line-height: 40rpx;
  248. padding: 4rpx 8rpx;
  249. /deep/ .u-number-box {
  250. border: 1px solid #dcdfe6;
  251. border-radius: 16rpx;
  252. .u-number-box__minus,
  253. .u-number-box__plus {
  254. width: 56rpx !important;
  255. height: 56rpx !important;
  256. background-color: transparent !important;
  257. .u-icon__icon {
  258. .size(26rpx) !important;
  259. color: var(--text) !important;
  260. }
  261. &--hover {
  262. .u-icon__icon {
  263. color: var(--primary) !important;
  264. }
  265. }
  266. }
  267. .u-number-box__input {
  268. margin: 0;
  269. border-left: 1px solid #dcdfe6;
  270. border-right: 1px solid #dcdfe6;
  271. height: 56rpx !important;
  272. width: 60rpx !important;
  273. background-color: transparent !important;
  274. }
  275. }
  276. }
  277. }
  278. }
  279. }
  280. }
  281. }
  282. .no_data {
  283. margin-top: 30%;
  284. .ver();
  285. flex-direction: column;
  286. justify-content: space-between;
  287. .img {
  288. width: 348rpx;
  289. }
  290. .tips {
  291. margin-top: 4%;
  292. text-align: center;
  293. font-size: 28rpx;
  294. color: #333;
  295. }
  296. }
  297. }
  298. </style>