<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.platformId" placeholder="请选择资源平台" clearable>
          <el-option v-for="item in platformOptions" :key="item.value" :label="item.label"
            :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="关联设备：">
        <el-select v-model="form.deviceIds" placeholder="请选择关联设备" clearable>
          <el-option v-for="item in devOptions" :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="当前状态：">
        <el-select v-model="form.status" placeholder="请选择当前状态" clearable>
          <el-option v-for="item in statusOptions" :key="item.value" :label="item.label"
            :value="item.value" />
        </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-refresh" @click="getRefresh">重置</el-button>
        <el-button type="primary" plain icon="el-icon-plus" @click="getDetail()"
          v-hasPermi="['service:musicPackage:add']">新增</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading" :default-sort="{prop: 'sort'}">
      <el-table-column label="排序" align="center" prop="sort" :formatter="sortFormatter" />
      <el-table-column label="套餐名称" align="center" prop="name" show-overflow-tooltip />
      <el-table-column label="关联设备" align="center" prop="deviceIds" :formatter="devFormatter"
        show-overflow-tooltip />
      <el-table-column label="原价/元" align="center" prop="price" />
      <el-table-column label="活动价/元" align="center" prop="discount" />
      <el-table-column label="有效期" align="center" prop="indate" :formatter="timeFormatter" />
      <el-table-column label="资源平台" align="center" prop="platformId" :formatter="platformFormatter" />
      <el-table-column label="当前状态" align="center" prop="status" :formatter="statusFormatter" />
      <el-table-column label="是否推荐" align="center" prop="isRecommend" :formatter="recommendFormatter" />
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button type="text" @click="getDetail(scope.row.id)" v-hasPermi="['service:musicPackage:edit']">
            编辑
          </el-button>
          <el-button v-if="scope.row.status === 1" type="text" @click="getChange(scope.row)"
            v-hasPermi="['service:musicPackage:down']">下架</el-button>
          <el-button v-else type="delete" @click="getDelete(scope.row)"
            v-hasPermi="['service:musicPackage:delete']">删除</el-button>
        </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 { devMixin, serviceTimeMixin } from '@/mixin/index'
import { mixin, musicPackageMixin, indexMixin } from '../mixin/index'
export default {
  mixins: [devMixin, mixin, serviceTimeMixin, musicPackageMixin, indexMixin],
  data() {
    return {
      // 遮罩层
      loading: false,
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10,
        type: 13
      },
      // 列表
      tableData: [],
      total: 0
    }
  },
  methods: {
    // 重置
    getRefresh() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
        type: 13
      }
      this.getList()
    },

    // 新增 / 编辑
    getDetail(id) {
      this.$router.push({
        path: `/service/musicPackage/detail`,
        query: {
          id: id
        }
      })
    },

    // 字典翻译
    // 资源平台
    platformFormatter(row) {
      return this.selectDictLabel(this.platformOptions, row.platformId)
    },
    // 有效期
    timeFormatter(row) {
      return this.selectDictLabel(this.serviceTimeOptions, row.indate)
    }
  }
}
</script>