<template>
  <div class="app-container">
    <el-card shadow="never" class="mb16 filter-card">
      <el-form :model="queryParams" ref="queryForm" :inline="true" size="small">
        <el-form-item label="套餐名称" prop="packageName">
          <el-input v-model="queryParams.packageName" placeholder="请输入套餐名称" clearable @keyup.enter.native="handleQuery" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>

    <el-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" />
    </el-row>

    <el-table v-loading="loading" :data="packageList" border size="small" style="width:100%">
      <el-table-column label="套餐ID" align="center" prop="packageId" width="80" />
      <el-table-column label="套餐名称" align="center" prop="packageName" min-width="140" />
      <el-table-column label="套餐分钟数" align="center" prop="times" width="120">
        <template slot-scope="scope">
          <span>{{ scope.row.times }} 分钟</span>
        </template>
      </el-table-column>
      <el-table-column label="套餐价格" align="center" prop="price" width="120">
        <template slot-scope="scope">
          <span style="color:#E6A23C;font-weight:bold">¥{{ scope.row.price || '0.00' }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" prop="status" width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.status === 1" type="success" size="small">启用</el-tag>
          <el-tag v-else type="info" size="small">停用</el-tag>
        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total>0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
  </div>
</template>

<script>
import { listVoicePackage } from '@/api/admin/voicePackage'

export default {
  name: 'AdminVoicePackage',
  data() {
    return {
      loading: false,
      showSearch: true,
      total: 0,
      packageList: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        packageName: null
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.loading = true
      listVoicePackage(this.queryParams).then(res => {
        this.packageList = res.rows || []
        this.total = res.total || 0
        this.loading = false
      }).catch(() => { this.loading = false })
    },
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    }
  }
}
</script>

<style scoped>
.mb8 { margin-bottom: 8px; }
.mb16 { margin-bottom: 16px; }
.filter-card { padding-bottom: 0; }
</style>
