Browse Source

购物车全选,搜索

skyblued 3 years ago
parent
commit
e3a7b6fced
2 changed files with 35 additions and 16 deletions
  1. 34 16
      src/views/cart/index.tsx
  2. 1 0
      src/views/shop-mall/goods-list/index.tsx

+ 34 - 16
src/views/cart/index.tsx

@@ -1,7 +1,16 @@
 import { defineComponent, ref } from 'vue'
 import ColHeader from '@/components/col-header'
 import styles from './index.module.less'
-import { Checkbox, SubmitBar, Card, Stepper, CheckboxGroup, Dialog, Toast, Image } from 'vant'
+import {
+  Checkbox,
+  SubmitBar,
+  Card,
+  Stepper,
+  CheckboxGroup,
+  Dialog,
+  Toast,
+  Image
+} from 'vant'
 import request from '@/helpers/request'
 import { cartConfirm, formateAttr } from './cart'
 import ColResult from '@/components/col-result'
@@ -21,12 +30,12 @@ export default defineComponent({
   },
   computed: {
     checkAll() {
-      let selectLen = this.selectItems.length as any
-      let cartLen = this.cartList.length as any
+      let selectLen: number = this.selectItems.length
+      let cartLen: number = this.cartList.length
       return selectLen === cartLen
     },
     len() {
-      let n = this.selectItems.length as any
+      let n: number = this.selectItems.length
       return n
     },
     totalPrice() {
@@ -48,7 +57,7 @@ export default defineComponent({
       this.cartList = []
       try {
         let { code, data } = await request.get('/api-mall-portal/cart/list')
-        if (code === 200){
+        if (code === 200) {
           this.cartList = data.map(n => {
             n.stock = n.stock - n.lockStock
             n.stock = n.stock <= 0 ? 0 : n.stock
@@ -62,7 +71,13 @@ export default defineComponent({
       const selectItems = [] as any
       if (!this.checkAll) {
         this.cartList.forEach((n: any) => {
-          selectItems.push(n.id)
+          if (!this.isManage) {
+            if (n.stock > 0) {
+              selectItems.push(n.id)
+            }
+          } else {
+            selectItems.push(n.id)
+          }
         })
       }
       this.selectItems = selectItems
@@ -80,15 +95,13 @@ export default defineComponent({
           }
         )
         item.stock = data
-        if (item.quantity > data){
+        if (item.quantity > data) {
           item.quantity = data
           setTimeout(() => {
             Toast('库存不足')
-          },500)
-          
+          }, 500)
         }
-      } catch (err) {
-      }
+      } catch (err) {}
     },
 
     onChecked(id: number) {
@@ -162,10 +175,12 @@ export default defineComponent({
             <ColHeader
               onClickRight={() => {
                 this.isManage = !this.isManage
-                if (!this.isManage){
-                  this.cartList.forEach((n:any) => {
-                    if (n.stock <= 0){
-                      this.selectItems = this.selectItems.filter((item: any) => item != n.id)
+                if (!this.isManage) {
+                  this.cartList.forEach((n: any) => {
+                    if (n.stock <= 0) {
+                      this.selectItems = this.selectItems.filter(
+                        (item: any) => item != n.id
+                      )
                     }
                   })
                 }
@@ -183,7 +198,10 @@ export default defineComponent({
                 <CheckboxGroup v-model={this.selectItems}>
                   {this.cartList.map((item: any) => (
                     <div class={styles.cartItem}>
-                      <Checkbox name={item.id} disabled={item.stock <= 0 && !this.isManage}>
+                      <Checkbox
+                        name={item.id}
+                        disabled={item.stock <= 0 && !this.isManage}
+                      >
                         <Card
                           price={moneyFormat(item.price)}
                           desc={formateAttr(item.productAttr)}

+ 1 - 0
src/views/shop-mall/goods-list/index.tsx

@@ -135,6 +135,7 @@ export default defineComponent({
     },
     searchBtn(keyword?: string) {
       this.keyword = keyword
+      console.log(this.keyword)
       this.$nextTick(() => {
         this.onSearch()
       })