FinishProductManageModalEdit.vue 12.9 KB
<template>
    <j-modal :title="title" :width="width" :visible="visible" :confirmLoading="confirmLoading" :maskClosable="false"
        switchFullscreen @ok="handleOk" @cancel="handleCancel" cancelText="关闭">
        <a-spin :spinning="confirmLoading">
            <a-form-model ref="form" :model="model" :rules="validatorRules">
                <a-row>
                    <a-col :span="24">
                        <a-form-model-item label="编号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="partNumber">
                            <a-input v-model="model.partNumber" placeholder="请输入编号" disabled></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="品名" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productName">
                            <a-input v-model="model.productName" placeholder="请输入品名"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="型号" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
                            <a-input v-model="model.type" placeholder="请输入型号"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="规格" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="spec">
                            <a-input v-model="model.spec" placeholder="请输入规格"></a-input>
                        </a-form-model-item>
                    </a-col>
                    <a-col :span="24">
                        <a-form-model-item label="单位" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="unit">
                            <j-dict-select-tag type="selectUnit" placeholder="请选择单位" v-model="model.unit" />
                        </a-form-model-item>
                    </a-col>
                </a-row>
            </a-form-model>
            <a-tabs v-model="activeKey" @change="handleChangeTabs" v-show="showState">
                <a-tab-pane tab="物料信息" :key="refKeys[0]" :forceRender="true">
                    <j-vxe-table keep-source :ref="refKeys[0]" :loading="tblPartSemifinishedTable.loading"
                        :columns="tblPartSemifinishedTable.columns" :dataSource="tblPartSemifinishedTable.dataSource"
                        :maxHeight="300" :disabled="false" :rowNumber="true" :rowSelection="true" :toolbar="true">
                    </j-vxe-table>
                </a-tab-pane>
            </a-tabs>
        </a-spin>
    </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import { duplicateCheck } from '@/api/api'
import { JVxeTableModelMixin } from '@/mixins/JVxeTableModelMixin.js'
import { JVXETypes } from '@/components/jeecg/JVxeTable'
import { getRefPromise, VALIDATE_FAILED } from '@/components/jeecg/JVxeTable/utils/vxeUtils.js'

