<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-button type="primary" icon="el-icon-plus" :disabled="ids.length > 0" @click="op('add')" v-hasPermi="['work:banner:add']">新增</el-button>
      <el-button type="success" icon="el-icon-edit" :disabled="ids.length != 1" @click="op('edit', ids)" v-hasPermi="['work:banner:edit']">修改</el-button>
      <el-button type="danger" icon="el-icon-delete" :disabled="ids.length == 0" @click="del" v-hasPermi="['work:banner: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 - 243px)">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="图片" align="center" prop="pic">
        <template slot-scope="scope">
          <el-image class="p_img" style="height: 45px; background-color: aliceblue" :fit="'contain'" :src="baseUrl + scope.row.pic" :preview-src-list="[baseUrl + scope.row.pic]"></el-image>
        </template>
      </el-table-column>
      <el-table-column label="展示位置" align="center" prop="type" width="130">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.type == 0">首页</el-tag>
          <el-tag type="danger" v-if="scope.row.type == 1">更多服务</el-tag>
        </template>
      </el-table-column>
      <el-table-column label="点击跳转到" align="center" prop="contentTitle" />
      <el-table-column label="所属模块" align="center" prop="contentType" width="130"/>
      <el-table-column label="显示顺序" align="center" prop="orderNum" width="130" />
      <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="创建时间" prop="createTime" align="center" width="220" />
      <el-table-column label="操作" align="center" width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-edit" @click="op('edit', scope.row)" v-hasPermi="['work:banner:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="del(scope.row)" v-hasPermi="['work:banner: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';
export default {
  name: 'Banner',
  data() {
    return {
      ids: [],
      showSearch: true,
      response: {},
      columnList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'order_num',
        isAsc: 'asc'
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.ajax({ url: '/work/banner/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 == 'add') {
        this.iframe({ obj: edit, param: {}, title: '新增', width: '35%', height: '45%' });
      }
      if (tag == 'edit') {
        const id = row.id || this.ids[0];
        this.iframe({ obj: edit, param: { id: id }, title: '编辑', width: '35%', height: '45%' });
      }
    },
    del(row) {
      this.$confirm('是否确认删除选中数据?', '警告', { type: 'warning' }).then(() => {
        this.get({ url: '/work/banner/remove/' + (row.id || this.ids) }).then((response) => {
          this.$modal.msgSuccess('删除成功');
          this.getList();
        });
      });
    }
  }
};
</script>
