<!--
 * @Author: zqm
 * @Date: 2021-06-22 13:24:57
 * @LastEditTime: 2022-03-26 12:27:14
 * @LastEditors: Please set LastEditors
 * @Description: 按钮展示区域
 * @FilePath: \taxFormToolFramework\src\components\buttonArea.vue
-->
<template>
  <div ref="parentButton" style="margin-left:10px" v-if="currentTaxData">
    <el-row :gutter="20" v-if="platform=='1'">
      <declareButton class="btnMargin left" :declareProp="declareProp" :state="sbResult"></declareButton>
      <saveButton ref="saveButton" class="btnMargin left" :buttonName="save" :state="sbResult" @isSave="isSave"></saveButton>
      <saveButton class="btnMargin left" :buttonName="scratch" :state="sbResult" @isSave="isSave"></saveButton>
      <closeButton class="btnMargin right" :closeProp="closeProp" :selected="selected"></closeButton>
      <removePopup class="btnMargin right" v-if="isRemovePopup"></removePopup>
      <allDeleteButton class="btnMargin right" :state="sbResult" @isSave="isSave"></allDeleteButton>
      <deleteButton class="btnMargin right" :deleteProp="deleteProp" :state="sbResult" @isSave="isSave"></deleteButton>
      <el-button type="primary" size="small" plain class="btnMargin right" @click="exportFun" :disabled="sbResult=='success'">导出</el-button>
      <el-button type="primary" size="small" plain class="btnMargin right" @click="importFun" :disabled="sbResult=='success'">导入</el-button>
      <extractDataButton class="btnMargin right" :extractDataProp="extractDataProp" :state="sbResult"></extractDataButton>
      <el-button type="primary" size="small" plain class="btnMargin right" @click="viewVerificationFun" v-if="isShowView" :disabled="sbResult=='success'">查看校验</el-button>
    </el-row>
    <el-row :gutter="20" v-if="platform=='2'">
      <el-col :span="16">
        <saveButton class="btnMargin left" :buttonName="save"></saveButton>
        <deleteButton class="btnMargin left" :deleteProp="deleteProp"></deleteButton>
        <closeButton class="btnMargin left" :closeProp="closeProp" :selected="selected"></closeButton>
      </el-col>
      <el-col :span="5" style="text-align: left">
        <el-button type="primary" size="small" @click="openBar">填表说明</el-button>
      </el-col>
      <el-col :span="3" style="text-align: right">
        <el-button type="primary" size="small" @click="closeBar" id="closeBar" v-show="closeShow">关闭</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import closeButton from "./closeButton";
import declareButton from "./declareButton";
import deleteButton from "./deleteButton";
import extractDataButton from "./extractDataButton";
import saveButton from "./saveButton";
import allDeleteButton from "./allDeleteButton";
import removePopup from "./removePopup";
import FileSaver from 'file-saver'
export default {
  name: "buttonArea",
  components: {
    closeButton, declareButton, deleteButton, extractDataButton, saveButton, allDeleteButton, removePopup
  },
  props: {
    currentTaxData: { type: Object, default: () => ({}) },
    sbResult: { type: String, default: "" }
  },
  data: function () {
    return {
      platform: this.$store.state.data.platform,
      selected: "",//操作类型
      declareProp: {//申报按钮
        name: "",
      },
      save: "保存",//保存按钮名称
      scratch: '暂存',//保存按钮名称
      closeProp: {//关闭按钮
        isPlain: false
      },
      deleteProp: {//删除按钮
        name: "",
        isPlain: false
      },
      extractDataProp: {//提取数据按钮
        isPlain: false
      },
      closeShow: false,//填表说明关闭按钮
      isShowView: false,//查看校验按钮
      isRemovePopup:false//删除弹窗按钮
    };
  },
  methods: {
    initButton() {
      if (this.platform == "1") { //涉税
        //申报按钮
        this.declareProp.name = "申报";
        if (this.currentTaxData.fillingFlag == 'corrections') {
          this.declareProp.name = "更正申报";
        } else if (this.currentTaxData.fillingFlag == 'cancellation') {
          this.declareProp.name = "清算申报";
        } else if (this.currentTaxData.fillingFlag == 'overdue') {
          this.declareProp.name = "逾期申报";
        } else {
          this.declareProp.name = "申报";
        }
        //关闭按钮
        this.closeProp.isPlain = true;
        //删除按钮
        this.deleteProp.name = "重置当前报表";
        this.deleteProp.isPlain = true;
        //提取数据按钮
        this.extractDataProp.isPlain = true;
      } else {//云代账
        //关闭按钮
        this.closeProp.isPlain = false;
        //删除按钮
        this.deleteProp.name = "删除";
        this.deleteProp.isPlain = false;
        //提取数据按钮
        this.extractDataProp.isPlain = false;
      }
    },
    openBar() {
      $(".bar").show();
      this.closeShow = true;
      this.$store.commit("selectInfoBar", "first");
      //TODO调整样式
      var obj = this.recursionChild(this.$parent.$parent.$children, "informationBar");
      obj.getInstruction();
    },
    closeBar() {
      $(".bar").hide();
      this.closeShow = false;
      //TODO调整样式
    },
    //导入按钮
    importFun() {
      this.selected = 'import';
      var obj = this.recursionParent(this.$parent, "importFile");
      obj.importDialog.visible = true;
    },
    //导出按钮
    exportFun() {
      this.selected = 'export';
      var openData = this.$store.state.data.openData;
      if (openData.bblxDm != '12002') {
        var obj = this.recursionChild(this.$children, "saveButton");
        obj.saveFun('export');
      }
      var tableData = this.$store.state.data.engines;
      var bblxHeader = this.$store.state.data.bblxHeader;
      var exportData = {
        data: this.deepClone(tableData.getTableData()),
        bblxHeader: bblxHeader,
        sourceFlag: "ssfwpt_sbzj_version_2"
      }
      var data = JSON.stringify(exportData);
      var blob = new Blob([data], { type: '' });
      var bbMc = Enumerable.From(this.$store.state.data.menuList).Where(function (val) { return val.bbDm == bblxHeader.bbDm }).ToArray()[0].bbMc;
      FileSaver.saveAs(blob, bbMc + '.txt');
      this.loading = false;
    },
    //查看校验按钮
    viewVerificationFun() {
      var tableData = this.$store.state.data.engines;
      var saveTableData = tableData.getTableData();
      var checkList = saveTableData.checkList.checkList
      this.$store.commit("checkList", checkList);
      var obj = this.recursionParent(this.$parent, "checkResult")
      obj.inTableCheck()
    },
    //判断是否展示查看校验按钮
    isSave() {
      var menuList = this.$store.state.data.menuList;
      var defaultMenu = this.$store.state.data.defaultMenu;
      var menu = Enumerable.From(menuList).Where(function (val) { return val.bbDm + '_' + val.detailPcdm == defaultMenu }).ToArray()[0];
      if (menu.verificationState != "empty") {
        this.isShowView = true
      } else {
        this.isShowView = false
      }
      this.$refs.saveButton.saveBtnDisable()
    },
  },
  mounted() {
    this.$on('changeSelected', function (type) {
      this.selected = type;
    });
  },
  created: function () {
    this.initButton();
  },
};
</script>

<style scoped>
.btnMargin {
  margin: 0 auto !important;
  margin-right: 10px !important;
}
</style>
