<template>
  <div class="app-container">
    <div class="filter-container">
      <el-input v-model="search.keyWord" placeholder="关键字" style="width: 200px;" class="filter-item"/>
      <el-button class="filter-item" type="primary" icon="el-icon-search" @click="searchData">
        搜索
      </el-button>
      <div class="top-right-btn">
        <el-tooltip class="item" effect="dark" content="刷新" placement="top">
          <el-button size="mini" circle icon="el-icon-refresh" @click="getRelateManDept" />
        </el-tooltip>
      </div>
    </div>
      <el-table
        :data="tableData"
        v-loading="listLoading"
        style="width: 100%;margin-bottom: 20px;"
        size="mini"
        ref="table"
        row-key="id"
        :row-style="customRowStyle"
        @row-click="clickTableRow"
        border
        default-expand-all>
        <el-table-column
          type="index"
          label="序号"
          width="50">
          <template slot-scope="scope">
            <span>{{ (listData.page - 1) * listData.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column label="部门名称" prop="deptName" width="130">
        </el-table-column>
        <el-table-column
          prop="rewardMoneyCount"
          label="奖励金额">
        </el-table-column>
        <el-table-column
          label="处罚金额"
          prop="deductMoneyCount"
          width="100"
        >
        </el-table-column>
        <el-table-column
          prop="totalMoney"
          label="奖惩合计">
        </el-table-column>
        <el-table-column
          prop="rewardCount"
          label="奖励处理单数">
        </el-table-column>
        <el-table-column
          prop="deductCount"
          label="处罚处理单数"></el-table-column>
        <el-table-column
          prop="billCount"
          label="单数合计"></el-table-column>
      </el-table>
      <pagination
        v-show="listData.total>0"
        :total="listData.total"
        :page.sync="listData.page"
        :limit.sync="listData.pageSize"
        @pagination="getRelateManDept"/>
    <el-card>
      <el-table
        :data="tableData1"
        v-loading="listLoading"
        style="width: 100%;margin-bottom: 20px;"
        size="mini"
        ref="table"
        row-key="id"
        border
        default-expand-all>
        <el-table-column
          type="index"
          label="序号"
          width="50">
          <template slot-scope="scope">
            <span>{{ (listData.page - 1) * listData.pageSize + scope.$index + 1 }}</span>
          </template>
        </el-table-column>
        <el-table-column
        label="投诉标题"
        prop="tsTitle"
        width="100"
      ></el-table-column>
        <el-table-column
          label="投诉单号"
          prop="complaintBillCode"
          width="130"
        >
          <template slot-scope="{row}">
            <el-link type="primary" @click="openStep(row)">{{row.complaintBillCode}}</el-link>
          </template>
        </el-table-column>
        <el-table-column label="调查单号" prop="surveyBillCode" width="130">
        </el-table-column>
        <el-table-column
          prop="relateMan"
          label="人员名称">
        </el-table-column>
        <el-table-column
          label="所属部门"
        prop="relateManDept">
        </el-table-column>
        <el-table-column
          prop="deductMoney"
          label="处罚金额">
        </el-table-column>
        <el-table-column
          prop="rewardMoney"
          label="奖励金额"
          width="125">
        </el-table-column>
        <el-table-column
          prop="creDate"
          label="审核时间"
          width="160">
          <template slot-scope="{row}">
            <span v-if="row.creDate != null">{{ row.creDate | getTime }}</span>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="listData1.total>0"
        :total="listData1.total"
        :page.sync="listData1.page"
        :limit.sync="listData1.pageSize"
        @pagination="getRelateManDept"/>
    </el-card>
    <cancledialog @tableRefresh="tableRefresh" ref="confirmDialog"></cancledialog>
<!--    <el-dialog title="投诉单" :visible.sync="complaintDialog" width="1250px" top="20px" class="complaintDialog">-->
      <complaint-details ref="complaintDetail" :type="detailsType" @tableReload='acceptSuccess'></complaint-details>
<!--    </el-dialog>-->
    <complaint-step ref="complaintStep"></complaint-step>
  </div>
</template>

<script>
import Cancledialog from '@/components/Dialog/Cancledialog.vue'
import Pagination from '@/components/Pagination'
import ComplaintDetails from '@/components/complaintDetails/complaintDetails'
import ComplaintStep from "@/components/complaintStep/complaintStep";
import {relateManCountPage, getRelateManInfoList} from "@/api/complaint/relateManCountPage";

const form = {}
export default {
  name: 'relateManCountPage',
  components: {
    ComplaintStep,
    ComplaintDetails,
    Cancledialog, Pagination
  },
  data() {
    return {
      detailsType: 0,
      form: Object.assign({}, form),
      search: {
        'keyWord': ''
      },
      tableData: [],
      listData: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      listLoading: false,

      rowID: '',
      tableData1: [],
      listData1: {
        total: 0,
        page: 1,
        pageSize: 10
      },
      search1: {
        "idDept":'',
        'keyWord': ''
      },
      // 弹窗投诉单详情
      complaintDialog: false
    }
  },
  mounted() {
    this.getRelateManDept()
  },
  methods: {
    // 获取列表
    getRelateManDept() {
      const _that = this
      _that.listLoading = true

      var params = _that.search
      var page = {
        pageIndex: _that.listData.page,
        pageSize: _that.listData.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }

      relateManCountPage(data).then(response => {
        const data = response.data
        // //  组合表单数据
        _that.tableData = data
        _that.listData.total = response.total
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },
    // 搜索
    searchData() {
      this.listData.page = 1
      this.getRelateManDept()
    },

    customRowStyle({row, rowIndex}) {
      if (this.rowID == row.idDept) {
        return {
          // color: '#F56C6C'
          background: '#f7b1b1'
        }
      }
    },
    // 点击行
    clickTableRow(row) {
      console.log(row);
      if (this.rowID == row.idDept) {
        return
      }
      this.rowID = row.idDept;
      this.getRelateManInfo(row);
    },
    getRelateManInfo(row) {
      const _that = this
      _that.listLoading = true

      _that.search1.idDept = row.idDept
      var params = _that.search1
      var page = {
        pageIndex: _that.listData1.page,
        pageSize: _that.listData1.pageSize
      }
      var data = {
        'params': JSON.stringify(params),
        'page': JSON.stringify(page)
      }

      getRelateManInfoList(data).then(response => {
        const data = response.data
        // //  组合表单数据
        _that.tableData1 = data
        _that.listData1.total = response.total
        _that.listLoading = false
      }).catch(err => {
        _that.$message.error(err)
        _that.listLoading = false
      })
    },

    // 调查单脚印
    openStep(row) {
      const _that = this
      _that.$refs.complaintStep.idComplaintBill = row.idComplaint
      _that.$refs.complaintStep.getComplaintStep()
    },
    // 对比时间
    timeContrast(time) {
      var times = time.substring(0, 19)
      var nowTime = new Date() // 当前时间
      var endD = new Date(times) // 对比时间
      if (nowTime.getTime() > endD.getTime()) { // getTime() 方法可返回距 1970 年 1 月 1 日之间的毫秒数。
        // alert('当前时间大于对比时间')
        return true
      } else {
        // alert('当前时间小于对比时间')
        return false
      }
    },
    // 刷新表格
    tableRefresh() {
      this.getRelateManDept()
    },
    // 受理成功
    acceptSuccess() {
      this.complaintDialog = false
      this.getRelateManDept()
    },
    // 行政审核
    reviewBill(row) {
      const _that = this
      _that.detailsType = 4
      _that.complaintDialog = true
      _that.$nextTick(() => {
        _that.$refs.complaintDetail.complaintDialog = true
        _that.$refs.complaintDetail.surveyId = row.id
        _that.$refs.complaintDetail.complaintId = row.idComplaintBill
        _that.$refs.complaintDetail.registerInfo.finishMemo = ''
        _that.$refs.complaintDetail.getInfo()
        _that.$refs.complaintDetail.getSurveyList()
      })
    },
  }
}
</script>

<style lang="scss" scoped>
.complaintDialog{
   ::v-deep .el-dialog__body{
     padding-top: 0px ;
   }
}

</style>
