<!--
 * @Author:zqm
 * @Date: 2021-06-25 13:44:04
 * @LastEditTime: 2022-03-29 15:33:46
 * @LastEditors: Please set LastEditors
 * @Description: 校验结果展示
 * @FilePath: \taxFormToolFramework\src\components\checkResult.vue
-->
<template>
  <div>
    <!-- 必填表校验 -->
    <el-dialog class="dialogShadow" :title="requiredDialog.title" :visible.sync="requiredDialog.visible" top="5%" width="40%" center :close-on-click-modal="false" :close-on-press-escape="false" :modal="false">
      <el-table :data="requiredDialog.tableData" max-height="360" border style="width: 100%" :header-cell-style="headerCellStyle" :cell-style="trCellStyle">
        <el-table-column prop="state" label="校验状态" width="100" align="center">
          <template slot-scope="scope">
            <span v-if="scope.row.flag=='0'" class="error">强制校验</span>
            <span v-if="scope.row.flag=='1'" class="success">提示校验</span>
          </template>
        </el-table-column>
        <el-table-column prop="msg" label="提示信息" header-align="center" align="left"></el-table-column>
      </el-table>
    </el-dialog>
    <!-- 表内/表间 校验 -->
    <el-dialog class="dialogShadow" title="校验信息" :visible.sync="checkDialog.visible" top="5%" width="40%" center :close-on-click-modal="false" :close-on-press-escape="false" :modal="false">
      <el-table :data="checkDialog.tableData" height="360" border style="width: 100%" :header-cell-style="headerCellStyle" :cell-style="trCellStyle">
        <el-table-column align="center" prop="bbMc" min-width="25%" label="报表名称">
          <template slot-scope="scope">
            <span v-if="scope.row.pcDm" v-html="scope.row.bbMc+'('+scope.row.pcDm.split('_')[1]+')'">强制校验</span>
            <span v-if="!scope.row.pcDm" v-html="scope.row.bbMc"></span>
          </template>
        </el-table-column>
        <el-table-column align="center" prop="mes" min-width="60%" label="提示信息"></el-table-column>
        <el-table-column align="center" prop="mesType" min-width="15%" label="校验类型">
          <template slot-scope="scope">
            <span v-if="scope.row.mesType==1" class="error">强制校验</span>
            <span v-if="scope.row.mesType==2" class="success">提示校验</span>
          </template>
        </el-table-column>
      </el-table>
      <span slot="footer" class="dialog-footer">
        <el-button size="small" type="primary" @click="goOnReport('init')" v-if="showGoOnReport">继续申报</el-button>
        <el-button size="small" type="primary" @click="checkDialog.visible = false">确定</el-button>
      </span>
    </el-dialog>
    <noticeDialog ref="noticeDialog" :yf="month" @nextReport="nextReport"></noticeDialog>
  </div>
