zuozhengqing
2023-11-24 58ac82fceff96784dd9e16872d1e2316fa2cfdec
src/views/productManage/productCategory/AddProductCategoryDialog.vue
@@ -1,14 +1,14 @@
<template>
  <div class="add-common">
    <el-dialog
      :title="editCommonConfig.title + '产品类别'"
      :title="modalTitle + '产品类别'"
      :visible.sync="editConfig.visible"
      :width="dialogWidth"
      :before-close="handleClose"
    >
      <!-- 头 -->
      <div slot="title" class="dialog-header">
        <span>{{ editCommonConfig.title + "产品类别" }}</span>
        <span>{{ modalTitle + "产品类别" }}</span>
        <div class="header_btns">
          <!-- <span class="btn">
            <i class="el-icon-printer"></i>
@@ -36,10 +36,14 @@
        label-position="right"
        label-width="110px"
        size="mini"
        style="height: 290px; overflow-x: hidden"
      >
        <div class="basic-info">
          <FormBtnsView :showProduct="true" @productClick="productClick" />
          <FormBtnsView
            :showProduct="true"
            :countObject="statisticsMap"
            @productClick="productClick"
            @listingRulesClick="listingRulesClick"
          />
          <div class="basic-info-view">
            <!-- <el-row> -->
            <!-- <el-col :span="24">
@@ -161,9 +165,9 @@
        </div>
      </el-form>
      <!-- 尾 -->
      <div v-if="showFooter" slot="footer" class="dialog-footer">
      <div slot="footer" class="dialog-footer">
        <!-- <el-button type="primary" size="small" @click="editConfig.visible = false">保并提交审批</el-button> -->
        <el-button type="primary" size="small" @click="saveClick('form')">保存</el-button>
        <el-button type="primary" size="small" @click="saveClick('form')" :disabled="!showFooter">保存</el-button>
        <el-button size="small" @click="editConfig.visible = false">取消</el-button>
      </div>
    </el-dialog>
@@ -174,6 +178,7 @@
import { addProductCategory, updateProductCategory, deleteProductCategory } from "@/api/product/productCategory"
import { getDataByType } from "@/api/data"
import { getProductList } from "@/api/product/product"
export default {
  name: "AddProductCategoryDialog",
  props: {
@@ -183,7 +188,8 @@
        return {
          visible: false,
          title: "新建",
          infomation: { type: [] }
          infomation: { type: [] },
          autoEdit: false
        }
      }
    },
@@ -195,7 +201,17 @@
    }
  },
  components: {},
  computed: {},
  computed: {
    modalTitle() {
      if (this.editConfig.title === "编辑" && this.editConfig.autoEdit) {
        return "编辑"
      } else if (this.editConfig.title === "编辑") {
        return !this.showEdit ? "编辑" : "查看"
      } else {
        return "新建"
      }
    }
  },
  data() {
    return {
      dialogWidth: "50%",
@@ -213,13 +229,65 @@
      showButton: true,
      showEdit: false, // 是否显示编辑按钮
      isDelClick: false, // 删除按钮是否可点击
      showFooter: false // 是否显示取消保存
      showFooter: false, // 是否显示取消保存,
      statisticsMap: {
        product: 0 // 产品数量
      }
    }
  },
  created() {
    this.setBottonView()
    this.getProductCount()
    if (this.editConfig.autoEdit) {
      this.editClick()
    }
    this.setOptionalFieldsToEmpty()
  },
  methods: {
    /**
     * 非必填项后端返回的是数字 0,表单需要空串才能视为未选择回显
     */
    setOptionalFieldsToEmpty() {
      let arr = ["parentId", "costingMethod", "inventoryValuation", "forceRemovalStrategy"]
      arr
        .filter((filed) => this.editConfig.infomation[filed] === 0)
        .forEach((filed) => {
          this.editConfig.infomation[filed] = ""
        })
    },
    /**
     * 后端只接受数字形式, 保存时还得再转回去
     */
    unsetFieldsToNumber() {
      let arr = ["parentId", "costingMethod", "inventoryValuation", "forceRemovalStrategy"]
      arr
        .filter((filed) => this.editConfig.infomation[filed] === "")
        .forEach((filed) => {
          this.editConfig.infomation[filed] = 0
        })
    },
    // 获取产品数量
    getProductCount() {
      if (this.editConfig.title !== "新建") {
        getProductList({
          keyWord: "",
          categoryId: this.editConfig.title === "新建" ? null : this.editConfig.infomation.id,
          page: 1,
          pageSize: 1
        })
          .then((res) => {
            if (res.code === 200) {
              this.statisticsMap.product = res?.total ?? 0
            } else {
              this.statisticsMap.product = 0
            }
          })
          .catch((err) => {
            console.error(err)
            this.statisticsMap.product = 0
          })
      }
    },
    // 设置删除/打印/编辑是否显示
    setBottonView() {
      if (this.editConfig.title === "新建") {
@@ -255,6 +323,7 @@
      this.showFooter = true
    },
    saveParams() {
      this.unsetFieldsToNumber()
      let data = JSON.parse(JSON.stringify(this.editConfig.infomation))
      let params = {
@@ -316,6 +385,20 @@
          })
        }
      })
    },
    // 上架规则
    listingRulesClick() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$router.push({
            path: "/warehouseManage/listingRules",
            query: {
              categoryName: this.editConfig.infomation.name,
              id: this.editConfig.title === "新建" ? "" : this.editConfig.infomation.id
            }
          })
        }
      })
    }
  }
}