| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492 |
- <template>
- <ele-modal
- :title="title"
- :visible.sync="visible"
- :before-close="handleClose"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- width="75%"
- :maxable="true"
- >
- <el-card shadow="never">
- <el-form
- ref="formName"
- :model="formData"
- label-width="80px"
- :rules="rules"
- >
- <el-row :gutter="15">
- <el-col :span="6">
- <el-form-item label="编码:" prop="code">
- <el-input
- v-model="formData.code"
- placeholder="请输入内容"
- disabled
- ></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="6">
- <el-form-item label="类型:" prop="sourceType">
- <el-select
- style="width: 100%"
- v-model="formData.sourceType"
- placeholder="请选择类型"
- :disabled="readonlyMode"
- >
- <el-option label="余料退库" value="SurplusReturn"></el-option>
- <el-option
- label="不良退库"
- value="UnqualifiedReturn"
- ></el-option>
- <el-option label="完工入库" value="Finish"></el-option>
- <el-option label="暂存入库" value="Temp"></el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="6">
- <el-form-item label="备注" prop="remark">
- <el-input
- v-model="formData.remark"
- placeholder="请输入内容"
- :disabled="readonlyMode"
- ></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- </el-form>
- <div style="margin-top: 12px">
- <ele-pro-table
- ref="eleTable"
- row-key="outInDetailId"
- :columns="tableColumns"
- :datasource="datasource"
- height="calc(100vh - 405px)"
- full-height="calc(100vh - 116px)"
- tool-class="ele-toolbar-form"
- :pageSize="20"
- @selection-change="handleSelectionChange"
- :initLoad="false"
- @done="onDone"
- >
- <template v-slot:measureQuantity="{ row }">
- <el-input
- v-model="row.measureQuantity"
- placeholder="请输入"
- :disabled="readonlyMode"
- @input="(value) => inputNum(value, row)"
- ></el-input>
- </template>
- <template v-slot:purpose="{ row }">
- <el-input
- v-model="row.purpose"
- placeholder="请输入"
- :disabled="readonlyMode"
- ></el-input>
- </template>
- <template v-slot:certificateNumber="{ row, $index }">
- <div>
- <el-input
- v-model="row.certificateNumber"
- placeholder="请输入"
- :disabled="readonlyMode"
- @blur="validateCertificate(row, $index)"
- :class="{ 'is-error': row.certificateError }"
- ></el-input>
- <div v-if="row.certificateError" class="el-form-item__error">
- {{ row.certificateError }}
- </div>
- </div>
- </template>
- </ele-pro-table>
- </div>
- </el-card>
- <div class="btns" v-if="title != '详情'">
- <el-button type="primary" size="small" @click="handleSave"
- >确认</el-button
- >
- <el-button size="small" @click="handleClose">取消</el-button>
- </div>
- </ele-modal>
- </template>
- <script>
- import storageApi from '@/api/warehouseManagement';
- import { getCode } from '@/api/codeManagement/index.js';
- export default {
- props: {},
- data() {
- return {
- visible: false,
- title: '',
- formData: {
- code: '',
- sourceType: '',
- remark: ''
- },
- rules: {
- sourceType: [
- { required: true, message: '请选择申请类型', trigger: 'change' }
- ]
- },
- loading: false,
- selectionList: [],
- ids: [],
- detailJnVOList: []
- };
- },
- computed: {
- readonlyMode() {
- return this.title === '详情';
- },
- tableColumns() {
- return this.title === '详情'
- ? this.columns.filter((c) => c.type !== 'selection')
- : this.columns;
- },
- columns() {
- return [
- {
- columnKey: 'selection',
- type: 'selection',
- width: 45,
- align: 'center'
- },
- {
- columnKey: 'index',
- type: 'index',
- width: 50,
- align: 'center',
- label: '序号',
- showOverflowTooltip: true,
- fixed: 'left'
- },
- {
- prop: 'batchNo',
- label: '批次号',
- align: 'center',
- width: 100
- },
- {
- prop: 'categoryCode',
- label: '物品编码',
- align: 'center',
- showOverflowTooltip: true,
- width: 100
- },
- {
- slot: 'categoryName',
- prop: 'categoryName',
- label: '物品名称',
- align: 'center',
- showOverflowTooltip: true,
- minWidth: 160
- },
- {
- prop: 'inventoryCycle',
- label: '存货周期(天)',
- align: 'center',
- width: 120,
- showOverflowTooltip: true
- },
- {
- prop: 'brandNum',
- label: '牌号',
- align: 'center',
- showOverflowTooltip: true
- },
- {
- prop: 'categoryModel',
- label: '型号',
- align: 'center',
- width: 120,
- showOverflowTooltip: true
- },
- {
- prop: 'specification',
- label: '规格',
- align: 'center',
- width: 120,
- showOverflowTooltip: true
- },
- {
- prop: 'supplierName',
- label: '供应商',
- showOverflowTooltip: true,
- width: 130,
- align: 'center'
- },
- {
- prop: 'level',
- label: '级别',
- showOverflowTooltip: true
- },
- {
- prop: 'certificateNumber',
- slot: 'certificateNumber',
- label: '合格证号',
- showOverflowTooltip: true,
- width: 160
- },
- {
- prop: 'stockCountBase',
- label: '库存数量',
- sortable: 'custom',
- isNone: this.title == '详情',
- showOverflowTooltip: true,
- width: 130,
- align: 'center'
- },
- {
- prop: 'availableCountBase',
- isNone: this.title == '详情',
- label: '可用数量',
- sortable: 'custom',
- showOverflowTooltip: true,
- width: 130,
- align: 'center'
- },
- {
- prop: 'lockQuantity',
- isNone: this.title == '详情',
- label: '锁定数量',
- sortable: 'custom',
- showOverflowTooltip: true,
- width: 130,
- align: 'center'
- },
- {
- prop: 'measureQuantity',
- slot: 'measureQuantity',
- label: '计量数量',
- sortable: 'custom',
- showOverflowTooltip: true,
- width: 130,
- align: 'center'
- },
- {
- prop: 'measureUnit',
- label: '计量单位',
- align: 'center'
- },
- {
- prop: 'weight',
- label: '重量',
- showOverflowTooltip: true
- },
- {
- prop: 'weightUnit',
- label: '重量单位',
- showOverflowTooltip: true
- },
- {
- prop: 'purpose',
- slot: 'purpose',
- label: '用途',
- showOverflowTooltip: true,
- width: 130
- }
- ].filter((c) => !c.isNone);
- }
- },
- methods: {
- async datasource({ page, where, limit }) {
- if (this.readonlyMode) {
- return (this.detailJnVOList || []).map((item) => ({
- ...item,
- originalMeasureQuantity:
- item.originalMeasureQuantity ?? item.measureQuantity,
- certificateError: ''
- }));
- }
- const res = await storageApi.getBatchList({ ...where, page, limit });
- const data = res.list.map((item) => {
- item.originalMeasureQuantity = item.measureQuantity;
- item.certificateError = '';
- item.outInDetailId = item.id;
- delete item.id;
- return {
- ...item
- };
- });
- return data;
- },
- reload(where) {
- this.$nextTick(() => {
- if (this.$refs.eleTable && this.$refs.eleTable.reload)
- this.$refs.eleTable.reload({ page: 1, where: where });
- });
- },
- onDone() {
- this.$nextTick(() => {
- this.$refs.eleTable.setSelectedRowKeys(this.ids);
- });
- if (this.detailJnVOList.length > 0) {
- let list = this.$refs.eleTable.getData();
- for (let i = 0; i < list.length; i++) {
- for (let j = 0; j < this.detailJnVOList.length; j++) {
- if (
- list[i].outInDetailId == this.detailJnVOList[j].outInDetailId
- ) {
- this.$set(
- list[i],
- 'certificateNumber',
- this.detailJnVOList[j].certificateNumber
- );
- this.$set(
- list[i],
- 'measureQuantity',
- this.detailJnVOList[j].measureQuantity
- );
- this.$set(list[i], 'purpose', this.detailJnVOList[j].purpose);
- }
- }
- }
- }
- },
- resetData() {
- this.formData = {
- code: '',
- sourceType: '',
- remark: ''
- };
- this.detailJnVOList = [];
- },
- validateCertificate(row, index) {
- let list = this.$refs.eleTable.getData();
- if (!row.certificateNumber || row.certificateNumber.trim() === '') {
- this.$set(list[index], 'certificateError', '证书号不能为空');
- } else {
- this.$set(list[index], 'certificateError', '');
- }
- },
- async open(type, row) {
- this.resetData();
- this.visible = true;
- this.title =
- type == 'add' ? '新增' : type == 'detail' ? '详情' : '编辑';
- if (type == 'add') {
- const code = await getCode('Storage_application');
- this.formData.code = code;
- } else if (row?.id) {
- await this.getDraftDetail(row.id);
- }
- await this.reload();
- },
- async getDraftDetail(id) {
- const res = await storageApi.getStoragejnDetails(id);
- if (res) {
- this.$set(this, 'formData', res);
- this.ids =
- res.detailJnVOList?.map((item) => item.outInDetailId) || [];
- this.detailJnVOList = res.detailJnVOList || [];
- }
- },
- inputNum(value, row) {
- const num = value.replace(/[^\d.]/g, '');
- const oldValue = row.originalMeasureQuantity;
- if (num > oldValue) {
- this.$set(row, 'measureQuantity', oldValue);
- } else {
- this.$set(row, 'measureQuantity', num);
- }
- },
- handleSelectionChange(selection) {
- console.log(selection, '勾选');
- if (this.title === '新增' && selection.length > 1) {
- const last = selection[selection.length - 1];
- this.selectionList = [last];
- this.$nextTick(() => {
- if (this.$refs.eleTable && this.$refs.eleTable.setSelectedRowKeys) {
- this.$refs.eleTable.setSelectedRowKeys([last.outInDetailId]);
- }
- });
- return;
- }
- this.selectionList = selection;
- },
- handleClose() {
- this.visible = false;
- this.resetData();
- },
- handleSave() {
- this.$refs.formName.validate(async (valid) => {
- if (valid) {
- if (this.selectionList.length == 0)
- return this.$message.warning('请选择入库物品');
- let isValid = true;
- this.selectionList.forEach((item) => {
- if (!item.certificateNumber?.trim()) {
- isValid = false;
- this.$set(item, 'certificateError', '证书号不能为空');
- }
- });
- if (!isValid) {
- this.$message.error('请填写所有必填项');
- return;
- }
- let postData = {
- type: 1,
- code: this.formData.code,
- sourceType: this.formData.sourceType,
- detailJnAddPOList: this.selectionList,
- id: this.title == '编辑' ? this.formData.id : null
- };
- this.loading = true;
- storageApi
- .saveStoragejn(postData)
- .then(async (res) => {
- if (res == 0) {
- try {
- this.$message.success('保存成功');
- this.loading = false;
- this.visible = false;
- this.$emit('success');
- } catch (error) {
- this.visible = false;
- console.log('失败', error);
- }
- }
- })
- .catch((err) => {
- console.log('申请失败', err);
- this.loading = false;
- this.visible = false;
- });
- } else {
- return false;
- }
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .btns {
- text-align: center;
- padding: 10px 0;
- }
- .el-form-item__error {
- color: red;
- font-size: 12px;
- line-height: 1;
- padding-top: 4px;
- position: relative;
- }
- .is-error .el-input__inner {
- border-color: red;
- }
- </style>
|