songshankun
2023-11-03 cf6a4b874aed82592eea78294715c7c688f9b248
src/views/productManage/product/AddProductDialog.vue
@@ -43,6 +43,8 @@
            :show-procure="showProcure"
            :countObject="statisticsMap"
            :show-sale="showSale"
            @listingRulesClick="listingRulesClick"
            @reorderRulesClick="reorderRulesClick"
          />
          <div class="bottom">
            <el-tabs v-model="activeName" type="card">
@@ -165,7 +167,7 @@
                      :disabled="!showFooter"
                    >
                      <el-option
                        v-for="item in productCategoryListWithDefault"
                        v-for="item in productCategoryOptions"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id"
@@ -482,9 +484,6 @@
  },
  components: {},
  computed: {
    productCategoryListWithDefault() {
      return [{ id: 0, name: "请选择" }, ...(this.productCategoryOptions ?? [])]
    },
    modalTitle() {
      if (this.editConfig.title === "编辑" && this.editConfig.autoEdit) {
        return "编辑"
@@ -508,7 +507,6 @@
      memberOptions: [{ name: "管理员", id: 1 }],
      productCategoryOptions: [], // 产品类别
      productTypeOptions: [
        { name: "请选择", id: 0 },
        { name: "能消耗", id: 1 },
        { name: "服务", id: 2 },
        { name: "可库存产品", id: 3 }
@@ -556,8 +554,31 @@
    if (this.editConfig.autoEdit) {
      this.editClick()
    }
    this.setOptionalFieldsToEmpty()
  },
  methods: {
    /**
     * 非必填项后端返回的是数字 0,表单需要空串才能视为未选择回显
     */
    setOptionalFieldsToEmpty() {
      let arr = ["productType", "categoryId"]
      arr
        .filter((filed) => this.editConfig.infomation[filed] === 0)
        .forEach((filed) => {
          this.editConfig.infomation[filed] = ""
        })
    },
    /**
     * 后端只接受数字形式, 保存时还得再转回去
     */
    unsetFieldsToNumber() {
      let arr = ["productType", "categoryId"]
      arr
        .filter((filed) => this.editConfig.infomation[filed] === "")
        .forEach((filed) => {
          this.editConfig.infomation[filed] = 0
        })
    },
    // 获取产品类别
    async getProductCategoryList() {
      await getProductCategoryList({
@@ -618,6 +639,7 @@
      this.$refs[formName].validate((valid) => {
        if (valid) {
          let requestUrl = this.editConfig.title === "新建" ? addProduct : updateProduct
          this.unsetFieldsToNumber()
          requestUrl({
            ...this.editConfig.infomation
          }).then((res) => {
@@ -627,7 +649,7 @@
              this.$message.success("添加成功")
              this.$parent.getData()
            }
          })
          }, console.error)
        }
      })
    },
@@ -761,6 +783,34 @@
        })
      }
    },
    // 上架规则
    listingRulesClick() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$router.push({
            path: "/warehouseManage/listingRules",
            query: {
              productName: this.editConfig.infomation.name,
              productId: this.editConfig.title === "新建" ? "" : this.editConfig.infomation.id
            }
          })
        }
      })
    },
    // 重订购规则
    reorderRulesClick() {
      this.$refs.form.validate((valid) => {
        if (valid) {
          this.$router.push({
            path: "/productManage/reorderRules",
            query: {
              productName: this.editConfig.infomation.name,
              productId: this.editConfig.title === "新建" ? "" : this.editConfig.infomation.id
            }
          })
        }
      })
    },
    // 可销售/可采购
    checkboxChange(val, param) {
      if (val === "采购") {