index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <template>
  2. <div class="cart-pages">
  3. <div class="cart-bos">
  4. <div class="cart-head flex-row-between">
  5. <div class="flex-row-start head1">
  6. <img src="@/assets/images/cart1.png" alt="" />
  7. <div>我的购物车</div>
  8. </div>
  9. <div class="head2">导出订单</div>
  10. </div>
  11. <el-table
  12. ref="multipleTableRef"
  13. :data="tableData"
  14. style="width: 100%"
  15. :header-cell-style="{
  16. color: '#1D2129',
  17. backgroundColor: '#F2F3F5',
  18. fontWeight: 'normal'
  19. }"
  20. @selection-change="handleSelectionChange1"
  21. >
  22. <el-table-column type="selection" width="55" />
  23. <el-table-column label="商品信息" width="490">
  24. <template #default="scope">
  25. <div class="cart-info">
  26. <img class="cart-img" :src="scope.row.productImage" alt="" />
  27. <div class="cart-text">
  28. <div class="text1">{{ scope.row.itemName }}</div>
  29. <div class="text2">
  30. <span>单位:{{ scope.row.unitName }}</span>
  31. </div>
  32. </div>
  33. </div>
  34. </template>
  35. </el-table-column>
  36. <el-table-column label="单价" width="130">
  37. <template #default="scope"> ¥{{ scope.row.memberPrice }} </template>
  38. </el-table-column>
  39. <el-table-column label="数量" width="200">
  40. <template #default="scope">
  41. <el-input-number v-model="scope.row.productNum" :min="1" :max="scope.row.allStock" @change="(res) => handleChange(res, scope.row)" />
  42. </template>
  43. </el-table-column>
  44. <el-table-column label="小计" width="140">
  45. <template #default="scope"> ¥{{ (scope.row.memberPrice * scope.row.productNum).toFixed(2) }} </template>
  46. </el-table-column>
  47. <el-table-column label="操作">
  48. <template #default="scope">
  49. <div>
  50. <el-button @click="editCollection(scope.row)" link>{{ scope.row.isCollect == 1 ? '取消收藏' : '移入收藏' }} </el-button>
  51. </div>
  52. <div>
  53. <el-button link @click="onDel(scope.row)"> 删除 </el-button>
  54. </div>
  55. </template>
  56. </el-table-column>
  57. </el-table>
  58. <div class="cart-shi">失效商品</div>
  59. <el-table
  60. :data="noTableData"
  61. style="width: 100%"
  62. :header-cell-style="{
  63. color: '#1D2129',
  64. backgroundColor: '#F2F3F5',
  65. fontWeight: 'normal'
  66. }"
  67. :row-style="{
  68. backgroundColor: '#F9F9F9'
  69. }"
  70. >
  71. <el-table-column type="selection" width="55" />
  72. <el-table-column label="商品信息" width="490">
  73. <template #default="scope">
  74. <div class="cart-info">
  75. <img class="cart-img" :src="scope.row.productImage" alt="" />
  76. <div class="cart-text">
  77. <div class="text1">{{ scope.row.itemName }}</div>
  78. <div class="text2">
  79. <span>单位:{{ scope.row.unitName }}</span>
  80. </div>
  81. <div class="text3">当前商品库存不足,当前库存量:0</div>
  82. </div>
  83. </div>
  84. </template>
  85. </el-table-column>
  86. <el-table-column label="单价" width="130" align="center">
  87. <template #default="scope"> ¥{{ scope.row.memberPrice }} </template>
  88. </el-table-column>
  89. <el-table-column label="数量" width="200" align="center">
  90. <template #default="scope">
  91. <el-input-number disabled v-model="scope.row.productNum" :controls="false" :min="1" :max="10" style="width: 130px" />
  92. </template>
  93. </el-table-column>
  94. <el-table-column label="小计" width="140" align="center">
  95. <template #default="scope"> ¥{{ (scope.row.memberPrice * scope.row.productNum).toFixed(2) }} </template>
  96. </el-table-column>
  97. <el-table-column label="操作">
  98. <template #default="scope">
  99. <div>
  100. <el-button @click="editCollection(scope.row)" link>{{ scope.row.isCollect == 1 ? '取消收藏' : '移入收藏' }} </el-button>
  101. </div>
  102. <div>
  103. <el-button link @click="onDel(scope.row)"> 删除 </el-button>
  104. </div>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. </div>
  109. <div class="cart-bnt">
  110. <div class="bnt-bos flex-row-between">
  111. <div></div>
  112. <!-- <div class="flex-row-start">
  113. <el-checkbox v-model="checked1" label="全选" @change="handleSelectAll" />
  114. <el-button style="margin-left: 10px">删除</el-button>
  115. <el-button>移入收藏</el-button>
  116. </div> -->
  117. <div class="bnt-box flex-row-start">
  118. <span>共</span>
  119. <span class="hig">{{ tableData.length }}</span>
  120. <span>种商品,已选择</span>
  121. <span class="hig">{{ selectedList.length }}</span>
  122. <span>件,商品合计:</span>
  123. <span class="hig">¥{{ onMoney }}</span>
  124. <span>,活动优惠:0.00</span>
  125. <span class="span1">合计:</span>
  126. <span class="span2">¥{{ onMoney }}</span>
  127. <el-button class="bnt" type="primary" @click="goTrad">去结算</el-button>
  128. </div>
  129. </div>
  130. </div>
  131. <!-- 取消收藏 -->
  132. <el-dialog
  133. v-model="dialogVisible"
  134. title="选择取消的收藏夹"
  135. width="500"
  136. :before-close="
  137. () => {
  138. dialogVisible = false;
  139. }
  140. "
  141. >
  142. <div>
  143. <el-radio-group v-model="radio">
  144. <el-radio v-for="(item, index) in favorites" :key="index" :value="item.id">{{ item.title }}</el-radio>
  145. </el-radio-group>
  146. </div>
  147. <template #footer>
  148. <div class="dialog-footer">
  149. <el-button @click="dialogVisible = false">取消</el-button>
  150. <el-button type="primary" @click="onCancel"> 确认 </el-button>
  151. </div>
  152. </template>
  153. </el-dialog>
  154. </div>
  155. </template>
  156. <script setup lang="ts">
  157. import type { TableInstance } from 'element-plus';
  158. const tableData = ref<any>([]);
  159. const selectedList = ref<any>([]);
  160. const noTableData = ref<any>([]);
  161. const multipleTableRef = ref<TableInstance>();
  162. const checked1 = ref(false);
  163. const dialogVisible = ref<any>(false);
  164. const favorites = ref<any>([]);
  165. const radio = ref<any>(null);
  166. const radioRow = ref<any>({});
  167. import {
  168. shoppingCartList,
  169. deleteProductShoppingCart,
  170. isProductInDefaultCollect,
  171. cancelProductCollect,
  172. addProductCollect,
  173. favoritesList
  174. } from '@/api/goods/index';
  175. import { onPath } from '@/utils/siteConfig';
  176. onMounted(() => {
  177. getInfo();
  178. });
  179. const getInfo = () => {
  180. shoppingCartList({}).then((res) => {
  181. if (res.code == 200) {
  182. tableData.value = [];
  183. noTableData.value = [];
  184. if (res.rows && res.rows.length > 0) {
  185. res.rows.forEach((item: any) => {
  186. item.allStock = Number(item.totalInventory || 0) + Number(item.nowInventory || 0) + Number(item.virtualInventory || 0);
  187. // item.allStock = 8888;
  188. if (item.productStatus == 1 && item.allStock > 0) {
  189. tableData.value.push(item);
  190. } else {
  191. noTableData.value.push(item);
  192. }
  193. });
  194. }
  195. }
  196. });
  197. };
  198. const handleChange = (val: any, row: any) => {
  199. const numberVal = Number(val);
  200. const step = row.minOrderQuantity || 1;
  201. row.productNum = Math.ceil(numberVal / step) * step;
  202. };
  203. //购物车选中
  204. const handleSelectionChange1 = (val: any) => {
  205. selectedList.value = val;
  206. };
  207. //全选
  208. const handleSelectAll = (val: any) => {
  209. if (val) {
  210. multipleTableRef.value?.toggleAllSelection();
  211. } else {
  212. multipleTableRef.value?.clearSelection();
  213. }
  214. };
  215. import { cartStore } from '@/store/modules/cart';
  216. const cart = cartStore();
  217. const onDel = (row: any) => {
  218. ElMessageBox.confirm(`确定要删除吗?`, '提示', {
  219. confirmButtonText: '确定',
  220. cancelButtonText: '取消',
  221. type: 'warning'
  222. }).then(() => {
  223. deleteProductShoppingCart(row.shoppingCartId).then((res) => {
  224. if (res.code == 200) {
  225. ElMessage.success('删除成功');
  226. getInfo();
  227. cart.onCartCount();
  228. }
  229. });
  230. });
  231. };
  232. const goTrad = () => {
  233. if (selectedList.value.length == 0) {
  234. ElMessage.warning('请选择商品');
  235. return;
  236. }
  237. const ids = selectedList.value.map((item: any) => item.shoppingCartId).join(',');
  238. onPath('/trad?ids=' + ids);
  239. };
  240. const onMoney = computed(() => {
  241. let money = 0;
  242. let price = '';
  243. selectedList.value.forEach((item: any) => {
  244. money = money + Number(item.memberPrice * item.productNum);
  245. });
  246. price = Number(money).toFixed(2);
  247. return price;
  248. });
  249. //修改收藏
  250. const editCollection = (row: any) => {
  251. if (row.isCollect == 1) {
  252. dialogVisible.value = true;
  253. favoritesList(row.id).then((res) => {
  254. if (res.code == 200) {
  255. if (res.rows.length > 0) {
  256. radio.value = res.rows[0].id;
  257. }
  258. favorites.value = res.rows;
  259. radioRow.value = row;
  260. }
  261. });
  262. } else {
  263. // 添加
  264. addProductCollect({ productId: row.id }).then((res) => {
  265. if (res.code == 200) {
  266. getInfo();
  267. }
  268. });
  269. }
  270. };
  271. // 取消收藏
  272. const onCancel = () => {
  273. cancelProductCollect({ productId: radioRow.value.id, favoritesId: radio.value }).then((res) => {
  274. if (res.code == 200) {
  275. dialogVisible.value = false;
  276. getInfo();
  277. }
  278. });
  279. };
  280. </script>
  281. <style lang="scss" scoped>
  282. .cart-pages {
  283. width: 100%;
  284. background: #ffffff;
  285. .cart-bos {
  286. width: 1200px;
  287. margin: 0 auto;
  288. }
  289. .cart-head {
  290. margin-bottom: 20px;
  291. padding-top: 20px;
  292. .head1 {
  293. font-weight: 600;
  294. font-size: 16px;
  295. color: #101828;
  296. img {
  297. width: 18px;
  298. height: 18px;
  299. margin-right: 6px;
  300. }
  301. }
  302. .head2 {
  303. width: 88px;
  304. height: 25px;
  305. border-radius: 4px 4px 4px 4px;
  306. border: 1px solid #e7000b;
  307. font-size: 12px;
  308. color: #e7000b;
  309. line-height: 25px;
  310. text-align: center;
  311. }
  312. }
  313. .cart-info {
  314. width: 490px;
  315. height: 94px;
  316. display: flex;
  317. .cart-img {
  318. width: 94px;
  319. height: 94px;
  320. border-radius: 6px;
  321. }
  322. .cart-text {
  323. flex: 1;
  324. width: 0;
  325. padding-left: 10px;
  326. .text1 {
  327. font-size: 14px;
  328. color: #000000;
  329. height: 50px;
  330. }
  331. .text2 {
  332. font-size: 14px;
  333. color: #364153;
  334. span {
  335. margin-right: 10px;
  336. }
  337. }
  338. .text3 {
  339. font-size: 14px;
  340. color: #e7000b;
  341. }
  342. }
  343. }
  344. .cart-shi {
  345. font-weight: 600;
  346. font-size: 16px;
  347. color: #101828;
  348. padding: 20px 0;
  349. }
  350. .cart-bnt {
  351. width: 100%;
  352. height: 82px;
  353. background: #ffffff;
  354. box-shadow: 0px -2px 13px 0px rgba(0, 0, 0, 0.05);
  355. margin-top: 48px;
  356. .bnt-bos {
  357. width: 1200px;
  358. margin: 0 auto;
  359. height: 82px;
  360. .bnt-box {
  361. font-size: 14px;
  362. color: #000000;
  363. .span1 {
  364. font-weight: 600;
  365. color: #101828;
  366. margin-left: 20px;
  367. }
  368. .span2 {
  369. font-weight: 600;
  370. color: #e7000b;
  371. font-size: 16px;
  372. margin-top: 2px;
  373. margin-left: 2px;
  374. }
  375. .hig {
  376. color: #e7000b;
  377. }
  378. .bnt {
  379. width: 142px;
  380. height: 50px;
  381. font-size: 16px;
  382. margin-left: 20px;
  383. }
  384. }
  385. }
  386. }
  387. }
  388. </style>