| | |
| | | <template> |
| | | <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"> |
| | | <win-md class="stock-edit" :title="`${setting.title}采购入库`" @close="close" :width="'800px'" :loading="loading"> |
| | | <el-form v-loading="loading" 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-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 v-model="formData.warehouseId" placeholder="请选择" clearable 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-col :span="12"> |
| | | <el-form-item label="采购时间" prop="procureTime"> |
| | | <el-date-picker |
| | | v-model="formData.procureTime" |
| | | type="datetime" |
| | | value="yyyy-MM-dd HH:mm:ss" |
| | | value-format="yyyyMMddHHmmss" |
| | | placeholder="请选择日期" |
| | | style="width: 100%" |
| | | v-model="formData.procureTime" |
| | | type="datetime" |
| | | clearable |
| | | value="yyyy-MM-dd HH:mm:ss" |
| | | value-format="yyyyMMddHHmmss" |
| | | placeholder="请选择日期" |
| | | style="width: 100%" |
| | | > |
| | | </el-date-picker> |
| | | </el-form-item> |
| | |
| | | <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-option v-for="item in buyTypeOptions" :key="item.value" :label="item.label" :value="item.value"/> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | |
| | | <el-row :gutter="24"> |
| | | <el-col :span="12"> |
| | | <el-form-item |
| | | label="物品分类" |
| | | :prop="`procureGoods[${goodsIndex}].baseCategoryIds`" |
| | | :rules="{ |
| | | label="物品分类" |
| | | :prop="`procureGoods.${goodsIndex}.baseCategoryId`" |
| | | :rules="{ |
| | | required: true, |
| | | message: '请选择', |
| | | message: '请选择物品分类', |
| | | trigger: 'change', |
| | | }" |
| | | > |
| | | <el-cascader |
| | | v-model="goodsItem.baseCategoryIds" |
| | | :options="categoryOptions" |
| | | :props="{ value: 'id' }" |
| | | @change="categoryChange($event, goodsIndex)" |
| | | style="width: 100%" |
| | | v-model="goodsItem.baseCategoryId" |
| | | :options="categoryOptions" |
| | | :props="{ value: 'id',emitPath: false }" |
| | | :show-all-levels="false" |
| | | filterable |
| | | clearable |
| | | @change="categoryChange($event, goodsIndex)" |
| | | style="width: 100%" |
| | | ></el-cascader> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item |
| | | label="物品名称" |
| | | :prop="`procureGoods[${goodsIndex}].baseGoodsTemplateId`" |
| | | :rules="{ |
| | | required: true, |
| | | message: '请选择', |
| | | trigger: 'change', |
| | | }" |
| | | label="物品名称" |
| | | :prop="`procureGoods.${goodsIndex}.baseGoodsTemplateId`" |
| | | :rules="rules.baseGoodsTemplateId" |
| | | > |
| | | <el-select |
| | | v-model="goodsItem.baseGoodsTemplateId" |
| | | placeholder="请先择物品分类" |
| | | filterable |
| | | :disabled="!goodsItem.baseCategoryId" |
| | | style="width: 100%" |
| | | @change="goodsTemplateChange($event, goodsIndex)" |
| | | v-model="goodsItem.baseGoodsTemplateId" |
| | | :placeholder="goodsItem.baseCategoryId?'请选择物品':'请先选择物品分类'" |
| | | filterable |
| | | clearable |
| | | :disabled="!goodsItem.baseCategoryId" |
| | | style="width: 100%" |
| | | @change="goodsTemplateChange($event, goodsIndex)" |
| | | > |
| | | <el-option |
| | | v-for="item in goodsItem.goodsOptions" |
| | | :key="item.id" |
| | | :label="item.goodsName" |
| | | :value="item.id" |
| | | v-for="item in goodsItem.goodsOptions" |
| | | :key="item.id" |
| | | :label="item.goodsName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | |
| | | <el-row :gutter="24"> |
| | | <el-col :span="12"> |
| | | <el-form-item |
| | | label="规格型号" |
| | | :prop="`procureGoods[${goodsIndex}].modelsIds`" |
| | | :rules="{ |
| | | label="规格型号" |
| | | :prop="`procureGoods.${goodsIndex}.modelsIds`" |
| | | :rules="{ |
| | | required: true, |
| | | message: '请选择', |
| | | message: '请选择规格型号', |
| | | trigger: 'change', |
| | | }" |
| | | > |
| | | <el-select |
| | | v-model="goodsItem.modelsIds" |
| | | multiple |
| | | placeholder="请先择物品名称" |
| | | :disabled="!goodsItem.baseCategoryId" |
| | | @change="modelChange($event, goodsIndex)" |
| | | @remove-tag="modelRemoveTag($event, goodsIndex)" |
| | | style="width: 100%" |
| | | v-model="goodsItem.modelsIds" |
| | | multiple |
| | | clearable |
| | | :placeholder="goodsItem.baseGoodsTemplateId?'请选择规格型号':'请先选择物品名称'" |
| | | :disabled="!goodsItem.baseGoodsTemplateId" |
| | | @change="modelChange($event, goodsIndex)" |
| | | @remove-tag="modelRemoveTag($event, goodsIndex)" |
| | | @clear="modelRemoveTag(-1, goodsIndex)" |
| | | style="width: 100%" |
| | | > |
| | | <el-option |
| | | v-for="item in goodsItem.modelsOptions" |
| | | :key="item.id" |
| | | :label="item.modelName" |
| | | :value="item.id" |
| | | v-for="item in goodsItem.modelsOptions" |
| | | :key="item.id" |
| | | :label="item.modelName" |
| | | :value="item.id" |
| | | /> |
| | | </el-select> |
| | | </el-form-item> |
| | | </el-col> |
| | | <el-col :span="12"> |
| | | <el-form-item label="供货商" prop="supplier"> |
| | | <el-input v-model="goodsItem.supplier" clearable maxlength="20" show-word-limit /> |
| | | <el-input v-model="goodsItem.supplier" clearable maxlength="20" show-word-limit/> |
| | | </el-form-item> |
| | | </el-col> |
| | | </el-row> |
| | |
| | | {{ scope.row.unit }} |
| | | </template> |
| | | </el-table-column> |
| | | <el-table-column prop="price" label="单价(元)" align="center"> |
| | | <el-table-column prop="priceYuan" label="单价(元)" align="center"> |
| | | <template slot-scope="scope"> |
| | | <el-input type="number" v-model="scope.row.price"></el-input> |
| | | <el-form-item |
| | | label-width="0" |
| | | style="margin-bottom: 0" |
| | | :prop="`procureGoods[${goodsIndex}].models[${scope.$index}].priceYuan`" |
| | | :rules="rules.priceYuan" |
| | | > |
| | | <el-input |
| | | type="number" |
| | | v-model.number="scope.row.priceYuan" |
| | | @change="priceChange($event, goodsIndex, scope.$index)" |
| | | ></el-input> |
| | | </el-form-item> |
| | | </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-form-item |
| | | label-width="0" |
| | | style="margin-bottom: 0" |
| | | :prop="`procureGoods[${goodsIndex}].models[${scope.$index}].counts`" |
| | | :rules="rules.counts" |
| | | > |
| | | <el-input v-model.number="scope.row.counts"></el-input> |
| | | </el-form-item> |
| | | </template> |
| | | </el-table-column> |
| | | </el-table> |
| | | <div class="btn-group"> |
| | | <el-button |
| | | v-if="formData.procureGoods.length > 1" |
| | | name="移除" |
| | | type="danger" |
| | | plain |
| | | size="mini" |
| | | @click="removeGoods(goodsIndex)" |
| | | >移除</el-button |
| | | v-if="formData.procureGoods.length > 1" |
| | | name="移除" |
| | | type="danger" |
| | | plain |
| | | size="mini" |
| | | @click="removeGoods(goodsIndex)" |
| | | >移除 |
| | | </el-button |
| | | > |
| | | <el-button |
| | | v-if="formData.procureGoods.length - 1 == goodsIndex" |
| | | name="新增物品" |
| | | type="primary" |
| | | plain |
| | | size="mini" |
| | | @click="addGoods" |
| | | >新增物品</el-button |
| | | v-if="formData.procureGoods.length - 1 == goodsIndex" |
| | | name="新增物品" |
| | | type="primary" |
| | | plain |
| | | size="mini" |
| | | @click="addGoods" |
| | | >新增物品 |
| | | </el-button |
| | | > |
| | | </div> |
| | | </div> |
| | |
| | | </template> |
| | | <script> |
| | | import { |
| | | goodsModel, |
| | | goodsTemplate, |
| | | procureAdd, |
| | | procureDetail, |
| | | procureEdit, |
| | | selectTenantWarehouse, |
| | | goodsModel, |
| | | procureDetail, |
| | | } from '@/api/stock/procure/purchaseOrder'; |
| | | import { getTree } from '@/api/foudation/classification'; |
| | | 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 SettingIplatform from '../../../../../public/static/config'; |
| | | import {getUploadUrl} from '@/utils/base'; |
| | | import {findParentIds} from '@/utils/index'; |
| | | import {mapGetters} from 'vuex'; |
| | | import * as DateFormatter from "@/utils/DateFormatter"; |
| | | |
| | | export default { |
| | | components: { MyButton, winMd, upload }, |
| | | components: {MyButton, winMd, upload}, |
| | | props: { |
| | | setting: { |
| | | type: Object, |
| | | default: () => { |
| | | } |
| | | } |
| | | }, |
| | | }, |
| | | }, |
| | | data() { |
| | | // 自定义校验 |
| | | // 物品重复校验 |
| | | var checkGoodsTemplateId = (rule, value, callback) => { |
| | | if (!value) { |
| | | return callback(new Error('请选择')); |
| | | } |
| | | let temp = this.formData.procureGoods.filter((v) => v.baseGoodsTemplateId == value); |
| | | if (!temp || temp.length != 1) { |
| | | return callback(new Error('已选过此物品')); |
| | | } |
| | | callback(); |
| | | }; |
| | | // 金额校验 |
| | | var checkPrice = (rule, value, callback) => { |
| | | if (!value) { |
| | | return callback(new Error('请输入')); |
| | | } |
| | | if (value == 0) { |
| | | this.$message.warning('数字值不能为0'); |
| | | return callback(new Error('数字值不能为0')); |
| | | } |
| | | callback(); |
| | | }; |
| | | // 数量校验 |
| | | var checkCounts = (rule, value, callback) => { |
| | | if (!value) { |
| | | return callback(new Error('请输入')); |
| | | } |
| | | if (!Number.isInteger(value)) { |
| | | this.$message.warning('请输入数字值'); |
| | | return callback(new Error('请输入数字值')); |
| | | } |
| | | if (value == 0) { |
| | | this.$message.warning('数字值不能为0'); |
| | | return callback(new Error('数字值不能为0')); |
| | | } |
| | | callback(); |
| | | }; |
| | | return { |
| | | visible: false, |
| | | loading: false, |
| | | buyTypeOptions:[{ |
| | | label:'集采', |
| | | value: '1' |
| | | },{ |
| | | label:'自采', |
| | | value: '2' |
| | | }], |
| | | fileList:[], |
| | | loading: true, |
| | | buyTypeOptions: [ |
| | | { |
| | | label: '集采', |
| | | value: '1', |
| | | }, |
| | | { |
| | | label: '自采', |
| | | value: '2', |
| | | }, |
| | | ], |
| | | fileList: [], |
| | | warehouses: [], // 入库仓库列表 |
| | | categoryOptions: [], // 物品分类列表 |
| | | modelList: [], //型号列表 |
| | | formData: { |
| | | procureDoc:'', |
| | | procureDoc: '', |
| | | warehouseId: '', // 入库仓库id |
| | | procureTime: '', // 采购时间 |
| | | procureTime: DateFormatter.formatDate(new Date(), 'yyyyMMddhhmmss'), // 采购时间 |
| | | buyType: '2', // 采购方式(1:集采;2=自采) |
| | | procureGoods: [], |
| | | }, |
| | | goodsItem: { |
| | | whFormProcureId: '', // 采购单ID |
| | | baseCategoryIds: '', // 分类编号数组 |
| | | baseCategoryId: '', // 分类编号 |
| | | baseGoodsTemplateId: '', // 物品模版编号 |
| | |
| | | }, |
| | | modelsItem: { |
| | | baseGoodsModelsId: '', // 规格型号编号 |
| | | price: 0, // 单价(采购需要,调拨不需要) |
| | | counts: 0, // 操作数量 |
| | | supplier: '', // 供应商 |
| | | priceYuan: null, // 单价(元) |
| | | price: null, // 单价(分 采购需要,调拨不需要) |
| | | counts: null, // 操作数量 |
| | | unit: null, //单位 |
| | | }, |
| | | rules: { |
| | | warehouseId: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | procureTime: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | buyType: [{ required: true, message: '请选择', trigger: 'change' }], |
| | | warehouseId: [{required: true, message: '请选择', trigger: 'change'}], |
| | | procureTime: [{required: true, message: '请选择', trigger: 'change'}], |
| | | buyType: [{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' }], |
| | | procureDoc: [{required: true, message: '请上传', trigger: 'change'}], |
| | | baseCategoryIds: [{required: true, message: '请选择', trigger: 'change'}], |
| | | baseGoodsTemplateId: [{required: true, message: '请选择', trigger: 'change'},{validator: checkGoodsTemplateId, trigger: ['blur', 'change']}], |
| | | modelsIds: [{required: true, message: '请选择', trigger: 'change'}], |
| | | priceYuan: [{validator: checkPrice, trigger: 'blur'}], |
| | | counts: [{validator: checkCounts, trigger: 'blur'}], |
| | | }, |
| | | |
| | | uploadSettings: { |
| | | title: '上传', |
| | | max: 20, // 最大大小,单位M |
| | | num: 10, // 支持上传图片个数 |
| | | accept: '.jpg,.png', // 限制格式 |
| | | tip: '', // 提示 默认:`只能上传${this.defaultSettings.num}个${this.defaultSettings.accept}文件,且不超过${this.defaultSettings.max}kb` |
| | | uploadUrl: getUploadUrl(), // 上传路径 |
| | | multiple: true, // 是否支持批量上传 |
| | |
| | | }, |
| | | }; |
| | | }, |
| | | computed: { |
| | | ...mapGetters(['userInfo']), |
| | | }, |
| | | created() { |
| | | this.init() |
| | | this.init(); |
| | | }, |
| | | methods: { |
| | | async init() { |
| | | this.getWarehouseList(); |
| | | this.getgoodsTemplate() |
| | | this.getgoodsModel(); |
| | | await this.getWarehouseList(); |
| | | await this.getgoodsTemplate(); |
| | | await this.getgoodsModel(); |
| | | |
| | | // 获取物品分类列表 |
| | | const treeRes = await getTree(); |
| | | this.categoryOptions = this.removeEmptyChildren(treeRes); |
| | | if (this.setting.id) { |
| | | const detail = await procureDetail({ id: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) |
| | | if (this.formData.procureDoc) { |
| | | this.fileList = JSON.parse(this.formData.procureDoc); |
| | | } |
| | | this.$set(this.formData,'buyType',this.formData.buyType.toString()) |
| | | this.$set(this.formData, 'buyType', this.formData.buyType.toString()); |
| | | this.formData.procureTime = this.formData.procureTime.toString(); |
| | | this.formData.procureGoods.map((item, index) => { |
| | | this.formData.procureGoods.map(async (item, index) => { |
| | | // 根据子集ID拼接物品分类列表 |
| | | let pIds = this.findParentIds(this.categoryOptions, item.baseCategoryId); |
| | | item.baseCategoryIds = [...pIds, item.baseCategoryId]; |
| | | 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 |
| | | item.baseCategoryIds = findParentIds(this.categoryOptions, item.baseCategoryId); |
| | | this.$set( |
| | | this.formData.procureGoods[index], |
| | | 'modelsIds', |
| | | item.models.map((v) => v.baseGoodsModelsId), |
| | | ); |
| | | await this.getgoodsTemplate(item.baseCategoryId, index); |
| | | await this.getgoodsModel(item.baseGoodsTemplateId, index); |
| | | await item.models.forEach((child, childIndex) => { |
| | | this.$set(this.formData.procureGoods[index].models[childIndex], 'priceYuan', child.price / 100); |
| | | }); |
| | | return item; |
| | | }); |
| | | } else { |
| | | this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | } |
| | | this.visible = true; |
| | | this.loading = false; |
| | | }, |
| | | |
| | | // 获取入库仓库列表 |
| | | getWarehouseList() { |
| | | selectTenantWarehouse() |
| | | .then((res) => { |
| | | this.warehouses = res; |
| | | if (this.warehouses.length && !this.formData.warehouseId) { |
| | | // 默认选中第一个仓库 |
| | | this.formData.warehouseId = this.warehouses[0].id; |
| | | } |
| | | }) |
| | | .catch((err) => { |
| | | console.log('err', err); |
| | | }); |
| | | async getWarehouseList() { |
| | | await selectTenantWarehouse({agencyId: this.userInfo.tenantId}) |
| | | .then((res) => { |
| | | this.warehouses = res; |
| | | if (!this.setting.id && res.length) { |
| | | this.formData.procureGoods.push(JSON.parse(JSON.stringify(this.goodsItem))); |
| | | } |
| | | if (this.warehouses.length && !this.formData.warehouseId) { |
| | | // 默认选中第一个仓库 |
| | | this.formData.warehouseId = this.warehouses[0].id; |
| | | } |
| | | }) |
| | | .catch((err) => { |
| | | console.log('err', err); |
| | | }); |
| | | }, |
| | | |
| | | removeEmptyChildren(arr) { |
| | |
| | | }, |
| | | |
| | | // 获取物品名称列表 |
| | | getgoodsTemplate(id, index) { |
| | | goodsTemplate({ categoryId: id || '' }).then((res) => { |
| | | async getgoodsTemplate(id, index) { |
| | | await goodsTemplate({agencyId: this.userInfo.tenantId, categoryId: id || ''}).then((res) => { |
| | | if (index || index == 0) { |
| | | this.$set(this.formData.procureGoods[index], 'goodsOptions', res); |
| | | }else { |
| | | } else { |
| | | this.goodsTemplatelAll = res; |
| | | } |
| | | }); |
| | | }, |
| | | |
| | | // 规格型号 |
| | | getgoodsModel(id, index) { |
| | | goodsModel({ goodsTemplatesId: id || '' }).then((res) => { |
| | | async getgoodsModel(id, index) { |
| | | await goodsModel({goodsTemplatesId: id || ''}).then((res) => { |
| | | if (index || index == 0) { |
| | | this.$set(this.formData.procureGoods[index], 'modelsOptions', res); |
| | | } else { |
| | |
| | | |
| | | // 物品分类选择 |
| | | 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.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.procureGoods[index].baseCategoryId = e[e.length - 1]; |
| | | // 根据选中分类请求物品名称列表 |
| | | this.getgoodsTemplate(e[e.length - 1], index); |
| | | this.getgoodsTemplate(e, index); |
| | | }, |
| | | |
| | | // 物品名称列表 |
| | | goodsTemplateChange(e, index) { |
| | | this.formData.procureGoods[index].modelsOptions = [] |
| | | this.formData.procureGoods[index].modelsIds = [] |
| | | this.formData.procureGoods[index].models = [] |
| | | this.formData.procureGoods[index].modelsOptions = []; |
| | | this.formData.procureGoods[index].modelsIds = []; |
| | | this.formData.procureGoods[index].models = []; |
| | | |
| | | this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e) |
| | | this.formData.procureGoods[index].goodsTemplateName = this.getGoodsTemplateName(e); |
| | | // 根据选中物品名称id获取规格型号列表 |
| | | this.getgoodsModel(e, index); |
| | | }, |
| | |
| | | e.forEach((item) => { |
| | | if (str.indexOf(item) == -1) { |
| | | let temp = this.goodsModelAll.find((v) => v.id == item); |
| | | arr.push({ ...this.modelsItem, baseGoodsModelsId: item, unit: temp.unit }); |
| | | arr.push({...this.modelsItem, baseGoodsModelsId: item, unit: temp.unit}); |
| | | } |
| | | }); |
| | | this.formData.procureGoods[index].models = arr; |
| | |
| | | |
| | | // 规格型号移除 |
| | | modelRemoveTag(e, index) { |
| | | if(e===-1){ |
| | | this.formData.procureGoods[index].models = [] |
| | | return |
| | | } |
| | | let arr = this.formData.procureGoods[index].models; |
| | | let delIndex = arr.findIndex((v) => v.baseGoodsModelsId == e); |
| | | this.formData.procureGoods[index].models.splice(delIndex, 1); |
| | | }, |
| | | |
| | | // 价格input监听 转为分 |
| | | priceChange(e, goodsIndex, index) { |
| | | this.formData.procureGoods[goodsIndex].models[index].price = e * 100; |
| | | }, |
| | | |
| | | // 上传 |
| | | uploadChange() { |
| | | let arr = this.$refs.uploadRef.fileList |
| | | this.formData.procureDoc = JSON.stringify(arr) |
| | | let arr = this.$refs.uploadRef.fileList; |
| | | this.formData.procureDoc = JSON.stringify(arr); |
| | | }, |
| | | |
| | | // 点击新增物品 |
| | |
| | | handleSubmit() { |
| | | this.$refs['ruleForm'].validate((valid) => { |
| | | if (valid) { |
| | | console.log('this.formData', this.formData); |
| | | if (this.loading) return |
| | | this.loading = true; |
| | | 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('保存失败'); |
| | | }); |
| | | .then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }) |
| | | .catch((err) => { |
| | | this.loading = false; |
| | | 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('保存失败'); |
| | | }); |
| | | .then((res) => { |
| | | this.$message.success('保存成功!'); |
| | | this.close(); |
| | | this.$emit('search'); |
| | | }) |
| | | .catch((err) => { |
| | | this.loading = false; |
| | | this.$message.error('保存失败'); |
| | | }); |
| | | } |
| | | } else { |
| | | this.$message.error('校验未通过,请检查。'); |
| | |
| | | }, |
| | | |
| | | close() { |
| | | this.formData ={ |
| | | this.formData = { |
| | | warehouseId: '', // 入库仓库id |
| | | procureTime: '', // 采购时间 |
| | | procureGoods: [], |
| | | } |
| | | 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的数组 |
| | | }; |
| | | this.$emit('close'); |
| | | }, |
| | | }, |
| | | }; |