<!--
import { types } from 'util';
 * @Author: zqm
 * @Date: 2021-06-28 15:44:47
 * @LastEditTime: 2022-04-15 16:24:38
 * @LastEditors: Please set LastEditors
 * @Description: 保存按钮
 * @FilePath: \taxFormToolFramework\src\components\saveButton.vue
-->
<template>
  <div>
    <el-button ref="saveButton" type="primary" size="small" :disabled="state=='success'||saveDisable" @click="saveFun()">{{buttonName}}</el-button>
  </div>
</template>
<script>
export default {
  name: "saveButton",
  props: {
    buttonName: { type: String, default: "" },
    state: { type: String, default: "" }
  },
  data: function () {
    return {
      saveDisable: "",
    }
  },
  computed: {
    saveDisableWatch() {
      return this.$store.state.data.saveDisable
    }
  },
  watch: {
    saveDisableWatch: {
      handler(val) {
        this.saveDisable = val
      },
      immediate: true,
      deep: true
    },
  },
  methods: {
    saveFun(type) {
      var tableData = this.$store.state.data.engines;
      var saveTableData = tableData.getTableData();
      var checkList = saveTableData.checkList.checkList
      this.$store.commit("checkList", checkList);
      //清除定位
      tableData.clearDefectBackgroundColor();
      if (this.$store.state.data.platform == "1") {
        if (this.buttonName == "保存" && !['tab', 'export', "modal", 'declare', "initModal"].includes(type)) {
          //保存时的校验
          var alertList = this.$store.state.data.configData.alert
          var saveModalList = Enumerable.From(alertList).Where(function (val) { return val.type == "2" }).ToArray();
          if (saveModalList.length > 0) {//展示弹窗，再调表内校验
            var obj = this.recursionParent(this.$parent, "inTablemodal")
            obj.initModal("save")
          } else {
            //表内校验
            if (checkList.length > 0) {
              var obj = this.recursionParent(this.$parent, "checkResult")
              obj.inTableCheck()
            }
          }
        }
        if (["10101_002", "10102_001"].includes(this.$store.state.data.bblxHeader.bbDm) && type != "modal") {
          var alertList = this.$store.state.data.configData.alert
          var saveModalList = Enumerable.From(alertList).Where(function (val) { return val.type == "2" }).ToArray();
          if (saveModalList.length > 0) {
            return
          }
        }
        var _self = this
        var saveUrl = interfacePrefix + config.requestAddress.saveTable;
        //判断是否存在拦截性校验
        var checkFlag = false
        for (var c = 0; c < checkList.length; c++) {
          var checkObj = checkList[c];
          if (checkObj.mesType == '1') {
            checkFlag = true
            break;
          }
        }
        //整理保存数据
        var saveData = {}
        saveData.bblxHeader = this.$store.state.data.bblxHeader;
        saveData.bblxHeader.bczt = this.buttonName != "保存" ? "Z" : (checkFlag ? "N" : 'Y')
        saveData.data = [];
        this.$store.state.data.saveStructure.header.verificationState = checkFlag ? false : true;
        delete this.$store.state.data.saveStructure.header.state;
        this.$store.state.data.saveStructure.pageData = saveTableData;
        saveData.data.push(this.$store.state.data.saveStructure)
        var flag = "3"; //1 清算 2 更正 3或者空 正常申报
        var fillingFlag = this.$store.state.data.openData.fillingFlag
        if (fillingFlag == "cancellation") {
          flag = "1"
        } else if (fillingFlag == "corrections") {
          flag = "2"
        }
        var params = {
          tableData: JSON.stringify(saveData),
          value: this.$store.state.data.openData.value,
          djxh: this.$store.state.data.openData.djxh,
          zsDjxh: this.$store.state.data.openData.zsDjxh,
          flag: flag
        }
        this.ajax.post(saveUrl, params, function (data) {
          if (data.returnCode == '00') {
            _self.$parent.$parent.$emit('changeSelected', "saveButton");
            _self.$store.commit("saveStatus", true);
            if (!['export'].includes(type)) {
              if (type != "declare") {
                _self.$message({ message: '保存报表成功！', type: 'success' });
              }
              //更新报表状态
              var menu = Enumerable.From(_self.$store.state.data.menuList).Where(function (val) {
                return val.bbDm + '_' + val.detailPcdm == saveData.bblxHeader.bbDm + '_' + saveData.bblxHeader.detailPcdm
              }).ToArray()[0]
              menu.verificationState = checkFlag ? false : true;
              if (type == "declare") {
                var nextObj = _self.recursionParent(_self.$parent, "checkResult");
                nextObj.betweenTableCheck('init');
              }
            }
          } else {
            _self.$message({ message: '保存报表失败！', type: 'error' });
            _self.$parent.isShowView = true;
          }
          _self.$emit('isSave');
        }, "json", true);
      } else {
        var _self = this
        var saveUrl = config.saveSbbInfo;
        var fakeData = { "pageData": { "nsrxx": { "nsrsbh": "911200006794173544", "nsrmc": "星展银行（中国）有限公司天津分行", "sbrq1": "2021-07-07", "skssqq": "2021-04-01", "skssqz": "2021-06-30", "xzqhszDm": "", "sbsxDm1": "11", "yjfs": "1", "sbqylx": "" }, "sbxx": { "qccyrs": "0", "qmcyrs": "0", "qczcze": "0.00", "qmzcze": "0.00", "qccyrs1": "", "qmcyrs1": "", "qczcze1": "", "qmzcze1": "", "qccyrs2": "", "qmcyrs2": "", "qczcze2": "", "qmzcze2": "", "qccyrs3": "", "qmcyrs3": "", "qczcze3": "", "qmzcze3": "", "qccyrs4": "", "qmcyrs4": "", "qczcze4": "", "qmzcze4": "", "gjxzhjzhy": "N", "sfsyxxwlqy": "N", "yysrLj": "0.00", "yycbLj": "0.00", "lrzeLj": "0.00", "tdywjsdynssdeLj": "0.00", "bzssrLj": "0.00", "gdzcjszjkctjeLj": "0.00", "mssrLj": "0.00", "sdjmLj": "0.00", "mbyqndksLj": "0.00", "sjlreLj": "0.00", "slLj": "0.25", "ynsdseLj": "0.00", "jmsdseLj": "0.00", "sjyyjsdseLj": "0.00", "tdywyjzsdseLj": "0.00", "ybtsdseLj": "0.00", "zjgybtsdseBq": "0.00", "zjgftbl": "0.2500", "zjgyftsdseBq": "0.00", "zjgczjzftbl": "0.2500", "czjzfpsdseBq": "0.00", "fzjgftbl": "0.5000", "dlscjybmftbl": "0.00", "zjgdlscjybmyftsdseBq": "0.00", "fpbl": "0.0000000000", "fzjgfpsdseBq": "0.00", "zyjsrsjynseBq": "0.00", "dfjsrynseBq": "0.00", "jzmzlx": "0", "jzfd": "0.0000", "mzzzdqdfjmBq": "0.00", "mzzzdqdfjmLj": "0.00", "mzzzdqdfjmzfjghjLj": "0.00", "dfjsrsjynseBq": "0.00", "sjybtsdseBq": "0.00", "sfgxjsqy": "", "sfkjxzxqy": "", "sffsjsrgdynssx": "", "fhtjxwqyyhjzsdseLj": "", "yhjnsds": "", "bhzsm": "", "qycyrsQnpjrs": "0", "zczeQnpjs": "0.00" }, "qtxx": { "tbrq1": "2021-07-07", "sfdlsb": "", "dlsbzjjg": "", "jbr": "111", "blrysfzjlxDm": "216", "blrysfzjhm": "11", "slr": "网上税务局", "slrq": "2021-07-07", "zgswjg": "", "dljgtyshxydm": "" }, "checkData": { "isReadOnly": { "isReadOnlyA": false, "isReadOnlyCol4": true, "isReadOnlyB": true, "isReadOnlyC": false, "isReadOnlyL15": true, "isReadOnlyD": true, "isReadOnlyE": true, "isReadOnlyF": true, "isReadOnlyJd": false, "isReadOnlyQyLx": false, "isReadOnlyFirst": true, "isReadOnlySecond": true, "isReadOnlyThird": true, "isReadOnlyFourth": true, "isUpdateFirst": false, "isUpdateSecond": false, "isUpdateThird": false, "isUpdateFourth": false }, "wqData": { "qccyrs1": "0", "qmcyrs1": "0", "qczcze1": "0.00", "qmzcze1": "0.00", "qccyrs2": "0", "qmcyrs2": "0", "qczcze2": "0.00", "qmzcze2": "0.00", "qccyrs3": "0", "qmcyrs3": "0", "qczcze3": "0.00", "qmzcze3": "0.00", "qccyrs4": "0", "qmcyrs4": "0", "qczcze4": "0.00", "qmzcze4": "0.00" }, "wqsbjds": "0", "isDisplayL15": false, "zfjglxDM": "2", "zyjbl": "", "zfjgbzDM": "", "nsqxDM": "08", "tsnsr": "N", "isFirstIssue": "0", "mbyqndks": "", "tsclynsbl": "1", "zjgsnsfwWX": "N", "HYMXDM": "6621", "cyrspjsLj": "0", "zczepjsLj": "0.00", "ysbjds": "0.00", "pjcyrs": "0", "pjzcze": "0.00", "isEndSeason": "1", "sqData": {}, "sqRow14": "0.00", "bjData4": {}, "bjData6": [], "bjData7": {}, "bjData8": {}, "L21": "", "hjI34": "0.00", "jzmzlx": "", "jzfd": "0.00", "HYDM": "6621", "isXW": "0", "mzzzdqdfjmLj": "0.00", "tdywyjzsdseLj": "0.00", "sjyyjsdseLj": "0.00", "fzjgData": ["星展银行（中国）有限公司天津分行", "星展银行（中国）有限公司天津分行"], "fbsxGridFirstData": [], "SDSKDQZYLX": "" }, "otherData": { "xzqhszDmmc": "", "sfzjlxDmmc": "216  外交官证", "nsrsbq": "202107", "skssqzMonth": "06", "XSXWHJYHBZ": "N", "mssrGridlb": [{ "ewbhxhNum": "7.1", "ewbhxh": "1", "yhswsx": "", "zyywsrzb": "0", "yhjmje": "0.00", "jejslx": "", "ssjmxzDm": "", "ssjmxzDmmc": "", "ewbhgjz": "mssrGrid", "checkXH": "", "valueLx": "" }], "sdjmGridlb": [{ "ewbhxhNum": "8.1", "ewbhxh": "1", "yhswsx": "", "zyywsrzb": "0", "yhjmje": "0.00", "jejslx": "", "ssjmxzDm": "", "ssjmxzDmmc": "", "ewbhgjz": "sdjmGrid", "checkXH": "", "valueLx": "" }], "jmsdGridlb": [{ "ewbhxhNum": "13.1", "ewbhxh": "1", "yhswsx": "", "zyywsrzb": "0", "yhjmje": "0.00", "jejslx": "", "ssjmxzDm": "", "ssjmxzDmmc": "", "ewbhgjz": "jmsdGrid", "checkXH": "", "valueLx": "", "yhjmjeEdit": false, "yhjmjeOption": [] }], "fbsxGrid": { "fbsxGridlb": [{ "hmc": "事项1", "hxx": "支持新型冠状病毒感染的肺炎疫情防控捐赠支出全额扣除（本年累计，元）", "ewbhgjz": "K01001", "xxbz": "", "jehxxz": "0.00", "isDisabled": true, "status": false }, { "hmc": "事项2", "hxx": "扶贫捐赠支出全额扣除（本年累计，元）", "ewbhgjz": "K01002", "xxbz": "", "jehxxz": "0.00", "isDisabled": false, "status": false }, { "hmc": "事项3", "hxx": "软件集成电路企业优惠政策适用类型", "ewbhgjz": "Y01001", "xxbz": "", "jehxxz": "", "isDisabled": false, "isDisabledNew": false, "isDisabledOld": false, "status": false }] }, "mssrGrid": { "mssrGridlb": [{ "ewbhxhNum": "7.1", "ewbhxh": "1", "yhswsx": "", "zyywsrzb": "0", "yhjmje": "0.00", "jejslx": "", "ssjmxzDm": "", "ssjmxzDmmc": "", "ewbhgjz": "mssrGrid", "checkXH": "", "valueLx": "" }] }, "sdjmGrid": { "sdjmGridlb": [{ "ewbhxhNum": "8.1", "ewbhxh": "1", "yhswsx": "", "zyywsrzb": "0", "yhjmje": "0.00", "jejslx": "", "ssjmxzDm": "", "ssjmxzDmmc": "", "ewbhgjz": "sdjmGrid", "checkXH": "", "valueLx": "" }] }, "jmsdGrid": { "jmsdGridlb": [{ "ewbhxhNum": "13.1", "ewbhxh": "1", "yhswsx": "", "zyywsrzb": "0", "yhjmje": "0.00", "jejslx": "", "ssjmxzDm": "", "ssjmxzDmmc": "", "ewbhgjz": "jmsdGrid", "checkXH": "", "valueLx": "", "yhjmjeEdit": false, "yhjmjeOption": [] }] }, "fbsxGridlb": [{ "hmc": "", "hxx": "", "ewbhgjz": "", "xxbz": "", "jehxxz": "0.00" }], "checkFlag": true, "backUpTipsList": [], "tipsData": [] } }, "header": { "sksssjz": "20210630", "bbDm": "10401_001", "nsqxdm": "08", "pzxh": "", "sksssjq": "20210401", "multiPatch": "N", "sbxxId": "4090647", "sbuuid": "", "detailPcdm": "001", "otherBbdms": "-1", "djxh": "10111291000025950120", "sourceFlag": "ykj1", "bqybtse": "", "bblxDm": "10401", "pcDm": "001", "nsrsbq": "202107", "btbbjy": "N", "zspmDmList": [], "zsxmDm": "10104", "versionNumber": "15", "relatedBbDms": [], "nsrsbh": "911200006794173544", "gzbz": "0", "verificationState": true, "nsrType": "ybr", "saveUserId": "ykj1_102148", "sbzjbtbbjy": "N" } }
        this.ajax.post(saveUrl, { tableData: JSON.stringify(fakeData) }, function (data) {
          if (type != "close") {
            if (_self.buttonName == "保存" && checkList.length > 0) {
              var obj = _self.recursionParent(_self.$parent, "infoBar")
              obj.initCheck(checkList)
              if (data.returnCode == '00') {
                _self.$alert("验证没通过，请核对数据", '提示', { type: 'error' });
                _self.$parent.$parent.$parent.$emit('changeSelected', "saveButton");
                _self.$store.commit("saveStatus", true);
                tableData.setTableData(saveTableData.tableData)
              } else {
                _self.$alert("验证没通过," + data.returnMessage, '提示', { type: 'error' });
              }
            } else {
              if (data.returnCode == '00') {
                _self.$alert(data.returnMessage, '提示', { type: 'success' });
                _self.$parent.$parent.$parent.$emit('changeSelected', "saveButton");
                _self.$store.commit("saveStatus", true);
                tableData.setTableData(saveTableData.tableData)
              } else {
                _self.$alert(data.returnMessage, '提示', { type: 'error' });
              }
            }
          }
        }, "json", true);
      }
    },
    //控制保存按钮是否可编辑
    saveBtnDisable() {
      var selected = this.$store.state.data.engines.bbdm;
      var saveStatus = this.$store.state.data.saveStatus
      if (this.saveAttr.includes(selected) && !saveStatus) {
        var str = "请先点击提取数据，再进行保存操作!"
        this.$message({ message: str, type: 'warning' });
        this.$store.commit("saveDisable", true);
      } else {
        this.$store.commit("saveDisable", false);
      }
    }
  }
}
</script>
<style scoped>
</style>