<template>
  <div class='m-container'>
    <h2>
      <div class="squrt"></div>VIP分部活动列表
    </h2>
    <div class="m-core">
      <el-button type="primary" @click="openActive('create')" style="margin-bottom: 20px"
           v-permission="'/branchActiveOperationAdd'" >新建</el-button>
      <!-- 搜索类型 -->
      <save-form :inline="true"
               ref="searchForm"
               @submit.native.prevent
               @submit="onSearch"
               @reset="onReset"
               :model.sync="searchForm">
        <el-form-item prop="search">
          <el-input type="text"
                    v-model.trim="searchForm.search"
                    @keyup.enter.native='getList'
                    placeholder="分部活动名"></el-input>
        </el-form-item>
        <el-form-item prop="rewardMode">
          <el-select v-model.trim="searchForm.rewardMode"
                     clearable
                     placeholder="分部活动类型">
            <el-option v-for="(item,index) in rewardModeTypeList"
                       :key="index"
                       :label="item.label"
                       :value="item.value"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="teacherId">
          <el-select v-model.trim="searchForm.teacherId"
                     clearable
                     filterable
                     placeholder="适用老师">
            <el-option v-for="item in selects.teachers"
                       :key="item.id"
                       :label="item.realName"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item prop="vipGroupCategoryId">
          <el-select v-model.trim="searchForm.vipGroupCategoryId"
                     filterable
                     clearable
                     placeholder="课程类型">
            <el-option v-for="item in selects.vipGroupCategory"
                       :key="item.id"
                       :label="item.name"
                       :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button native-type="submit" type="danger">搜索</el-button>
          <el-button native-type="reset" type="primary">重置</el-button>
        </el-form-item>
      </save-form>
      <!-- 列表 -->
      <div class="tableWrap">
        <el-table :data='tableList'
                  :header-cell-style="{background:'#EDEEF0',color:'#444'}">
          <el-table-column align='center'
                           prop='name'
                           label="分部活动名">
          </el-table-column>
          <el-table-column align='center'
                           prop='rewardMode'
                           label="分部活动类型">
            <template slot-scope="scope">
              {{ scope.row.rewardMode | rewardModeTypeFormat }}
            </template>
          </el-table-column>
          <el-table-column align='center'
                           label="适用老师">
            <template slot-scope="scope">
              <span style="max-height: 68px;display: block;"
                    :title="scope.row.teacherNames | joinArray(',')">{{ scope.row.teacherNames | joinArray(',') }}</span>
            </template>
          </el-table-column>
          <el-table-column align='center'
                           prop='vipGroupCategoryNameList'
                           label="课程类型">
          </el-table-column>
          <el-table-column align='center'
                           label="操作"
                           width='100'>
            <template slot-scope="scope">
              <el-button @click="openActive('update', scope.row)"
                         v-permission="'/branchActiveOperationUpdate'"
                         type="text">修改</el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination :total.sync="pageInfo.total"
                    :page.sync="pageInfo.page"
                    :limit.sync="pageInfo.limit"
                    sync
                    :page-sizes="pageInfo.page_size"
                    @pagination="getList" />
      </div>
    </div>
  </div>
</template>
<script>
import pagination from '@/components/Pagination/index'
import { courseScheduleRewards } from '@/api/systemManage'
import { rewardModeTypeList } from "@/utils/searchArray";
export default {
  name: 'branchActive',
  components: { pagination },
  data () {
    return {
      rewardModeTypeList,
      searchForm: {
        search: null,
        rewardMode: null,
        vipGroupCategoryId: null,
        teacherId: null,
      },
      organId: null,
      tableList: [],
      pageInfo: {
        // 分页规则
        limit: 10, // 限制显示条数
        page: 1, // 当前页
        total: 0, // 总条数
        page_size: [10, 20, 40, 50] // 选择限制显示条数
      },

    }
  },
  mounted () {
    this.getList() // 获取列表数据
    this.__init()
  },
  methods: {
    async __init () {
      // 获取类型
      this.$store.dispatch('setVipGroupCategory')

      this.$store.dispatch('setTeachers')
    },
    getList () {
      let params = this.searchForm
      params.rows = this.pageInfo.limit
      params.page = this.pageInfo.page
      courseScheduleRewards(params).then(res => {
        if (res.code == 200 && res.data) {
          this.tableList = res.data.rows
          this.pageInfo.total = res.data.total
        }
      })
    },
    openActive (type, row) {
      let params = {
        path: '/vipClassSet/branchActiveOperation',
        query: {
          type: type
        },
      }
      let tagTitle = '新建'
      if (row) {
        params.query.id = row.id
        tagTitle = '修改'
      }
      this.$router.push(params, (route) => {
        route.meta.title = tagTitle + 'VIP分部活动'
      })
    },
    onFormClose (formName) { // 关闭弹窗重置验证
      this.$refs[formName].clearValidate()
    },
    onSearch() {
      this.$refs.searchForm.validate(valid => {
        this.pageInfo.page = 1
        this.getList()
      })
    },
    onReset() {
      this.$refs.searchForm.resetFields()
      this.onSearch()
    }
  }
}
</script>
<style lang="scss">
.el-button--primary {
  background: #14928a;
  border-color: #14928a;
  color: #fff;
  &:hover,
  &:active,
  &:focus {
    background: #14928a;
    border-color: #14928a;
    color: #fff;
  }
}
.el-vue-search-box-container {
  position: absolute !important;
  left: 10px;
  margin-top: 10px;
  z-index: 99999 !important;
}
</style>