zuozhengqing
2023-11-06 e7ccd2a06e4cdf3709e699507e1e15379ded5b83
src/views/productManage/productCategory/AddProductCategoryDialog.vue
@@ -38,7 +38,12 @@
        size="mini"
      >
        <div class="basic-info">
          <FormBtnsView :showProduct="true" :countObject="statisticsMap" @productClick="productClick" />
          <FormBtnsView
            :showProduct="true"
            :countObject="statisticsMap"
            @productClick="productClick"
            @listingRulesClick="listingRulesClick"
          />
          <div class="basic-info-view">
            <!-- <el-row> -->
            <!-- <el-col :span="24">
@@ -173,7 +178,7 @@
import { addProductCategory, updateProductCategory, deleteProductCategory } from "@/api/product/productCategory"
import { getDataByType } from "@/api/data"
import {getProductList} from "@/api/product/product";
import { getProductList } from "@/api/product/product"
export default {
  name: "AddProductCategoryDialog",
  props: {
@@ -184,7 +189,7 @@
          visible: false,
          title: "新建",
          infomation: { type: [] },
          autoEdit: false,
          autoEdit: false
        }
      }
    },
@@ -197,13 +202,13 @@
  },
  components: {},
  computed: {
    modalTitle(){
      if (this.editConfig.title === '编辑' && this.editConfig.autoEdit){
        return '编辑'
      }else if (this.editConfig.title === '编辑') {
        return !this.showEdit ? '编辑' : '查看'
      }else {
        return '新建'
    modalTitle() {
      if (this.editConfig.title === "编辑" && this.editConfig.autoEdit) {
        return "编辑"
      } else if (this.editConfig.title === "编辑") {
        return !this.showEdit ? "编辑" : "查看"
      } else {
        return "新建"
      }
    }
  },
@@ -225,7 +230,7 @@
      showEdit: false, // 是否显示编辑按钮
      isDelClick: false, // 删除按钮是否可点击
      showFooter: false, // 是否显示取消保存,
      statisticsMap:{
      statisticsMap: {
        product: 0 // 产品数量
      }
    }
@@ -233,7 +238,7 @@
  created() {
    this.setBottonView()
    this.getProductCount()
    if (this.editConfig.autoEdit){
    if (this.editConfig.autoEdit) {
      this.editClick()
    }
    this.setOptionalFieldsToEmpty()
@@ -242,40 +247,44 @@
    /**
     * 非必填项后端返回的是数字 0,表单需要空串才能视为未选择回显
     */
    setOptionalFieldsToEmpty(){
      ['parentId','costingMethod','inventoryValuation','forceRemovalStrategy']
          .filter(filed => this.editConfig.infomation[filed] === 0)
          .forEach(filed => {
            this.editConfig.infomation[filed] = ''
          })
    setOptionalFieldsToEmpty() {
      let arr = ["parentId", "costingMethod", "inventoryValuation", "forceRemovalStrategy"]
      arr
        .filter((filed) => this.editConfig.infomation[filed] === 0)
        .forEach((filed) => {
          this.editConfig.infomation[filed] = ""
        })
    },
    /**
     * 后端只接受数字形式, 保存时还得再转回去
     */
    unsetFieldsToNumber(){
      ['parentId','costingMethod','inventoryValuation','forceRemovalStrategy']
          .filter(filed => this.editConfig.infomation[filed] === '')
          .forEach(filed => {
            this.editConfig.infomation[filed] = 0
          })
    unsetFieldsToNumber() {
      let arr = ["parentId", "costingMethod", "inventoryValuation", "forceRemovalStrategy"]
      arr
        .filter((filed) => this.editConfig.infomation[filed] === "")
        .forEach((filed) => {
          this.editConfig.infomation[filed] = 0
        })
    },
    // 获取产品数量
    getProductCount(){
    getProductCount() {
      getProductList({
        keyWord: '',
        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
      })
        .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() {
@@ -374,6 +383,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
            }
          })
        }
      })
    }
  }
}