<template>
  <div>

    <div>
      <div ref="lxHeader">
        <lx-header icon="md-apps" :text="$route.meta.title" style="margin-bottom: 10px; border: 0px; margin-top: 15px">
          <div slot="content">
            <div class="searchwrap" style="display: flex;align-items: center;">
              <div>
                <el-input v-model="select.name" placeholder="请输入课程名称"></el-input>
              </div>
              <div>
                <el-date-picker @change="changeDateRange" v-model="dateRange" type="daterange" range-separator="至"
                  start-placeholder="开课日期" value-format="yyyy-MM-dd" format="yyyy-MM-dd" end-placeholder="结束日期">
                </el-date-picker>
              </div>
              <div>
                <el-select v-model="select.type" placeholder="请选择类别" clearable>
                  <el-option v-for="item in course_type" :key="item.id" :label="item.value" :value="item.id">
                  </el-option>
                </el-select>
              </div>
              <div>
                <el-button type="primary" size="small">查询</el-button>
              </div>
            </div>
          </div>

        </lx-header>
      </div>
    </div>

    <div>
      <xy-table :list="list" :total="total" @pageIndexChange="pageIndexChange" @pageSizeChange="pageSizeChange"  :table-item="table_item">
        <template v-slot:dateRange>
          <el-table-column align='center' label="开课日期" width="200" header-align="center">
            <template slot-scope="scope">
              {{scope.row.start_date}}至{{scope.row.end_date}}
            </template>
          </el-table-column>
        </template>
        <template v-slot:type>
          <el-table-column align='center' label="类别" width="120" header-align="center">
            <template slot-scope="scope">
              <div v-for="item in course_type">
                <div v-if="scope.row.type===item.id">{{item.value}}</div>
              </div>
            </template>
          </el-table-column>
        </template>
        <template v-slot:btns>
          <el-table-column align='center' label="操作" width="280" header-align="center">
            <template slot-scope="scope">
              <el-button type="primary" size="small" @click="showCourse('show',scope.row.id)">查看课程</el-button>
              <el-button type="primary" size="small" @click="goTxl(scope.row)">通讯录</el-button>
              <el-button type="primary" size="small" @click="goPay(scope.row)">缴费</el-button>
            </template>
          </el-table-column>
        </template>
      </xy-table>
    </div>

    <show-course ref="showCourse"></show-course>
  </div>
</template>

<script>
  import showCourse from './components/showCourse.vue';
  import myMixins from "@/mixin/selectMixin.js";
  import {
    index
  } from "@/api/course/index.js"
  export default {
    mixins: [myMixins],
    components: {
      showCourse
    },
    data() {
      return {
        dateRange: [],
        select: {
          name: '',
          dateRange: '',
          type: "",
          date_status:'已结束',
          page: 1,
          page_size: 10,
        },
        list: [],
        total: 0,
        table_item: [{
          prop: 'name',
          label: '课程名称',
          align: 'left'
        }, {
          prop: 'dateRange',
          label: '开课日期',
          align: 'center',
          width: 180,
        }, {
          prop: 'type',
          label: '类别',
          align: 'center',
          width: 180,
        }, ]

      }
    },
    created() {
      this.getList()
    },
    methods: {
      pageIndexChange(e){
        this.select.page = e
        this.getList()
      },
      pageSizeChange(e){
        this.select.page_size = e
        this.select.page = 1
        this.getList()
      },
      async getList() {
        const res = await index({
          page: this.select.page,
          page_size: this.select.page_size,
          filter: [{
            key: 'name',
            op: 'like',
            value: this.select.name
          }, {
            key: 'type',
            op: 'eq',
            value: this.select.type
          },
          // {
          //   key: 'date_status',
          //   op: 'eq',
          //   value: this.select.date_status
          // },
          {
            key: 'start_date',
            op: 'range',
            value: this.select.dateRange
          }]
        })
        this.list = res.data
        this.total = res.total
      },
      changeDateRange(e) {
        if (e) {
          this.select.dateRange = e.join(",")
        } else {
          this.select.dateRange = ''
        }
      },
      showCourse(type, id) {
        if(id){
          this.$refs.showCourse.id = id
        }
        this.$refs.showCourse.type = type
        this.$refs.showCourse.isShow = true
      },
      goTxl(row) {
        let value = ''
        this.course_type.map(item=>{
          if(item.id==row.type){
            value = item.value
          }
        })
        this.$router.push({
          path: '/course/txl',
          query: { title: row.name, id:row.id, date: row.start_date+'至'+row.end_date,leibie:value }
        })
      },
      goPay(row) {
        let value = ''
        this.course_type.map(item=>{
          if(item.id==row.type){
            value = item.value
          }
        })

        this.$router.push({
          path: '/course/pay',
          query: {
            type: 'history',
             title: row.name, id:row.id, date: row.start_date+'至'+row.end_date,leibie:value
          }
        })
      }

    }
  }
</script>

<style lang="scss" scoped>
  .searchwrap {
    display: flex;
    align-items: center;

    &>div {
      display: flex;
      align-items: center;
      margin-right: 10px;

      span {
        min-width: 70px;
      }
    }
  }
</style>
