From 301cbea766080fb65b8c6af563388b61606322f3 Mon Sep 17 00:00:00 2001
From: songshankun <songshankun@foxmail.com>
Date: 星期四, 19 十月 2023 14:23:25 +0800
Subject: [PATCH] Merge branch 'dev' into songshankun/adjust-style

---
 src/views/warehouseManage/listingRules/index.vue |  365 +++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 275 insertions(+), 90 deletions(-)

diff --git a/src/views/warehouseManage/listingRules/index.vue b/src/views/warehouseManage/listingRules/index.vue
index 1b6f8c0..78e234e 100644
--- a/src/views/warehouseManage/listingRules/index.vue
+++ b/src/views/warehouseManage/listingRules/index.vue
@@ -2,57 +2,94 @@
   <div class="rightContent">
     <div class="top">
       <SearchCommonView
-        :add-title="'鏂板缓'"
-        :placeholder="'璇疯緭鍏ュ崟鍙�'"
+        :add-title="addTitle"
+        :show-discard="showDiscard"
+        :placeholder="'璇疯緭鍏ヤ綅缃�/浜у搧'"
         :amount-view="false"
-        @addCommonClick="addBtnClick"
+        @addCommonClick="addProductClick"
         @searchClick="getList"
+        @discardBtnClick="discardBtnClick"
+        @applyBtnClick="applyBtnClick"
       />
     </div>
     <div class="list-view">
       <div class="table">
-        <TableCommonView
-          ref="tableListRef"
-          :table-list="tableList"
-          :show-checkcol="false"
+        <CommonFormTableView
+          :islistingrules="true"
+          :product-table-list="tableList"
+          @inputContent="inputContent"
           @tableRowClick="tableRowClick"
-        ></TableCommonView>
+          @selLocationClick="selLocationClick"
+          @selProductClick="selProductClick"
+        >
+          <template slot="tableButton">
+            <el-table-column label="鎿嶄綔" width="90" align="center">
+              <template slot-scope="scope">
+                <span v-if="scope.row.isEdit" @click.stop="delClick(scope)" class="yes-cursor">
+                  <span style="color: #2a78fb">鍒犻櫎</span>
+                </span>
+              </template>
+            </el-table-column>
+          </template>
+        </CommonFormTableView>
       </div>
       <div class="btn-pager">
         <PagerView class="page" :pager-options="pagerOptions" v-on="pagerEvents" />
       </div>
     </div>
-    <!-- 鏂板缓/缂栬緫 -->
-    <AddDialog
-      v-if="editConfig.visible"
-      @refresh="refresh"
-      :positionList="tableList.tableInfomation"
-      :edit-common-config="editConfig"
-    />
   </div>
 </template>
 
 <script>
+import CommonFormTableView from "@/components/makepager/CommonFormTableView"
 import pageMixin from "@/components/makepager/pager/mixin/pageMixin"
