import { split } from "lodash";
import Api from "~/service/Api"
import Utils from "~/utils/index"
export default {
    async onUsfmodShwflt() {
        let rtnmsg = await this.executeRule("usfmod_shwflt")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
    },
    async onTake() {
        let rtnmsg = await this.executeRule("take")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
    },
    async onDelete(idx,row) {
        let params = {selDst:"sptstm",selIds:[idx+1]}
        let rtnmsg = await this.executeRule("del",params)
        if (rtnmsg.respCode == SUCCESS) {
            this.stmData.data = rtnmsg.data.sptstm.rows;
            this.$notify({ title: '成功', message: '删除成功！' });
        }
        else {
            this.$notify.error({ title: '错误', message: '删除失败！' });
        }
    },
    async onRouting() {
        let rtnmsg = await this.executeRule("routing")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
    },
    async onShowInc() {
        let rtnmsg = await this.executeRule("show_inc")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑

        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
    },
    async onDetails(idx, row) {
        let viewurl = "business/sptpopup";
        const selIds= [idx + 1];
        const selDst= "sptstm";
        let params = {selIds,selDst};
        this.executeRule("sptstm,butspt",params).then((res) => {
            if (res.respCode == SUCCESS) {
                Utils.copyValueFromVO(this.model, res.data);
                sessionStorage.setItem('Sptpopup', JSON.stringify(this.model));
                this.$router.push({ path: viewurl, query: {}});
            }else {
                this.$notify.error({ title: '错误', message: '服务请求失败！' });
            }
        })
        /* let rtnmsg = await this.executeRule("details")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑
        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        } */
    },
    async continueEdit(row) {
        //let rtnmsg = await Api.post("getPendingData",{params:{'selsptinr':row[0]}})
        //if (rtnmsg.respCode == SUCCESS) {
        //var cacheFileName = rtnmsg.data.cacheFileName;
        this.model.selsptinr = row['INR'];
        let rtnmsg = await this.executeRule("tak")
        if (rtnmsg.respCode == SUCCESS) {
            //TODO 处理数据逻辑
            let trnName = row.交易代码.toLowerCase();
            // let viewurl = "/business/ditopn?selsptinr=" + row[0];
            //let viewurl = "/business/"+trnName+"?selsptinr=" + row['INR'];
            let viewurl = "/business/"+trnName;
            this.$router.push(viewurl);
        }
        else {
            this.$notify.error({ title: '错误', message: '服务请求失败！' });
        }
     
       
        //}
    },
    async handleReset() {
        this.model.chkinc = "";
        this.model.chkdzt = "";
        this.model.chkpen = "";
        this.model.chkcor = "";
        this.model.chkaut = "";
        this.model.chkdel = "";
        this.model.chktco = "";
        this.model.chkcan = "";
        this.model.selobj = "";
        this.model.seltxt = "";
        this.model.usfmod.flt = "";
        this.model.inidatfro = "";
        this.model.inidattil = "";
        this.model.dflg = "1";
        this.model.chkypt = "";
        this.model.yptinf = "";

    },
    async handleSearch() {
            if(this.sourceModel.length===0){
                this.sourceData.forEach(s => {
                    this.model[s.value] = 't';
                  })
            }
           const res = await this.executeDefault("sptstm")
           //TODO 处理数据逻辑
           this.stmData.data = res.data.sptstm.rows;
           this.$store.commit("setTaskList", {key: "sptsel", val: this.stmData.data.length});
        //    if(res.data.sptstm.rows.length == 0){
        //     this.$notify({
        //         title: '成功',
        //         message: '搜索完毕，无满足条件记录',
        //         type: 'success'
        //     });
        //     }
        },

        async sptfndHandleReset() {
            this.model.chkinc = "";
            this.model.chkdzt = "";
            this.model.chkpen = "";
            this.model.chkcor = "";
            this.model.chkaut = "";
            this.model.chkdel = "";
            this.model.chktco = "";
            this.model.chkcan = "";
            this.model.selobj = "";
            this.model.seltxt = "";
            this.model.usfmod.flt = "";
            this.model.inidatfro = "";
            this.model.inidattil = "";
            this.model.dflg = "1";
            this.model.chkypt = "";
            this.model.yptinf = "";
    
        },
        async sptfndHandleSearch() {
                this.model.chkpen = "t";
                // this.executeDefault("sptstm").then(res => {
                //     //TODO 处理数据逻辑
                //     this.stmData.data = res.data.sptstm.rows;
                // })
                const res = await this.executeDefault("sptstm")
                this.stmData.data = res.data.sptstm.rows;
                this.$store.commit("setTaskList", {key: "sptbrk", val: this.stmData.data.length});
                // if(res.data.sptstm.rows.length == 0){
                //     this.$notify({
                //         title: '成功',
                //         message: '搜索完毕，无满足条件记录',
                //         type: 'success'
                //     });
                //     }
            },
            async onSptpButord(){
                let rtnmsg = await this.executeRule("sptp.butord")
                if(rtnmsg.respCode == SUCCESS)
                {
                //TODO 处理数据逻辑

                }
                else
                {
                this.$notify.error({title: '错误',message: '服务请求失败！'});
                }
            },
        async onSptpButcls(){
                let rtnmsg = await this.executeRule("sptp.butcls")
                if(rtnmsg.respCode == SUCCESS)
                {
                //TODO 处理数据逻辑

                }
                else
                {
                this.$notify.error({title: '错误',message: '服务请求失败！'});
                }
            },

}