songshankun
2023-11-03 cf6a4b874aed82592eea78294715c7c688f9b248
src/views/warehouseManage/listingRules/index.vue
@@ -2,147 +2,341 @@
  <div class="rightContent">
    <div class="top">
      <SearchCommonView
        :add-title="'新建'"
        :placeholder="'请输入单号'"
        :add-title="addTitle"
        :show-discard="showDiscard"
        :placeholder="'请输入产品/产品类别'"
        :amount-view="false"
        @addCommonClick="addBtnClick"
        :search-task-map="searchTaskMap"
        @addCommonClick="addProductClick"
        @searchClick="getList"
        @discardBtnClick="discardBtnClick"
        @applyBtnClick="applyBtnClick"
        @delSelectClick="delSelectClick"
      />
    </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"
          @selProductTypeClick="selProductTypeClick"
        >
          <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,
      productCategoryId: 0,
      subLocationId: 0,
      currentRowId: 0,
      rowIndex: -1,
      RuleType: 0,
      queryProductId: null,
      categoryId: null,
      searchTaskMap: []
    }
  },
  created() {
    this.setTable()
    let query = this.$route.query
    if (query) {
      console.log("aaaaaaaaaaaaa", query)
      this.queryProductId = query.productId?.length ? query.productId : null
      this.categoryId = query.id ? Number(query.id) : null
      this.pagerOptions.currPage = 1
      this.searchTaskMap =
        query?.id > 0
          ? [{ categoryId: this.categoryId, title: query.categoryName }]
          : query.productId?.length > 0
          ? [{ productId: this.queryProductId, title: query.productName }]
          : []
      console.log(this.searchTaskMap)
    }
    this.getData()
  },
  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", productType: true },
          { 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({
        productId: this.queryProductId ? this.queryProductId : null,
        productCategoryId: this.categoryId ? this.categoryId : null,
        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() {
      this.tableList.tableColumn[1].product = true
      this.tableList.tableColumn[2].productType = true
      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,
          isOrder: true
        })
        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.productCategoryId === "") {
          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({
            RuleType: this.RuleType,
            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 = true // 暂时修改为true,如果产品以后是必填,改为false就行
          break
        } else {
          this.isNoProduct = true
        }
      }
    },
    // 取消
    discardBtnClick() {
      this.tableList.tableColumn[1].product = true
      this.tableList.tableColumn[2].productType = true
      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) {
      this.rowIndex = rowIndex
      this.isSel()
      if (!this.isNoProduct && this.currentRowId === 0) {
        this.$message.error("请完成当前新建或取消新建")
      } else {
        this.tableList.tableColumn[2].productType = true
        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
            item.isOrder = true
          } else {
            item.isEdit = true
          }
        })
        this.areaId = row.areaId
        this.subLocationId = row.locationId
        this.productCategoryId = row.productCategoryId
        this.productId = row.productId
        if (
          this.tableList.tableData[rowIndex].productName === "" ||
          this.tableList.tableData[rowIndex].productName === " "
        ) {
          this.tableList.tableColumn[1].product = false
          this.tableList.tableColumn[2].productType = true
        } else {
          this.tableList.tableColumn[1].product = true
          this.tableList.tableColumn[2].productType = false
        }
      }
    },
    // 搜索
    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 +354,74 @@
      }
      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.RuleType = 1
      this.tableList.tableColumn[2].productType = false
      this.productId = item.value
      this.productCategoryId = item.categoryId
    },
    // 选中产品类型方法
    selProductTypeClick(item) {
      this.RuleType = 2
      if (this.currentRowId === 0) {
        this.productCategoryId = item.value
      } else {
        this.tableList.tableColumn[1].product = false
        this.tableList.tableData[this.rowIndex].productName = " "
        this.productId = ""
        this.productCategoryId = this.tableList.tableData[this.rowIndex].productCategoryId
      }
    },
    // 删除
    async delClick(scope) {
      console.log(scope)
      await deleteListingRules(scope.row.id).then((res) => {
        if (res.code === 200) {
          this.$message.success("删除成功")
          this.getData()
        }
      })
    },
    // 删除产品类型
    delSelectClick() {
      this.categoryId = 0
      this.queryProductId = ""
      this.getData()
    }
  },
  watch: {
    rowIndex(newVal) {
      if (this.tableList.tableData[newVal].productName === " ") {
        this.tableList.tableColumn[1].product = false
        this.tableList.tableColumn[2].productType = true
      } else {
        this.tableList.tableColumn[1].product = true
        this.tableList.tableColumn[2].productType = false
      }
    }
  }
}
</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>