<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8"  style="margin-left: 0; margin-top: 10px">
      <el-button
        type="primary"
        plain
        icon="el-icon-plus"
        size="mini"
        @click="handleAdd"
        v-hasPermi="['system:ticketAdver:add']"
      >新增</el-button>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table ref="tables" v-loading="loading" :data="dataList" border>
      <el-table-column label="序号" align="center" type="index" width="50"></el-table-column>
      <el-table-column label="标题名称" align="center" prop="name" />
      <el-table-column label="banner图片" align="center" prop="type">
        <template slot-scope="scope">
          <el-image
            style="width: 100px; height: 50px"
            :src="scope.row.sliderImg" 
            :preview-src-list="[scope.row.sliderImg]"
            @click="vbs(scope.row.staffIcon)"
          />
        </template>
      </el-table-column>
      <!-- <el-table-column label="类型" align="center" prop="type">
        <template slot-scope="scope">
          <span>{{ scope.row.type == 1 ? '图文' : scope.row.type == 2 ? '视频' : '链接' }}</span>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="状态" align="center">
        <template slot-scope="scope">
          <el-tag type="success" v-if="scope.row.onlineStatus == '1'">己上线</el-tag>
          <el-tag type="danger" v-else-if="scope.row.onlineStatus == '0'">未上线</el-tag>
          <el-tag type="info" v-else>未发布</el-tag>
        </template>
      </el-table-column> -->
      <el-table-column label="创建时间" align="center" prop="createTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <!-- <el-button
            size="mini"
            type="text"
            @click="ionlineApi(scope.row)"
            v-hasPermi="['system:ticketAdver:release']"
          >{{scope.row.onlineStatus == '1' ? '取消发布' : '发布'}}</el-button> -->
          <el-button
            size="mini"
            type="text"
            @click="openDetails(scope.row)"
            v-hasPermi="['system:ticketAdver:details']"
          >详情</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['system:ticketAdver:edit']"
          >编辑</el-button>
          <el-button
            size="mini"
            type="text"
            @click="handleDelete(scope.row,scope.index)"
            v-hasPermi="['system:ticketAdver:delete']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 详情 -->
    <!-- 新增/编辑弹框 -->
    <data-box
      ref="addAndEdit"
      @getList="getList"
    />
  </div>
</template>

<script>
import { pageList,deleteById } from "@/api/system/ticketAdver";
import dataBox from "./dialog/dataBox";
export default {
  name: "ticketAdver",
  components: { dataBox },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      dataList: null,
      // 弹出层标题
      title: "",

      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        postion: 2,
      },

      srcList: []
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    getList() {
      this.loading = true;
      pageList(this.queryParams)
      .then(response => {
          this.dataList = response.data.rows;
          this.total = response.data.total;
          this.loading = false;
        }
      );
    },
    // 取消按钮
    cancel() {
      this.open = false;
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.$set(this.queryParams, 'id', '');
      this.$set(this.queryParams, 'businessType', '');
      this.$set(this.queryParams, 'incomeExpenses', '');
      this.queryParams.pageNum = 1;
      this.handleQuery();
    },
    /** 详情按钮操作 */
    openDetails(row, type) {
      this.$refs["addAndEdit"].openDialog("详情", row,3);
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs["addAndEdit"].openDialog("新增数据", null,1);
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs["addAndEdit"].openDialog("修改数据", row,2);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const dataIds = row.id || this.ids;
      this.$modal.confirm('是否确认删除标题名称为"' + row.name + '"的数据项？').then(function() {
        return deleteById(row.id);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 查看按钮操作 */
    vbs(val) {
      this.srcList = []
      this.srcList.push(val)
    }
  }
};
</script>
