<template>
  <div class='app-container'>
    <el-form inline>
      <el-form-item label="歌曲ID：">
        <el-input v-model="data.form.id" placeholder="请输入歌曲ID" clearable />
      </el-form-item>
      <el-form-item label="歌曲名称：">
        <el-input v-model="data.form.name" placeholder="请输入歌曲名称" clearable />
      </el-form-item>
      <el-form-item label="歌手名称：">
        <el-input v-model="data.form.singerName" placeholder="请输入歌手名称" clearable />
      </el-form-item>
      <el-form-item label="资源平台：">
        <el-select v-model="data.form.platformId" placeholder="请选择资源平台" clearable>
          <el-option v-for="item in data.platformOptions" :key="item.value" :value="item.value" :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item label="当前状态：">
        <el-select v-model="data.form.status" placeholder="请选择当前状态" clearable>
          <el-option v-for="item in ohplay_change_status" :key="item.value" :value="item.value" :label="item.label" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="Search" @click="getSearch">搜索</el-button>
        <el-button icon="Refresh" @click="getRefresh">重置</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="data.tableData" v-loading="loading">
      <el-table-column label="歌曲ID" prop="id" align="center"></el-table-column>
      <el-table-column label="歌曲名称" prop="name" align="center"></el-table-column>
      <el-table-column label="歌曲封面" prop="thumbUrl" align="center" width="100px">
        <template #default="scope">
          <el-image v-if="scope.row.thumbUrl" :src="scope.row.thumbUrl" />
        </template>
      </el-table-column>
      <el-table-column label="歌手名称" prop="singerName" align="center"></el-table-column>
      <el-table-column label="资源平台" prop="platformId" align="center" :formatter="platformFormatter"></el-table-column>
      <el-table-column label="当前状态" prop="status" align="center">
        <template #default="scope">
          <dict-tag :options="ohplay_change_status" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="更新时间" prop="updateTime" align="center">
        <template #default="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total > 0" :total="total" v-model:page="data.form.pageNum" v-model:limit="data.form.pageSize"
      @pagination="getList" />
  </div>
</template>

<script setup>
import { list, options } from '@/api/content/ohplay.js'

const { proxy } = getCurrentInstance();
const { ohplay_change_status } = proxy.useDict("ohplay_change_status")

// 遮罩层
const loading = ref(false)

const data = reactive({
  // 表单
  form: {
    pageNum: 1,
    pageSize: 10
  },
  // 列表
  tableData: [],
  // 资源平台
  platformOptions: []
})

// 总数据
const total = ref(0)

// 列表
function getList() {
  loading.value = true
  list(data.form).then(res => {
    if (res.code === 0) {
      data.tableData = res.data.records
      total.value = res.data.total
      loading.value = false
    }
  })
}
getList()

// 搜索
function getSearch() {
  data.form.pageNum = 1
  getList()
}

// 重置
function getRefresh() {
  data.form = {
    pageNum: 1,
    pageSize: 10
  }
  getList()
}

// 资源平台
function getOptions() {
  options({
    audioType: 11
  }).then(res => {
    if (res.code === 0) {
      res.data.forEach(i => {
        data.platformOptions.push({
          value: i.id,
          label: i.name
        })
      })
    }
  })
}
getOptions()

function platformFormatter(row) {
  return proxy.selectDictLabel(data.platformOptions, row.platformId)
}
</script>