import { getUUID } from "../query-actions/util/lib";
export default {
  execute: function (bill, param) {
      if(bill){
          if(param.param.isNeedSave){
              let saveParam = {
                  actions: "bill.Basic.save",
                  afterAction: "",
                  confirmTitle: "",
                  customSaveAction: "",
                  noCheckCardDepressPeriod: true,
                  noCheckSubTable: true,
                  viewName: ""
              }
              bill.executeServerAction(saveParam,function(code,data){
                  if(code===200){
                      this.approval(bill, param);
                      bill.setControlsSate(param["_control_name_"],"loading",false)
                  }else{
                      bill.setControlsSate(param["_control_name_"],"loading",false)
                      GMS.$hideContainer.$message.error("操作异常请联系管理员");
                  }
              }.bind(this));
          } else {
              this.approval(bill, param);
          }
      }else{
          alert('缺少参数');
      }
  },
  approval: function(bill, param){
      let billId = bill.getMasterData().getValue('id');
      let taskId = bill.getGlobalParam('reviewParam').taskId;
      let comments = bill.getGlobalParam('reviewParam').suggestions ? bill.getGlobalParam('reviewParam').suggestions:"";
      GMS.$http.post('/gms/workflow/task/completed/' + taskId + '?result=3&comments='+comments).then(
          function(response) {
              if (response.status == 200 || response.statusText == 'OK') {
                  // console.log('驳回成功');
                  bill.setControlsSate(param["_control_name_"],"loading",false)
                  GMS.$hideContainer.$Message.success('驳回成功！')
                  if (
                    window.osConfig.appOpenMode &&
                    window.osConfig.appOpenMode == "apploader"
                  ) {
                    GMS.$hideContainer.$portalAPI.emit('nros-tag-close')
                    GMS.$hideContainer.$portalAPI.emit(
                      "open-new-page", //打开一个新的页签
                      getUUID(),
                      "runner-bill-form",
                      {
                        templateName: param.param.viewName,
                        id: billId,
                        state:'readOnly'
                      },
                      {
                        openWay: "FUNCTAB",
                        title: "单据详情",
                      }
                    );
                  }
                  else {
                    GMS.$hideContainer.$router.push({
                      path: "/showInnerBillForm/" + param.param.viewName + "/" + billId
                    })
                  }
              }
          }.bind(this)
      )
      .catch(
          function(error) {
              bill.setControlsSate(param["_control_name_"],"loading",false)
          }.bind(this)
      );
  }
}