</template>
<script>
import noticeDialog from './noticeDialog' //通知弹窗
export default {
  name: "checkResult",
  components: {
    noticeDialog
  },
  props: {
    currentTaxData: { type: Object, default: () => ({}) },
  },
  data() {
    return {
      requiredDialog: {//必填表校验 暂存表校验
        title: "",
        visible: false,
        tableData: []
      },
      checkDialog: {//表间校验
        visible: false,
        tableData: []
      },
      showGoOnReport: false,//是否展示继续申报按钮
      checkBbDm: [],//表间校验报表代码
      checkData: [],
      bjjyData: [],//表间校验暂存
      checkBbxlDm: [],//若存在税种间校验，填写bbxlDm
      flagNum: 0,//统计强制校验次数
      copybjJson: [],
      month: ''
    };
  },
  watch: {
  },
  destroyed() {
    this.requiredDialog = {//必填表校验
      title: "",
      visible: false,
      tableData: []
    };
    this.checkDialog = {//表间校验
      visible: false,
      tableData: []
    };
    this.showGoOnReport = false;//是否展示继续申报按钮
    this.checkBbDm = [];//表间校验报表代码
  },
  mounted: function () {
  },
  methods: {
    //表内校验
    inTableCheck() {
      this.checkDialog.tableData = [];
      var checkList = this.deepClone(this.$store.state.data.checkList);
      var tableData = this.$store.state.data.engines;
      for (let i = 0; i < checkList.length; i++) {
        var obj = checkList[i];
        obj.bbMc = this.currentTaxData.bblxMc;
        //定位
        tableData.defectLOcation({ defectLOcation: obj });
      }
      this.checkDialog.tableData = checkList;
      this.checkDialog.visible = true;
      this.showGoOnReport = false;
    },
    //表间校验
    betweenTableCheck(operate) {
      var menuList = this.deepClone(this.$store.state.data.menuList);
      this.requiredDialog.visible = false;
      this.requiredDialog.tableData = [];
      var requiredNum = 0;//必填表个数
      var requiredData = [];
      var checkData = [];
      this.checkBbDm = [];
      for (let i = 0; i < menuList.length; i++) {
        var item = menuList[i];
        var state = item.verificationState
        if (state == 'empty' && item.xtbz == "B") {
          requiredData.push({
            flag: "0",
            state: state,
            msg: "《" + item.bbMc + "》为必填表,申报期【" + this.currentTaxData.nsrsbq + "】必须填写!!"
          })
        } else if (state == 'false' || state == false) {
          requiredData.push({
            flag: "0",
            state: state,
            msg: "《" + item.bbMc + "》填写错误,申报期【" + this.currentTaxData.nsrsbq + "】必须填写正确!!"
          })
        } else if (state == 'true' || state == true) {
          var obj = this.deepClone(item);
          obj.zsDjxh = this.currentTaxData.zsDjxh;
          checkData.push(obj);
          var mcObj = {}
          mcObj.bbDm = item.bbDm
          mcObj.bbMc = obj.bbMc
          this.checkBbDm.push(mcObj)
          if (this.checkBbxlDm.indexOf(item.bblxDm) == -1) {
            this.checkBbxlDm.push(item.bblxDm)
          }
        }
      }
      // 必填表填写状态过滤，必填表状态若为true已填写，进行表间校验，若为false填写错误或empty未填写，弹出必填校验提示
      if (requiredData.length > 0) {
        this.requiredDialog.title = "必填表校验"
        this.requiredDialog.tableData = this.deepClone(requiredData);
        this.requiredDialog.visible = true;
      } else {
        //表间校验
        this.checkData = this.deepClone(checkData);
        this.getBetweenCheck(operate);
      }
    },
    //获取表间校验
    getBetweenCheck(operate) {
      var taxData = this.deepClone(this.currentTaxData)
      taxData.bbDm = null;
      taxData.detailPcdm = "";
      var list = [];
      list.push(taxData)
      var params = {
        param: JSON.stringify(list),
        nsrsbh: taxData.nsrsbh,
        nsrsbq: taxData.nsrsbq,
        djxh: taxData.djxh,
        type: 2,
        value: taxData.value,
        bblxDm: taxData.bblxDm
      }
      var _self = this;
      var checkUrl = interfacePrefix + config.requestAddress.checkTaxTable
      this.ajax.post(checkUrl, params, function (data) {
        if (data.returnCode == "00") {
          var list = data.content[0].results
          _self.copybjJson = list
          if (list.length > 0) {
            //通知型校验
            var noticeList = Enumerable.From(list).Where(function (val) { return val.checkType == '2' }).ToArray()
            if (noticeList.length > 0) {
              _self.noticeShow(noticeList[0], taxData.nsrsbq)
            } else {
              //其他
              _self.checkShow(list)
            }
          } else {
            _self.goOnReport(operate)
          }
        }
      }, "json", true);
    },
    noticeShow(obj, nsrsbq) {
      if (obj.bbDm == "10102_001") {
        var yf = this.currentTaxData.sksssjq
        if (Number(yf) < 20210401) {
          this.month = false
        } else {
          this.month = true
        }
        this.$refs.noticeDialog.xgmSbTip.visible = true;
      } else if (obj.bbDm == "10414_003") {//todo 所得税

      }
    },
    nextReport() {
      if (this.copybjJson.length > 0) {
        var noNoticeList = Enumerable.From(list).Where(function (val) { return val.checkType != '2' }).ToArray()
        if (noNoticeList.length > 0) {
          this.checkShow(noNoticeList)
        } else {
          this.goOnReport('init')
        }
      } else {
        this.goOnReport('init')
      }
    },
    // 表间校验 展示
    checkShow(checkList) {
      this.flagNum = 0;
      for (var index in checkList) {
        checkList[index].bbMc = Enumerable.From(this.checkBbDm).Where(function (val) { return val.bbDm == checkList[index].bbDm }).ToArray()[0].bbMc;
        if (Number(checkList[index].mesType) == 1) {
          this.flagNum++;
        }
      }
      checkList.sort(function (a, b) {
        var bs_A = a.bbDm.split("_")[1]
        var bs_B = b.bbDm.split("_")[1]
        return Number(bs_A) - Number(bs_B)
      })
      this.checkDialog.tableData = this.deepClone(checkList);
      this.checkDialog.visible = true;
      if (Number(this.flagNum) == 0) {
        this.showGoOnReport = true;
      } else {
        this.showGoOnReport = false;
      }
      //表间定位显示
      var tableData = this.$store.state.data.engines;
      var postList = tableData.bjjy(checkList)
      var bbDm = this.$store.state.data.bblxHeader.bbDm
      postList.forEach(obj => {
        if (obj.bbDm == bbDm) {
          tableData.defectLOcation({ defectLOcation: obj })
        }
      });
    },
    //继续申报
    goOnReport(operate) {
      this.checkDialog.visible = false;
      //调用申报接口
      var obj = this.recursionChild(this.$parent.$children, "declareButton")
      obj.declareData(operate)
    },
    // header-cell-style 
    headerCellStyle({ row, column, rowIndex, columnIndex }) {
      var style = {
        height: '40px',
        lineHeight: '40px',
        padding: "0"
      };
      return style
    },
    // cell-style
    trCellStyle({ row, column, rowIndex, columnIndex }) {
      var style = {
        'padding': "0"
      };
      return style
    },
  },
  created: function () {
  }
}

</script>
<style scoped>
.success {
  color: #4ec87c;
}
.error {
  color: #ff3d33;
}
</style>

