<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" clearable />
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select v-model="queryParams.state" placeholder="状态" clearable class="se">
          <el-option value="0" label="待认证"></el-option>
          <el-option value="1" label="认证通过"></el-option>
          <el-option value="2" label="认证不通过"></el-option>
        </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-row :gutter="10" class="mb8">
      <el-button type="primary" icon="el-icon-plus" :disabled="ids.length > 0" @click="op('add')" v-hasPermi="['work:enterprise:add']">新增</el-button>
      <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit', ids)" v-hasPermi="['work:enterprise:edit']">修改</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:enterprise:remove']">删除{{ ids.length > 0 ? '(' + ids.length + ')' : '' }}</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :data="response.rows" border @selection-change="selects" height="calc(100vh - 270px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="公司名称" align="center" prop="name" />
      <el-table-column label="法定代表人" align="center" prop="legalPerson" width="110"/>
      <el-table-column label="电话" align="center" prop="phone" />
      <el-table-column label="邮箱" align="center" prop="email" />
      <el-table-column label="注册资本" align="center" prop="capital" width="100" />
      <el-table-column label="地址" align="center" prop="address">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="地址" trigger="hover" width="400" :content="scope.row.address">
            <div slot="reference">
              <div class="omit">{{ scope.row.address }}</div>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="简介" align="center" prop="contents">
        <template slot-scope="scope">
          <el-popover placement="top-start" title="简介" trigger="hover" width="400" :content="scope.row.contents">
            <div slot="reference">
              <div class="omit">{{ scope.row.contents }}</div>
            </div>
          </el-popover>
        </template>
      </el-table-column>
      <el-table-column label="营业执照" align="center" prop="p1" width="90">
        <template slot-scope="scope">
          <preview v-model="scope.row.p1"></preview>
        </template>
      </el-table-column>
      <el-table-column label="是否推荐" align="center" prop="recommend" width="80">
        <template slot-scope="scope">
          <el-tag type="info" v-if="scope.row.recommend == 0">否</el-tag>
          <el-tag type="success" v-if="scope.row.recommend == 1">是</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="是否认证" align="center" width="110">
        <template slot-scope="scope">
          <el-tag type="danger" v-if="scope.row.state == 0">待认证</el-tag>
          <el-tag type="success" v-if="scope.row.state == 1" :title="'充值时间：' + scope.row.updateTime">认证成功</el-tag>
          <el-popover placement="top-start" v-if="scope.row.state == 2" title="原因" width="200" trigger="hover" :content="scope.row.msg">
            <div slot="reference" :title="'操作时间：' + scope.row.updateTime">
              <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="createTime" width="160" />
      <el-table-column label="操作" align="center" width="180">
        <template slot-scope="scope">
          <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-edit" @click="op('audit', scope.row)" v-hasPermi="['work:enterprise:edit']" v-if="scope.row.state == 0">审核</el-button>
          <el-button size="mini" type="text" icon="el-icon-sell" @click="op('recommend', scope.row)" v-hasPermi="['work:enterprise:recommend']" v-if="scope.row.state == 1">推荐</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:enterprise: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 edit from './edit';
import recommend from './recommend';
export default {
  name: 'Enterprise',
  data() {
    return {
      ids: [],
      showSearch: true,
      response: {},
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        name: null,
        state: null,
        orderByColumn: 'id',
        isAsc: 'desc'
      }
    };
  },
  created() {
    if (this.$route.query.state) {
      this.queryParams.state = this.$route.query.state;
    }
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/enterprise/list', data: this.queryParams }).then((response) => {
        this.response = response;
      });
    },
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    resetQuery() {
      this.resetForm('queryForm');
      this.queryParams.state = null;
      this.handleQuery();
    },
    selects(rows) {
      this.ids = rows.map((item) => item.id);
    },
    op(tag, row) {
      if (tag == 'detail') {
        this.iframe({ obj: edit, param: { id: row.id, detail: true }, title: '企业详情', width: '50%', height: '65%' });
      }
      if (tag == 'recommend') {
        this.iframe({ obj: recommend, param: { id: row.id }, title: '设为推荐', width: '25%', height: '35%' });
      }
      if (tag == 'audit') {
        this.iframe({ obj: edit, param: { id: row.id, detail: true }, title: '审核', width: '50%', height: '65%' });
      }
    },
    del(row) {
      this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/enterprise/remove/' + (row.id || this.ids) }).then((response) => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    }
  }
};
</script>
