Antd-UI表单自主化

需求 :根据类型,生成不同表单

涉及表单:人事信息 项目信息 实验信息等多个表单

技术涉及:vue-porps antdv

入口文件

判断是由CREAT按钮进入 || 由RowsClick进入

<template>
    <ProjectTaskDetail
      pageType="project"
      :entrance="entrance"
    />
</template>

<script>
import ProjectTaskDetail from '@/components/details/task-details'
export default {
  name : 'ProjectDetail' ,
  data (){
    return {
      entrance: '',
    }
  },
  created (){
    /* 入口判断 */
    let rowsClick = this.$route.params.record
    if(rowsClick === undefined){
      return this.entrance = false
    }else{
      return this.entrance = true
    }
  },
  components : {
    ProjectTaskDetail
  }
}
</script>

组件 【按钮 && 主体】

当entrance为false时,页面数据为空,此时是创建项目,故只保留SUBMIT按钮
当entrance未true时,页面获取数据,此时是修改项目,故去除SUBMIT按钮
代码待优化【此处v-for配合按钮模块化,可以大幅减少代码】
查看完整代码

script

<script>
export default {
    name : "TaskDetail" ,
    data(){
        return{
            /* ALL-DATA */
            projectData : '',
            /* ENTRANCE Copy */
            entranceCopy : '',
            /* NEW TASK */
            taskType : false,
            /* LOCK OF DISABLED */
            disabled : true,
            /* SESSION USER GET */
            user : '',
            /* DETAILS TABLE TITLE */
            title : 'Your ' + this.pageType +' Name',
            /* FORM LIST */
            form: this.$form.createForm(this, { name: 'dynamic_rule' }),
            /* NEW TASK PAGE */
            newTaskPage : ''
        }
    },
    props : {
        /* DETAILE NAME [DEMO : experiment_detail]*/
        pageType: {
            type: String,
            default() {return null}
        },
        entrance: {
            type: Boolean,
            default() {return null}
        },
    },
    created() {
        this.entranceCopy = this.entrance
        /* ROWCLICK DETAILS DATA */
        if(this.$route.params.record !=undefined){
            console.log(this.$route.params.record)
            console.log(this.pageType)
            if(this.entrance == true){
                console.log(this.pageType)
                let id = {"_id": this.$route.params.record._id}
                this.axios({
                    method: 'post',
                    url: '/api/'+ this.pageType + '/details',
                    data : id,
                }).then( data => {
                    console.log(data)
                    let backData = data.data.data;
                    sessionStorage.setItem( 'pageTypeData' , JSON.stringify(backData))
                    this.projectData = JSON.parse(
                        sessionStorage.getItem( 'pageTypeData' )
                    )
                })
            }
        }else{
            /* SESSION STATUS */
            let pageTypeData = JSON.parse(
                sessionStorage.getItem('pageTypeData')
            )
            if(pageTypeData != null){
                this.projectData = JSON.parse(
                    sessionStorage.getItem('pageTypeData')
                )
                if(this.projectData != null){
                    this.entranceCopy = true
                }
            }
        }
    },
    watch: {

    },
    mounted(){
        /* DISABLED STATUS */
        switch(this.entrance){
            case false :
                this.disabled = false
            break;
            case true :
                this.disabled = true
            break;
            default :
                this.disabled = false
        }

        /* USER INFO GET */
        let currentUser = JSON.parse(
            sessionStorage.getItem("currentUser")
        );
        this.user = currentUser.user.basic;
        console.log(this.user)
    },
    methods : {
        detailEdit() {
            this.disabled = false
            this.tableShow.dataEdit = false
            this.tableShow.dataSave = true
        },

        onChange(e) {
            console.log(e.target.value)
            this.newTaskPage = e.target.value
        },

        /* ADD NEW TASK */
        detailTask() {
            /* 优先提示 */
             this.$notification.open({
                message: 'TIPS',
                duration: 3.5,
                description:
                'Please select the type of new task first, and then follow the prompts to complete the form.',
                icon: <a-icon type="smile" style="color: #108ee9" />,
            });
            this.pageType = 'newTask'

        },

        /* SUBMIT BTN */
        detailSubmit(e) {
            this.$notification.open({
                message: 'WARNING',
                duration: 3.5,
                description:
                'Uploading information, please do not close the window.',
                icon: <a-icon type="info-circle" style="color: #f50" />,
            });
            e.preventDefault();
            this.form.validateFields((err, values) => {
                if (!err) {
                    this.axios({
                        method: 'post',
                        url: '/api/'+ this.pageType + '/add',
                        data : values ,
                    }).then( data => {
                        console.log(data)
                        let status = data.data.status;
                        let backData = data.data.data;
                        if(status == 0){
                            this.$notification.open({
                                message: 'Successfully',
                                duration: 3.5,
                                description:
                                'The upload is successful, you can now fill in more '+ this.pageType +' information.',
                                icon: <a-icon type="smile" style="color: #108ee9" />,
                            });
                            sessionStorage.setItem( 'pageTypeData' , JSON.stringify(backData))
                            console.log()
                            this.projectData = JSON.parse(
                                sessionStorage.getItem( 'pageTypeData' )
                            )
                            console.log(this.projectData)
                        }else if(status == 1){
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'Duplicate '+ this.pageType +' name, please modify and submit.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }else{
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'An unknown error occurred, please try again later or contact the system administrator.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }
                    }).catch( error =>{
                        this.$notification.open({
                            message: 'An Error Occurred',
                            duration: 3.5,
                            description:
                            'Please wait a while and try again.',
                            icon: <a-icon type="info-circle" style="color: #f50" />,
                        });
                    });
                }
            });
        },

        /* 修改 && 保存 */
        detailSave(e) {
            this.$notification.open({
                message: 'WARNING',
                duration: 3.5,
                description:
                'Uploading information, please do not close the window.',
                icon: <a-icon type="info-circle" style="color: #f50" />,
            });
            e.preventDefault();
            this.form.validateFields((err, values) => {
                if (!err) {
                    values["_id"] = this.$route.params.record._id
                    this.axios({
                        method: 'post',
                        url: '/api/'+ this.pageType + '/save',
                        data : values ,
                    }).then( data => {
                        console.log(data)
                        let status = data.data.status;
                        let backData = data.data.data;
                        if(status == 0){
                            this.$notification.open({
                                message: 'Successfully',
                                duration: 3.5,
                                description:
                                'The upload is successful, you can now fill in more '+ this.pageType +' information.',
                                icon: <a-icon type="smile" style="color: #108ee9" />,
                            });
                            sessionStorage.setItem( 'pageTypeData' , JSON.stringify(values))
                            this.projectData = JSON.parse(
                                sessionStorage.getItem( 'pageTypeData' )
                            )
                            console.log(this.projectData)
                        }else if(status == 1){
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'Duplicate '+ this.pageType +' name, please modify and submit.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }else{
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'An unknown error occurred, please try again later or contact the system administrator.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }
                    }).catch( error =>{
                        
                    });
                }
            });
        },

        /* LOCK BTN */
        detailLock(e) {
            console.log(e.value)
            const key = `open${Date.now()}`;
            this.$notification.open({
                message: 'Warning',
                description:
                'You are trying to lock an item, please confirm the operation.',
                btn: h => {
                    return h(
                        'a-button',
                        {
                            props: {
                                type: 'danger',
                                size: 'small',
                            },
                            on: {
                                click: () => {
                                    let lockStatus = this.projectData.lock
                                    let status = ''
                                    if(lockStatus == false){
                                        status = true
                                    }else{
                                        status = false
                                    }
                                    let data = [{
                                        _id : this.projectData._id , 
                                        status : status ,
                                    }];
                                    let addType = this.taskTypeFoucs
                                    let saveApi = ''
                                    switch(addType) {
                                        /* experiment api */
                                        case 'experiment':
                                            saveApi = '/api/experiment/lock';
                                            break;
                                        /* sample api */
                                        case 'sample':
                                            saveApi = '/api/sample/lock';
                                            break;
                                        /* datanalysis api */
                                        case 'datanalysis':
                                            saveApi = '/api/datanalysis/lock';
                                        /* project save api */
                                        default:
                                            saveApi = '/api/project/lock';
                                    }
                                    this.axios({
                                        method: 'post' ,
                                        url : saveApi ,
                                        data : data
                                    }).then( detailLock => {
                                        console.log(detailLock)
                                        if(detailLock.data.status == 0){
                                            this.$notification.open({
                                                message: 'Successfully',
                                                description:
                                                'The project is successfully locked, and the members participating in the project will receive relevant information prompts after logging in.',
                                                icon: <a-icon type="smile" style="color: #108ee9" />,
                                            });
                                        }else{
                                            this.$notification.open({
                                                message: 'Warning',
                                                description:
                                                'Project lock failed, please try again later.',
                                            });
                                        }
                                    }).catch( error =>{
                                        this.$notification.open({
                                            message: 'An Error Occurred',
                                            description:
                                            'Please wait a while and try again.',
                                        });
                                    });
                                    this.$notification.close(key)
                                }
                            },
                        },
                        'Sure',
                    )
                },
                key,
                onClose: close,
            });
        }

    }
}
</script>

接口部分按写了三种方法,一种是最原始的,一种是用Switch做判断,一种是按变量
这个部分可以大批量优化,参照a-button组件封装
数据存入session是暂时防止刷新数据丢失,vuex暂未配置

完整代码

<template>
    <div>
        <a-form :form="form">
            <a-page-header
                class="details-header"
                @back="() => $router.go(-1)"
                :title="title"
            >
                <!-- BUTTON SHOW FUNCTION -->
                <template slot="extra">
                    <a-form-item>
                        <span v-if="entranceCopy === false">
                            <a-button class="button-submit" key="4" type="primary" @click="detailSubmit">
                                <a-icon type="cloud-upload" />SUBMIT
                            </a-button>
                        </span>
                        <span v-else>
                            <a-button class="button-newTask" key="7" type="primary" @click="detailTask">
                                <a-icon type="file-add" />NEW TASK
                            </a-button>
                            <a-button class="button-delete" key="6" type="danger">
                                <a-icon type="delete" />DELETE
                            </a-button>
                            <a-button class="button-save" key="5" type="primary" @click="detailSave">
                                <a-icon type="save" />SAVE
                            </a-button>
                            <a-button class="button-edit" key="3" type="primary" @click="detailEdit">
                                <a-icon type="edit" />EDIT
                            </a-button>
                            <!-- <a-button class="button-unlock" key="2">
                                <a-icon type="unlock" />UNLOCK
                            </a-button> -->
                            <a-button class="button-lock" key="1" type="danger" value="lock" @click="detailLock">
                                <a-icon type="lock" />LOCK
                            </a-button>
                        </span>
                    </a-form-item>
                </template>
                <!-- 项目 -->
                <a-descriptions size="small">
                    <a-descriptions-item label="Created By">
                        <a-form-item>
                            <a-input
                                class="create-outline"
                                disabled
                                v-decorator="[
                                'created_by',
                                    {
                                        initialValue : user.name
                                    },
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="Created Time">
                        {{projectData.created_time}}
                    </a-descriptions-item>
                </a-descriptions>
            </a-page-header>
            <!-- 传递页面类型+INFO 即 TITLE -->
            <a-descriptions :title="this.pageType.toUpperCase() + ' INFO'" layout="vertical" bordered>
                <template v-if="pageType == 'newTask'">
                    <a-descriptions-item label="TASK TYPE" :span='3'>
                        <a-radio-group default-value="" button-style="solid" @change="onChange">
                            <a-radio-button value="newexperiment">
                                EXPERIMENT
                            </a-radio-button>
                            <a-radio-button value="newsample">
                                SAMPLE
                            </a-radio-button>
                            <a-radio-button value="newdatanalysis">
                                DATA-ANALYSIS
                            </a-radio-button>
                        </a-radio-group>
                    </a-descriptions-item>
                    <template v-if="newTaskPage == 'newexperiment'">
                        <a-descriptions-item label="BELONGING PROJECT">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'belonging_project',
                                        { 
                                            initialValue : projectData.belonging_project,
                                        },
                                    ]"
                                    placeholder="Belonging Project"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="EXPERIMENT NAME">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'experiment_name',
                                        { 
                                            initialValue : projectData.experiment_name,
                                        },
                                    ]"
                                    placeholder="Experiment Name"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="EXPERIMENT NUMBER">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'experiment_number',
                                        { 
                                            initialValue : projectData.experiment_number,
                                        },
                                    ]"
                                    placeholder="Experiment Number"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="ASSIGN">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'assign',
                                        { 
                                            initialValue : projectData.assign,
                                        },
                                    ]"
                                    placeholder="Experiment assign"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="START TIME">
                            <a-form-item>
                                <a-date-picker
                                    class="time-style"
                                    show-time
                                    placeholder="Select Time"
                                    :disabled='disabled'
                                    v-decorator="[
                                        'start_time' ,
                                        { 
                                            initialValue : projectData.start_time,
                                        },
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="LAST OPERATION TIME">
                            <a-form-item>
                                <a-input
                                    disabled
                                    v-decorator="[
                                    'last_operation_time',
                                        {
                                            initialValue : projectData.last_operation_time,
                                        }
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="STATUS">
                            <a-select
                                :disabled="disabled"
                                :default-value="projectData.status"
                                v-decorator="['status']"
                            >
                                <a-select-option value="Done">
                                    Done
                                </a-select-option>
                                <a-select-option value="Abort">
                                    Abort
                                </a-select-option>
                                <a-select-option value="Ongoing">
                                    Ongoing
                                </a-select-option>
                                <a-select-option value="Suspend">
                                    Suspend
                                </a-select-option>
                                <a-select-option value="Normal">
                                    Normal
                                </a-select-option>
                                <a-select-option value="Locked">
                                    Locked
                                </a-select-option>
                                <a-select-option value="Abandoned">
                                    Abandoned
                                </a-select-option>
                            </a-select>
                        </a-descriptions-item><br><br>
                        <a-descriptions-item label="NOTES" :span='3'>
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    type="textarea"
                                    v-decorator="['notes',
                                        {initialValue : projectData.notes},
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                    </template>
                    <template v-if="newTaskPage == 'newsample'">
                        <a-descriptions-item label="BELONGING EXPERIMENT">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'experiment_name',
                                        { 
                                            initialValue : projectData.experiment_name != undefined ? projectData.experiment_name : '',
                                        },
                                    ]"
                                    placeholder="Experiment name"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="Number">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'number',
                                        { 
                                            initialValue : projectData.assign,
                                        },
                                    ]"
                                    placeholder="Sample Number"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="GROUP">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'group',
                                        { 
                                            initialValue : projectData.assign,
                                        },
                                    ]"
                                    placeholder="Sample Group"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="SAMPLE NAME">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'sample_name',
                                        { 
                                            initialValue : projectData.sample_name,
                                        },
                                    ]"
                                    placeholder="Please input sample name"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="SAMPLE TYPE">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'sample_type',
                                        { 
                                            initialValue : projectData.sample_type,
                                        },
                                    ]"
                                    placeholder="Please input sample type"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="AMOUNT">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'amount',
                                        { 
                                            initialValue : projectData.amount,
                                        },
                                    ]"
                                    placeholder="Please input sample amount"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="STORAGE WAY">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'storage_way',
                                        { 
                                            initialValue : projectData.storage_way,
                                        },
                                    ]"
                                    placeholder="Please input sample storage way"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="COLLECT TIME">
                            <a-form-item>
                                <a-date-picker
                                    class="time-style"
                                    show-time
                                    placeholder="Select Time"
                                    @change="onChange"
                                    @ok="onOk"
                                    :disabled='disabled'
                                    v-decorator="[
                                        'collect_time' ,
                                        { 
                                            initialValue : projectData.start_time,
                                        },
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="LAST OPERATION TIME">
                        <a-form-item>
                            <a-input
                                disabled
                                v-decorator="[
                                'last_operation_time',
                                    {
                                        initialValue : projectData.last_operation_time,
                                    }
                                ]"
                            />
                        </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="ASSIGN">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    v-decorator="[
                                    'assign',
                                        { 
                                            initialValue : projectData.assign,
                                        },
                                    ]"
                                    placeholder="Experiment assign"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="STATUS">
                                <a-select
                                    :disabled="disabled"
                                    v-decorator="[
                                    'status',
                                        { 
                                            rules: [
                                                { 
                                                    initialValue : projectData.start_time,
                                                },
                                            ] 
                                        },
                                    ]"
                                >
                                    <a-select-option value="done">
                                        done
                                    </a-select-option>
                                    <a-select-option value="abort">
                                        abort
                                    </a-select-option>
                                    <a-select-option value="ongoing">
                                        ongoing
                                    </a-select-option>
                                    <a-select-option value="suspend">
                                        suspend
                                    </a-select-option>
                                    <a-select-option value="normal">
                                        normal
                                    </a-select-option>
                                    <a-select-option value="locked">
                                        locked
                                    </a-select-option>
                                    <a-select-option value="abandoned">
                                        abandoned
                                    </a-select-option>
                                </a-select>
                        </a-descriptions-item><br>
                        <a-descriptions-item label="NOTES">
                            <a-form-item>
                                <a-input
                                    :disabled='disabled'
                                    type="textarea"
                                    v-decorator="['notes',
                                        {initialValue : projectData.notes},
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                    </template>
                    <template v-if="newTaskPage == 'newdatanalysis'">

                    </template>
                </template>
                <!-- PROJECT MODULE && TEMPLATE -->
                <template v-if="pageType == 'project'">
                    <!-- BEFORE CREATE -->
                    <a-descriptions-item label="PROJECT NUMBER">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'number',
                                    {initialValue : projectData.number},
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="PROJECT NAME">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                    'project_name',
                                    {
                                        initialValue : projectData.project_name
                                    },
                                ]"
                                
                                placeholder="Project Name"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="DEPARTMENT">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'department',
                                    {
                                        initialValue : projectData.department,
                                    }
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="PROJECT LEADER">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'leader',
                                    { 
                                        initialValue : projectData.leader,
                                    },
                                ]"
                                placeholder="Project Leader"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="PROJECT MANAGER">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'manager',
                                    { 
                                        initialValue : projectData.manager,
                                    },
                                ]"
                                placeholder="Project Manager"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="LAST OPERATION TIME">
                        <a-form-item>
                            <a-input
                                disabled
                                v-decorator="[
                                'last_operation_time',
                                    {
                                        initialValue : projectData.last_operation_time,
                                    }
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <!-- CREATED -->
                    <template v-if="entranceCopy">
                        <a-descriptions-item label="SHARE INFO">
                            <a-form-item>
                                <a-input
                                    :disabled="disabled"
                                    v-decorator="['last_operation_time',
                                        {
                                            initialValue : projectData.last_operation_time 
                                        },
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="PROJECT START TIME">
                            <a-form-item>
                                <a-date-picker
                                    class="time-style"
                                    show-time
                                    placeholder="Select Time"
                                    @change="onChange"
                                    @ok="onOk"
                                    :disabled='disabled'
                                    v-decorator="[
                                        'start_time' ,
                                        { 
                                            initialValue : projectData.start_time,
                                        },
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                        <a-descriptions-item label="STATUS">
                            <a-select
                                :disabled="disabled"
                                v-decorator="[
                                'status',
                                    { 
                                        rules: [
                                            { 
                                                initialValue : projectData.start_time,
                                            },
                                        ] 
                                    },
                                ]"
                            >
                                <a-select-option value="done">
                                    done
                                </a-select-option>
                                <a-select-option value="abort">
                                    abort
                                </a-select-option>
                                <a-select-option value="ongoing">
                                    ongoing
                                </a-select-option>
                                <a-select-option value="suspend">
                                    suspend
                                </a-select-option>
                                <a-select-option value="normal">
                                    normal
                                </a-select-option>
                                <a-select-option value="locked">
                                    locked
                                </a-select-option>
                                <a-select-option value="abandoned">
                                    abandoned
                                </a-select-option>
                            </a-select>
                        </a-descriptions-item>
                        <a-descriptions-item label="DISCRIPTION">
                            <a-form-item>
                                <a-input
                                    type="textarea"
                                    v-decorator="['description',
                                        {initialValue : projectData.description},
                                    ]"
                                />
                            </a-form-item>
                        </a-descriptions-item>
                    </template>
                </template>
                <!-- EXPERIMENT MODULE && TEMPLATE -->
                <template v-if="pageType == 'experiment'">
                    <a-descriptions-item label="BELONGING PROJECT">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'belonging_project',
                                    { 
                                        initialValue : projectData.belonging_project,
                                    },
                                ]"
                                placeholder="Belonging Project"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="EXPERIMENT NAME">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'experiment_name',
                                    { 
                                        initialValue : projectData.experiment_name,
                                    },
                                ]"
                                placeholder="Experiment Name"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="EXPERIMENT NUMBER">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'experiment_number',
                                    { 
                                        initialValue : projectData.experiment_number,
                                    },
                                ]"
                                placeholder="Experiment Number"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="ASSIGN">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'assign',
                                    { 
                                        initialValue : projectData.assign,
                                    },
                                ]"
                                placeholder="Experiment assign"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="START TIME">
                        <a-form-item>
                            <a-date-picker
                                class="time-style"
                                show-time
                                placeholder="Select Time"
                                @change="onChange"
                                @ok="onOk"
                                :disabled='disabled'
                                v-decorator="[
                                    'start_time' ,
                                    { 
                                        initialValue : projectData.start_time,
                                    },
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="LAST OPERATION TIME">
                        <a-form-item>
                            <a-input
                                disabled
                                v-decorator="[
                                'last_operation_time',
                                    {
                                        initialValue : projectData.last_operation_time,
                                    }
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="STATUS">
                        <a-select
                            :disabled="disabled"
                            :default-value="projectData.status"
                            v-decorator="['status']"
                        >
                            <a-select-option value="Done">
                                Done
                            </a-select-option>
                            <a-select-option value="Abort">
                                Abort
                            </a-select-option>
                            <a-select-option value="Ongoing">
                                Ongoing
                            </a-select-option>
                            <a-select-option value="Suspend">
                                Suspend
                            </a-select-option>
                            <a-select-option value="Normal">
                                Normal
                            </a-select-option>
                            <a-select-option value="Locked">
                                Locked
                            </a-select-option>
                            <a-select-option value="Abandoned">
                                Abandoned
                            </a-select-option>
                        </a-select>
                    </a-descriptions-item><br><br>
                    <a-descriptions-item label="NOTES" :span='3'>
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                type="textarea"
                                v-decorator="['notes',
                                    {initialValue : projectData.notes},
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                </template>
                <!-- SAMPLE MODULE && TEMPLATE -->
                <template v-if="pageType == 'sample'">
                    <a-descriptions-item label="BELONGING EXPERIMENT">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'experiment_name',
                                    { 
                                        initialValue : projectData.experiment_name != undefined ? projectData.experiment_name : '',
                                    },
                                ]"
                                placeholder="Experiment name"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="Number">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'number',
                                    { 
                                        initialValue : projectData.assign,
                                    },
                                ]"
                                placeholder="Sample Number"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="GROUP">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'group',
                                    { 
                                        initialValue : projectData.assign,
                                    },
                                ]"
                                placeholder="Sample Group"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="SAMPLE NAME">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'sample_name',
                                    { 
                                        initialValue : projectData.sample_name,
                                    },
                                ]"
                                placeholder="Please input sample name"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="SAMPLE TYPE">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'sample_type',
                                    { 
                                        initialValue : projectData.sample_type,
                                    },
                                ]"
                                placeholder="Please input sample type"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="AMOUNT">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'amount',
                                    { 
                                        initialValue : projectData.amount,
                                    },
                                ]"
                                placeholder="Please input sample amount"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="STORAGE WAY">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'storage_way',
                                    { 
                                        initialValue : projectData.storage_way,
                                    },
                                ]"
                                placeholder="Please input sample storage way"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="COLLECT TIME">
                        <a-form-item>
                            <a-date-picker
                                class="time-style"
                                show-time
                                placeholder="Select Time"
                                @change="onChange"
                                @ok="onOk"
                                :disabled='disabled'
                                v-decorator="[
                                    'collect_time' ,
                                    { 
                                        initialValue : projectData.start_time,
                                    },
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="LAST OPERATION TIME">
                    <a-form-item>
                        <a-input
                            disabled
                            v-decorator="[
                            'last_operation_time',
                                {
                                    initialValue : projectData.last_operation_time,
                                }
                            ]"
                        />
                    </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="ASSIGN">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                v-decorator="[
                                'assign',
                                    { 
                                        initialValue : projectData.assign,
                                    },
                                ]"
                                placeholder="Experiment assign"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                    <a-descriptions-item label="STATUS">
                            <a-select
                                :disabled="disabled"
                                v-decorator="[
                                'status',
                                    { 
                                        rules: [
                                            { 
                                                initialValue : projectData.start_time,
                                            },
                                        ] 
                                    },
                                ]"
                            >
                                <a-select-option value="done">
                                    done
                                </a-select-option>
                                <a-select-option value="abort">
                                    abort
                                </a-select-option>
                                <a-select-option value="ongoing">
                                    ongoing
                                </a-select-option>
                                <a-select-option value="suspend">
                                    suspend
                                </a-select-option>
                                <a-select-option value="normal">
                                    normal
                                </a-select-option>
                                <a-select-option value="locked">
                                    locked
                                </a-select-option>
                                <a-select-option value="abandoned">
                                    abandoned
                                </a-select-option>
                            </a-select>
                    </a-descriptions-item><br>
                    <a-descriptions-item label="NOTES">
                        <a-form-item>
                            <a-input
                                :disabled='disabled'
                                type="textarea"
                                v-decorator="['notes',
                                    {initialValue : projectData.notes},
                                ]"
                            />
                        </a-form-item>
                    </a-descriptions-item>
                </template>
            </a-descriptions>
        </a-form>
    </div>
