<template>
  <div class="app-container">
    <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" 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-form>
    <el-table :data="response.rows" border height="calc(100vh - 230px)">
      <el-table-column label="合同名称" align="center" prop="name" />
      <el-table-column label="合同状态" align="center" prop="state" width="130">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.state == 0">启用</el-tag>
          <el-tag type="danger" v-if="scope.row.state == 1">停用</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" width="200" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-document">
            <a target="_blank" :href="baseUrl+scope.row.url">查看合同</a>
          </el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit', scope.row)" v-hasPermi="['work:contract:edit']">修改</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 look from './look';
  import edit from './edit';
  export default {
    name: 'Contract',
    data() {
      return {
        response: {},
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          name: null,
          state: null,
          orderByColumn: 'id',
          isAsc: 'desc'
        }
      };
    },
    created() {
      this.getList();
    },
    methods: {
      getList() {
        this.ajax({ url: '/work/contract/list', data: this.queryParams }).then((response) => {
          this.response = response;
        });
      },
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      resetQuery() {
        this.resetForm('queryForm');
        this.handleQuery();
      },
      selects(rows) {
        this.ids = rows.map((item) => item.id);
      },
      op(tag, row) {
        if (tag == 'look') {
          //this.iframe({ obj: look, param: { url: row.url }, title: '查看合同', width: '55%', height: '85%' });
        }
        if (tag == 'edit') {
          this.iframe({ obj: edit, param: { id: row.id }, title: '编辑合同', width: '35%', height: '40%' });
        }
      },
      del(row) {
        this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
          this.get({ url: '/work/contract/remove/' + (row.id || this.ids) }).then((response) => {
            this.$modal.msgSuccess('删除成功');
            this.getList();
          });
        });
      }
    }
  };
</script>
