<template>
  <at-table
    @load="loadData"
    :data="data"
    :page-result="pageResult"
    ref="AtTable"
    :default-sorter="[{direction: 'DESC', property: 'projectName'}]"
    :dialogTitle="dialogTitle"
    :dialogVisible="dialogVisible"
    @select-all="handleSelect"
    @select="handleSelect"
    @handleDialogCancel="handleDialogCancel"
    @handleDialogClose="handleDialogClose"
    @handleDialogSubmit="handleDialogSubmit"
    @row-dblclick="handleRowDBClick"
  >
    <template v-slot:searchInput>
      <el-form
        ref="searchForm"
        :model="searchForm"
        label-width="80px"
        class="search-top"
      >
        <project-info-selector
          v-model="searchForm.projectId"
          style="width: 100%"
        ></project-info-selector>
        <dict-select
          dictCode="xmgl-xmlx"
          :hasDefaultOption="true"
          clearable
          placeholder="请选择项目类型"
          v-model="searchForm.projectType"
          style="width: 100%"
        />
        <dict-select
          dictCode="xmgl-jsms"
          :hasDefaultOption="true"
          clearable
          placeholder="请选择建设模式"
          v-model="searchForm.projectModel"
          style="width: 100%"
        />
        <el-button
          size="small"
          @click="findinfo"
          type="primary"
          class="el-icon-search search-btn"
        >查询</el-button>
        <el-button
          size="small"
          @click="handleReset"
          type="primary"
          plain
          class="el-icon-refresh"
        >重置</el-button>
      </el-form>
    </template>
    <template v-slot:operationBtn> </template>
    <template>
      <el-table-column
        type="selection"
        width="55"
        align="center"
      >
      </el-table-column>
      <el-table-column
        type="index"
        label="序号"
        width="55"
        align="center"
      >
      </el-table-column>
      <!-- <el-table-column
        prop="projectCode"
        label="项目代码"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <el-table-column
        prop="projectName"
        label="项目名称"
        align="center"
        min-width="200"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <ht-table-column
        prop="projectType"
        label="项目类型"
        align="center"
        min-width="100"
        :show-overflow-tooltip="true"
        :filters="getDictData('xmgl-xmlx')"
      >
        <template v-slot="{row}">
          {{ getDictName('xmgl-xmlx', row.projectType) }}
        </template>
      </ht-table-column>
      <!-- <el-table-column
        prop="ownerUnit"
        label="业主单位"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="responsibleUnit"
        label="责任单位"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        prop="constructUnit"
        label="施工单位"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->

      <ht-table-column
        prop="projectModel"
        label="建设模式"
        align="center"
        min-width='100'
        :show-overflow-tooltip="true"
        :filters="getDictData('xmgl-jsms')"
      >
        <template v-slot="{row}">
          {{ getDictName('xmgl-jsms', row.projectModel) }}
        </template>
      </ht-table-column>
      <!-- <el-table-column
        prop="projectAddress"
        label="项目地址"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column> -->
      <ht-table-column
        prop="projectStatus"
        label="项目状态"
        align="center"
        min-width='100'
        :show-overflow-tooltip="true"
        :filters="getDictData('xmgl-xmzt')"
      >
        <template v-slot="{row}">
          {{ getDictName('xmgl-xmzt', row.projectStatus) }}
        </template>
      </ht-table-column>
      <el-table-column
        prop="preliminaryEstimate"
        label="初设概算总投资(万元)"
        align="center"
        width="180"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <!-- <el-table-column
        prop="commencementTime"
        label="开工时间"
        :show-overflow-tooltip="true"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="completionTime"
        label="完工时间"
        :show-overflow-tooltip="true"
        align="center"
      >
      </el-table-column> -->
      <el-table-column
        prop="remarks"
        label="备注"
        align="center"
        :show-overflow-tooltip="true"
      >
      </el-table-column>
      <el-table-column
        label="操作"
        width="120"
        align="center"
        v-if="getMethodauth('project_person')"
      >
        <template v-slot="{row}">
          <el-link
            type="primary"
            @click="handleRouterClick(row)"
          >
            <i class="el-icon-user-solid"> 人员管理 </i></el-link>
        </template>
      </el-table-column>
    </template>
  </at-table>