-import { getLocationList } from "@/api/warehouseManage/warehouse"
-import AddDialog from "@/views/warehouseManage/position/AddDialog"
-import { getDataByType } from "@/api/data"
+import {
+  getListingRulesList,
+  addListingRules,
+  updateListingRules,
+  deleteListingRules
+} from "@/api/warehouseManage/listingRules"
 export default {
-  name: "ListingRules",
+  name: "listingRules",
   props: {},
-  components: { AddDialog },
+  components: { CommonFormTableView },
   mixins: [pageMixin],
   computed: {},
   data() {
     return {
+      addTitle: "鏂板缓",
+      showDiscard: false,
       tableList: {},
+      tableData: [
+        {
+          location: "HC/閿�鍞尯",
+          productName: "澶忓鐪熶笣鍚婂甫瑁�",
+          amount: "0.00",
+          unit: "浠�",
+          count: "0.00",
+          date: "2023-12-31",
+          user: "绠$悊鍛�",
+          isSet: true,
+          isEdit: true
+        },
+        {
+          location: "HM/閿�鍞尯",
+          productName: "澶忓鐪熶笣鍚婂甫瑁�",
+          productCategory: "",
+          subLocation: "A鍖�",
+          companyName: "璐濇�濈",
+          isSet: true,
+          isEdit: true
+        }
+      ],
       searchOptions: [],
-      editConfig: {
-        visible: false,
-        title: "鏂板缓",
-        infomation: {}
-      },
-      positionTypeList: getDataByType("positionType")
+      countId: 0,
+      isNoProduct: true, // 娣诲姞鏄庣粏琛屾椂鏄惁鏈変骇鍝佹湭閫夋嫨
+      isRowClick: false,
+      areaId: 0,
+      productId: 0,
+      subLocationId: 0,
+      currentRowId: 0
     }
   },
   created() {
@@ -62,87 +99,202 @@
   methods: {
     setTable() {
       this.tableList = {
-        tableInfomation: [],
-        selectBox: true,
-        showcol: this.showcol,
-        allcol: [],
-        tableColumn: this.setTableColumn(this.showcol)
+        tableData: [],
+        selectBox: false,
+        selectIndex: true,
+        tableColumn: [
+          { label: "褰撲骇鍝佸埌杈�", prop: "areaName", location: true },
+          { label: "浜у搧", prop: "productName", product: true },
+          { label: "浜у搧绫诲埆", prop: "productCategory" },
+          { label: "瀛樺偍鍒板瓙浣嶇疆", prop: "subLocation", location: true }
+          // { label: "鍏徃", prop: "companyName", company: true }
+        ]
       }
-      let allcol = []
-      for (let i = 0; i < this.tableList.tableColumn.length; i++) {
-        if (!this.tableList.tableColumn[i].default) {
-          const label = this.tableList.tableColumn[i].label
-          allcol.push(label)
-        }
-      }
-      this.tableList.allcol = allcol
-    },
-    setTableColumn(showcol) {
-      console.log(showcol)
-      let tableColumn = [
-        {
-          label: "浣嶇疆",
-          prop: "jointName",
-          isShowColumn: true,
-          default: true
-        },
-        {
-          label: "浣嶇疆绫诲瀷",
-          prop: "type",
-          isShowColumn: true,
-          default: true,
-          conversion: true,
-          getStatus: this.getTypesList
-        }
-      ]
-      return tableColumn
-    },
-    getTypesList(val) {
-      let string = "--"
-      if (val) {
-        for (let i in this.positionTypeList) {
-          if (this.positionTypeList[i].id == val) {
-            return this.positionTypeList[i].name
-          }
-        }
-      }
-      return string
-    },
-    selTableCol(val) {
-      this.showcol = val
-      this.tableList.tableColumn = this.setTableColumn(val)
     },
     // 璇锋眰鏁版嵁
     async getData() {
-      await getLocationList({
-        keyword: this.keyword,
+      await getListingRulesList({
+        // 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
+          const list = res.data.map((item) => {
+            return {
+              ...item,
+              areaName: {label:item.area.jointName,value:item.area.id},
+              subLocation: {label:item.location.jointName,value:item.location.id},
+              productName: item.product.name,
+              productCategory: item.productCategory.name,
+              isSet: false,
+              isEdit: true
+            }
+          })
+          this.tableList.tableData = list || []
+          this.tableData = list || []
           this.pagerOptions.totalCount = res.total
         }
       })
     },
-    refresh() {
-      this.pagerOptions.currPage = 1
-      this.getData()
+    // 鎿嶄綔杈撳叆
+    inputContent(val, prop, row) {
+      this.countId = row.countId
+      this.tableData.map((item) => {
+        if (item.countId === row.countId) {
+          item[prop] = val
+        }
+      })
+    },
+    // 鏂板
+    addProductClick() {
+      console.log(this.tableData)
+      this.isSel()
+      if (this.isNoProduct && this.addTitle === "鏂板缓") {
+        this.addTitle = "淇濆瓨"
+        this.showDiscard = true
+        this.isRowClick = false
+        this.currentRowId = 0
+        this.countId++
+        this.tableData.unshift({
+          countId: this.countId,
+          areaId: 0,
+          areaName: "",
+          locationId: 0,
+          productId: "",
+          subLocation: "",
+          productName: "",
+          companyName: "",
+          isSet: true,
+          isEdit: false
+        })
+        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) {
+              this.getData()
+              let tipStr = this.currentRowId === 0 ? "娣诲姞鎴愬姛" : "淇敼鎴愬姛"
+              this.$message.success(tipStr)
+            }
+          })
+        }
+      }
+    },
+    // 鏄惁閫夋嫨浜у搧
+    isSel() {
+      for (let i = 0; i < this.tableData.length; i++) {
+        if (this.tableData[i].productName.length === 0) {
+          this.isNoProduct = false
+          break
+        } else {
+          this.isNoProduct = true
+        }
+      }
+    },
+    // 鍙栨秷
+    discardBtnClick() {
+      if (this.isRowClick) {
+        this.tableData.map((item) => {
+          item.isEdit = true
+        })
+      } else {
+        this.tableData.splice(0, 1)
+      }
+      this.addTitle = "鏂板缓"
+      this.showDiscard = false
+    },
+    // 搴旂敤鍏ㄩ儴
+    applyBtnClick() {
+      console.log("搴旂敤鍏ㄩ儴")
+    },
+    // 鍘嗗彶
+    handleHistoryClick(row) {
+      this.isSel()
+      console.log(row)
+      if (this.isNoProduct) {
+        console.log("鍘嗗彶")
+        this.$router.push({
+          name: "inventoryAdjustmentHistory",
+          params: { id: row.id }
+        })
+      }
+    },
+    // 璁剧疆
+    handleSetClick(scope) {
+      this.isSel()
+      if (this.isNoProduct) {
+        scope.row.isSet = !scope.row.isSet
+      }
+    },
+    // 搴旂敤
+    handleUseClick(scope) {
+      scope.row.isSet = !scope.row.isSet
+    },
+    // 娓呴櫎
+    handleCleanupClick(scope) {
+      scope.row.isSet = !scope.row.isSet
+    },
+    // 琛岀偣鍑�
+    tableRowClick(row, rowIndex) {
+      console.log("11111")
+      this.isSel()
+      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
+      }
     },
     // 鎼滅储
     getList(val) {
       this.keyword = val
       this.pagerOptions.currPage = 1
       this.getData()
-    },
-    // 琛岀偣鍑�
-    tableRowClick(row) {
-      console.log(row)
-      this.editConfig.title = "缂栬緫"
-      this.editConfig.infomation = { ...row }
-      this.editConfig.infomation.parentId = Number(this.editConfig.infomation.parentId)
-      this.editConfig.visible = true
     },
     // 鏂板缓
     addBtnClick() {
@@ -160,10 +312,43 @@
       }
       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()
+        }
+      })
     }
   }
 }
 </script>
 
 <!-- Add "scoped" attribute to limit CSS to this component only -->
-<style lang="scss" scoped></style>
+<style lang="scss" scoped>
+::v-deep {
+  .el-table {
+    border-top-left-radius: 12px;
+    border-top-right-radius: 12px;
+    overflow: auto;
+  }
+}
+</style>

--
Gitblit v1.8.0