<!--
 * @Author: zqm
 * @Date: 2021-06-29 09:08:16
 * @LastEditTime: 2022-03-17 14:35:38
 * @LastEditors: Please set LastEditors
 * @Description: 删除按钮
 * @FilePath: \taxFormToolFramework\src\components\deleteButton.vue
-->
<template>
  <div>
    <el-button ref="deleteButton" type="primary" size="small" v-html="deleteProp.name" :plain="deleteProp.isPlain" :disabled="state=='success'" @click="deleteFun"></el-button>
  </div>
</template>
<script>
export default {
  name: "deleteButton",
  props: {
    deleteProp: { type: Object, default: () => ({}) },
    state: { type: String, default: "" }
  },
  data() {
    return {
      platform: this.$store.state.data.platform,
      type: '',
    }
  },
  methods: {
    deleteFun(type) {
      var title = "";
      var message = "";
      if (this.platform == "1") {
        if (type == "delete") {
          this.type = "mult";
          title = "删除当前报表";
          message = '确定要删除该批次报表吗？';
        } else {
          this.type = "online";
          title = "重置当前报表";
          message = '确定要重置当前报表全部信息吗？';
        }
      } else {
        var engines = this.$store.state.data.configData;
        var formName = engines.formName;
        this.type = "cloud";
        title = "提示";
        message = "是否删除" + formName + "表？";
      }
      var _self = this;
      this.$confirm(message, title, {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        _self.confirm(_self.type);
      }).catch(() => {
      });
    },
    confirm(type) {
      this.$store.commit("loading", true);
      var message = "";
      if (type == "online") {
        message = "重置当前报表成功！";
      } else {
        message = "删除报表成功!";
      }
      this.$store.commit("loading", false);
      var tableData = this.$store.state.data.engines;
      var _self = this;
      tableData.deleteData(function (e) {
        _self.$parent.$parent.$emit('changeSelected', "deleteButton");
        var that = _self;
        var deleteUrl = interfacePrefix + config.requestAddress.deleteTable;
        var deleteData = _self.$store.state.data.saveStructure.header;
        var flag = "3"; //1 清算 2 更正 3或者空 正常申报
        var fillingFlag = _self.$store.state.data.openData.fillingFlag
        if (fillingFlag == "cancellation") {
          flag = "1"
        } else if (fillingFlag == "corrections") {
          flag = "2"
        }
        var params = {
          tableData: deleteData,
          flag: flag
        }
        _self.ajax.post(deleteUrl, deleteData,
          function (data) {
            var message = "";
            if (type == "online") {
              message = "重置当前报表";
            } else {
              message = "删除报表";
            }
            if (data.returnCode == '00') {
              that.$store.commit("loading", false);
              that.$message({ message: message + "成功！", type: 'success' });
              //更新报表状态
              var menu = Enumerable.From(that.$store.state.data.menuList).Where(function (val) {
                return val.bbDm + '_' + val.detailPcdm == deleteData.bbDm + '_' + deleteData.detailPcdm
              }).ToArray()[0];
              menu.state = "N";
              menu.verificationState = "empty";
              //多批次删除
              if (type == "mult") {
                var selectPcdm = Number(tableData.addtLProp.detailPcdm) - 1;
                var backupBbdm = tableData.addtLProp.bbDm + '_' + selectPcdm;
                that.$store.commit("defaultMenu", backupBbdm);
                var menu = that.recursionParent(that.$parent, "menuGroup");
                menu.deletePcList();
              }
            } else {
              that.$message({ message: message + "失败！", type: 'error' });
            }
            _self.$emit('isSave');
          }, "json", true);
      })
    },
  },
}
</script>
<style scoped>
</style>