<template>
  <div class="app-container">

    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="90px">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="工号" prop="workNo">
        <el-input v-model="queryParams.workNo" placeholder="请输入工号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="手机号" prop="tel">
        <el-input v-model="queryParams.tel" placeholder="请输入手机号" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="交接时间" prop="changeTimeArray">
        <el-date-picker v-model="queryParams.changeTimeArray" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
                        type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
        />
      </el-form-item>
      <el-form-item label="交接状态" prop="changeType">
        <el-select v-model="queryParams.changeType" placeholder="请选择交接状态" clearable size="small">
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.STAFF_CHANGE_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="序号" align="center">
        <template scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="交出方姓名" align="center" prop="oldStaff.name" width="180" />
      <el-table-column label="交出方工号" align="center" prop="oldStaff.workNo" width="180" />
      <el-table-column label="交出方电话" align="center" prop="oldStaff.tel" width="180" />
      <el-table-column label="交出方性别" align="center" prop="oldStaff.sex" width="180">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.oldStaff.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="交出方地址" :show-overflow-tooltip="true" align="center" prop="oldStaff.address" width="180"/>

      <el-table-column label="接收方姓名" align="center" prop="newStaff.name" width="180" />
      <el-table-column label="接收方工号" align="center" prop="newStaff.workNo" width="180" />
      <el-table-column label="接收方电话" align="center" prop="newStaff.tel" width="180" />
      <el-table-column label="接收方性别" align="center" prop="newStaff.sex" width="180">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_USER_SEX" :value="scope.row.newStaff.sex"/>
        </template>
      </el-table-column>
      <el-table-column label="接收方地址" :show-overflow-tooltip="true" align="center" prop="newStaff.address" width="180" />
      <el-table-column label="交接时间" align="center" prop="changeTime" width="180" />
      <el-table-column label="交接备注" :show-overflow-tooltip="true" align="center" prop="remark" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-search" @click="openForm(scope.row)"
          >列表查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />

    <StaffChangeFormData ref="staffChangeFormData" :success="getList" />
  </div>
</template>

<script>
import * as StaffChangeApi from '@/api/company/staffChange'
import StaffChangeFormData from './form/StaffChangeFormData'

export default {
  name: 'StaffChange',
  components: {
    StaffChangeFormData
  },
  data() {
    return{
      // 显示搜索条件
      showSearch: true,
      // 导出遮罩层
      exportLoading: false,
      queryParams:{
        pageNo: 1,
        pageSize: 10,
        workNo: null,
        name: null,
        changeType: null,
        changeTimeArray:null,
        tel: null
      },
      list: [],
      total: 0,
      // 遮罩层
      loading: true,
    }
  },
  watch: {
    '$route.query.data':{
      immediate: true,
      handler(newVal){
        if (newVal){
          this.getQueryData(JSON.parse(newVal))
          this.getList()
        }
      }
    },
  },
  created() {
    this.getList()
  },
  methods:{
    /** 处理点击过来的数据 */
    async getQueryData(row){
      this.queryParams.name = row.name;
      this.queryParams.workNo = row.workNo;
      this.queryParams.tel = row.tel;
    },
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true
        const res = await StaffChangeApi.getStaffChangePage(this.queryParams)
        this.list = res.data.records
        this.total = res.data.total
      } finally {
        this.loading = false
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams = {
        pageNo: 1,
        pageSize: 10,
        workNo: null,
        name: null,
        changeType: null,
        changeTimeArray:null,
        tel: null
      }
      // this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 列表查看操作 */
    openForm(row) {
      this.$refs['staffChangeFormData'].open(row)
    },
  }
}
</script>

<style scoped>

</style>
