<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
    >
      <el-form-item label="单位">
        <el-select
          v-model="selectVal"
          placeholder="请选择..."
          @clear="delValue"
          clearable
          ref="select"
          style="width: 300px"
        >
          <el-option hidden key="id" :value="selectVal" :label="selectName"></el-option>
          <el-tree
            :data="options1"
            :props="defaultProps"
            @node-click="handleNodeClick"
            :expand-on-click-node="false"
            :check-on-click-node="true"
            ref="tree"
            node-key="id"
            :default-expand-all="true"
            :filter-node-method="filterNode"
          >
            <span slot-scope="{ data }">
            <span>{{ data.deptName }}</span>
          <el-tag
            size="mini"
            style="margin: 0 10px"
            v-show="filterorgType(data.tag)"
          >{{ filterorgType(data.tag) }}</el-tag
          >
        </span>
          </el-tree>
        </el-select>
      </el-form-item>
<!--      <el-form-item label="数据来源" >-->
<!--        <el-select v-model="queryParams.sourceType" clearable>-->
<!--          <el-option label="合同信息表" value="0"></el-option>-->
<!--          <el-option label="发票信息表" value="1"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
<!--      <el-form-item label="处理状态" >-->
<!--        <el-select v-model="queryParams.status" clearable>-->
<!--          <el-option label="未处理" value="0"></el-option>-->
<!--          <el-option label="已处理" value="1"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          @click="getList"
        >搜索</el-button>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          @click="onClickDialogRiskPreventList"
        >风险防控清单</el-button>
        <el-button
          type="primary"
          @click="onClickDialogRiskRulesList"
        >风险规则清单</el-button>
      </el-form-item>
    </el-form>
    <div class="table">
<!--      <el-button    type="success" size="mini" @click="downloadExport">导出</el-button>-->
      <el-table
        v-loading="loading"
        border
        :data="deptList"
        height="55vh"
        row-key="deptId"
      >
        <el-table-column
          type="index"
          label="序号"
        >
        </el-table-column>
        <el-table-column prop="description" label="风险描述" align="center" ></el-table-column>
        <el-table-column prop="rule" label="风险规则" align="center"></el-table-column>
        <el-table-column prop="level" label="风险等级" align="center" ></el-table-column>
        <el-table-column
          align="center"
          label="意见反馈"
        >
          <template slot-scope="scope">
            <el-button type="primary"  @click="chak(scope.row)">查看</el-button>
<!--            <el-button type="primary" :disabled="scope.row.status===1" @click="hand(scope.row)">手工反馈</el-button>-->
          </template>
        </el-table-column>
      </el-table>
<!--      <el-pagination-->
<!--        style="display: flex;justify-content: flex-end ;margin: 15px 0px 0px 0px"-->
<!--        @size-change="handleSizeChange"-->
<!--        @current-change="handleCurrentChange"-->
<!--        :current-page="pageNo"-->
<!--        :page-sizes="[10, 20, 30, 40]"-->
<!--        :page-size="pageSize"-->
<!--        layout="total, sizes, prev, pager, next, jumper"-->
<!--        :total="total" />-->
    </div>
    <el-dialog
      title="反馈"
      :visible.sync="dialogVisible"
      width="70%"
    >
      <el-form ref="form"  label-width="80px">
        <el-form-item label="反馈描述">
          <el-input
            type="textarea"
            style="width: 100%"
            autosize
            placeholder="请输入内容"
            v-model="ruleForm.remark">
          </el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer" style="display: flex;justify-content: center">
        <el-button @click="dialogVisible = false">取 消</el-button>
