<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent v-show="showSearch">
      <el-form-item label="姓名" prop="name">
        <el-input v-model="queryParams.name" placeholder="请输入姓名" @keyup.enter.native="handleQuery" class="inp" clearable />
      </el-form-item>
      <el-form-item label="手机号" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入手机号" @keyup.enter.native="handleQuery" class="inp" clearable />
      </el-form-item>
      <el-form-item label="身份证号" prop="idCard">
        <el-input v-model="queryParams.idCard" placeholder="请输入身份证号" @keyup.enter.native="handleQuery" clearable />
      </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-button type="primary" icon="el-icon-download" @click="handleExport" v-hasPermi="['work:relate:export']" style="float: right">导出</el-button>
    </el-form>
    <el-table :data="response.rows" border height="calc(100vh - 230px)">
      <el-table-column type="index" label="序号" align="center" width="80" />
      <el-table-column label="姓名" align="center" prop="name" />
      <el-table-column label="身份证" align="center" prop="idCard" />
      <el-table-column label="手机号" align="center" prop="phone" />
      <el-table-column label="关联方式" align="center" prop="way" />
      <el-table-column label="关联时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="op('contract', scope.row)" v-if="scope.row.isContract == 1">查看合同</el-button>
          <el-button size="mini" type="text" icon="el-icon-view" @click="op('detail', scope.row)">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:relate:remove']">解除</el-button>
        </template>
      </el-table-column>
      <template slot="empty">
        <el-empty></el-empty>
      </template>
    </el-table>
    <pagination v-if="response.total > 0" :total="response.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import contract from '@/views/work/user/contract';
import info from '@/views/work/user/edit';
export default {
  name: 'Relate',
  data() {
    return {
      showSearch: true,
      response: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        phone: null,
        idCard: null,
        orderByColumn: 'r.id',
        isAsc: 'desc'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/relate/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },
    op(tag, row) {
      if (tag == 'detail') {
        this.iframe({ obj: info, param: { id: row.userId, detail: true }, title: '查看详情', width: '55%', height: '65%' });
      }
      if (tag == 'contract') {
        this.iframe({ obj: contract, param: { id: row.userId }, title: '查看合同', width: '55%', height: '85%' });
      }
    },
    del(row) {
      this.$confirm('是否确认解除选中关联用户?', '警告', { type: 'warning' }).then(() => {
        this.ajax({ method: 'post', url: '/work/relate/remove', data: { userId: row.userId } }).then((response) => {
          this.$modal.msgSuccess('解除成功');
          this.getList();
        });
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('/work/relate/export', { ...this.queryParams }, '企业关联用户.xlsx');
    }
  }
};
</script>
