<!-- 音频管理 猫王精选电台 -->
<template>
  <div class="app-container">
    <!-- 搜索 -->
    <el-form inline size="mini">
      <el-form-item label="电台名称：">
        <el-input v-model="form.name" placeholder="请输入电台名称" clearable />
      </el-form-item>
      <el-form-item label="当前状态：">
        <el-select v-model="form.status" placeholder="请选择当前状态">
          <el-option
            v-for="item in onOrOffOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
            clearable
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="getSearch"
          >搜索</el-button
        >
        <el-button icon="el-icon-refrash" @click="getRefrash">重置</el-button>
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          @click="getDetail()"
          v-hasPermi="['music:choiceness:add']"
          >新增</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <el-table-column type="index" label="序号" align="center" />
      <el-table-column
        label="电台ID"
        prop="id"
        align="center"
        show-overflow-tooltip
      />
      <el-table-column label="电台名称" prop="name" align="center" />
      <el-table-column label="电台封面" align="center" width="100px">
        <template slot-scope="scope">
          <el-image v-if="scope.row.thumb" :src="scope.row.thumb" />
        </template>
      </el-table-column>
      <el-table-column
        label="资源平台"
        prop="platformId"
        align="center"
        :formatter="platformFormatter"
      />
      <el-table-column
        label="当前状态"
        prop="status"
        align="center"
        :formatter="statusFormatter"
      />
      <el-table-column label="更新时间" align="center">
        <template slot-scope="scope">
          <span>{{
            parseTime(scope.row.updateTime, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <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 === 1"
            type="text"
            @click="getChange(scope.row, 2)"
            v-hasPermi="['music:choiceness:down']"
            >下架</el-button
          >
          <span v-else>
            <el-button
              type="text"
              style="margin-left: 10px"
              @click="getDetail(scope.row.id)"
              v-hasPermi="['music:choiceness:edit']"
              >编辑</el-button
            >
            <el-button
              type="text"
              @click="getChange(scope.row, 1)"
              v-hasPermi="['music:choiceness:up']"
            >
              上架
            </el-button>
            <el-button
              type="delete"
              @click="getDelete(scope.row)"
              v-hasPermi="['music:choiceness:delete']"
            >
              删除
            </el-button>
          </span>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="form.pageNum"
      :limit.sync="form.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { change, list, remove } from "@/api/music/choiceness";
import { onOrOffMixin, platformMixin } from "@/mixin/index";
import { dialogCallBack } from "@/utils/DialogUtil";
export default {
  name:"MusicChoiceness",
  mixins: [onOrOffMixin, platformMixin],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10,
      },
      total: 0,
      // 列表
      tableData: [],
    };
  },
  mounted() {
    this.getList();
    this.getPlatform({});
  },
  methods: {
    // 列表
    getList() {
      this.loading = true;
      list(this.form).then((res) => {
        if (res.code === 0) {
          this.tableData = res.data.records;
          this.total = res.data.total;
          this.loading = false;
        }
      });
    },

    // 搜索
    getSearch() {
      this.form.pageNum = 1;
      this.getList();
    },

    // 重置
    getRefrash() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
      };
      this.getList();
    },

    // 详情
    getDetail(id, boolean) {
      this.$router.push({
        path: `/music/choiceness/detail`,
        query: {
          id: id,
          disabled: boolean,
        },
      });
    },

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

    // 删除
    getDelete(row) {
      var that = this;
      dialogCallBack(that, function () {
        that
          .$confirm(`是否删除${row.name}?`, "提示", {
            type: "warning",
          })
          .then(() => {
            remove(row.id).then((res) => {
              if (res.code === 0) {
                that.$message.success(`删除成功！`);
                that.getList();
              }
            });
          });
      });
    },

    // 字典翻译
    platformFormatter(row) {
      return this.selectDictLabel(this.platformTypeOptions, row.platformId);
    },
    statusFormatter(row) {
      return this.selectDictLabel(this.onOrOffOptions, row.status);
    },
  },
};
</script>

<style lang="scss" scoped></style>
