<template>
  <div class="app-content" style="height:70vh;overflow:auto;">
    <a-form :form="form" :model="searchForm" layout="inline" class="search_form">
      <a-form-item>
        <a-input v-model="searchForm.personName" placeholder="姓名" :maxLength="100" style="width: 130px" />
      </a-form-item>
      <a-form-item>
        <a-input v-model="searchForm.certId" placeholder="证件号" :maxLength="100" style="width: 150px" />
      </a-form-item>
      <a-form-item>
        <a-select v-model="searchForm.sex" style="width: 130px">
          <a-select-option value="">--请选择性别--</a-select-option>
          <a-select-option value="男">男</a-select-option>
          <a-select-option value="女">女</a-select-option>
        </a-select>
      </a-form-item>
      <a-form-item>
        <a-button type="primary" icon="search" @click="search">搜索</a-button>
        <a-button icon="reload" style="margin-left: 10px" @click="reset" class="bt-normal">重置</a-button>
      </a-form-item>
      <a-form-item>
        <a-tag :color="'#2db7f5'">{{ '技术专家' }}</a-tag>&nbsp;<a-tag :color="'#87d068'">{{ '财务专家' }}</a-tag>
      </a-form-item>
    </a-form>
    <a-divider style="height: 1px; background-color: #e8e8e8;" />
    <a-table :dataSource="tableData" :columns="columns" rowKey="id" :pagination="false" :loading="loading">
      <template slot="personName" slot-scope="record">
        <a-tag :color="'#2db7f5'" v-if="record.expertType==1">{{record.personName}}</a-tag>
        <a-tag :color="'#87d068'" v-if="record.expertType==2">{{record.personName}}</a-tag>
      </template>
      <template slot="spec" slot-scope="record">
        <span v-for="data in record.specList" :key="data.id" :color="'green'">{{data.specName+' '}}</span>
      </template>
      <template slot="evaluationType" slot-scope="record">
        <a-tag :color="'#87d068'" v-if="record.evaluationType==1">A类(通过)</a-tag>
        <a-tag :color="'#2db7f5'" v-if="record.evaluationType==2">B类(建议修改)</a-tag>
        <a-tag :color="'#f50'" v-if="record.evaluationType==3">C类(不通过)</a-tag>
      </template>
      <!-- <template slot="expertEvaluation" slot-scope="record">
        <a-tag :color="evaluationColor(record)">{{evaluationText(record)}}</a-tag>
      </template> -->
      <template slot="option" slot-scope="record">
        <a-button type="link" size="small" v-if="!!record.auditState && record.auditState == 2" @click="recordClick(record,'eView')">查看</a-button>
        <!-- <a-popconfirm title="确定要删除吗？" ok-text="确定" cancel-text="取消" @confirm="recordClick(record,'del')">
          <a-button type="link" size="small">删除</a-button>
        </a-popconfirm> -->
      </template>
    </a-table>
    <a-pagination v-if="pagination.total > 0" :total="pagination.total" show-size-changer show-quick-jumper v-model="pagination.pageIndex" :page-size="pagination.pageSize" :page-size-options="pagination.pageSizeOptions" @showSizeChange="showSizeChange" @change="change" :showTotal="() => `共 ${pagination.total} 条`" />
    <a-modal v-model="visibleEvaluationView" title="专家评分" width="90%" :dialog-style="{ top: '8%' }" :footer="null" destroyOnClose>
      <score-view v-model="id" @close="() => this.visibleEvaluationView = false" />
    </a-modal>
  </div>
</template>

<script>
import moment from 'moment'
import { getType } from '@/views/utils/auth'
import scoreView from '@/views/evaluation/components/scoreView'
import { isEmptyParams } from '@/views/utils/common'

export default {
  name: 'projectAssignDetail',
  components: {
    scoreView
  },
  data () {
    return {
      form: this.$form.createForm(this, { name: 'assign_search' }),
      searchForm: { projId: null, personName: null, certId: null, sex: "", projType: getType() },
      tableData: [],
      columns: [
        { title: "姓名", scopedSlots: { customRender: 'personName' }, align: 'center' },
        { title: '性别', dataIndex: 'sex', align: 'center' },
        { title: '职称', dataIndex: 'titleName', align: 'center' },
        { title: "专家单位", dataIndex: "workUnit", align: 'center' },
        { title: "评审意见", dataIndex: "remark", align: 'center' },
        { title: '评分', dataIndex: 'totalScore', align: 'center' },
        { title: '评审结果', scopedSlots: { customRender: 'evaluationType' }, align: 'center' },
        // { title: '评审状态', scopedSlots: { customRender: 'expertEvaluation' }, align: 'center' },
        { title: '操作', scopedSlots: { customRender: 'option' }, align: 'center', fixed: 'right', width: 120, },
      ],
      pagination: { pageIndex: 1, pageSize: this.$defaultPageSize, total: 0, pageSizeOptions: this.$defaultPageSizeOptions },
      loading: true,
      visible: false,
      visibleEvaluationView: false,
      id: false,
    }
  },
  props: {
    value: {
      type: String,
      default: () => {
        return null
      }
    }
  },
  created () {
    this.searchForm.projId = this.value
    this.getListByPage()
  },
  methods: {
    moment,
    getListByPage () {
      this.loading = true
      let pars = isEmptyParams(this.searchForm)
      let par = { ...pars, pageIndex: this.pagination.pageIndex, pageSize: this.pagination.pageSize }
      this.$api.projectAssign.getListByPage(par).then(({ data = {} }) => {
        if (data) {
          const { dataList = [], total = 0 } = data
          this.tableData = dataList
          this.pagination.total = total
          this.loading = false
        }
      }).catch(() => {
        this.loading = false
      })
    },
    change () {
      this.getListByPage()
    },
    showSizeChange (current, pageSize) {
      this.pagination.pageSize = pageSize
      this.getListByPage()
    },
    search () {
      this.pagination.pageIndex = 1
      this.getListByPage()
    },
    reset () {
      this.searchForm.personName = ''
      this.searchForm.certId = ''
      this.searchForm.sex = ''
      this.pagination.pageIndex = 1
      this.getListByPage()
    },
    recordClick (record, type) {
      if (type === 'view') {
        this.id = record.id
        this.visible = true
      } else if (type === 'eView') {
        this.id = record.id
        this.visibleEvaluationView = true
      } else if (type === 'del') {
        this.loading = true
        this.$api.projectAssign.deleteAssignExpert({ id: record.id }).then(({ data = {} }) => {
          if (data) {
            this.$message.success('删除成功')
            this.getListByPage()
          }
          this.loading = false
        }).catch(() => {
          this.loading = false
        })
      }
    },
    evaluationColor (record) {
      let color = ''
      switch (record.auditState) {
        case 0:
          color = '#f50';
          break;
        case 1:
          color = '#f50';
          break;
        case 2:
          color = '#87d068';
          break;
      }
      return color
    },
    evaluationText (record) {
      let text = ''
      switch (record.auditState) {
        case 0:
          text = '未评审';
          break;
        case 1:
          text = '未评审';
          break;
        case 2:
          text = '已提交';
          break;
      }
      return text
    },
  }
}
</script>
