| | |
| | | <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> |
| | |
| | | <FormBtnsView |
| | | :add-product="addProduct" |
| | | @inOutBoundClick="inOutBoundClick" |
| | | @inLibraryClick="inLibraryClick" |
| | | :show-procure="showProcure" |
| | | :countObject="statisticsMap" |
| | | :show-sale="showSale" |
| | | @listingRulesClick="listingRulesClick" |
| | | @reorderRulesClick="reorderRulesClick" |
| | | /> |
| | | <div class="bottom"> |
| | | <el-tabs v-model="activeName" type="card"> |
| | |
| | | return { |
| | | visible: false, |
| | | title: "新建", |
| | | infomation: {} |
| | | infomation: {}, |
| | | autoEdit: false |
| | | } |
| | | } |
| | | } |
| | | }, |
| | | 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%", |
| | |
| | | rules: { |
| | | name: [{ required: true, message: "请输入产品名称", trigger: "blur" }], |
| | | model: [{ required: true, message: "请选择物料类型", trigger: "change" }], |
| | | salePrice: [{ required: true, message: "请输入销售价格", trigger: "blur" }], |
| | | // salePrice: [{ required: true, message: "请输入销售价格", trigger: "blur" }], |
| | | unit: [{ required: true, message: "请输入单位", trigger: "blur" }] |
| | | }, |
| | | memberOptions: [{ name: "管理员", id: 1 }], |
| | |
| | | { name: "辅料", id: "辅料" }, |
| | | { name: "耗材", id: "耗材" }, |
| | | { name: "其他", id: "其他" } |
| | | ] |
| | | ], |
| | | statisticsMap: { |
| | | inLibrary: 0 // 在库 |
| | | } |
| | | } |
| | | }, |
| | | created() { |
| | |
| | | this.getProductList() |
| | | this.setTableForm() |
| | | this.setBottonView() |
| | | this.statisticsMap.inLibrary = this.editConfig?.infomation?.amount ?? 0 |
| | | 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({ |
| | |
| | | this.$refs[formName].validate((valid) => { |
| | | if (valid) { |
| | | let requestUrl = this.editConfig.title === "新建" ? addProduct : updateProduct |
| | | this.unsetFieldsToNumber() |
| | | requestUrl({ |
| | | ...this.editConfig.infomation |
| | | }).then((res) => { |
| | |
| | | this.$message.success("添加成功") |
| | | this.$parent.getData() |
| | | } |
| | | }) |
| | | }, console.error) |
| | | } |
| | | }) |
| | | }, |
| | |
| | | }) |
| | | } |
| | | }, |
| | | // 在库点击 |
| | | inLibraryClick() { |
| | | if (this.editConfig.title !== "新建") { |
| | | console.log(this.editConfig.infomation) |
| | | this.$router.push({ |
| | | name: "inventoryReport", |
| | | params: { |
| | | name: this.editConfig.infomation.name, |
| | | id: this.editConfig.infomation.id |
| | | } |
| | | }) |
| | | } |
| | | }, |
| | | // 上架规则 |
| | | 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 === "采购") { |