</template>

<script>
import projectArr from '../../../src/assets/data.json'
export default {
  name: 'projectPersonnel',
  data() {
    return {
      searchForm: {
        projectId: '',
        projectType: '',
        projectModel: ''
      }, //顶部搜索参数
      dataBaseOptions: {
        dataBaseId: '',
        tableName: '', // 必填
        tableSchema: ''
      },
      originAPIOptions: {
        url: '', // 列表请求接口地址
        method: 'post', // 列表请求方法
        moduleRoot: '' // 微服务根路径
      },
      exportQuery: {},
      data: [], //表格数据
      pageResult: {
        page: 1,
        pageSize: 20,
        total: 0
      },
      dialogTitle: '',
      dialogVisible: false,
      rules: {}
    }
  },
  computed: {
    deleteUrl: function() {
      return window.context.cqxy + '/biz/projectManagement/pm/v1/delete'
    }
  },
  methods: {
    handleReset() {
      this.searchForm.projectId = ''
      this.searchForm.projectType = ''
      this.searchForm.projectModel = ''
      this.$refs['searchForm'].resetFields()
      this.$refs.AtTable.load()
    },
    handleSelect(selection) {},
    handleDialogCancel() {
      this.dialogVisible = false
    },
    handleDialogClose() {
      this.dialogVisible = false
    },
    handleRowDBClick(data) {},
    handleDialogSubmit() {},
    handleRouterClick(params) {
      this.$router.push({
        name: 'PersonnelManagement',
        params
      })
    },
    loadData(param, cb) {
      let query = []
      let search = {
        id_: this.searchForm.projectId,
        project_type_: this.searchForm.projectType,
        project_model_: this.searchForm.projectModel
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'advance',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i]
          })
        }
      }
      if (param.querys && param.querys.length) {
        param.querys.push(...query)
      } else {
        param.querys = query
      }
      this.$http
        .post('${cqxy}/biz/projectManagement/pm/v1/page', param)
        .then(
          resp => {
            let response = resp.data.value
            this.data = response.rows
            this.pageResult = {
              page: response.page,
              pageSize: response.pageSize,
              total: response.total
            }
          },
          error => {
            reject(error)
          }
        )
        .finally(() => {
          if (cb) {
            cb()
          }
        })
    },
    findinfo() {
      let query = []
      let search = {
        id_: this.searchForm.projectId,
        project_type_: this.searchForm.projectType,
        project_model_: this.searchForm.projectModel
      }
      for (let i in search) {
        if (search[i]) {
          query.push({
            group: 'advance',
            operation: 'LIKE',
            property: i,
            relation: 'AND',
            value: search[i]
          })
        }
      }
      let data = {
        pageBean: {
          page: 1,
          pageSize: 20,
          showTotal: true
        },
        querys: query
      }
      this.$http
        .post('${cqxy}/biz/projectManagement/pm/v1/page', data)
        .then(resp => {
          let response = resp.data.value
          this.data = response.rows
          this.pageResult = {
            page: response.page,
            pageSize: response.pageSize,
            total: response.total
          }
        })
    },
    //返回一个boolean类型，是否显示列表按钮
    getMethodauth(elAuth) {
      let allMethod = window.sessionStorage.allMethod
      let methodAuth = window.sessionStorage.methodAuth
      let allMethodArray = allMethod && allMethod.split(',')
      let methodAuthArray = methodAuth && methodAuth.split(',')
      // 无权限则隐藏按钮
      if (
        methodAuthArray &&
        methodAuthArray.includes(elAuth) &&
        allMethodArray &&
        allMethodArray.includes(elAuth)
      ) {
        return true
      } else {
        return false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '@/assets/css/common.scss';
</style>
