<template>
  <div>
    <el-table
      v-loading="listLoading"
      :data="varList"
      :header-cell-style="{
        'font-weight': 'bold',
        'color': '#000'
      }"
      tooltip-effect="dark"
      border
      fit
      highlight-current-row
    >
      <el-table-column type="index" label="序号" width="50" align="center" />
      <el-table-column prop="DEPTNAME" label="部门" />
      <el-table-column prop="POST_NAME" label="岗位" />
      <el-table-column prop="USERNAME" label="人员" />
      <el-table-column prop="SIGNTIME" label="签署时间" />
      <el-table-column label="状态">
        <template slot-scope="{row}">
          {{ row.ISSIGN === 0 ? '未签署' : '已签署' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="{row}">
          <el-button icon="el-icon-view" size="mini" @click="goView(row.PROMISEPEOPLE_ID)">查看</el-button>
          <el-button v-show="row.ISSIGN == 0" type="danger" icon="el-icon-delete" size="mini" @click="removeUnsignedPeopleDetail(row.PROMISEPEOPLE_ID)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <div class="ui-foot" style="width:100%">
      <el-button plain type="info" @click="goBack">返 回</el-button>
    </div>
    <pagination :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
    <promise-book-dialog :visible.sync="dialog.visible" :dialog-data="dialog.data"/>
  </div>
</template>

<script>
import Pagination from '@/components/Pagination' // 通过 el-pagination二次打包
import { requestFN } from '@/utils/request'
import waves from '@/directive/waves' // waves directive
import PromiseBookDialog from './promise_book_dialog'

export default {
  components: { Pagination, PromiseBookDialog },
  directives: { waves },
  data() {
    return {
      listLoading: true,
      listQuery: {
        page: 1,
        limit: 20
      },
      total: 0,
      varList: [],
      dialog: {
        visible: false,
        data: {}
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    // 获取列表
    getList() {
      this.listLoading = true
      requestFN(
        '/corppromise/peopledetails?showCount=' + this.listQuery.limit + '&currentPage=' + this.listQuery.page,
        {
          PROMISE_ID: this.$parent.PROMISE_ID
        }
      ).then((data) => {
        this.listLoading = false
        this.varList = data.varList
        this.total = data.page.totalResult
      }).catch((e) => {
        this.listLoading = false
      })
    },
    removeUnsignedPeopleDetail(PROMISEPEOPLE_ID) {
      this.$confirm('确定删除?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        requestFN(
          '/corppromise/removeUnsignedPeopleDetail',
          {
            PROMISE_ID: this.$parent.PROMISE_ID,
            PROMISEPEOPLE_ID: PROMISEPEOPLE_ID
          }
        ).then((data) => {
          this.$message.success('删除成功')
          this.getList()
          this.$parent.$refs.list.getList()
        }).catch((e) => {
          console.log(e)
        })
      }).catch(() => {
      })
    },
    goView(PROMISEPEOPLE_ID) {
      requestFN(
        '/corppromise/peopleview',
        {
          PROMISE_ID: this.$parent.PROMISE_ID,
          PROMISEPEOPLE_ID
        }
      ).then((data) => {
        const DETAIL = data.COLLATERAL.map(item => ({ value: item.COLLATERAL, id: item.PROMISEDETAIL_ID }))
        this.dialog.visible = true
        this.dialog.data = { ...data.varList, DETAIL, FILEPATH: data.ISGN.FILEPATH, SIGNTIME: data.ISGN.SIGNTIME, COVERPEOPLE: data.COVERPEOPLE[0].USERNAME }
      }).catch((e) => {
      })
    },
    goBack() {
      this.$parent.activeName = 'List'
    }
  }
}
</script>