| | |
| | | <template> |
| | | <win-md class="stock-edit" :title="`${setting.title}报废报废`" @close="close" :width="'800px'"> |
| | | <win-md class="stock-edit" :title="`${setting.title}报废`" @close="close" :width="'800px'"> |
| | | <el-form class="form" ref="ruleForm" :model="formData" :rules="rules" label-width="120px"> |
| | | <div class="main-w"> |
| | | <el-row :gutter="24" class="headerHeight"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="机构" prop="warehouseId"> |
| | | <el-form-item label="机构" prop="agencyName"> |
| | | <el-input :value="formData.agencyName" disabled></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="报废仓库" prop="warehouseId"> |
| | | <el-input :value="formData.warehouseName" disabled></el-input> |
| | | <el-select v-model="formData.warehouseId" placeholder="请选择" style="width: 100%"> |
| | | <el-option v-for="item in warehouses" :key="item.id" :label="item.warehouseName" :value="item.id" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="24" class="headerHeight"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="报废人" prop="buyType"> |
| | | <el-form-item label="报废人" prop="operatorName"> |
| | | <el-input :value="formData.operatorName" disabled></el-input> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="报废时间" prop="procureTime"> |
| | | <el-form-item label="报废时间" prop="dealTime"> |
| | | <el-date-picker |
| | | v-model="formData.procureTime" |
| | | v-model="formData.dealTime" |
| | | type="datetime" |
| | | value="yyyy-MM-dd HH:mm:ss" |
| | | value-format="yyyyMMddHHmmss" |
| | |
| | | </el-row> |
| | | <el-row :gutter="24" class="headerHeight"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="报废审批手续" prop="procureDoc"> |
| | | <el-form-item label="报废审批手续" prop="uploadFiles"> |
| | | <upload ref="uploadRef" :values="fileList" :settings="uploadSettings" @on-change="uploadChange"></upload> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <div class="goods-card" v-for="(goodsItem, goodsIndex) in formData.procureGoods" :key="goodsIndex"> |
| | | <div class="goods-card" v-for="(goodsItem, goodsIndex) in formData.scrappedGoodsInfo" :key="goodsIndex"> |
| | | <el-row :gutter="24"> |
| | | <el-col :span="12"> |
| | | <el-form-item |
| | | label="物品分类" |
| | | :prop="`procureGoods[${goodsIndex}].baseCategoryIds`" |
| | | :prop="`scrappedGoodsInfo[${goodsIndex}].baseCategoryIds`" |
| | | :rules="{ |
| | | required: true, |
| | | message: '请选择', |
| | |
| | | <el-col :span="12"> |
| | | <el-form-item |
| | | label="物品名称" |
| | | :prop="`procureGoods[${goodsIndex}].baseGoodsTemplateId`" |
| | | :rules="{ |
| | | required: true, |
| | | message: '请选择', |
| | | trigger: 'change', |
| | | }" |
| | | :prop="`scrappedGoodsInfo[${goodsIndex}].baseGoodsTemplateId`" |
| | | :rules="rules.baseGoodsTemplateId" |
| | | > |
| | | <el-select |
| | | v-model="goodsItem.baseGoodsTemplateId" |
| | |
| | | <el-col :span="12"> |
| | | <el-form-item |
| | | label="规格型号" |
| | | :prop="`procureGoods[${goodsIndex}].modelsIds`" |
| | | :prop="`scrappedGoodsInfo[${goodsIndex}].modelsIds`" |
| | | :rules="{ |
| | | required: true, |
| | | message: '请选择', |
| | |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-table :data="goodsItem.models" :stripe="true"> |
| | | <el-table :data="goodsItem.scrappedGoodsList" :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="price" label="剩余数量" align="center"> |
| | | <el-table-column prop="total" label="剩余数量" align="center"> |
| | | <template slot-scope="scope"> |
| | | <el-input type="number" v-model="scope.row.price"></el-input> |
| | | {{ scope.row.total }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="counts" label="报废数量" align="center"> |
| | | <template slot-scope="scope"> |
| | | <el-input type="number" v-model="scope.row.counts"></el-input> |
| | | <el-input v-model.number="scope.row.counts"></el-input> |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="counts" label="报废原因" align="center"> |
| | | <el-table-column prop="scrappedCode" label="报废原因" align="center"> |
| | | <template slot-scope="scope"> |
| | | <el-select v-model="scope.row.modelsIds" multiple placeholder="请选择"> |
| | | <el-option v-for="item in []" :key="item.id" :label="item.label" :value="item.id" /> |
| | | <el-select v-model="scope.row.scrappedCode" placeholder="请选择"> |
| | | <el-option |
| | | v-for="item in scrapReasonOptions" |
| | | :key="item.dict_value" |
| | | :label="item.dict_label" |
| | | :value="item.dict_value" |
| | | /> |
| | | </el-select> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <div class="btn-group"> |
| | | <el-button |
| | | v-if="formData.procureGoods.length > 1" |
| | | v-if="formData.scrappedGoodsInfo.length > 1" |
| | | name="移除" |
| | | type="danger" |
| | | plain |
| | |
| | | >移除</el-button |
| | | > |
| | | <el-button |
| | | v-if="formData.procureGoods.length - 1 == goodsIndex" |
| | | v-if="formData.scrappedGoodsInfo.length - 1 == goodsIndex" |
| | | name="新增物品" |
| | | type="primary" |
| | | plain |
| | |
| | | </win-md> |
| | | </template> |
| | | <script> |
| | | import { scrappedAdd } from '@/api/stock/scrap'; |
| | | import { |
| | | goodsTemplate, |
| | | procureAdd, |
| | | procureEdit, |
| | | selectTenantWarehouse, |
| | | goodsModel, |
| | | procureDetail, |
| | | } from '@/api/stock/procure/purchaseOrder'; |
| | | warehouseSelectNumber, |
| | | } from '@/api/baseSetting/finsystenant'; |
| | | import { getTree } from '@/api/foudation/classification'; |
| | | import MyButton from '@/components/myButton/myButton'; |
| | | import winMd from '@/components/win/win-md'; |
| | | import upload from '@/components/upload/index'; |
| | | import { getUploadUrl, getDownUrl } from '@/utils/base'; |
| | | import { getUploadUrl } from '@/utils/base'; |
| | | import { mapGetters } from 'vuex'; |
| | | import SettingIplatform from '../../../../../public/static/config'; |
| | | import { getDicts } from '@/api/system/dict/data'; |
| | | |
| | | export default { |
| | | components: { MyButton, winMd, upload }, |
| | |
| | | }, |
| | | }, |
| | | data() { |
| | | // 自定义校验 |
| | | // 物品重复校验 |
| | | var checkGoodsTemplateId = (rule, value, callback) => { |
| | | if (!value) { |
| | | return callback(new Error('请选择')); |
| | | } |
| | | let temp = this.formData.scrappedGoodsInfo.filter((v) => v.baseGoodsTemplateId == value); |
| | | if (!temp || temp.length != 1) { |
| | | return callback(new Error('已选过此物品')); |
| | | } |
| | | callback(); |
| | | }; |
| | | return { |
| | | visible: false, |
| | | loading: false, |
| | | buyTypeOptions: [ |
| | | { |
| | | label: '集采', |
| | | value: '1', |
| | | }, |
| | | { |
| | | label: '自采', |
| | | value: '2', |
| | | }, |
| | | ], |
| | | fileList: [], |
| | | warehouses: [], // 报废仓库列表 |
| | | categoryOptions: [], // 物品分类列表 |
| | | modelList: [], //型号列表 |
| | | scrapReasonOptions: [], // 报废原因列表 |
| | | formData: { |
| | | procureDoc: '', |
| | | uploadFiles: '', |
| | | warehouseId: '', // 报废仓库id |
| | | procureTime: '', // 报废时间 |
| | | buyType: '2', // 报废方式(1:集采;2=自采) |
| | | procureGoods: [], |
| | | dealTime: '', // 报废时间 |
| | | scrappedGoodsInfo: [], |
| | | }, |
| | | goodsItem: { |
| | | baseCategoryIds: '', // 分类编号数组 |
| | |
| | | sort: '', // 显示顺序 |
| | | goodsOptions: [], // 物品列表select |
| | | modelsOptions: [], //规格型号select |
| | | models: [], // 物品名称 |
| | | scrappedGoodsList: [], // 物品名称 |
| | | modelsIds: [], //规格型号 |
| | | }, |
| | | modelsItem: { |
| | | baseGoodsModelsId: '', // 规格型号编号 |
| | | counts: 0, // 操作数量 |
| | | }, |
| | | rules: { |
| | | warehouseId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | procureTime: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | dealTime: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | buyType: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | |
| | | procureDoc: [{ required: true, message: '请上传', trigger: 'change' }], |
| | | uploadFiles: [{ required: true, message: '请上传', trigger: 'change' }], |
| | | baseCategoryIds: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | baseGoodsTemplateId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | baseGoodsTemplateId: [{ validator: checkGoodsTemplateId, trigger: ['blur', 'change'] }], |
| | | modelsIds: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | }, |
| | | |
| | |
| | | this.getgoodsTemplate(); |
| | | this.getgoodsModel(); |
| | | this.getCategoryTree(); |
| | | this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | this.formData.operatorId = this.userInfo.userCode; |
| | | this.formData.scrappedGoodsInfo.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | this.formData.operatorId = this.userInfo.id; |
| | | this.formData.operatorName = this.userInfo.userName; |
| | | this.formData.agencyId = this.userInfo.tenantId; |
| | | this.formData.agencyName = this.userInfo.tenantName; |
| | | this.formData.warehouseId = this.userInfo.tenantId; |
| | | this.formData.warehouseName = this.userInfo.tenantName; |
| | | this.formData.warehouseType = 0; |
| | | getDicts('SCRAP_REASON').then((res) => { |
| | | this.scrapReasonOptions = res; |
| | | }); |
| | | }, |
| | | async getCategoryTree() { |
| | | // 获取物品分类列表 |
| | |
| | | getgoodsTemplate(id, index) { |
| | | goodsTemplate({ categoryId: id || '' }).then((res) => { |
| | | if (index || index == 0) { |
| | | this.$set(this.formData.procureGoods[index], 'goodsOptions', res); |
| | | this.$set(this.formData.scrappedGoodsInfo[index], 'goodsOptions', res); |
| | | } else { |
| | | this.goodsTemplatelAll = res; |
| | | } |
| | |
| | | getgoodsModel(id, index) { |
| | | goodsModel({ goodsTemplatesId: id || '' }).then((res) => { |
| | | if (index || index == 0) { |
| | | this.$set(this.formData.procureGoods[index], 'modelsOptions', res); |
| | | this.$set(this.formData.scrappedGoodsInfo[index], 'modelsOptions', res); |
| | | } else { |
| | | this.goodsModelAll = res; |
| | | } |
| | |
| | | |
| | | // 物品分类选择 |
| | | categoryChange(e, index) { |
| | | this.formData.procureGoods[index].goodsOptions = []; |
| | | this.formData.procureGoods[index].baseGoodsTemplateId = ''; |
| | | this.formData.procureGoods[index].goodsTemplateName = ''; |
| | | this.formData.procureGoods[index].modelsOptions = []; |
| | | this.formData.procureGoods[index].modelsIds = []; |
| | | this.formData.procureGoods[index].models = []; |
| | | this.formData.scrappedGoodsInfo[index].goodsOptions = []; |
| | | this.formData.scrappedGoodsInfo[index].baseGoodsTemplateId = ''; |
| | | this.formData.scrappedGoodsInfo[index].goodsTemplateName = ''; |
| | | this.formData.scrappedGoodsInfo[index].modelsOptions = []; |
| | | this.formData.scrappedGoodsInfo[index].modelsIds = []; |
| | | this.formData.scrappedGoodsInfo[index].scrappedGoodsList = []; |
| | | |
| | | this.formData.procureGoods[index].baseCategoryId = e[e.length - 1]; |
| | | this.formData.scrappedGoodsInfo[index].baseCategoryId = e[e.length - 1]; |
| | | // 根据选中分类请求物品名称列表 |
| | | this.getgoodsTemplate(e[e.length - 1], index); |
| | | }, |
| | | |
| | | // 物品名称列表 |
| | | goodsTemplateChange(e, index) { |
| | | this.formData.procureGoods[index].modelsOptions = []; |
| | | this.formData.procureGoods[index].modelsIds = []; |
| | | this.formData.procureGoods[index].models = []; |
| | | this.formData.scrappedGoodsInfo[index].modelsOptions = []; |
| | | this.formData.scrappedGoodsInfo[index].modelsIds = []; |
| | | this.formData.scrappedGoodsInfo[index].scrappedGoodsList = []; |
| | | |
| | | this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e); |
| | | this.formData.scrappedGoodsInfo[index].goodsTemplateName = this.getGoodsTemplateName(e); |
| | | // 根据选中物品名称id获取规格型号列表 |
| | | this.getgoodsModel(e, index); |
| | | }, |
| | | |
| | | // 规格型号选择 |
| | | modelChange(e, index) { |
| | | let arr = [...this.formData.procureGoods[index].models]; |
| | | async modelChange(e, index) { |
| | | let arr = [...this.formData.scrappedGoodsInfo[index].scrappedGoodsList]; |
| | | let str = JSON.stringify(arr); |
| | | e.forEach((item) => { |
| | | for (let item of e) { |
| | | if (str.indexOf(item) == -1) { |
| | | let temp = this.goodsModelAll.find((v) => v.id == item); |
| | | arr.push({ ...this.modelsItem, baseGoodsModelsId: item, unit: temp.unit }); |
| | | // 获取库存 |
| | | let num = await warehouseSelectNumber({ |
| | | warehouseId: this.formData.warehouseId, |
| | | baseGoodsModelsId: item, |
| | | warehouseType: 0, |
| | | states: 1, |
| | | buyType: null, |
| | | }); |
| | | arr.push({ baseGoodsModelsId: item, total: num, counts: null, scrappedCode: null }); |
| | | } |
| | | }); |
| | | this.formData.procureGoods[index].models = arr; |
| | | } |
| | | this.formData.scrappedGoodsInfo[index].scrappedGoodsList = arr; |
| | | }, |
| | | |
| | | // 规格型号移除 |
| | | modelRemoveTag(e, index) { |
| | | let arr = this.formData.procureGoods[index].models; |
| | | let arr = this.formData.scrappedGoodsInfo[index].scrappedGoodsList; |
| | | let delIndex = arr.findIndex((v) => v.baseGoodsModelsId == e); |
| | | this.formData.procureGoods[index].models.splice(delIndex, 1); |
| | | this.formData.scrappedGoodsInfo[index].scrappedGoodsList.splice(delIndex, 1); |
| | | }, |
| | | |
| | | // 上传 |
| | | uploadChange() { |
| | | let arr = this.$refs.uploadRef.fileList; |
| | | this.formData.procureDoc = JSON.stringify(arr); |
| | | this.formData.uploadFiles = JSON.stringify(arr); |
| | | }, |
| | | |
| | | // 点击新增物品 |
| | | addGoods() { |
| | | this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | this.formData.scrappedGoodsInfo.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | }, |
| | | |
| | | // 点击移除 |
| | | removeGoods(index) { |
| | | this.formData.procureGoods.splice(index, 1); |
| | | this.formData.scrappedGoodsInfo.splice(index, 1); |
| | | }, |
| | | |
| | | // 提交 |
| | |
| | | this.$refs['ruleForm'].validate((valid) => { |
| | | if (valid) { |
| | | console.log('this.formData', this.formData); |
| | | if (!this.setting.id) { |
| | | procureAdd(this.formData) |
| | | .then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }) |
| | | .catch((err) => { |
| | | console.log('create err', err); |
| | | this.$message.error('保存失败'); |
| | | }); |
| | | } else { |
| | | procureEdit(this.formData) |
| | | .then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }) |
| | | .catch((err) => { |
| | | console.log('edit err', err); |
| | | this.$message.error('保存失败'); |
| | | }); |
| | | } |
| | | scrappedAdd(this.formData) |
| | | .then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }) |
| | | .catch((err) => { |
| | | console.log('create err', err); |
| | | this.$message.error('保存失败'); |
| | | }); |
| | | } else { |
| | | this.$message.error('校验未通过,请检查。'); |
| | | } |
| | |
| | | close() { |
| | | this.formData = { |
| | | warehouseId: '', // 报废仓库id |
| | | procureTime: '', // 报废时间 |
| | | procureGoods: [], |
| | | dealTime: '', // 报废时间 |
| | | scrappedGoodsInfo: [], |
| | | }; |
| | | this.$emit('close'); |
| | | }, |
| | | |
| | | // 通过子集id查到所以相关父级id并返回数组 |
| | | findParentIds(dataSource, nodeId) { |
| | | const parentIds = [nodeId]; // 用于存储所有父节点ID的数组 |
| | | |
| | | // 定义一个递归函数,用于遍历整棵树并查找子节点的所有父节点 |
| | | function traverse(node, nodeId) { |
| | | if (node.id === nodeId) { |
| | | // 如果当前节点的ID等于子节点的ID,则表示已经找到了子节点,可以开始向上查找父节点 |
| | | return true; // 返回true表示已经找到了子节点 |
| | | } |
| | | |
| | | if (node.children) { |
| | | // 如果当前节点有子节点,则继续遍历子节点 |
| | | for (const childNode of node.children) { |
| | | if (traverse(childNode, nodeId)) { |
| | | // 如果在子节点中找到了子节点的父节点,则将当前节点的ID添加到父节点ID数组中,并返回true表示已经找到了子节点 |
| | | parentIds.unshift(node.id); |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | |
| | | return false; // 如果当前节点不是子节点的父节点,则返回false |
| | | } |
| | | |
| | | // 从根节点开始遍历整棵树,并调用递归函数查找子节点的所有父节点 |
| | | for (const node of dataSource) { |
| | | if (traverse(node, nodeId)) { |
| | | // 如果在当前节点的子树中找到了子节点的父节点,则直接退出循环 |
| | | break; |
| | | } |
| | | } |
| | | |
| | | return parentIds; // 返回所有父节点ID的数组 |
| | | }, |
| | | }, |
| | | }; |