소스 검색

Merge remote-tracking branch 'origin/master'

Nivek 2 년 전
부모
커밋
8a7fbcd000
2개의 변경된 파일69개의 추가작업 그리고 14개의 파일을 삭제
  1. 8 0
      src/api/product.ts
  2. 61 14
      src/views/portal/ProductDetail.vue

+ 8 - 0
src/api/product.ts

@@ -25,3 +25,11 @@ export const getProductById = productId => {
             return res;
             return res;
         })
         })
 }
 }
+
+// 添加库存
+export const addStock = (id, number) => {
+    return axios.post(`${PRODUCT_MODULE}/${id}/stock?number=${number}`)
+        .then(res => {
+            return res;
+        })
+}

+ 61 - 14
src/views/portal/ProductDetail.vue

@@ -1,26 +1,25 @@
 <script setup lang="ts">
 <script setup lang="ts">
 import {useRouter} from "vue-router";
 import {useRouter} from "vue-router";
 import {ref} from "vue";
 import {ref} from "vue";
-import {getProductById} from "../../api/product.ts";
+import {addStock, getProductById} from "../../api/product.ts";
 
 
 const router = useRouter();
 const router = useRouter();
 const productId = router.currentRoute.value.params.productId;
 const productId = router.currentRoute.value.params.productId;
 const productVO = ref()
 const productVO = ref()
-let storeId = ref(0)
-let name = ref('')
-let photoUrlList = ref([])
-let rating = ref(0)
-let number = ref(0)
-let salesAmount = ref(0)
-let stock = ref(0)
-let category = ref('')
-let price = ref(0)
+const storeId = ref(0)
+const name = ref('')
+const photoUrlList = ref([])
+const rating = ref(0)
+const number = ref(0)
+const salesAmount = ref(0)
+const stock = ref(0)
+const category = ref('')
+const price = ref(0)
 
 
 getProductDetail()
 getProductDetail()
 
 
 function getProductDetail() {
 function getProductDetail() {
   getProductById(productId).then(res => {
   getProductById(productId).then(res => {
-    console.log(res.result)
     productVO.value = res.result
     productVO.value = res.result
     storeId.value = productVO.value.storeId
     storeId.value = productVO.value.storeId
     name.value = productVO.value.name
     name.value = productVO.value.name
@@ -34,6 +33,37 @@ function getProductDetail() {
   })
   })
 }
 }
 
 
+const addStockNumber = ref(null)
+
+function AddStock() {
+  if (addStockNumber.value === null) {
+    ElMessage({
+      message: "请输入添加库存数!",
+      type: 'error',
+      center: true,
+    })
+    return
+  }
+  addStock(productId, addStockNumber.value).then(res => {
+    if (res.code === '000') {
+      ElMessage({
+        message: '添加库存成功!',
+        type: 'success',
+        center: true,
+      })
+      addStockNumber.value = null
+      getProductDetail()
+    } else if (res.code === '400') {
+      ElMessage({
+        message: res.msg,
+        type: 'error',
+        center: true,
+      })
+    }
+
+  })
+}
+
 function toBuyProduct() {
 function toBuyProduct() {
   router.push("/customer/buyProduct/" + productId)
   router.push("/customer/buyProduct/" + productId)
 }
 }
@@ -53,16 +83,23 @@ function toBuyProduct() {
         评分:{{ rating }}
         评分:{{ rating }}
       </el-row>
       </el-row>
       <el-row style="font-size: 10px">
       <el-row style="font-size: 10px">
-        销量:{{ salesAmount }}
+        销量:{{ salesAmount }}
       </el-row>
       </el-row>
       <el-row style="font-size: 10px">
       <el-row style="font-size: 10px">
         品类:{{ category }}
         品类:{{ category }}
       </el-row>
       </el-row>
       <el-row style="font-size: 10px">
       <el-row style="font-size: 10px">
-        价格:{{ price }}
+        价格:{{ price }}
       </el-row>
       </el-row>
       <el-row style="font-size: 10px">
       <el-row style="font-size: 10px">
-        库存:{{ stock }}
+          库存:{{ stock }} 件
+      </el-row>
+      <el-row>
+        <el-input size="small" class="addStockNumber-input"
+                  v-model="addStockNumber" placeholder="请输入添加库存数" />
+        <el-button class="add-stock-button" type="primary" plain
+                   @click="AddStock">确认添加
+        </el-button>
       </el-row>
       </el-row>
       <el-button class="buy-product-button" type="primary" plain
       <el-button class="buy-product-button" type="primary" plain
                  @click="toBuyProduct">购买商品
                  @click="toBuyProduct">购买商品
@@ -78,6 +115,16 @@ function toBuyProduct() {
   margin-left: 50px;
   margin-left: 50px;
 }
 }
 
 
+.addStockNumber-input {
+  width: 120px;
+  margin-top: 10px;
+}
+
+.add-stock-button {
+  margin-top: 10px;
+  margin-left: 10px;
+}
+
 .buy-product-button {
 .buy-product-button {
   margin-top: 20px;
   margin-top: 20px;
 }
 }