import Utils from "~/utils";

export default {
  methods: {
		// 表单提交
    async handleSubmit() {
      let result = await this.save();
      if (result.respCode == SUCCESS && Object.keys(result.fieldErrors).length == 0) {
        this.$notify({
          title: "成功",
          message: "保存成功",
          type: "success",
        });
        this.$store.dispatch("TagsView/delView", this.$route)
        this.$router.history.push("/taskList", () => {
          this.$store.commit("setTaskListTabVal", 'trnrel')
        });
      }else  if(result.fieldErrors && Object.keys(result.fieldErrors).length > 0 ){
        const tab = this.showBackendErrors(result.fieldErrors)
        if (tab) {
          // tab切换之后，需出发tab-click的事件
          this.tabClick(tab);
        }
        this.$notify({
          title: "错误",
          message: "检核失败！",
          type: "error",
        });
      }
      else{
        this.$notify({
          title: "失败",
          message: "保存失败",
          type: "error",
        });
       
      }
    },
		// 表单暂存
    async handleStash() {
      let result = await this.pedding();
      if (result.respCode == SUCCESS) {
        this.$notify({
          title: "成功",
          message: "暂存成功",
          type: "success",
        });
        this.$store.dispatch("TagsView/delView", this.$route)
        this.$router.history.push("/taskList", () => {
          this.$store.commit("setTaskListTabVal", 'sptbrk')
        });
      } else {
        this.$notify({
          title: "失败",
          message: "暂存失败",
          type: "error",
        });
      }
    },
		// 表单校验
    async handleCheck() {
      let result = await this.checkAll();
      if (result.respCode == SUCCESS) {
        const fieldErrors = result.fieldErrors;
        this.updateModel(result.data);
        if(fieldErrors && Object.keys(fieldErrors).length == 0){
            this.$notify({
              title: "成功",
              message: "校验成功",
              type: "success",
            });
            reutrn
        }
        const tab = this.showBackendErrors(fieldErrors)

        if (tab) {
          // tab切换之后，需出发tab-click的事件
          this.tabClick(tab);
          this.$notify({
            title: "错误",
            message: "校核失败",
            type: "error",
          });
          return
        }
      } else {
        this.$notify.error({ title: "错误", message: result.respMsg });
      }
    },
    async handlePass(data) {
      debugger;

        this.$confirm('您确定复核该笔交易?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
      }).then(
       
        async ()=>{
          let idxInt = parseInt(data.idx);
          const selIds = [idxInt+1]; //rowno选中行
          const selDst = "trncorco.trnstm" //列表对应后台模型中的stream
  
          let params = { selDst: selDst, selIds: selIds };

          this.declareParams.trnName = "trnrel";
      
          console.log(this);
          this.model.pageId = data.pageId;
  
          let rtnmsg = await this.executeRule("relrow", params)
          if (rtnmsg.respCode == SUCCESS) {
              debugger;
              let errorMsg = "";
              let fieldErrorsFlag = (JSON.stringify(rtnmsg.fieldErrors) == "{}");
              if(!fieldErrorsFlag){
                  let errorMsgkey = "";
                  let errorMsgVal = "";
                  for (const key in rtnmsg.fieldErrors) {
                      errorMsgkey = key;
                      errorMsgVal = rtnmsg.fieldErrors[key];
                  }
                  errorMsg = errorMsgkey+':'+errorMsgVal;
                  this.$notify.error({title: '错误',message: '复核失败！错误信息['+errorMsg+']'});
              }else{
                  this.$notify({
                      title: '成功',
                      message: '复核成功',
                      type: 'success'
                  });
                  debugger;
                  // const that = this.root;
                  // that.executeRule("searow").then(res => {
                  //     //TODO 处理数据逻辑
                  //     that.$refs.inftrnps.stmData.data = res.data.trncorco_trnstm.rows;
                  //     this.model.trncorco.trnstm = res.data.trncorco_trnstm;
                  // })
                  this.$router.history.push("/taskList", () => {
                    this.$store.commit("setTaskListTabVal", 'trnrel')
                  })
              }         
          }
          else {
              let errorMsg = "";
              let fieldErrorsFlag = (JSON.stringify(rtnmsg.fieldErrors) == "{}");
              if(!fieldErrorsFlag){
                  let errorMsgkey = "";
                  let errorMsgVal = "";
                  for (const key in rtnmsg.fieldErrors) {
                      errorMsgkey = key;
                      errorMsgVal = rtnmsg.fieldErrors[key];
                  }
                  errorMsg = errorMsgkey+':'+errorMsgVal;
              }else if(rtnmsg.respMsg){
                  errorMsg = rtnmsg.respMsg;
              }
              this.$notify.error({title: '错误',message: '复核失败！错误信息['+errorMsg+']'});
          }
      }
      
      )


  },
  },
};