export default {
    name: 'FinishProductManageModalEdit',
    mixins: [JVxeTableModelMixin],
    components: {},
    data() {
        return {
            title: '操作',
            width: 1200,
            visible: false,
            model: {},
            labelCol: {
                xs: { span: 24 },
                sm: { span: 5 },
            },
            wrapperCol: {
                xs: { span: 24 },
                sm: { span: 16 },
            },

            confirmLoading: false,
            validatorRules: {
                partNumber: [{ required: true, message: '请输入编号!' }, { validator: this.validateBidNo }],
                productName: [{ required: true, message: '请输入品名!' }],
                type: [
                    {
                        required: true,
                        message: '请输入型号!',
                    },
                ],
                spec: [
                    {
                        required: true,
                        message: '请输入规格!',
                    },
                ],
                unit: [
                    {
                        required: true,
                        message: '请输入单位!',
                    },
                ]
            },
            url: {
                add: '/baseLibrary/baseLibraryInfo/add',
                edit: '/baseLibrary/baseLibraryInfo/edit',
                tblFinishProductRelation: {
                    list: '/baseLibrary/baseLibraryInfoRelation/queryTblFinishProductRelationById'
                },
            },
            refKeys: ['零件半成品表'],
            activeKey: '零件半成品表',
            tableKeys: ['零件半成品表'],
            showState: true,
            tblPartSemifinishedTable: {
                loading: false,
                dataSource: [],
                columns: [
                    {
                        title: '物料编号',
                        key: 'partNumber',
                        type: JVXETypes.popup,
                        popupCode: 'material_list',
                        field: 'id,part_number,product_name,type,spec,buying_classify,meterial_type',
                        orgFields: 'id,part_number,product_name,type,spec,buying_classify,meterial_type',
                        destFields: 'id,partNumber,productName,type,spec,buyingClassify,meterialType',
                        width: '16%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                        validateRules: [
                            {
                                required: true,
                                message: '请输入${title}',
                            },
                        ],
                    },
                    {
                        title: '品名',
                        key: 'productName',
                        type: JVXETypes.input,
                        disabled: true,
                        width: '16%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                    },
                    {
                        title: '型号',
                        key: 'type',
                        type: JVXETypes.input,
                        disabled: true,
                        width: '16%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                    },
                    {
                        title: '规格',
                        key: 'spec',
                        type: JVXETypes.input,
                        disabled: true,
                        width: '14%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                    },
                    {
                        title: '采购性质',
                        key: 'buyingClassify',
                        type: JVXETypes.input,
                        disabled: true,
                        width: '12%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                    },
                    {
                        title: '物料分类',
                        key: 'meterialType',
                        type: JVXETypes.input,
                        disabled: true,
                        width: '12%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                        validateRules: [
                            {

                            },
                        ],
                    },
                    {
                        title: '数量',
                        key: 'count',
                        type: JVXETypes.input,
                        width: '10%',
                        placeholder: '请输入${title}',
                        defaultValue: '',
                        validateRules: [
                            {
                                required: true,
                                message: '请输入${title}',
                            },
                        ],
                    },
                    {
                        title: 'id',
                        key: 'id',
                        type: 'hidden',
                    },
                    {
                        title: 'part_number',
                        key: 'part_number',
                        type: 'hidden',
                    },
                    {
                        title: 'product_name',
                        key: 'product_name',
                        type: 'hidden',
                    },

                    {
                        title: 'buying_classify',
                        key: 'buying_classify',
                        type: 'hidden',
                    },
                ],
            },
        }
    },
    created() {
        //备份model原始值
        this.modelDefault = JSON.parse(JSON.stringify(this.model))
    },
    methods: {
        add() {
            this.edit(this.modelDefault)
        },
        editAfter() {
            this.$nextTick(() => { })
            // 加载子表数据
            if (this.model.id) {
                let params = {
                    id: this.model.id
                }
                this.requestSubTableData(this.url.tblFinishProductRelation.list, params, this.tblPartSemifinishedTable)
            }
        },
        edit(record) {
            this.model = Object.assign({}, record)
            this.visible = true
            this.editAfter(this.model)
        },
        close() {
            this.$emit('close')
            this.visible = false
            this.$refs.form.clearValidate()
        },
        // handleOk() {
        //     console.log('handleOk', this.tblPartSemifinishedTable.dataSource)
        //     // const that = this
        //     // // 触发表单验证
        //     // this.$refs.form.validate((valid) => {
        //     //     if (valid) {
        //     //         that.confirmLoading = true
        //     //         let httpurl = ''
        //     //         let method = ''
        //     //         if (!this.model.id) {
        //     //             httpurl += this.url.add
        //     //             method = 'post'
        //     //         } else {
        //     //             httpurl += this.url.edit
        //     //             method = 'put'
        //     //         }
        //     //         httpAction(httpurl, this.model, method)
        //     //             .then((res) => {
        //     //                 if (res.success) {
        //     //                     that.$message.success(res.message)
        //     //                     that.$emit('ok')
        //     //                 } else {
        //     //                     that.$message.warning(res.message)
        //     //                 }
        //     //             })
        //     //             .finally(() => {
        //     //                 that.confirmLoading = false
        //     //                 that.close()
        //     //             })
        //     //     } else {
        //     //         return false
        //     //     }
        //     // })
        // },
        handleCancel() {
            this.close()
        },
        validateBidNo(rule, value, callback) {
            var params = {
                tableName: 'tbl_finish_product',
                fieldName: 'part_number',
                fieldVal: value,
                dataId: this.model.id,
            }
            duplicateCheck(params).then((res) => {
                if (res.success) {
                    callback()
                } else {
                    callback('编号已存在!')
                }
            })
        },
        //校验所有一对一子表表单
        validateSubForm(allValues) {
            return new Promise((resolve, reject) => {
                Promise.all([])
                    .then(() => {
                        resolve(allValues)
                    })
                    .catch((e) => {
                        if (e.error === VALIDATE_FAILED) {
                            // 如果有未通过表单验证的子表,就自动跳转到它所在的tab
                            this.activeKey = e.index == null ? this.activeKey : this.refKeys[e.index]
                        } else {
                            console.error(e)
                        }
                    })
            })
        },
        getAllTable() {
            let values = this.tableKeys.map((key) => getRefPromise(this, key))
            return Promise.all(values)
        },
        classifyIntoFormData(allValues) {
            let main = Object.assign(this.model, allValues.formValue)
            return {
                ...main, // 展开
                tblPartSemifinishedList: allValues.tablesValue[0].tableData,
            }
        },
    },
}
</script>