import {getDectyp, init} from "../../../../../../service/business/rmb";
import Utils from "../../../../../../utils";
import event from "../../tcr/event"

export default {
    mixins: [event],
    methods: {
        // commitMod() {
        //     this.$refs['modelForm'].validate(async (validStatic) => {
        //         if (validStatic) {
        //             save('rmb2112', this.model).then(response => {
        //                 if (response.respCode === SUCCESS) {
        //                     this.$notify({
        //                         title: "成功",
        //                         message: "提交成功",
        //                         type: "success",
        //                     });
        //                     this.$store.commit('delTagsArry', this.$route.path);
        //                     this.$router.back()
        //                 } else {
        //                     this.$notify({
        //                         title: "失败",
        //                         message: "提交失败",
        //                         type: "error",
        //                     });
        //                 }
        //             });
        //         } else {
        //             // 前端校验失败
        //             this.$notify({
        //                 title: '失败',
        //                 message: '校验失败',
        //                 type: 'error',
        //             });
        //         }
        //     })
        // },
        // async mod() {
        //     let params = {
        //         inr: this.model.tcr2112.inr,
        //         markSet: this.model.tcr2112.markSet,
        //         modifySet: this.model.tcr2112.modifySet,
        //         reldat: this.model.tcr2112.reldat,
        //         ownextkey: this.model.tcr2112.ownextkey,
        //         tcrVo: this.model.tcr2112.tcrVo
        //     };
        //     let rtnmsg = await Api.post('/report/rmbsel/editTcr', params)
        //     if (rtnmsg.respCode == SUCCESS) {
        //         this.$notify({
        //             title: "成功",
        //             message: "提交成功",
        //             type: "success",
        //         });
        //         this.$store.commit('delTagsArry', this.$route.path);
        //         this.$router.back()
        //     } else {
        //         this.$notify({
        //             title: "失败",
        //             message: "提交失败",
        //             type: "error",
        //         });
        //     }
        // },
        // flgChange(val) {
        //     if (val == 'X') {
        //         this.model.tcr2112.tcrVo.opertype = '2'
        //         this.model.filterKeys = ['2']
        //     } else {
        //         this.model.tcr2112.tcrVo = JSON.parse(JSON.stringify(this.model.old2111))
        //         this.model.filterKeys = ['1', '2', '3']
        //     }
        //     this.$nextTick(() => {
        //         this.root.$refs['modelForm'].validateField(['tcr2112.tcrVo.actiondesc']);
        //     })
        // }
        async checkTcr() {
            this.$refs['modelForm'].validate(async (validStatic) => {
                if (validStatic) {
                    const loading = this.loading('正在校验数据');
                    const rtnmsg = await Api.post("/report/rmbsel/validate2112", this.model.tcr2112.tcrVo);
                    if (rtnmsg.respCode == SUCCESS) {
                        const fieldErrors = rtnmsg.data;
                        if (fieldErrors && Object.keys(fieldErrors).length == 0) {
                            // 清除之前的校验状态
                            this.$refs.modelForm.clearValidate();
                            this.$notify({
                                title: "成功",
                                message: "校验成功",
                                type: "success",
                            });
                            loading.close();
                            return
                        }
                        const tab = this.showBackendErrors(fieldErrors);
                        if (tab) {
                            // 判断校验失败的表单不属于当前的tab,则切换tab到对应报错的tab页面
                            if (tab.name !== this.tabVal) {
                                this.tabClick(tab, '1');
                            }
                        }
                        loading.close();
                    }
                } else {
                    // 前端校验失败
                    this.$notify({
                        title: '失败',
                        message: '校验失败',
                        type: 'error',
                    });
                }
            })
        },
    }
}