<!--        <el-button type="primary" @click="sumbit">保 存</el-button>-->
        <el-button type="primary" @click="clearWarning">保 存</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="预警明细"
      :visible.sync="Visible"
      width="80%"
    >
      <el-button style="margin-left:10px;height: 32px" type="success" size="mini" @click="detailExport">导出</el-button>
      <el-table
        :data="tableData"
        height="55vh"
        style="width: 100%"
        row-key="deptId"
        border>
        <el-table-column
          type="index"
          label="序号"
        >
        </el-table-column>
        <el-table-column
          prop="contractName"
          align="center"
          min-width="100px"
          label="合同名称"
        >
        </el-table-column>
        <el-table-column
          prop="contractCode"
          align="center"
          min-width="100px"
          label="合同编码"
        >
        </el-table-column>
        <el-table-column
          prop="contractType"
          align="center"
          min-width="100px"
          label="合同类型"
        >
        </el-table-column>
        <el-table-column
          prop="counterparty"
          align="center"
          min-width="100px"
          label="合同对方"
        >
        </el-table-column>
        <el-table-column
          prop="contractAmount"
          align="center"
          min-width="100px"
          label="合同金额"
        >
        </el-table-column>
        <el-table-column
          prop="taxRate"
          align="center"
          min-width="100px"
          label="税率"
        >
        </el-table-column>
        <el-table-column
          prop="preTaxAmount"
          align="center"
          min-width="100px"
          label="不含税金额"
        >
        </el-table-column>
        <el-table-column
          prop="effectiveDate"
          align="center"
          min-width="100px"
          label="合同生效时间"
        >
        </el-table-column>
        <el-table-column
          align="center"
          min-width="100px"
          prop="stampTaxItemId"
          label="	印花税税目"
        >
        </el-table-column>
        <el-table-column
          prop="stampTaxRate"
          align="center"
          min-width="130px"
          label="印花税税率(‰)"
        >
        </el-table-column>
        <el-table-column
          prop="taxableAmount"
          align="center"
          min-width="80px"
          label="应税金额"
        >
        </el-table-column>
        <el-table-column
          prop="taxationFlag"
          align="center"
          min-width="80px"
          label="计税标识"
        >
          <template slot-scope="{row}">
            <span>{{row.taxationFlag=='Y'?'是':'否'}}</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="createUserOrgName"
          align="center"
          min-width="80px"
          label="所属单位"
        >
        </el-table-column>
        <el-table-column
          align="center"
          label="意见反馈"
          min-width="100px"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="primary" :disabled="scope.row.status===1" @click="hand(scope.row)">手工反馈</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog
      title="发票信息"
      :visible.sync="logible"
      width="70%"
    >
      <el-button style="margin-left:10px;height: 32px" type="success" size="mini" @click="detailExport">导出</el-button>
      <el-table
        :data="tableData1"
        height="55vh"
        border
      >
        <el-table-column
          type="index"
          label="序号"
        >
        </el-table-column>
        <el-table-column
          prop="invoiceCode"
          align="center"
          min-width="100px"
          label="发票代码"
        >
        </el-table-column>
        <el-table-column
          prop="invoiceNumber"
          align="center"
          min-width="100px"
          label="发票号码"
        >
        </el-table-column>
        <el-table-column
          prop="invoiceTelexNumber"
          align="center"
          min-width="100px"
          label="数电票号码"
        >
        </el-table-column>
        <el-table-column
          prop="sellerId"
          align="center"
          min-width="100px"
          label="销方识别号"
        >
        </el-table-column>
        <el-table-column
          prop="sellerName"
          align="center"
          min-width="100px"
          label="销方名称"
        >
        </el-table-column>
        <el-table-column
          prop="makeDate"
          align="center"
          min-width="100px"
          label="开票日期"
        >
        </el-table-column>
        <el-table-column
          prop="spBusinessType"
          align="center"
          min-width="100px"
          label="特定业务类型"
        >
        </el-table-column>
        <el-table-column
          prop="itemDesc"
          align="center"
          min-width="150px"
          label="货物或应税劳务名称"
        >
        </el-table-column>
        <el-table-column
          prop="amount"
          align="center"
          min-width="100px"
          label="金额"
        >
        </el-table-column>
        <el-table-column
          prop="taxRate"
          align="center"
          min-width="100px"
          label="税率"
        >
        </el-table-column>
        <el-table-column
          prop="taxAmt"
          align="center"
          min-width="80px"
          label="税额"
        >
        </el-table-column>
        <el-table-column
          prop="totalAmount"
          align="center"
          min-width="80px"
          label="价税合计"
        >
        </el-table-column>
        <el-table-column
          prop="remark"
          align="center"
          min-width="130px"
          label="备注"
        >
        </el-table-column>
        <el-table-column
          prop="businessType"
          align="center"
          min-width="100px"
          label="业务分类"
        >
