<template>
  <div class="app-container">
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column label="序号" type="index" align="center" />
      <el-table-column label="场景标题" prop="name" align="center" />
      <el-table-column label="场景副标题" prop="subName" align="center" />
      <el-table-column label="场景封面" align="center" width="100px">
        <template slot-scope="scope">
          <el-image :src="scope.row.pic" />
        </template>
      </el-table-column>
      <el-table-column label="当前状态" prop="status" align="center" :formatter="statusFormatter" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="getDetail(scope.row.id, true)">查看</el-button>
          <el-button v-if="scope.row.status === 0" type="text" @click="getChange(scope.row, 1, '下架')"
            v-hasPermi="['operation:scene:down']">下架</el-button>
          <span v-else style="margin-left: 10px">
            <el-button type="text" @click="getDetail(scope.row.id)" v-hasPermi="['operation:scene:edit']">编辑</el-button>
            <el-button type="text" @click="getChange(scope.row, 0, '上架')"
              v-hasPermi="['operation:scene:up']">上架</el-button>
            <el-button type="delete" @click="getChange(scope.row, 2, '删除')"
              v-hasPermi="['operation:scene:delete']">删除</el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { list, change } from '@/api/operation/scene'
import { disabledMixin } from '@/mixin/index'
export default {
  mixins: [disabledMixin],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 列表
      tableData: []
    }
  },
  mounted() {
    this.getList()
  },
  methods: {
    // 列表
    getList() {
      this.loading = true
      list().then(res => {
        if (res.code === 0) {
          this.tableData = res.data
          this.loading = false
        }
      })
    },

    // 详情
    getDetail(id, boolean) {
      this.$router.push({
        path: '/operation/scene/detail',
        query: {
          id: id,
          boolean: boolean
        }
      })
    },

    // 上下架
    getChange(row, status, title) {
      this.$confirm(`是否${title}${row.name}?`, '提示', {
        type: 'warning'
      }).then(() => {
        change(row.id, 1, status).then(res => {
          if (res.code === 0) {
            this.$message.success(`${title}成功！`)
            this.getList()
          }
        })
      }).catch(() => { })
    },

    // 字典翻译
    statusFormatter(row) {
      return this.selectDictLabel(this.disabledOptions, row.status)
    }
  }
}
</script>

<style lang="scss" scoped>

</style>