<template>
  <div class="cmain">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent>
      <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" style="float: right">导出成结算单</el-button>
    </el-form>
    <el-table :data="response.rows" border>
      <el-table-column type="index" label="序号" align="center" width="70" />
      <el-table-column label="姓名" align="center" prop="name" width="100" />
      <el-table-column label="身份证" align="center" prop="idCard" width="180" />
      <el-table-column label="手机号" align="center" prop="phone" width="120" />
      <el-table-column label="开户行" align="center" prop="bankName" width="150" />
      <el-table-column label="银行卡号" align="center" prop="bankAccount" width="200" />
      <el-table-column label="支付宝账号" align="center" prop="alipay" width="120" />
      <el-table-column label="接包日期" align="center" prop="createTime" width="160" />
      <el-table-column label="接包凭证" align="center" width="130" fixed="right">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.audit == 0">待上传</el-tag>
          <el-tag type="info" v-if="scope.row.audit == 1">待审核</el-tag>
          <el-tag type="success" v-if="scope.row.audit == 2">已审核</el-tag>
          <preview v-model="scope.row.voucher" v-if="scope.row.audit != 0 && scope.row.audit != 3" msg="查看" style="float: right"></preview>
          <el-popover placement="top-start" v-if="scope.row.audit == 3" title="原因" width="200" trigger="hover" :content="scope.row.msg">
            <div slot="reference">
              <el-tag type="info">驳回</el-tag>
              <i class="el-icon-warning"></i>
              <preview v-model="scope.row.voucher" v-if="scope.row.audit != 0" msg="查看" style="float: right"></preview>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" width="250" fixed="right">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document" @click="op('contract', scope.row)">查看合同</el-button>
          <el-button size="mini" type="text" icon="el-icon-check" @click="op('success', scope.row)" v-if="scope.row.audit == 1">确认</el-button>
          <el-button size="mini" type="text" icon="el-icon-close" @click="op('reject', scope.row)" v-if="scope.row.audit == 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)">删除</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: 'Packages',
    data() {
      return {
        response: {},
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          projectId: null,
          name: null,
          phone: null,
          idCard: null,
          orderByColumn: 'p.id',
          isAsc: 'desc'
        }
      };
    },
    props: {
      param: {
        type: Object,
        default: () => {
          return {};
        }
      },
      layerid: {
        type: String
      }
    },
    mounted() {
      this.queryParams.projectId = this.param.projectId;
      this.getList();
    },
    methods: {
      getList() {
        this.ajax({ url: '/work/packages/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) {
        const id = row.id;
        if (tag == 'detail') {
          this.iframe({ obj: info, param: { id: row.userId, detail: true }, title: '查看详情', width: '55%', height: '65%' });
        }
        if (tag == 'success') {
          this.$confirm('是否确认审核通过?', '警告', { type: 'warning' }).then(() => {
            this.ajax({ url: '/work/packages/success/' + id }).then((response) => {
              this.$modal.msgSuccess('审核成功');
              this.getList();
            });
          });
        }
        if (tag == 'reject') {
          this.$prompt('确定审核驳回', {
            type: 'warning',
            showInput: true,
            inputType: 'textarea',
            inputPlaceholder: '驳回原因',
            inputValidator: (value) => {
              if (!value) {
                return '请输入驳回原因';
              }
            }
          }).then(({ value }) => {
            this.ajax({ method: 'post', url: '/work/packages/reject', data: { id: id, msg: value } }).then((response) => {
              this.$modal.msgSuccess('驳回成功');
              this.getList();
            });
          });
        }
        if (tag == 'contract') {
          this.iframe({ obj: contract, param: { id: row.userId }, title: '查看合同', width: '55%', height: '85%' });
        }
      },
      del(row) {
        this.$confirm('是否确认删除选中接包用户！', '警告', { type: 'warning' }).then(() => {
          this.get({ url: '/work/packages/remove/' + row.id }).then((response) => {
            this.$modal.msgSuccess('删除成功');
            this.getList();
          });
        });
      },
      /** 导出按钮操作 */
      handleExport() {
        this.download('/work/packages/export', { ...this.queryParams }, '结算单.xlsx');
      }
    }
  };
</script>