<!--          <template slot-scope="{row}">-->
<!--            <el-select v-model="row.businessType" @change="upload(row)" filterable placeholder="请选择">-->
<!--              <el-option-->
<!--                v-for="item in options"-->
<!--                :key="item.code"-->
<!--                :label="item.desc"-->
<!--                :value="item.code">-->
<!--              </el-option>-->
<!--            </el-select>-->
<!--          </template>-->
        </el-table-column>
        <el-table-column
          align="center"
          label="意见反馈"
          min-width="100px"
        >
          <template slot-scope="scope">
            <el-button size="mini" type="primary" :disabled="scope.row.status===1" @click="hand(scope.row)">手工反馈</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>

    <dialog-risk-prevent-list ref="refDialogRiskPreventList"/>
    <dialog-risk-rules-list ref="refDialogRiskRulesList"/>
  </div>
</template>

<script>
import {
  adsMatHyxtStampTaxComputeD,
  adsMatHyxtStampTaxComputeDqueryPage,
  adsMatHyxtStampTaxContractDL,
  adsMatHyxtStampTaxInvoiceD,
  adsMatHyxtStampTaxInvoiceDelc,
  adsMatHyxtStampTaxWarningD, adsMatHyxtStampTaxWarningDwarningList,
  adsMatHyxtStampTaxZhptInvoidataExport,
  contractImport,
  dataExportTaxInvoiceD,
  deleteadsMatHyxtStampTaxContractD,
  downloadTemplateD,
  downloadTemplateM, getWarningRules,
  invoiceDqueryPagee,
  invoiceImportP,
  queryList,
  queryListLI,
  clearStampTaxContractWarning,
  clearStampTaxInvoiceWarning,
  queryPageNo
} from '@/api/utils'
import  moment from 'moment'
import DialogRiskPreventList from './components/DialogRiskPreventList.vue'
import DialogRiskRulesList from './components/DialogRiskRulesList.vue'
import {listDept} from "@/api/system/dept";

