| | |
| | | <template> |
| | | <el-dialog |
| | | :title="`${type == 'create' ? '新增' : '编辑'}${title}`" |
| | | width="60%" |
| | | :modal="true" |
| | | :visible.sync="visible" |
| | | :top="'15vh'" |
| | | :close-on-click-modal="false" |
| | | :append-to-body="true" |
| | | :destroy-on-close="true" |
| | | @close="close" |
| | | > |
| | | <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> |
| | | </el-row> |
| | | <el-row :gutter="24" class="headerHeight"> |
| | | <el-col :span="12"> |
| | | <el-form-item label="采购类型" prop="buyType"> |
| | | <el-select v-model="formData.buyType" placeholder="请选择" style="width: 100%"> |
| | | <el-option v-for="item in buyTypeOptions" :key="item.value" :label="item.label" :value="item.value" /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | | <el-row :gutter="24" class="headerHeight"> |
| | | <el-col :span="24"> |
| | | <el-form-item label="采购入库手续" prop="procureDoc"> |
| | | <upload :settings="uploadSettings" @on-change="uploadChange"></upload> |
| | | <upload ref="uploadRef" :values="fileList" :settings="uploadSettings" @on-change="uploadChange"></upload> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | </div> |
| | | </el-form> |
| | | <div slot="footer" align="center" class="dialog-footer"> |
| | | <el-button name="确定" site="form" type="primary" @click="handleSubmit">确定</el-button> |
| | | <el-button name="取消" site="form" @click="close">取消</el-button> |
| | | <my-button name="取消" site="form" @click="close"/> |
| | | <my-button name="保存" site="form" @click="handleSubmit"/> |
| | | </div> |
| | | </el-dialog> |
| | | </win-md> |
| | | </template> |
| | | <script> |
| | | import { |
| | |
| | | import MyButton from '@/components/myButton/myButton'; |
| | | import winMd from '@/components/win/win-md'; |
| | | import upload from '@/components/upload/index'; |
| | | import { getUploadUrl } from '@/utils/base'; |
| | | import { getUploadUrl,getDownUrl} from '@/utils/base'; |
| | | |
| | | import SettingIplatform from '../../../../../public/static/config'; |
| | | |
| | | export default { |
| | | components: { MyButton, winMd, upload }, |
| | | props: { |
| | | title: { |
| | | type: String, |
| | | default: '采购入库', |
| | | }, |
| | | setting: { |
| | | type: Object, |
| | | default: () => { |
| | | } |
| | | } |
| | | }, |
| | | data() { |
| | | return { |
| | | type: 'create', |
| | | visible: false, |
| | | loading: false, |
| | | buyTypeOptions:[{ |
| | | label:'集采', |
| | | value: '1' |
| | | },{ |
| | | label:'自采', |
| | | value: '2' |
| | | }], |
| | | fileList:[], |
| | | warehouses: [], // 入库仓库列表 |
| | | categoryOptions: [], // 物品分类列表 |
| | | modelList: [], //型号列表 |
| | | formData: { |
| | | procureDoc:'', |
| | | warehouseId: '', // 入库仓库id |
| | | procureTime: '', // 采购时间 |
| | | buyType: '2', // 采购方式(1:集采;2=自采) |
| | | procureGoods: [], |
| | | }, |
| | | goodsItem: { |
| | |
| | | rules: { |
| | | warehouseId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | procureTime: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | buyType: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | |
| | | // procureDoc: [{ required: true, message: '请上传', trigger: 'change' }], |
| | | procureDoc: [{ required: true, message: '请上传', trigger: 'change' }], |
| | | baseCategoryIds: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | baseGoodsTemplateId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | modelsIds: [{ required: true, message: '请选择', trigger: 'change' }], |
| | |
| | | uploadSettings: { |
| | | title: '上传', |
| | | max: 20, // 最大大小,单位M |
| | | num: 2, // 支持上传图片个数 |
| | | num: 10, // 支持上传图片个数 |
| | | accept: '.jpg,.png', // 限制格式 |
| | | tip: '', // 提示 默认:`只能上传${this.defaultSettings.num}个${this.defaultSettings.accept}文件,且不超过${this.defaultSettings.max}kb` |
| | | uploadUrl: getUploadUrl(), // 上传路径 |
| | | multiple: true, // 是否支持批量上传 |
| | | disabled: false, // 是否禁用 |
| | | type: 'text', // text/picture |
| | | type: 'picture', // text/picture |
| | | }, |
| | | }; |
| | | }, |
| | | created() {}, |
| | | created() { |
| | | this.init() |
| | | }, |
| | | methods: { |
| | | async open(id) { |
| | | async init() { |
| | | this.getWarehouseList(); |
| | | this.getgoodsTemplate() |
| | | this.getgoodsModel(); |
| | | // 获取物品分类列表 |
| | | const treeRes = await getTree(); |
| | | this.categoryOptions = this.removeEmptyChildren(treeRes); |
| | | if (id) { |
| | | this.type = 'edit'; |
| | | const detail = await procureDetail({ id }); |
| | | console.log('procureDetail', detail); |
| | | if (this.setting.id) { |
| | | const detail = await procureDetail({ id:this.setting.id }); |
| | | this.formData = Object.assign(this.formData, detail); |
| | | if(this.formData.procureDoc) { |
| | | this.fileList = JSON.parse(this.formData.procureDoc) |
| | | } |
| | | this.$set(this.formData,'buyType',this.formData.buyType.toString()) |
| | | this.formData.procureTime = this.formData.procureTime.toString(); |
| | | this.formData.procureGoods.map((item, index) => { |
| | | // 根据子集ID拼接物品分类列表 |
| | | let pIds = this.findParentIds(this.categoryOptions, item.baseCategoryId); |
| | | pIds = pIds.reverse(); |
| | | item.baseCategoryIds = [...pIds, item.baseCategoryId]; |
| | | item.modelsIds = item.models.map((v) => v.baseGoodsModelsId); |
| | | this.$set(this.formData.procureGoods[index],'modelsIds',item.models.map((v) => v.baseGoodsModelsId)) |
| | | this.getgoodsTemplate(item.baseCategoryId, index); |
| | | this.getgoodsModel(item.baseGoodsTemplateId, index); |
| | | return item |
| | | }); |
| | | } else { |
| | | this.type = 'create'; |
| | | this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | } |
| | | this.visible = true; |
| | |
| | | goodsTemplate({ categoryId: id || '' }).then((res) => { |
| | | if (index || index == 0) { |
| | | this.$set(this.formData.procureGoods[index], 'goodsOptions', res); |
| | | }else { |
| | | this.goodsTemplatelAll = res; |
| | | } |
| | | }); |
| | | }, |
| | |
| | | }); |
| | | }, |
| | | |
| | | // 根据物品名称id获取名字 |
| | | getGoodsTemplateName(id) { |
| | | let item = this.goodsTemplatelAll.find((v) => v.id == id); |
| | | if (item) { |
| | | return item.goodsName; |
| | | } |
| | | return; |
| | | }, |
| | | |
| | | // 根据规格型号id获取名字 |
| | | getGoodsModelsName(id) { |
| | | let item = this.goodsModelAll.find((v) => v.id == id); |
| | |
| | | // 物品分类选择 |
| | | categoryChange(e, index) { |
| | | this.formData.procureGoods[index].goodsOptions = [] |
| | | this.formData.procureGoods[index].baseCategoryId = '' |
| | | 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.procureGoods[index].baseCategoryId = e[e.length - 1]; |
| | | // 根据选中分类请求物品名称列表 |
| | |
| | | this.formData.procureGoods[index].modelsIds = [] |
| | | this.formData.procureGoods[index].models = [] |
| | | |
| | | this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e) |
| | | // 根据选中物品名称id获取规格型号列表 |
| | | this.getgoodsModel(e, index); |
| | | }, |
| | |
| | | }, |
| | | |
| | | // 上传 |
| | | uploadChange(e) { |
| | | console.log('uploadChange', e); |
| | | uploadChange() { |
| | | let arr = this.$refs.uploadRef.fileList |
| | | this.formData.procureDoc = JSON.stringify(arr) |
| | | }, |
| | | |
| | | // 点击新增物品 |
| | |
| | | this.$refs['ruleForm'].validate((valid) => { |
| | | if (valid) { |
| | | console.log('this.formData', this.formData); |
| | | if (this.type == 'create') { |
| | | if (!this.setting.id) { |
| | | procureAdd(this.formData) |
| | | .then((res) => { |
| | | this.$message.success('保存成功!'); |
| | |
| | | procureTime: '', // 采购时间 |
| | | procureGoods: [], |
| | | } |
| | | this.visible = false; |
| | | this.$emit('close') |
| | | }, |
| | | |
| | | // 通过子集id查到所以相关父级id并返回数组 |
| | | findParentIds(dataSource, nodeId) { |
| | | const parentIds = []; // 用于存储所有父节点ID的数组 |
| | | const parentIds = [nodeId]; // 用于存储所有父节点ID的数组 |
| | | |
| | | // 定义一个递归函数,用于遍历整棵树并查找子节点的所有父节点 |
| | | function traverse(node, nodeId) { |
| | |
| | | for (const childNode of node.children) { |
| | | if (traverse(childNode, nodeId)) { |
| | | // 如果在子节点中找到了子节点的父节点,则将当前节点的ID添加到父节点ID数组中,并返回true表示已经找到了子节点 |
| | | parentIds.push(node.id); |
| | | parentIds.unshift(node.id); |
| | | return true; |
| | | } |
| | | } |
| | |
| | | }; |
| | | </script> |
| | | <style scoped lang="scss"> |
| | | .main-w { |
| | | width: 88%; |
| | | } |
| | | .goods-card { |
| | | position: relative; |
| | | background: #f6f6f6; |
| | | padding: 20px; |
| | | box-sizing: border-box; |
| | | border-radius: 4px; |
| | | background-color: #f9f9f9; |
| | | margin-top: 20px; |
| | | &:nth-of-type(1) { |
| | | margin-top: 0; |
| | | } |
| | | } |
| | | .btn-group { |
| | | width: 140px; |
| | | position: absolute; |
| | | right: -160px; |
| | | bottom: 0px; |
| | | .el-button { |
| | | margin-bottom: 10px; |
| | | margin-left: 0; |
| | | display: block; |
| | | &:last-child { |
| | | margin-bottom: 0; |
| | | } |
| | | } |
| | | } |
| | | @import url(../../index.scss); |
| | | </style> |