    <template>
      <div class="app-container calendar-list-container">
        <el-form label-position="right" label-width="100px"  style='width:100%;'>
          <el-row :gutter="24">
             <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('college.c_name')" >
                  <div class="block">
                   <el-input style="width: 100%;" class="filter-item"
                      v-model="seachQuery.c_name" :maxlength = "20">
                  </el-input>
                  </div>
                </el-form-item>
              </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="6" :xl="6">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('college.c_type')" >
                <div class="block">
                  <el-select style="width: 100%;" class="filter-item" v-model="seachQuery.c_type" @change="contentChange()">
                    <el-option v-for="item in contentOption"  :key="item.wct_code" :label="item.wct_name" :value="item.wct_code" >
                    </el-option>
                  </el-select>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('college.c_step')" >
                  <el-select style="width: 100%;" class="filter-item" v-model="seachQuery.c_step">
                    <el-option v-for="item in wcTypeOption" :key="item.value" :label="item.label" :value="item.value" >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="5" :xl="5">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('college.credit')" >
                  <div class="block">
                    <el-input-number style="width: 100%;" class="filter-item"
                        v-model="seachQuery.credit" :maxlength = 20  controls-position="right">
                    </el-input-number>
                  </div>
                </el-form-item>
              </div>
          </el-col>
          </el-row>

          <el-row :gutter="24">
            <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('promotion.mkt')" >
                  <el-select style="width: 100%;" class="filter-item" v-model="seachQuery.branches">
                    <el-option v-for="item in mktOption" :key="item.id" :label="item.mi_mktname" :value="item.id" >
                    </el-option>
                  </el-select>
                </el-form-item>
              </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="6" :xl="6">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('adminstock.startdate')" >
                <div class="block">
                  <el-date-picker v-model="seachQuery.startdate" value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions" style="width: 100%;">
                  </el-date-picker>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="12" :lg="6" :xl="6">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('adminstock.enddate')" >
                <div class="block">
                  <el-date-picker v-model="seachQuery.enddate" value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions" style="width: 100%;">
                  </el-date-picker>
                </div>
              </el-form-item>
            </div>
        </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="5" :xl="5">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('college.deadline')" >
                <div class="block">
                  <el-date-picker v-model="seachQuery.deadline" value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions" style="width: 100%;">
                  </el-date-picker>
                </div>
              </el-form-item>
            </div>
          </el-col>
          </el-row>
           <el-row :gutter="24" style="margin-bottom:15px;">
          <el-col :span="24">
              <div  align="center" > <el-button class="filter-item" type="primary" v-waves :loading ="buttonloading" icon="el-icon-search" @click="handleFilterfirst">
            {{$t('table.search')}}
          </el-button>
          <el-button class="filter-item" type="primary" v-waves icon="el-icon-delete" @click="handleref">
            {{$t('table.cancel')}}
          </el-button>
          </div>
          </el-col>
          </el-row>
          <el-row :gutter="24">
            <div align="right">
              <el-button class="filter-item" style="margin-left: 10px;" @click="hrefAdd" type="primary"
                    icon="el-icon-edit">{{$t('table.add')}}
            </el-button>&nbsp;&nbsp;&nbsp;</div>    
          </el-row>
        </el-form>
         <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="加载中......" border fit
                  highlight-current-row
                  style="width: 100%">
          <el-table-column type="index" align="center" :label="$t('table.seq')" width="70">
            <template slot-scope="scope">
              <a href="#" @click="infoshow(scope.row.id)"><span style="color:#409EFF">{{scope.$index+1}}</span></a>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.c_name')">
            <template slot-scope="scope">
               <span>{{scope.row.c_name}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.c_type')">
            <template slot-scope="scope">
               <span v-if="scope.row.c_type == 'P01'">孕期</span>
               <span v-if="scope.row.c_type == 'B01'">育儿期</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.c_step')">
              <template slot-scope="scope">
               <span>{{scope.row.c_step}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.credit')">
            <template slot-scope="scope">
              <span>{{scope.row.credit}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.branches')">
            <template slot-scope="scope">
              <span>{{scope.row.branches}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.startdate')">
            <template slot-scope="scope">
              <span>{{scope.row.startdate}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.enddate')">
            <template slot-scope="scope">
              <span>{{scope.row.enddate}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.deadline')">
            <template slot-scope="scope">
              <span>{{scope.row.deadline}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.maximum')">
            <template slot-scope="scope">
              <span>{{scope.row.maximum}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('table.actions')" width="206">
          <template slot-scope="scope" >
            <a href="#" @click="hrefedit(scope.row.id)"><el-tag >{{$t('table.edit')}}</el-tag></a>
            <a href="#" @click="hrefdel(scope.row.id)"><el-tag >{{$t('table.delete')}}</el-tag></a>
            <a href="#" @click="hrefQrCode(scope.row.qrcode)"><el-tag >{{$t('table.qrcode')}}</el-tag></a>
          </template>
        </el-table-column>
        </el-table>
        <el-dialog title="内容展示" :visible.sync="dialogFormVisible" :before-close="handleClose">
          <div class="editor-content" v-html="content"></div>
        </el-dialog>
        <div class="pagination-container">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="page" :page-sizes="[10,20,50,100]" :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
        <el-dialog  width="50%;"  :title="textMap[dialogStatus]" :visible.sync="dialogPvVisible" :before-close="handleClose">
          <img :src="imgpath" style="width:100%;"/>
        </el-dialog>
      </div>
    </template>
    <script>
      import { fetchPv, createArticle } from '@/api/article'
      import waves from '@/directive/waves' // 水波纹指令
      import { parseTime } from '@/utils'
      import { getWXContentTypes } from '@/api/wxmini'
      import { getCollegeCurriculumPractices, deleteCollegeCurriculumPractice } from '@/api/college'
      import { getAllMkt } from '@/api/wxmini'
      // arr to obj ,such as { CN : "China", US : "USA" }
      export default {
        name: 'introducer',
        directives: {
          waves
        },
        data() {
          return {
            content: null,
            dialogFormVisible: false,
            dialogPvVisible: false,
            dialogStatus: '',
            tableKey: 0,
            contentOption: [],
            wcTypeOption: [],
            imgpath: null,
            mktOption: [],
            list: null,
            dis: 1,
            total: null,
            page: 1,
            limit: 10,
            queryType: 'list',
            listLoading: true,
            buttonloading: false,
            listQuery: {
              importance: undefined,
              title: undefined,
              type: undefined,
              sort: '+id'
            },
            commentShow: {
              comment: null
            },
            seachQuery: {
              c_step: null,
              c_type: null,
              c_name: null,
              credit: null,
              branches: null,
              startdate: null,
              enddate: null,
              deadline: null,
              page: null,
              limit: null
            },
            pickerOptions: {
              shortcuts: [{
                text: '今天',
                onClick(picker) {
                  picker.$emit('pick', new Date())
                }
              }, {
                text: '昨天',
                onClick(picker) {
                  const date = new Date()
                  date.setTime(date.getTime() - 3600 * 1000 * 24)
                  picker.$emit('pick', date)
                }
              }, {
                text: '一周前',
                onClick(picker) {
                  const date = new Date()
                  date.setTime(date.getTime() - 3600 * 1000 * 24 * 7)
                  picker.$emit('pick', date)
                }
              }]
            },
            showReviewer: false,
            pvData: [],
            textMap: {
              update: 'Edit',
              create: '查看二维码'
            }
          }
        },
        created() {
          this.getList()
          getWXContentTypes().then(response => {
            this.contentOption = response.data
          })
          getAllMkt().then(response => {
            this.mktOption = response.data
          })
        },
        methods: {
          getList() {
            this.list = []
            this.listQuery.page = this.page
            this.listQuery.limit = this.limit
            this.queryType = 'list'
            this.listLoading = true
            getCollegeCurriculumPractices(this.listQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
            })
          },
          handleFilter() {
            this.seachQuery.page = this.page
            this.seachQuery.limit = this.limit
            this.queryType = 'query'
            this.listLoading = true
            getCollegeCurriculumPractices(this.seachQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
            })
          },
          comment_show(comment) {
            this.commentShow.comment = comment
            this.content = comment
            this.dialogFormVisible = true
          },
          handleFilterfirst() {
            this.seachQuery.page = 1
            this.seachQuery.limit = 10
            this.queryType = 'query'
            this.listLoading = true
            this.buttonloading = true
            getCollegeCurriculumPractices(this.seachQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
              this.buttonloading = false
            })
          },
          handleSizeChange(val) {
            this.limit = val
            if (this.queryType === 'list') {
              this.listQuery.limit = val
              this.listQuery.page = this.page
              this.getList()
            } else {
              this.seachQuery.limit = val
              this.seachQuery.page = this.page
              this.handleFilter()
            }
          },
          handleCurrentChange(val) {
            this.page = val
            if (this.queryType === 'list') {
              this.listQuery.limit = this.limit
              this.listQuery.page = val
              this.getList()
            } else {
              this.seachQuery.limit = this.limit
              this.seachQuery.page = val
              this.handleFilter()
            }
          },
          handleModifyStatus(row, status) {
            this.$message({
              message: '操作成功',
              type: 'success'
            })
            row.status = status
          },
          handleClose(done) {
            done()
          },
          contentChange() {
            this.wcTypeOption = []
            this.seachQuery.wc_showtime = null
            for (let i = 0; i < this.contentOption.length; i++) {
              if (this.contentOption[i].wct_code === this.seachQuery.c_type) {
                this.wcTypeOption = this.range(1, this.contentOption[i].wct_step, 1)
                break
              }
            }
          },
          hrefQrCode(qrcode) {
            this.dialogStatus = 'create'
            this.dialogPvVisible = true
            this.imgpath = qrcode
          },
          hrefdel(id) {
            createArticle(this.temp).then(() => {
              this.$confirm('此操作将永久删除该, 是否继续?', '提示', {
                confirmButtonText: '确定',
                cancelButtonText: '取消',
                type: 'warning'
              }).then(() => {
                var delParas = {
                  id: null
                }
                delParas.id = id
                deleteCollegeCurriculumPractice(delParas).then(response => {
                  if (response.data === 1) {
                    this.getList()
                    this.$notify({
                      title: '成功',
                      message: '删除成功',
                      type: 'success',
                      duration: 2000
                    })
                  } else {
                    this.$notify({
                      title: '失败',
                      message: '删除失败',
                      type: 'error',
                      duration: 2000
                    })
                  }
                })
              }).catch(() => {})
            })
          },
          hrefAdd() {
            this.$router.push({ name: 'curriculumpracticeadd' })
          },
          hrefedit(id) {
            this.$router.push({ name: 'curriculumpracticeedit', params: { contentID: id }})
          },
          infoshow(id) {
            this.$router.push({ name: 'curriculumpracticeshow', params: { contentID: id }})
          },
          handleDelete(row) {
            this.$notify({
              title: '成功',
              message: '删除成功',
              type: 'success',
              duration: 2000
            })
            const index = this.list.indexOf(row)
            this.list.splice(index, 1)
          },
          handleFetchPv(pv) {
            fetchPv(pv).then(response => {
              this.pvData = response.data.pvData
              this.dialogPvVisible = true
            })
          },
          handleref() {
            this.seachQuery.c_step = null
            this.seachQuery.c_type = null
            this.seachQuery.c_name = null
            this.seachQuery.credit = null
            this.seachQuery.branches = null
            this.seachQuery.startdate = null
            this.seachQuery.enddate = null
            this.seachQuery.deadline = null
            this.wcTypeOption = []
          },
          range(start, end, step) {
            var arr = []
            for (let i = start; i <= end; i++) {
              var tempOption = {
                label: null,
                value: null
              }
              if (i % step === 0) {
                tempOption.value = i
                tempOption.label = i
                arr.push(tempOption)
              }
            }
            return arr
          },
          formatJson(filterVal, jsonData) {
            return jsonData.map(v => filterVal.map(j => {
              if (j === 'timestamp') {
                return parseTime(v[j])
              } else {
                return v[j]
              }
            }))
          }
        }
      }
    </script>
    <style>
    .el-form--label-left .el-form-item__label{
      text-align:right
    }
    .el-rate{
      line-height: 0;
      margin-top:8px;
    }
    .el-checkbox.el-checkbox {
        margin-left: 30px;
    }
    .disabled .el-upload--picture-card {
        display: none;
    }
    </style>
    