| | |
| | | <template> |
| | | <win-sm :title="setting.title" @close="close" :width="'800px'"> |
| | | <win-md :title="`${setting.title}预警设置`" @close="close" :width="'800px'"> |
| | | <el-form ref="ruleForm" :model="formData" :rules="rules" class="demo-ruleForm" label-width="100px"> |
| | | <el-form-item label="编号" prop="code"> |
| | | <el-input disabled v-model="formData.code" clearable maxlength="20" show-word-limit style="width: 100%"/> |
| | | </el-form-item> |
| | | <el-form-item label="仓库名称" prop="name"> |
| | | <el-input v-model="formData.name" clearable maxlength="20" show-word-limit style="width: 100%"/> |
| | | </el-form-item> |
| | | <el-form-item label="地址" > |
| | | <el-input v-model="formData.adss" clearable maxlength="20" show-word-limit style="width: 100%"/> |
| | | </el-form-item> |
| | | <el-form-item label="状态" prop="status"> |
| | | <el-switch |
| | | v-model="formData.status" |
| | | active-color="#0d997c" |
| | | inactive-color="#C0CCDA"> |
| | | </el-switch> |
| | | </el-form-item> |
| | | <el-row :gutter="24"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="入库仓库" prop="baseWarehouseId"> |
| | | <el-select |
| | | v-model="formData.baseWarehouseId" |
| | | placeholder="请选择" |
| | | style="width: 100%" |
| | | :disabled="type == 'edit'" |
| | | > |
| | | <el-option v-for="item in warehouses" :key="item.id" :label="item.warehouseName" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="物品分类" prop="baseCategoryIds"> |
| | | <el-cascader |
| | | v-model="formData.baseCategoryIds" |
| | | :options="categoryOptions" |
| | | :props="{ value: 'id' }" |
| | | @change="categoryChange" |
| | | style="width: 100%" |
| | | :disabled="type == 'edit'" |
| | | ></el-cascader> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="24"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="物品名称" prop="baseGoodsTemplateId"> |
| | | <el-select |
| | | :value="formData.baseGoodsTemplateId" |
| | | placeholder="请先择物品分类" |
| | | filterable |
| | | :disabled="!formData.baseCategoryId || type == 'edit'" |
| | | @change="goodsTemplateChange" |
| | | style="width: 100%" |
| | | > |
| | | <el-option |
| | | v-for="item in goodsTemplatelOptions" |
| | | :key="item.id" |
| | | :label="item.goodsName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="规格型号" prop="modelsIds"> |
| | | <el-select |
| | | v-model="formData.modelsIds" |
| | | multiple |
| | | :disabled="!formData.baseGoodsTemplateId || type == 'edit'" |
| | | placeholder="请先择物品名称" |
| | | @change="modelChange" |
| | | @remove-tag="modelRemoveTag" |
| | | style="width: 100%" |
| | | > |
| | | <el-option v-for="item in modelsOptions" :key="item.id" :label="item.modelName" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row v-if="type == 'edit'"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="保底库存" prop="lowerLimit"> |
| | | <el-input placeholder="请输入" v-model.number="formData.lowerLimit"></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="封顶库存" prop="upperLimit"> |
| | | <el-input placeholder="请输入" v-model.number="formData.upperLimit"></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-table v-if="type != 'edit'" :data="formData.models" :stripe="true"> |
| | | <el-table-column prop="baseGoodsModelsId" label="规格型号" align="center"> |
| | | <template slot-scope="scope"> |
| | | {{ getGoodsModelsName(scope.row.baseGoodsModelsId) }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="lowerLimit" label="保底库存" align="center"> |
| | | <template slot-scope="scope"> |
| | | <el-form-item |
| | | v-if="scope.row.lowerLimit || scope.row.upperLimit" |
| | | label-width="0" |
| | | :prop="`models[${scope.$index}].lowerLimit`" |
| | | :rules="rules.lowerLimit" |
| | | > |
| | | <el-input v-model.number="scope.row.lowerLimit"></el-input> |
| | | </el-form-item> |
| | | <el-input v-else v-model.number="scope.row.lowerLimit" style="margin-bottom: 18px;"></el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="upperLimit" label="封顶库存" align="center"> |
| | | <template slot-scope="scope"> |
| | | <el-form-item |
| | | v-if="scope.row.lowerLimit || scope.row.upperLimit" |
| | | label-width="0" |
| | | :prop="`models[${scope.$index}].upperLimit`" |
| | | :rules="rules.upperLimit" |
| | | > |
| | | <el-input v-model.number="scope.row.upperLimit"></el-input> |
| | | </el-form-item> |
| | | <el-input v-else v-model.number="scope.row.upperLimit" style="margin-bottom: 18px;"></el-input> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | </el-form> |
| | | <div slot="footer" align="center" class="dialog-footer"> |
| | | <my-button name="取消" site="form" @click="close"/> |
| | | <my-button name="保存" site="form" @click="save"/> |
| | | <my-button name="取消" site="form" @click="close" /> |
| | | <my-button name="保存" site="form" @click="save" /> |
| | | </div> |
| | | </win-sm> |
| | | </win-md> |
| | | </template> |
| | | |
| | | <script> |
| | | import winSm from '@/components/win/win-sm' |
| | | import myButton from '@/components/myButton/myButton' |
| | | import * as finsystenant from '@/api/baseSetting/finsystenant' |
| | | import winMd from '@/components/win/win-md'; |
| | | import myButton from '@/components/myButton/myButton'; |
| | | import { |
| | | getCategorySelectTree, |
| | | goodsModel, |
| | | goodsTemplate, |
| | | queryGoodsModelInfo, |
| | | selectTenantWarehouse, |
| | | } from '@/api/baseSetting/finsystenant'; |
| | | import {warningConfigAdd, warningConfigGetById, warningConfigUpd,} from '@/api/stock/ledger'; |
| | | import {mapGetters} from 'vuex'; |
| | | import {findParentIds} from '@/utils/index'; |
| | | |
| | | export default { |
| | | components: {winSm, myButton}, |
| | | components: { winMd, myButton }, |
| | | props: { |
| | | setting: { |
| | | type: Object, |
| | | default: () => { |
| | | } |
| | | } |
| | | default: () => {}, |
| | | }, |
| | | }, |
| | | data() { |
| | | return { |
| | | checkAll: false, |
| | | checkedList: [], |
| | | type: '', |
| | | warehouses: [], // 入库仓库列表 |
| | | agencyOptions: [], // 调拨机构 |
| | | categoryOptions: [], // 物品分类列表 |
| | | goodsTemplatelOptions: [], //物品名称 |
| | | modelsOptions: [], //型号列表 |
| | | formData: { |
| | | code: '', |
| | | name: '', |
| | | status: true, |
| | | summary: '', |
| | | warehouseType: 0, //仓库类型0机构1部门 |
| | | baseWarehouseId: '', //仓库编号 |
| | | baseCategoryIds: '', // 分类编号数组 |
| | | baseCategoryId: '', // 分类编号 |
| | | baseGoodsTemplateId: '', // 物品名称模版编号 |
| | | modelsIds: [], //规格型号 |
| | | models: [], |
| | | }, |
| | | rules: { |
| | | code: [ |
| | | {required: true, message: '请输入机构编号', trigger: 'blur'} |
| | | baseCategoryIds: [{ required: true, message: '请选择', trigger: 'blur' }], |
| | | baseGoodsTemplateId: [{ required: true, message: '请选择', trigger: 'blur' }], |
| | | modelsIds: [{ required: true, message: '请选择', trigger: 'blur' }], |
| | | lowerLimit: [ |
| | | { required: true, message: '请输入', trigger: 'blur' }, |
| | | { type: 'number', message: '请输入数字值', trigger: 'blur' }, |
| | | ], |
| | | name: [ |
| | | {required: true, message: '请输入机构名称', trigger: 'blur'} |
| | | upperLimit: [ |
| | | { required: true, message: '请输入', trigger: 'blur' }, |
| | | { type: 'number', message: '请输入数字值', trigger: 'blur' }, |
| | | ], |
| | | status: [ |
| | | {required: true, message: '请选择状态', trigger: 'blur'} |
| | | ] |
| | | } |
| | | } |
| | | }, |
| | | }; |
| | | }, |
| | | computed: { |
| | | ...mapGetters(['userInfo']), |
| | | }, |
| | | created() { |
| | | if(this.setting.info){ |
| | | this.formData = Object.assign({},JSON.parse(this.setting.info)) |
| | | } |
| | | this.init(); |
| | | }, |
| | | methods: { |
| | | getEditInfo(id){ |
| | | |
| | | async init() { |
| | | if (this.setting.id) { |
| | | this.type = 'edit'; |
| | | const detail = await warningConfigGetById({ id: this.setting.id }); |
| | | await this.getCategoryTree(); |
| | | this.formData = Object.assign({}, detail); |
| | | // 分类反显 |
| | | let res = await queryGoodsModelInfo({ baseGoodsModelsId: this.formData.baseGoodsModelsId }); |
| | | this.formData.baseCategoryId = res[0].categoryId; |
| | | this.formData.baseCategoryIds = findParentIds(this.categoryOptions, this.formData.baseCategoryId); |
| | | // 物品名称反显 |
| | | this.getgoodsTemplate(this.formData.baseCategoryId); |
| | | // 规格型号反显 |
| | | this.getgoodsModel(this.formData.baseGoodsTemplateId); |
| | | this.formData.modelsIds = [this.formData.baseGoodsModelsId]; |
| | | this.getWarehouseList(); |
| | | } else { |
| | | this.getWarehouseList(); |
| | | this.getCategoryTree(); |
| | | } |
| | | }, |
| | | // 获取入库仓库列表 |
| | | getWarehouseList() { |
| | | selectTenantWarehouse({ agencyId: this.userInfo.tenantId }) |
| | | .then((res) => { |
| | | this.warehouses = res; |
| | | if (this.warehouses.length && !this.formData.baseWarehouseId) { |
| | | // 默认选中第一个仓库 |
| | | this.formData.baseWarehouseId = this.warehouses[0].id; |
| | | } |
| | | }) |
| | | .catch((err) => { |
| | | console.log('err', err); |
| | | }); |
| | | }, |
| | | |
| | | getCategoryTree() { |
| | | // 获取物品分类列表 |
| | | return new Promise(async (resolve) => { |
| | | const treeRes = await getCategorySelectTree(); |
| | | this.categoryOptions = this.removeEmptyChildren(treeRes); |
| | | resolve(); |
| | | }); |
| | | }, |
| | | |
| | | // 获取物品名称列表 |
| | | getgoodsTemplate(id) { |
| | | goodsTemplate({ categoryId: id || '', agencyId: this.userInfo.tenantId }).then((res) => { |
| | | this.goodsTemplatelOptions = res; |
| | | }); |
| | | }, |
| | | |
| | | // 规格型号 |
| | | getgoodsModel(id) { |
| | | goodsModel({ goodsTemplatesId: id || '' }).then((res) => { |
| | | this.modelsOptions = res; |
| | | }); |
| | | }, |
| | | |
| | | // 根据规格型号id获取名字 |
| | | getGoodsModelsName(id) { |
| | | let item = this.modelsOptions.find((v) => v.id == id); |
| | | if (item) { |
| | | return item.modelName; |
| | | } |
| | | return; |
| | | }, |
| | | |
| | | // 物品分类选择 |
| | | categoryChange(e) { |
| | | if (!e) return; |
| | | this.goodsTemplatelOptions = []; |
| | | this.modelsOptions = []; |
| | | this.formData.baseGoodsTemplateId = ''; |
| | | this.formData.modelsIds = []; |
| | | this.formData.models = []; |
| | | |
| | | this.formData.baseCategoryId = e[e.length - 1]; |
| | | // 根据选中分类请求物品名称列表 |
| | | this.getgoodsTemplate(this.formData.baseCategoryId); |
| | | }, |
| | | |
| | | // 物品名称列表选择 |
| | | goodsTemplateChange(e) { |
| | | this.formData.modelsIds = []; |
| | | this.formData.models = []; |
| | | |
| | | this.formData.baseGoodsTemplateId = e; |
| | | // 根据选中物品名称id获取规格型号列表 |
| | | this.getgoodsModel(e); |
| | | }, |
| | | |
| | | removeEmptyChildren(arr) { |
| | | arr.forEach((item) => { |
| | | if (!item.children || !item.children.length) { |
| | | delete item.children; |
| | | } else { |
| | | this.removeEmptyChildren(item.children); |
| | | } |
| | | }); |
| | | return arr; |
| | | }, |
| | | |
| | | // 规格型号选择 |
| | | modelChange(e) { |
| | | let arr = this.formData.models; |
| | | let str = JSON.stringify(arr); |
| | | e.forEach((item, index) => { |
| | | if (str && !str.includes(item)) { |
| | | arr.push({ baseGoodsModelsId: item, lowerLimit: null, upperLimit: null }); |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | // 规格型号移除 |
| | | modelRemoveTag(e) { |
| | | let delIndex = this.formData.models.findIndex((v) => v.baseGoodsModelsId == e); |
| | | this.formData.models.splice(delIndex, 1); |
| | | }, |
| | | |
| | | getEditInfo(id) {}, |
| | | close() { |
| | | this.$emit('close') |
| | | this.$emit('close'); |
| | | }, |
| | | save() { |
| | | this.$refs.ruleForm.validate((valid) => { |
| | | if (valid) { |
| | | const params = Object.assign({}, this.formData) |
| | | if(this.setting.id){ |
| | | if (this.setting.id) { |
| | | // 编辑接口 |
| | | finsystenant.edit(params).then(res => { |
| | | if (res) { |
| | | this.$message.success('保存成功!') |
| | | this.close() |
| | | this.$emit('search') |
| | | } else { |
| | | this.$message.error('保存失败') |
| | | } |
| | | }) |
| | | }else{ |
| | | params.orgId = this.setting.orgId |
| | | finsystenant.add(params).then(res => { |
| | | if (res) { |
| | | this.$message.success('保存成功!') |
| | | this.close() |
| | | this.$emit('search') |
| | | } else { |
| | | this.$message.error('保存失败') |
| | | } |
| | | }) |
| | | const params = { |
| | | id: this.setting.id, |
| | | lowerLimit: this.formData.lowerLimit, |
| | | upperLimit: this.formData.upperLimit, |
| | | }; |
| | | warningConfigUpd(params).then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }); |
| | | } else { |
| | | const params = { |
| | | warehouseType: this.formData.warehouseType, |
| | | baseWarehouseId: this.formData.baseWarehouseId, |
| | | baseGoodsTemplateId: this.formData.baseGoodsTemplateId, |
| | | modelConfigStr: JSON.stringify(this.formData.models), |
| | | }; |
| | | warningConfigAdd(params).then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }); |
| | | } |
| | | } else { |
| | | this.$message.error('校验未通过,请检查。') |
| | | this.$message.error('校验未通过,请检查。'); |
| | | } |
| | | }) |
| | | } |
| | | } |
| | | } |
| | | }); |
| | | }, |
| | | }, |
| | | }; |
| | | </script> |