<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.goodsId" placeholder="请选择流量套餐" clearable>
          <el-option v-for="(item, index) in goodsOptions" :key="index" :label="item" :value="index" />
        </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:flowPackage:add']">新增</el-button>
      </el-form-item>
    </el-form>
    <!-- 列表 -->
    <el-table :data="tableData" v-loading="loading">
      <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="intro" show-overflow-tooltip />
      <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">
          <span v-if="scope.row.status === 1">
            <el-button type="text" @click="getDetail(scope.row.id)" v-hasPermi="['service:flowPackage:edit']">
              编辑
            </el-button>
            <el-button type="text" @click="getChange(scope.row)" v-hasPermi="['service:flowPackage:down']">
              下架
            </el-button>
          </span>
          <el-button v-else type="delete" @click="getDelete(scope.row)"
            v-hasPermi="['service:flowPackage: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 } from '@/mixin/index'
import { mixin, indexMixin, goodsMixin } from '../mixin/index'
export default {
  mixins: [devMixin, mixin, goodsMixin, indexMixin],
  data() {
    return {
      // 表单
      form: {
        pageNum: 1,
        pageSize: 10,
        type: 12
      },
    }
  },
  methods: {
    // 重置
    getRefresh() {
      this.form = {
        pageNum: 1,
        pageSize: 10,
        type: 12
      }
      this.getList()
    },

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