From ecd4e0f81c47fcb4ae41e7b4377f49b8a326c0d9 Mon Sep 17 00:00:00 2001
From: yangfeng <wanwan926_4@163.com>
Date: 星期三, 27 九月 2023 17:33:27 +0800
Subject: [PATCH] 上架规则、库存调整模块接口联调

---
 src/views/overview/AddOverviewDialog.vue                             |    5 
 src/views/warehouseManage/listingRules/index.vue                     |  191 ++++++++++++++----
 src/api/warehouseManage/listingRules.js                              |   35 +++
 src/assets/style/index.scss                                          |    6 
 src/views/operate/inventoryAdjustment/inventoryAdjustmentHistory.vue |   30 +-
 src/api/operate/inventoryAdjustment.js                               |   27 ++
 src/components/makepager/CommonFormTableView.vue                     |   62 ++++-
 src/common/config/index.js                                           |   22 ++
 src/views/operate/inventoryAdjustment/index.vue                      |  176 ++++++++++------
 9 files changed, 402 insertions(+), 152 deletions(-)

diff --git a/src/api/operate/inventoryAdjustment.js b/src/api/operate/inventoryAdjustment.js
new file mode 100644
index 0000000..a541cb0
--- /dev/null
+++ b/src/api/operate/inventoryAdjustment.js
@@ -0,0 +1,27 @@
+import request from "@/common/untils/request.js"
+// import axios from "axios"
+
+// 搴撳瓨璋冩暣鍒楄〃
+export function getInventoryAdjustmentList(data) {
+  return request({
+    url: "/api-wms/v1/locationProductAmount/list",
+    method: "post",
+    data
+  })
+}
+// 娣诲姞搴撳瓨璋冩暣
+export function addInventoryAdjustment(data) {
+  return request({
+    url: "/api-wms/v1/locationProductAmount/add",
+    method: "post",
+    data
+  })
+}
+// 搴撳瓨璋冩暣/鍘嗗彶
+export function historyInventoryAdjustment(data) {
+  return request({
+    url: "/api-wms/v1/product/listHistory",
+    method: "post",
+    data
+  })
+}
diff --git a/src/api/warehouseManage/listingRules.js b/src/api/warehouseManage/listingRules.js
new file mode 100644
index 0000000..0627ec0
--- /dev/null
+++ b/src/api/warehouseManage/listingRules.js
@@ -0,0 +1,35 @@
+import request from "@/common/untils/request.js"
+// import axios from "axios"
+
+// 涓婃灦瑙勫垯鍒楄〃
+export const getListingRulesList = async (data) => {
+  return request({
+    url: "/api-wms/v1/locationProduct/list",
+    method: "post",
+    data
+  })
+}
+// 娣诲姞涓婃灦瑙勫垯
+export function addListingRules(data) {
+  return request({
+    url: "/api-wms/v1/locationProduct/add",
+    method: "post",
+    data
+  })
+}
+// 鍒犻櫎涓婃灦瑙勫垯
+export function deleteListingRules(id) {
+  return request({
+    url: `/api-wms/v1/locationProduct/delete/${id}`,
+    method: "delete",
+    id
+  })
+}
+// 淇敼涓婃灦瑙勫垯
+export function updateListingRules(data) {
+  return request({
+    url: "/api-wms/v1/locationProduct/update",
+    method: "post",
+    data
+  })
+}
diff --git a/src/assets/style/index.scss b/src/assets/style/index.scss
index 86a266b..ad72597 100644
--- a/src/assets/style/index.scss
+++ b/src/assets/style/index.scss
@@ -126,6 +126,12 @@
 .cursor_pointer {
   cursor: pointer;
 }
+.no-cursor {
+  cursor: no-drop;
+}
+.yes-cursor {
+  cursor: pointer;
+}
 
 .Badge {
   background: #d3d3d3;
diff --git a/src/common/config/index.js b/src/common/config/index.js
index 478e57a..3a4bbaf 100644
--- a/src/common/config/index.js
+++ b/src/common/config/index.js
@@ -59,3 +59,25 @@
   }
   return result
 }
