<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" @submit.native.prevent v-show="showSearch">
      <el-form-item label="结算单号" prop="num">
        <el-input v-model="queryParams.num" placeholder="请输入结算单号" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item label="结算批次" prop="batchName">
        <el-input v-model="queryParams.batchName" placeholder="请输入结算批次" @keyup.enter.native="handleQuery" clearable />
      </el-form-item>
      <el-form-item label="关联项目" prop="projectId">
        <projectSelect v-model="queryParams.projectId"></projectSelect>
      </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 :data="response.rows" border height="calc(100vh - 235px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column type="index" label="序号" align="center" width="80" />
      <el-table-column label="结算单号" align="center" prop="num" />
      <el-table-column label="结算批次" align="center" prop="batchName" />
      <el-table-column label="服务公司" align="center">
        <template slot-scope="scope">
          <div class="omit" :title="scope.row.serviceCompany">{{ scope.row.serviceCompany }}</div>
        </template>
      </el-table-column>
      <el-table-column label="关联项目" align="center" prop="projectName" />
      <el-table-column label="审核状态" align="center" width="110">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.audit == 0">待提交</el-tag>
          <el-tag type="danger" v-if="scope.row.audit == 1">待审核</el-tag>
          <el-tag type="success" v-if="scope.row.audit == 2">审核通过</el-tag>
          <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>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="创建日期" align="center" prop="generateTime" width="160" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view" @click="op('detail', scope.row)" v-hasPermi="['work:statement:manage']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('submit', scope.row)" v-hasPermi="['work:statement:manage']" v-if="scope.row.audit === 0||scope.row.audit ===3">提交审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-circle-close" @click="op('cancel', scope.row)" v-hasPermi="['work:statement:manage']" v-if="scope.row.audit === 1">撤回</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 record from './record';
  export default {
    data() {
      return {
        showSearch: true,
        response: {},
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          num: null,
          batchName: null,
          projectId: null,
          orderByColumn: 's.id',
          isAsc: 'desc'
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.ajax({ url: '/work/statement/manage', 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: record, param: { form: row, detail: true }, title: '查看结算单详情', width: '75%', height: '65%' });
        }
        if (tag == 'submit') {
          this.$confirm('是否提交审核?', '警告', { type: 'warning' }).then(() => {
            this.ajax({ url: '/work/statement/manage/submit/' + id }).then((response) => {
              this.$modal.msgSuccess('提交成功');
              this.getList();
            });
          });
        }
        if (tag == 'cancel') {
          this.$confirm('是否撤销审核?', '警告', { type: 'warning' }).then(() => {
            this.ajax({ url: '/work/statement/manage/cancel/' + id }).then((response) => {
              this.$modal.msgSuccess('撤销成功');
              this.getList();
            });
          });
        }
      }
    }
  };
</script>