export default {
  components:{
    DialogRiskPreventList,
    DialogRiskRulesList,
  },
  data() {
    return {
      defaultProps: {
        children: "children",
        label: "name",
      },
      // 标签数组
      tagList: [

      ],
      selectVal:'',
      selectName:'',
      options1:[],
      option:{},
      Visible:false,
      logible:false,
      dialogVisible:false,
      deptList:[],
      tableData:[],
      tableData1:[],
      queryParams:{
        status:'',
        sourceType:'',
        sellerName:'',
      },
      // 遮罩层
      loading: false,
      pageNo:1,
      pageSize:10,
      total:0,
      ruleForm:{
        remark:''
      },
      row:{},
      currentRow:{},
      currentRowData:{},
    };
  },
  watch: {
    // 搜索过滤，监听input搜索框绑定的treeFilter
    treeFilter(val) {
      this.$refs.tree.filter(val);
      // 当搜索框键入值改变时，将该值作为入参执行树形控件的过滤事件filterNode
    },
  },
  created() {
    this.getList()
    this.getListM()
  },
  computed:{

  },
  methods: {
    getListM() {
      listDept().then((response) => {
        this.options1 = this.handleTree(response.data, "deptId");
      });
    },
    // downloadExport(){
    //   let data={
    //     pageNo:this.pageNo,
    //     pageSize:this.pageSize,
    //     ...this.queryParams
    //   }
    //   adsMatHyxtStampTaxZhptInvoidataExport(data).then(res=>{
    //     const blob = new Blob([res]);
    //     const url = URL.createObjectURL(blob);
    //     const link = document.createElement('a');
    //     link.href = url;
    //     link.download = '风险待办清单.xls';
    //     link.click();
    //   })
    // },
    detailExport(){
      let data={
        // pageNo:this.pageNo,
        // pageSize:this.pageSize,
        // ...this.queryParams
        id:this.currentRow.id
      }
      adsMatHyxtStampTaxZhptInvoidataExport(data).then(res=>{
        const blob = new Blob([res]);
        const url = URL.createObjectURL(blob);
        const link = document.createElement('a');
        link.href = url;
        link.download = '风险待办清单.xls';
        link.click();
      })
    },
    refreshDetailTable() {
      this.chak(this.currentRow)
    },
    chak(row){
      this.currentRow = row;
      let params = {
        warningType: row.warningType
      }
      if(row.sourceType===1){
        this.logible=true
        // row.id=row.sourceId
        adsMatHyxtStampTaxInvoiceD(params).then(res=>{
          this.tableData1=res.data
        })
      }else {
        this.Visible=true
        // row.id=row.sourceId
        queryListLI(params).then(res=>{
            this.tableData=res.data
        })
      }
    },
    getHT(){

    },
    getFP(){

    },

    delValue() {
      this.selectVal = ''
      this.selectName = '';
    },
    // 结构树点击事件
    handleNodeClick(data) {
      console.log(data,'----')
      this.selectVal = data.deptId; // select绑定值为点击的选项的value
      this.selectName = data.deptName; // input中显示值为label
      this.treeFilter = ""; // 点击后搜索框清空
      this.$refs.select.blur(); // 点击后关闭下拉框，因为点击树形控件后select不会自动折叠
    },
    // 模糊查询（搜索过滤），实质为筛选出树形控件中符合输入条件的选项，过滤掉其他选项
    filterNode(value, data) {
      if (!value) return true;
      let filterRes = data.label.indexOf(value) !== -1;
      return filterRes;
    },
    // 选项卡标签（可忽略，增值迭代需求）
    filterorgType(val) {
      let arr = this.tagList.filter((item) => {
        return item.value == val;
      });
      return arr.length ? arr[0].label : "";
    },
    sumbit(){
      this.option.remark=this.ruleForm.remark
      adsMatHyxtStampTaxWarningD(this.option).then((res) => {
         if(res.code===200){
           this.$message.success('提交成功')
           this.dialogVisible=false
           this.getList()
         }else {
           this.$message.success(res.msg || '提交失败')
         }
      });
    },
    clearWarning() {
      let params = {
        id:this.currentRowData.id
      }
      if (this.currentRow.sourceType === 0) {
        // 清除合同预警
        clearStampTaxContractWarning(params).then((res) => {
          if(res.code===200){
            this.$message.success('提交成功')
            this.dialogVisible=false
            this.getList()
            this.refreshDetailTable()
          }else {
            this.$message.success(res.msg || '提交失败')
          }
        });
      } else {
        // 清除发票预警
        clearStampTaxInvoiceWarning(params).then((res) => {
          if(res.code===200){
            this.$message.success('提交成功')
            this.dialogVisible=false
            this.getList()
            this.refreshDetailTable()
          }else {
            this.$message.success(res.msg || '提交失败')
          }
        });
      }
    },
    hand(row){
      this.dialogVisible=true
      this.ruleForm.remark=''
      this.option=JSON.parse(JSON.stringify(row))
      this.currentRowData = row;
    },
    onClickDialogRiskPreventList() {
      this.$refs.refDialogRiskPreventList.open()
    },
    onClickDialogRiskRulesList() {
      this.$refs.refDialogRiskRulesList.open()
    },

    moment,
    /** 查询部门列表 */
    getList() {
      this.loading = true;
      this.queryParams.orgNo=this.selectVal
      let data={
        pageNo:this.pageNo,
        pageSize:this.pageSize,
        ...this.queryParams
      }
      adsMatHyxtStampTaxWarningDwarningList(data,this.queryParams).then((response) => {
        if(response && response.data){
          this.loading = false;
          this.deptList = response.data;
        }else {
          this.deptList =[]
          this.loading = false;
        }
      });
    },
    handleSizeChange(val) {
      this.pageSize=val
      this.getList()
    },
    handleCurrentChange(val) {
      this.pageNo=val
      this.getList()
    },
  },
};
</script>
<style lang="scss" scoped>
</style>