+
+/**
+ * 鑾峰彇褰撳墠鏃堕棿
+ */
+export function currentTime() {
+  var date = new Date()
+  var year = date.getFullYear() //鏈堜唤浠�0~11锛屾墍浠ュ姞涓�
+  let month = date.getMonth()
+  console.log("month", month)
+  var dateArr = [date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds()]
+  //濡傛灉鏍煎紡鏄疢M鍒欓渶瑕佹姝ラ锛屽鏋滄槸M鏍煎紡鍒欐寰幆娉ㄩ噴鎺�
+  for (var i = 0; i < dateArr.length; i++) {
+    if (dateArr[i] >= 1 && dateArr[i] <= 9) {
+      dateArr[i] = "0" + dateArr[i]
+    }
+  }
+  var strDate = year + "-" + dateArr[0] + "-" + dateArr[1] + " " + dateArr[2] + ":" + dateArr[3] + ":" + dateArr[4]
+  //姝ゅ鍙互鎷垮閮ㄧ殑鍙橀噺鎺ユ敹  strDate:2022-05-01 13:25:30
+  //this.date = strDate;
+  console.log("strDate", strDate)
+  return strDate
+}
diff --git a/src/components/makepager/CommonFormTableView.vue b/src/components/makepager/CommonFormTableView.vue
index ff7f169..997cf9e 100644
--- a/src/components/makepager/CommonFormTableView.vue
+++ b/src/components/makepager/CommonFormTableView.vue
@@ -57,7 +57,7 @@
                     style="width: 80%"
                     @change="
                       (val) => {
-                        selProductClick(val)
+                        selProductNameClick(val)
                       }
                     "
                   >
@@ -78,7 +78,7 @@
                 :rules="[{ required: item.isRequird ? true : false, message: '杈撳叆涓嶈兘涓虹┖' }]"
               >
                 <span v-if="scope.row.isEdit">{{ scope.row[item.prop] }}</span>
-                <el-date-picker v-else v-model="scope.row[item.prop]" type="date" size="mini" style="width: 110px">
+                <el-date-picker v-else v-model="scope.row[item.prop]" type="date" size="mini" style="width: 100%">
                 </el-date-picker>
               </el-form-item>
               <el-form-item
@@ -140,16 +140,25 @@
               <!-- 浣嶇疆 -->
               <el-form-item v-else-if="item.location" label=" " :prop="'tableData.' + scope.$index + '.' + item.prop">
                 <div class="custom-name">
-                  <span v-if="scope.row.isEdit">{{ scope.row[item.prop] }}</span>
+                  <span v-if="scope.row.isEdit || scope.row.editable">{{ scope.row[item.prop] }}</span>
                   <el-select
                     v-else
                     v-model="scope.row[item.prop]"
                     placeholder="璇烽�夋嫨"
                     size="mini"
                     style="width: 80%"
-                    @change="selLocationClick"
+                    @change="
+                      (val) => {
+                        selLocationClick(val, item.prop)
+                      }
+                    "
                   >
-                    <el-option v-for="item in selLocationOptions" :key="item.id" :label="item.name" :value="item.name">
+                    <el-option
+                      v-for="item in selLocationOptions"
+                      :key="item.id"
+                      :label="item.name"
+                      :value="{ value: item.id, label: item.name }"
+                    >
                     </el-option>
                   </el-select>
                 </div>
@@ -157,7 +166,7 @@
               <!-- 浜у搧 -->
               <el-form-item v-else-if="item.product" label=" " :prop="'tableData.' + scope.$index + '.' + item.prop">
                 <div class="custom-name">
-                  <span v-if="scope.row.isEdit">{{ scope.row[item.prop] }}</span>
+                  <span v-if="scope.row.isEdit || scope.row.editable">{{ scope.row[item.prop] }}</span>
                   <el-select
                     v-else
                     v-model="scope.row[item.prop]"
@@ -174,7 +183,14 @@
                       v-for="item in productNameOptions"
                       :key="item.id"
                       :label="item.name"
