import { getUUID } from "../query-actions/util/lib";
export default {
  execute: function (bill, param) {
    let postData = {
      updatebillState: "2",
      actions: "workflow.submitToFlow"
    }
    if (bill) {
      bill.setControlsSate(param["_control_name_"], 'enable', false)
      // GMS.$hideContainer.$Spin.show();
      bill.executeServerAction(postData, function (code, data) {
        bill.setControlsSate(param["_control_name_"], 'enable', true)
        if (code === 200) {
          // GMS.$hideContainer.$Spin.hide();
          const id = data.content.billData.id
          GMS.vbus.$emit('change-form-state', { state: 'readOnly', billId: id})
          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,
                state:'readOnly'
              },
              {
                openWay: "FUNCTAB",
                title: "单据详情",
              }
            );
          }
          else {
            GMS.$hideContainer.$router.push({
              path: "/showInnerBillForm/" + param.param.viewName + "/" + billId
            })
          }
        } else if (code === 201) {
          GMS.$hideContainer.$Spin.hide();
          GMS.$hideContainer.$Message.error("提交失败");
        } else if (code === 202) {
          GMS.$hideContainer.$Spin.hide();
          GMS.$hideContainer.$Message.error("暂存单据异常请联系管理员");
        }
      }.bind(this));
    } else {
      GMS.$hideContainer.$Spin.hide();
      alert('缺少参数');
    }
  }
}