</template>
<script>
export default {
    name : "TaskDetail" ,
    data(){
        return{
            /* ALL-DATA */
            projectData : '',
            /* ENTRANCE Copy */
            entranceCopy : '',
            /* NEW TASK */
            taskType : false,
            /* LOCK OF DISABLED */
            disabled : true,
            /* SESSION USER GET */
            user : '',
            /* DETAILS TABLE TITLE */
            title : 'Your ' + this.pageType +' Name',
            /* FORM LIST */
            form: this.$form.createForm(this, { name: 'dynamic_rule' }),
            /* NEW TASK PAGE */
            newTaskPage : ''
        }
    },
    props : {
        /* DETAILE NAME [DEMO : experiment_detail]*/
        pageType: {
            type: String,
            default() {return null}
        },
        entrance: {
            type: Boolean,
            default() {return null}
        },
    },
    created() {
        this.entranceCopy = this.entrance
        /* ROWCLICK DETAILS DATA */
        if(this.$route.params.record !=undefined){
            console.log(this.$route.params.record)
            console.log(this.pageType)
            if(this.entrance == true){
                console.log(this.pageType)
                let id = {"_id": this.$route.params.record._id}
                this.axios({
                    method: 'post',
                    url: '/api/'+ this.pageType + '/details',
                    data : id,
                }).then( data => {
                    console.log(data)
                    let backData = data.data.data;
                    sessionStorage.setItem( 'pageTypeData' , JSON.stringify(backData))
                    this.projectData = JSON.parse(
                        sessionStorage.getItem( 'pageTypeData' )
                    )
                })
            }
        }else{
            /* SESSION STATUS */
            let pageTypeData = JSON.parse(
                sessionStorage.getItem('pageTypeData')
            )
            if(pageTypeData != null){
                this.projectData = JSON.parse(
                    sessionStorage.getItem('pageTypeData')
                )
                if(this.projectData != null){
                    this.entranceCopy = true
                }
            }
        }
    },
    watch: {

    },
    mounted(){
        /* DISABLED STATUS */
        switch(this.entrance){
            case false :
                this.disabled = false
            break;
            case true :
                this.disabled = true
            break;
            default :
                this.disabled = false
        }

        /* USER INFO GET */
        let currentUser = JSON.parse(
            sessionStorage.getItem("currentUser")
        );
        this.user = currentUser.user.basic;
        console.log(this.user)
    },
    methods : {
        detailEdit() {
            this.disabled = false
            this.tableShow.dataEdit = false
            this.tableShow.dataSave = true
        },

        onChange(e) {
            console.log(e.target.value)
            this.newTaskPage = e.target.value
        },

        /* ADD NEW TASK */
        detailTask() {
            /* 优先提示 */
             this.$notification.open({
                message: 'TIPS',
                duration: 3.5,
                description:
                'Please select the type of new task first, and then follow the prompts to complete the form.',
                icon: <a-icon type="smile" style="color: #108ee9" />,
            });
            this.pageType = 'newTask'

        },

        /* SUBMIT BTN */
        detailSubmit(e) {
            this.$notification.open({
                message: 'WARNING',
                duration: 3.5,
                description:
                'Uploading information, please do not close the window.',
                icon: <a-icon type="info-circle" style="color: #f50" />,
            });
            e.preventDefault();
            this.form.validateFields((err, values) => {
                if (!err) {
                    this.axios({
                        method: 'post',
                        url: '/api/'+ this.pageType + '/add',
                        data : values ,
                    }).then( data => {
                        console.log(data)
                        let status = data.data.status;
                        let backData = data.data.data;
                        if(status == 0){
                            this.$notification.open({
                                message: 'Successfully',
                                duration: 3.5,
                                description:
                                'The upload is successful, you can now fill in more '+ this.pageType +' information.',
                                icon: <a-icon type="smile" style="color: #108ee9" />,
                            });
                            sessionStorage.setItem( 'pageTypeData' , JSON.stringify(backData))
                            console.log()
                            this.projectData = JSON.parse(
                                sessionStorage.getItem( 'pageTypeData' )
                            )
                            console.log(this.projectData)
                        }else if(status == 1){
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'Duplicate '+ this.pageType +' name, please modify and submit.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }else{
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'An unknown error occurred, please try again later or contact the system administrator.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }
                    }).catch( error =>{
                        this.$notification.open({
                            message: 'An Error Occurred',
                            duration: 3.5,
                            description:
                            'Please wait a while and try again.',
                            icon: <a-icon type="info-circle" style="color: #f50" />,
                        });
                    });
                }
            });
        },

        /* 修改 && 保存 */
        detailSave(e) {
            this.$notification.open({
                message: 'WARNING',
                duration: 3.5,
                description:
                'Uploading information, please do not close the window.',
                icon: <a-icon type="info-circle" style="color: #f50" />,
            });
            e.preventDefault();
            this.form.validateFields((err, values) => {
                if (!err) {
                    values["_id"] = this.$route.params.record._id
                    this.axios({
                        method: 'post',
                        url: '/api/'+ this.pageType + '/save',
                        data : values ,
                    }).then( data => {
                        console.log(data)
                        let status = data.data.status;
                        let backData = data.data.data;
                        if(status == 0){
                            this.$notification.open({
                                message: 'Successfully',
                                duration: 3.5,
                                description:
                                'The upload is successful, you can now fill in more '+ this.pageType +' information.',
                                icon: <a-icon type="smile" style="color: #108ee9" />,
                            });
                            sessionStorage.setItem( 'pageTypeData' , JSON.stringify(values))
                            this.projectData = JSON.parse(
                                sessionStorage.getItem( 'pageTypeData' )
                            )
                            console.log(this.projectData)
                        }else if(status == 1){
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'Duplicate '+ this.pageType +' name, please modify and submit.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }else{
                            this.$notification.open({
                                message: 'WARNING',
                                duration: 3.5,
                                description:
                                'An unknown error occurred, please try again later or contact the system administrator.',
                                icon: <a-icon type="info-circle" style="color: #f50" />,
                            });
                        }
                    }).catch( error =>{
                        
                    });
                }
            });
        },

        /* LOCK BTN */
        detailLock(e) {
            console.log(e.value)
            const key = `open${Date.now()}`;
            this.$notification.open({
                message: 'Warning',
                description:
                'You are trying to lock an item, please confirm the operation.',
                btn: h => {
                    return h(
                        'a-button',
                        {
                            props: {
                                type: 'danger',
                                size: 'small',
                            },
                            on: {
                                click: () => {
                                    let lockStatus = this.projectData.lock
                                    let status = ''
                                    if(lockStatus == false){
                                        status = true
                                    }else{
                                        status = false
                                    }
                                    let data = [{
                                        _id : this.projectData._id , 
                                        status : status ,
                                    }];
                                    let addType = this.taskTypeFoucs
                                    let saveApi = ''
                                    switch(addType) {
                                        /* experiment api */
                                        case 'experiment':
                                            saveApi = '/api/experiment/lock';
                                            break;
                                        /* sample api */
                                        case 'sample':
                                            saveApi = '/api/sample/lock';
                                            break;
                                        /* datanalysis api */
                                        case 'datanalysis':
                                            saveApi = '/api/datanalysis/lock';
                                        /* project save api */
                                        default:
                                            saveApi = '/api/project/lock';
                                    }
                                    this.axios({
                                        method: 'post' ,
                                        url : saveApi ,
                                        data : data
                                    }).then( detailLock => {
                                        console.log(detailLock)
                                        if(detailLock.data.status == 0){
                                            this.$notification.open({
                                                message: 'Successfully',
                                                description:
                                                'The project is successfully locked, and the members participating in the project will receive relevant information prompts after logging in.',
                                                icon: <a-icon type="smile" style="color: #108ee9" />,
                                            });
                                        }else{
                                            this.$notification.open({
                                                message: 'Warning',
                                                description:
                                                'Project lock failed, please try again later.',
                                            });
                                        }
                                    }).catch( error =>{
                                        this.$notification.open({
                                            message: 'An Error Occurred',
                                            description:
                                            'Please wait a while and try again.',
                                        });
                                    });
                                    this.$notification.close(key)
                                }
                            },
                        },
                        'Sure',
                    )
                },
                key,
                onClose: close,
            });
        }

    }
}
</script>
<style scoped lang="less">
@import './css/details.less';
</style>
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 217,907评论 6 506
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,987评论 3 395
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 164,298评论 0 354
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,586评论 1 293
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,633评论 6 392
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,488评论 1 302
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,275评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,176评论 0 276
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,619评论 1 314
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,819评论 3 336
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,932评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,655评论 5 346
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,265评论 3 329
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,871评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,994评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 48,095评论 3 370
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,884评论 2 354