-                      :value="{ value: item.id, label: item.name, amount: item.amount, unit: item.unit }"
+                      :value="{
+                        value: item.id,
+                        label: item.name,
+                        amount: item.amount,
+                        unit: item.unit,
+                        categoryId: item.categoryId,
+                        categoryName: item.categoryName
+                      }"
                     >
                     </el-option>
                   </el-select>
@@ -297,7 +313,7 @@
     }
     if (this.islistingrules) {
       this.getLocationList()
-      this.getCompanyList()
+      // this.getCompanyList()
     }
     this.tableList = this.productTableList
   },
@@ -344,8 +360,7 @@
         }
       })
     },
-    // 閫夋嫨浜у搧
-    selProductClick(item) {
+    selProductNameClick(item) {
       this.tableList.tableData.map((ite) => {
         if (ite.productName.label === item.label) {
           ite.productId = item.value
@@ -356,18 +371,27 @@
       })
       console.log(this.tableList.tableData)
     },
+    // 閫夋嫨浜у搧
+    selProductClick(item) {
+      console.log(item)
+      this.tableList.tableData.map((ite) => {
+        if (ite.productName.label === item.label) {
+          ite.productId = item.value
+          ite.productName = item.label
+          ite.categoryId = item.categoryId
+          ite.productCategory = item.categoryName
+          ite.amount = item.amount
+          ite.unit = item.unit
+        }
+      })
+      console.log(this.tableList.tableData)
+      this.$emit("selProductClick", item)
+    },
     // 閫夋嫨浣嶇疆
-    selLocationClick(item) {
+    selLocationClick(item, prop) {
       console.log(item)
       console.log(this.tableList.tableData)
-      // this.tableList.tableData.map((ite) => {
-      //   if (ite.location.label === item.label) {
-      //     ite.location = item.label
-      //   }
-      //   if (ite.subLocation.label === item.label) {
-      //     ite.subLocation = item.label
-      //   }
-      // })
+      this.$emit("selLocationClick", item, prop)
     },
     // 閫夋嫨鍗曚綅/鐢ㄦ埛
     selCommonClick(item) {
diff --git a/src/views/operate/inventoryAdjustment/index.vue b/src/views/operate/inventoryAdjustment/index.vue
index 9f6346e..8e9c374 100644
--- a/src/views/operate/inventoryAdjustment/index.vue
+++ b/src/views/operate/inventoryAdjustment/index.vue
@@ -4,7 +4,7 @@
       <SearchCommonView
         :add-title="addTitle"
         :show-discard="showDiscard"
-        :show-apply="true"
+        :show-apply="false"
         :placeholder="'璇疯緭鍏ヤ綅缃�/浜у搧'"
         :amount-view="false"
         @addCommonClick="addProductClick"
@@ -19,16 +19,17 @@
           :isinventory="true"
           :product-table-list="tableList"
           @inputContent="inputContent"
-          @tableRowClick="tableRowClick"
+          @selLocationClick="selLocationClick"
+          @selProductClick="selProductClick"
         >
           <template slot="tableButton">
             <el-table-column label="鎿嶄綔" width="180" fixed="right" align="center">
               <template slot-scope="scope">
-                <span @click="handleHistoryClick(scope.row)">
+                <span @click="handleHistoryClick(scope.row)" class="yes-cursor">
                   <i class="el-icon-refresh-left"></i>
                   <span>鍘嗗彶</span>
                 </span>
-                <span v-if="scope.row.isSet" @click="handleSetClick(scope)" class="margin_left_5px">
+                <!-- <span v-if="scope.row.isSet" @click="handleSetClick(scope)" class="margin_left_5px">
                   <i class="el-icon-setting"></i>
                   <span>璁剧疆</span>
                 </span>
@@ -41,7 +42,7 @@
                     <i class="el-icon-delete"></i>
                     <span>娓呴櫎</span>
                   </span>
-                </template>
+                </template> -->
               </template>
             </el-table-column>
           </template>
@@ -57,7 +58,8 @@
 <script>
 import CommonFormTableView from "@/components/makepager/CommonFormTableView"
 import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
-import { getLocationList } from "@/api/warehouseManage/warehouse"
+import { getInventoryAdjustmentList, addInventoryAdjustment } from "@/api/operate/inventoryAdjustment"
+import { currentTime } from "@/common/config/index"
 export default {
   name: "InventoryAdjustment",
   props: {},
@@ -69,23 +71,15 @@
       addTitle: "鏂板缓",
       showDiscard: false,
       tableList: {},
-      tableData: [
-        {
-          location: "HC/閿�鍞尯",
-          productName: "澶忓鐪熶笣鍚婂甫瑁�",
-          amount: "0.00",
-          unit: "浠�",
-          count: "0.00",
-          date: "2023-12-31",
-          user: "绠$悊鍛�",
-          isSet: true,
-          isEdit: true
-        }
-      ],
+      tableData: [],
       searchOptions: [],
       countId: 0,
       isNoProduct: true, // 娣诲姞鏄庣粏琛屾椂鏄惁鏈変骇鍝佹湭閫夋嫨
-      isRowClick: false
+      isRowClick: false,
+      locationId: 0,
+      productId: 0,
+      differenceAmount: 0,
+      Amount: 0
     }
   },
   created() {
@@ -98,48 +92,108 @@
         tableData: this.tableData,
         selectBox: true,
         tableColumn: [
-          { label: "浣嶇疆", prop: "location", location: true },
+          { label: "浣嶇疆", prop: "locationName", location: true },
           { label: "浜у搧", prop: "productName", product: true },
           { label: "鍦ㄥ簱鏁伴噺", prop: "amount" },
           { label: "璁¢噺鍗曚綅", prop: "unit" },
-          { label: "璁℃暟鐨勬暟閲�", prop: "count", inputFloat: true },
-          { label: "宸紓", prop: "difference" },
-          { label: "鏃ユ湡", prop: "date", date: true },
+          { label: "璁℃暟鐨勬暟閲�", prop: "differenceAmount", inputFloat: true },
+          { label: "宸紓", prop: "adjustAmount" },
+          { label: "鏃ユ湡", prop: "createDate" },
           { label: "鐢ㄦ埛", prop: "user", user: true }
         ]
       }
     },
-    // 鎿嶄綔杈撳叆
-    inputContent(val, prop, row) {
-      this.countId = row.countId
-      this.tableData.map((item) => {
-        if (item.countId === row.countId) {
-          item[prop] = val
+    // 璇锋眰鏁版嵁
+    async getData() {
+      await getInventoryAdjustmentList({
+        page: this.pagerOptions.currPage,
+        pageSize: this.pagerOptions.pageSize
+      }).then((res) => {
+        if (res.code === 200) {
+          console.log(res)
+          const list = res.data.map((item) => {
+            return {
+              ...item,
+              isSet: false,
+              isEdit: true,
+              editable: true
+            }
+          })
+          this.tableList.tableData = list || []
+          this.tableData = list || []
+          this.pagerOptions.totalCount = res.total
         }
       })
+    },
+    // 鎿嶄綔杈撳叆
+    inputContent(val, prop, row) {
+      console.log("22222222222222")
+      console.log(val, prop, row)
+      // this.countId = row.countId
+      // this.tableData.map((item) => {
+      //   if (item.countId === row.countId) {
+      //     item[prop] = val
+      //   }
+      // })
+      this.differenceAmount = val
     },
     // 鏂板
     addProductClick() {
       console.log(this.tableData)
       this.isSel()
+      this.isSel()
       if (this.isNoProduct && this.addTitle === "鏂板缓") {
         this.addTitle = "淇濆瓨"
         this.showDiscard = true
         this.isRowClick = false
+        this.currentRowId = 0
         this.countId++
         this.tableData.push({
           countId: this.countId,
+          Amount: 0,
+          areaName: "",
+          adjustAmount: 0,
           productId: "",
-          amount: 0,
-          unit: "",
-          productName: "",
-          count: "0.00",
+          differenceAmount: 0,
+          locationId: 0,
+          createDate: this.currentTime(),
           isSet: true,
-          isEdit: false
+          isEdit: false,
+          editable: false
         })
-      } else if (this.isNoProduct && this.addTitle === "淇濆瓨") {
-        this.addTitle = "鏂板缓"
-        this.showDiscard = false
+        this.locationId = 0
+        this.subLocationId = 0
+        this.productCategoryId = 0
+        this.productId = 0
+      } else {
+        if (this.locationId === 0) {
+          this.$message.error("璇烽�夋嫨浣嶇疆")
+        } else if (this.productId === 0) {
+          this.$message.error("璇烽�夋嫨浜у搧")
+        } else {
+          this.addTitle = "鏂板缓"
+          this.showDiscard = false
+          // let requestUrl = this.currentRowId === 0 ? addInventoryAdjustment : updateListingRules
+          addInventoryAdjustment({
+            // id: this.currentRowId,
+            locationId: this.locationId,
+            Amount: this.Amount,
+            differenceAmount: this.differenceAmount,
+            productId: this.productId
+          })
+            .then((res) => {
+              console.log(res)
+              if (res.code === 200) {
+                // let tipStr = this.currentRowId === 0 ? "娣诲姞鎴愬姛" : "淇敼鎴愬姛"
+                this.$message.success("娣诲姞鎴愬姛")
+                this.getData()
+              }
+            })
+            .catch((err) => {
+              console.log(err)
+              this.getData()
+            })
+        }
       }
     },
     // 鏄惁閫夋嫨浜у搧
@@ -177,7 +231,7 @@
         console.log("鍘嗗彶")
         this.$router.push({
           name: "inventoryAdjustmentHistory",
-          params: { id: row.id }
+          params: { locationId: row.locationId, productId: row.productId }
         })
       }
     },
@@ -209,22 +263,9 @@
       this.tableData.map((item, index) => {
         if (index === rowIndex) {
           item.isEdit = false
+          item.editable = true
         } else {
           item.isEdit = true
-        }
-      })
-    },
-    // 璇锋眰鏁版嵁
-    async getData() {
-      await getLocationList({
-        keyword: this.keyword,
-        page: this.pagerOptions.currPage,
-        pageSize: this.pagerOptions.pageSize
-      }).then((res) => {
-        if (res.code === 200) {
-          const list = res.data ? res.data : []
-          this.tableList.tableInfomation = list
-          this.pagerOptions.totalCount = res.total
         }
       })
     },
@@ -234,22 +275,19 @@
       this.pagerOptions.currPage = 1
       this.getData()
     },
-    // 鏂板缓
-    addBtnClick() {
-      this.editConfig.infomation = {
-        name: "",
-        parentId: null,
-        type: 3,
-        isScrapLocation: null,
-        isReturnLocation: null,
-        replenishLocation: null,
-        countFrequency: 0,
-        recentlyCount: "",
-        nextCount: "",
-        notes: ""
-      }
-      this.editConfig.visible = true
-      this.editConfig.title = "鏂板缓"
+    // 閫夋嫨浣嶇疆鏂规硶
+    selLocationClick(item, prop) {
+      console.log(item, prop)
+      this.locationId = item.value
+    },
+    // 閫変腑浜у搧鏂规硶
+    selProductClick(item) {
+      console.log(item)
+      this.productId = item.value
+    },
+    // 鑾峰彇褰撳墠鏃堕棿
+    currentTime() {
+      return currentTime()
     }
   }
 }
diff --git a/src/views/operate/inventoryAdjustment/inventoryAdjustmentHistory.vue b/src/views/operate/inventoryAdjustment/inventoryAdjustmentHistory.vue
index cb0de4a..10bb66e 100644
--- a/src/views/operate/inventoryAdjustment/inventoryAdjustmentHistory.vue
+++ b/src/views/operate/inventoryAdjustment/inventoryAdjustmentHistory.vue
@@ -1,12 +1,7 @@
 <template>
   <div class="rightContent">
     <div class="top">
-      <SearchCommonView
-        :show-add="false"
-        :placeholder="'璇疯緭鍏ュ崟鍙�/浜у搧'"
-        :amount-view="false"
-        @searchClick="getList"
-      />
+      <SearchCommonView :show-add="false" :placeholder="'璇疯緭鍏ュ崟鍙�'" :amount-view="false" @searchClick="getList" />
     </div>
     <div class="list-view">
       <div class="table">
@@ -21,7 +16,7 @@
 
 <script>
 import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
-import { getAllList } from "@/api/overview/overview"
+import { historyInventoryAdjustment } from "@/api/operate/inventoryAdjustment"
 
 export default {
   name: "InventoryAdjustmentHistory",
@@ -34,11 +29,15 @@
       tableList: {},
       showcol: ["鐘舵��"],
       searchOptions: [],
-      keyword: ""
+      keyword: "",
+      locationId: 0,
+      productId: ""
     }
   },
   created() {
     this.setTable()
+    this.locationId = this.$route.params.locationId
+    this.productId = this.$route.params.productId
     this.getData()
   },
   methods: {
@@ -65,8 +64,7 @@
           label: "鏃ユ湡",
           prop: "operationDate",
           isShowColumn: true,
-          default: true,
-          date: true
+          default: true
         },
         {
           label: "鍗曞彿",
@@ -129,18 +127,22 @@
     },
     // 璇锋眰鏁版嵁
     async getData() {
-      await getAllList({
-        number: this.keyword,
+      await historyInventoryAdjustment({
+        locationId: this.locationId,
         page: this.pagerOptions.currPage,
         pageSize: this.pagerOptions.pageSize,
-        sourceNumber: this.keyword
+        productId: this.productId
       }).then((res) => {
         if (res.code === 200) {
           const list = res.data.map((item) => {
+            let product = item.details[0].product
             return {
               ...item,
               from: item.fromLocation.name,
-              to: item.toLocation.name
+              to: item.toLocation.name,
+              productName: product.name,
+              amount: product.amount,
+              unit: product.unit
             }
           })
           this.tableList.tableInfomation = list || []
diff --git a/src/views/overview/AddOverviewDialog.vue b/src/views/overview/AddOverviewDialog.vue
index cc0d9d5..0a83a4f 100644
--- a/src/views/overview/AddOverviewDialog.vue
+++ b/src/views/overview/AddOverviewDialog.vue
@@ -108,7 +108,7 @@
                 </el-form-item>
               </el-col>
               <el-col :span="12">
-                <el-form-item label="鍏ュ簱绫诲瀷">
+                <el-form-item label="鍏ュ簱绫诲瀷" prop="operationTypeId">
                   <el-select
                     v-if="showOperationType"
                     v-model="editConfig.infomation.operationTypeId"
@@ -317,7 +317,8 @@
         sourceNumber: [{ required: true, message: "璇疯緭鍏ユ潵婧愬崟鎹�", trigger: "blur" }],
         operationDate: [{ required: true, message: "璇烽�夋嫨鏃ユ湡", trigger: "change" }],
         toLocationId: [{ required: true, message: "璇烽�夋嫨浠撳簱浣嶇疆", trigger: "change" }],
-        fromLocationId: [{ required: true, message: "璇烽�夋嫨婧愪綅缃�", trigger: "change" }]
+        fromLocationId: [{ required: true, message: "璇烽�夋嫨婧愪綅缃�", trigger: "change" }],
+        operationTypeId: [{ required: true, message: "璇烽�夋嫨鍏ュ簱绫诲瀷", trigger: "change" }]
       },
       companyOptions: [], // 鍏徃
       memberOptions: [{ id: 1, name: "绠$悊鍛�" }],
diff --git a/src/views/warehouseManage/listingRules/index.vue b/src/views/warehouseManage/listingRules/index.vue
index ee066a3..b84d797 100644
--- a/src/views/warehouseManage/listingRules/index.vue
+++ b/src/views/warehouseManage/listingRules/index.vue
@@ -19,7 +19,18 @@
           :product-table-list="tableList"
           @inputContent="inputContent"
           @tableRowClick="tableRowClick"
+          @selLocationClick="selLocationClick"
+          @selProductClick="selProductClick"
         >
+          <template slot="tableButton">
+            <el-table-column label="鎿嶄綔" width="90" fixed="right" align="center">
+              <template slot-scope="scope">
+                <el-button v-if="scope.row.isEdit" @click.stop="delClick(scope)" type="text" size="small"
+                  >鍒犻櫎</el-button
+                >
+              </template>
+            </el-table-column>
+          </template>
         </CommonFormTableView>
       </div>
       <div class="btn-pager">
@@ -32,7 +43,12 @@
 <script>
 import CommonFormTableView from "@/components/makepager/CommonFormTableView"
 import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
-import { getLocationList } from "@/api/warehouseManage/warehouse"
+import {
+  getListingRulesList,
+  addListingRules,
+  updateListingRules,
+  deleteListingRules
+} from "@/api/warehouseManage/listingRules"
 export default {
   name: "listingRules",
   props: {},
@@ -69,7 +85,11 @@
       searchOptions: [],
       countId: 0,
       isNoProduct: true, // 娣诲姞鏄庣粏琛屾椂鏄惁鏈変骇鍝佹湭閫夋嫨
-      isRowClick: false
+      isRowClick: false,
+      areaId: 0,
+      productId: 0,
+      subLocationId: 0,
+      currentRowId: 0
     }
   },
   created() {
@@ -79,16 +99,41 @@
   methods: {
     setTable() {
       this.tableList = {
-        tableData: this.tableData,
+        tableData: [],
         selectBox: true,
         tableColumn: [
-          { label: "褰撲骇鍝佸埌杈�", prop: "location", location: true },
+          { label: "褰撲骇鍝佸埌杈�", prop: "areaName", location: true },
           { label: "浜у搧", prop: "productName", product: true },
-          // { label: "浜у搧绫诲埆", prop: "productCategory", productCategory: true },
-          { label: "瀛樺偍鍒板瓙浣嶇疆", prop: "subLocation", location: true },
-          { label: "鍏徃", prop: "companyName", company: true }
+          { label: "浜у搧绫诲埆", prop: "productCategory" },
+          { label: "瀛樺偍鍒板瓙浣嶇疆", prop: "subLocation", location: true }
+          // { label: "鍏徃", prop: "companyName", company: true }
         ]
       }
+    },
+    // 璇锋眰鏁版嵁
+    async getData() {
+      await getListingRulesList({
+        // keyword: this.keyword,
+        page: this.pagerOptions.currPage,
+        pageSize: this.pagerOptions.pageSize
+      }).then((res) => {
+        if (res.code === 200) {
+          const list = res.data.map((item) => {
+            return {
+              ...item,
+              areaName: item.area.jointName,
+              subLocation: item.location.jointName,
+              productName: item.product.name,
+              productCategory: item.productCategory.name,
+              isSet: false,
+              isEdit: true
+            }
+          })
+          this.tableList.tableData = list || []
+          this.tableData = list || []
+          this.pagerOptions.totalCount = res.total
+        }
+      })
     },
     // 鎿嶄綔杈撳叆
     inputContent(val, prop, row) {
@@ -107,30 +152,60 @@
         this.addTitle = "淇濆瓨"
         this.showDiscard = true
         this.isRowClick = false
+        this.currentRowId = 0
         this.countId++
         this.tableData.push({
           countId: this.countId,
+          areaId: 0,
+          areaName: "",
+          locationId: 0,
           productId: "",
-          location: 0,
           subLocation: "",
           productName: "",
           companyName: "",
           isSet: true,
           isEdit: false
         })
-      } else if (this.isNoProduct && this.addTitle === "淇濆瓨") {
-        this.addTitle = "鏂板缓"
-        this.showDiscard = false
-        this.tableData.map((item) => {
-          item.isEdit = true
-          console.log(item)
-          if (typeof item.location === "object") {
-            item.location = item.location.name
-          }
-          if (typeof item.subLocation === "object") {
-            item.location = item.subLocation.name
-          }
-        })
+        this.areaId = 0
+        this.subLocationId = 0
+        this.productCategoryId = 0
+        this.productId = 0
+      } else {
+        if (this.areaId === 0) {
+          this.$message.error("璇烽�夋嫨褰撳墠浜у搧鍒拌揪浣嶇疆")
+        } else if (this.productId === 0) {
+          this.$message.error("璇烽�夋嫨浜у搧")
+        } else if (this.subLocationId === 0) {
+          this.$message.error("璇烽�夋嫨瀛樺偍鍒板瓙浣嶇疆")
+        } else {
+          this.addTitle = "鏂板缓"
+          this.showDiscard = false
+          this.tableData.map((item) => {
+            item.isEdit = true
+            console.log(item)
+            if (typeof item.location === "object") {
+              item.location = item.location.name
+            }
+            if (typeof item.subLocation === "object") {
+              item.location = item.subLocation.name
+            }
+          })
+          let requestUrl = this.currentRowId === 0 ? addListingRules : updateListingRules
+          requestUrl({
+            id: this.currentRowId,
+            areaId: this.areaId,
+            locationId: this.subLocationId,
+            productCategoryId: this.productCategoryId,
+            productId: this.productId
+          }).then((res) => {
+            console.log(res)
+            if (res.code === 200) {
+              let tipStr = this.currentRowId === 0 ? "娣诲姞鎴愬姛" : "淇敼鎴愬姛"
+              this.$message.success(tipStr)
+              this.getData()
+            }
+          })
+        }
       }
     },
     // 鏄惁閫夋嫨浜у搧
@@ -189,35 +264,30 @@
     },
     // 琛岀偣鍑�
     tableRowClick(row, rowIndex) {
-      console.log(row, rowIndex)
-      this.addTitle = "淇濆瓨"
-      this.showDiscard = true
-      this.isRowClick = true
+      console.log("11111")
       this.isSel()
-      if (!this.isNoProduct) {
-        this.tableData.splice(this.tableData.length - 1, 1)
+      if (!this.isNoProduct && this.currentRowId === 0) {
+        this.$message.error("璇峰畬鎴愬綋鍓嶆柊寤烘垨鍙栨秷鏂板缓")
+      } else {
+        this.currentRowId = row.id
+        this.addTitle = "淇濆瓨"
+        this.showDiscard = true
+        this.isRowClick = true
+        if (!this.isNoProduct) {
+          this.tableData.splice(this.tableData.length - 1, 1)
+        }
+        this.tableData.map((item, index) => {
+          if (index === rowIndex) {
+            item.isEdit = false
+          } else {
+            item.isEdit = true
+          }
+        })
+        this.areaId = row.areaId
+        this.subLocationId = row.locationId
+        this.productCategoryId = row.productCategoryId
+        this.productId = row.productId
       }
-      this.tableData.map((item, index) => {
-        if (index === rowIndex) {
-          item.isEdit = false
-        } else {
-          item.isEdit = true
-        }
-      })
-    },
-    // 璇锋眰鏁版嵁
-    async getData() {
-      await getLocationList({
-        keyword: this.keyword,
-        page: this.pagerOptions.currPage,
-        pageSize: this.pagerOptions.pageSize
-      }).then((res) => {
-        if (res.code === 200) {
-          const list = res.data ? res.data : []
-          this.tableList.tableInfomation = list
-          this.pagerOptions.totalCount = res.total
-        }
-      })
     },
     // 鎼滅储
     getList(val) {
@@ -241,6 +311,31 @@
       }
       this.editConfig.visible = true
       this.editConfig.title = "鏂板缓"
+    },
+    // 閫夋嫨浣嶇疆鏂规硶
+    selLocationClick(item, prop) {
+      console.log(item, prop)
+      if (prop === "areaName") {
+        this.areaId = item.value
+      } else if (prop === "subLocation") {
+        this.subLocationId = item.value
+      }
+    },
+    // 閫変腑浜у搧鏂规硶
+    selProductClick(item) {
+      console.log(item)
+      this.productId = item.value
+      this.productCategoryId = item.categoryId
+    },
+    // 鍒犻櫎
+    async delClick(scope) {
+      console.log(scope)
+      await deleteListingRules(scope.row.id).then((res) => {
+        if (res.code === 200) {
+          this.$message.success("鍒犻櫎鎴愬姛")
+          this.getData()
+        }
+      })
     }
   }
 }

--
Gitblit v1.8.0