    <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="8" :xl="8">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('querylist.mobilephone')" >
                  <div class="block">
                   <el-input style="width: 100%;" class="filter-item"
                      v-model="seachQuery.xu_phone" :maxlength = "20">
                  </el-input>
                  </div>
                </el-form-item>
              </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="8" :xl="8">
            <div class="grid-content bg-purple" >
              <el-form-item  :label="$t('college.present')" >
                <div class="block">
                  <el-select style="width: 100%;" class="filter-item" v-model="seachQuery.rule_id">
                    <el-option v-for="item in contentOption"  :key="item.id" :label="item.present_name" :value="item.id" >
                    </el-option>
                  </el-select>
                </div>
              </el-form-item>
            </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="12" :lg="7" :xl="7">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('college.create_at')" >
                  <el-date-picker v-model="seachQuery.date" value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions1" style="width: 100%;">
                  </el-date-picker>
                </el-form-item>
              </div>
          </el-col>
          </el-row>
          <el-row :gutter="24" style="margin-bottom:15px;">
            <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>
          <el-button class="filter-item" type="primary" icon="document" @click="handleDownload" :loading="downloadLoading">{{$t('excel.export')}} excel</el-button>
          </div>
          </el-row>
        </el-form>
        <el-table :data="list" v-loading="listLoading" element-loading-text="加载中......" border fit
                  highlight-current-row
                  style="width: 100%">
          <el-table-column align="center" :label="$t('querylist.mobilephone')">
            <template slot-scope="scope">
              <span>{{scope.row.xu_phone}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.present')">
            <template slot-scope="scope">
              <span>{{scope.row.context}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('college.collection_date')">
            <template slot-scope="scope">
              <span>{{scope.row.date}}</span>
            </template>
          </el-table-column>         
        </el-table>
        <div class="pagination-container">
          <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                        :current-page="page" :page-sizes="[10,300,500,1000]" :page-size="limit"
                        layout="total, sizes, prev, pager, next, jumper" :total="total">
          </el-pagination>
        </div>
        <el-dialog title="Reading statistics" :visible.sync="dialogPvVisible">
          <el-table :data="pvData" border fit highlight-current-row style="width: 100%">
            <el-table-column prop="key" label="Channel"></el-table-column>
            <el-table-column prop="pv" label="Pv"></el-table-column>
          </el-table>
          <span slot="footer" class="dialog-footer">
            <el-button type="primary" @click="dialogPvVisible = false">{{$t('table.confirm')}}</el-button>
          </span>
        </el-dialog>
      </div>
    </template>
    <script>
      import { fetchPv, updateArticle } from '@/api/article'
      import { queryCreditsLogs, getCollegePresentCredits } from '@/api/college'
      import { getAllMkt } from '@/api/wxmini'
      import waves from '@/directive/waves' // 水波纹指令
      import { parseTime } from '@/utils'
      // arr to obj ,such as { CN : "China", US : "USA" }
      export default {
        name: 'booking',
        directives: {
          waves
        },
        data() {
          return {
            list: null,
            total: null,
            page: 1,
            limit: 10,
            mktEnable: null,
            userMkt: null,
            queryType: 'list',
            contentOption: [],
            listLoading: true,
            buttonloading: false,
            listQuery: {
              importance: undefined,
              title: undefined,
              type: undefined,
              sort: '+id'
            },
            seachQuery: {
              xu_phone: null,
              rule_id: null,
              date: null,
              page: 1,
              limit: 10
            },
            pickerOptions1: {
              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)
                }
              }]
            },
            sortOptions: [{ label: 'ID Ascending', key: '+id' }, { label: 'ID Descending', key: '-id' }],
            present_type: [{ label: '优惠券', key: '1' }, { label: '到店领取', key: '2' }, { label: '邮寄', key: '3' }],
            showReviewer: false,
            ethnicgroupptions: '',
            provinceoptions: '',
            dialogFormVisible: false,
            checkidcard: {
              idcard: undefined
            },
            dialogStatus: '',
            textMap: {
              update: 'Edit',
              create: '添加月嫂'
            },
            dialogPvVisible: false,
            pvData: [],
            mktOptions: [],
            updateStatus: {
              id: undefined,
              status: undefined
            },
            downloadLoading: false
          }
        },
        created() {
          this.getList()
          getAllMkt().then(response5 => {
            this.mktOptions = response5.data
          })
          getCollegePresentCredits().then(response => {
            this.contentOption = response.data
          })
          this.userMkt = this.$store.getters.mkt
          if (this.userMkt !== 'ALL') {
            this.seachQuery.od_cityid = this.userMkt
            this.mktEnable = true
          }
        },
        methods: {
          getList() {
            this.listQuery.page = this.page
            this.listQuery.limit = this.limit
            this.queryType = 'list'
            this.listLoading = true
            queryCreditsLogs(this.listQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
            })
          },
          handleFilter() {
            if (this.seachQuery.experience === 0) {
              this.seachQuery.experience = null
            }
            this.seachQuery.page = this.page
            this.seachQuery.limit = this.limit
            this.queryType = 'query'
            this.listLoading = true
            queryCreditsLogs(this.seachQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.listLoading = false
            })
          },
          handleFilterfirst() {
            this.seachQuery.page = 1
            this.seachQuery.limit = 10
            this.queryType = 'query'
            this.listLoading = true
            this.buttonloading = true
            queryCreditsLogs(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) {
            this.$confirm('确认关闭？').then(_ => {
              done()
            }).catch(_ => {})
          },
          handleUpdate(row) {
            this.temp = Object.assign({}, row) // copy obj
            this.temp.timestamp = new Date(this.temp.timestamp)
            this.dialogStatus = 'update'
            this.dialogFormVisible = true
            this.$nextTick(() => {
              this.$refs['dataForm'].clearValidate()
            })
          },
          hrefordertempedit(id) {
            this.$router.push({ name: 'ysordereditedit', params: { orderid: id }})
          },
          updateData() {
            this.$refs['dataForm'].validate((valid) => {
              if (valid) {
                const tempData = Object.assign({}, this.temp)
                tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
                updateArticle(tempData).then(() => {
                  for (const v of this.list) {
                    if (v.id === this.temp.id) {
                      const index = this.list.indexOf(v)
                      this.list.splice(index, 1, this.temp)
                      break
                    }
                  }
                  this.dialogFormVisible = false
                  this.$notify({
                    title: '成功',
                    message: '更新成功',
                    type: 'success',
                    duration: 2000
                  })
                })
              }
            })
          },
          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
            })
          },
          handleDownload() {
            this.downloadLoading = true
            import('@/vendor/Export2Excel').then(excel => {
              const tHeader = ['手机号', '预约日期', '预约类型', '预产期', '介绍人手机号', '介绍人顾问', '描述']
              const filterVal = ['bk_phone', 'bk_date', 'bk_typedesc', 'bk_duedate', 'bk_introducer_phone', 'bk_introducer_consultant', 'bk_desc']
              const list = this.list
              const data = this.formatJson(filterVal, list)
              excel.export_json_to_excel({
                header: tHeader,
                data,
                filename: '小程序预约信息',
                autoWidth: this.autoWidth
              })
              this.downloadLoading = false
            })
          },
          handleref() {
            this.seachQuery.xu_phone = null
            this.seachQuery.date = null
            this.seachQuery.rule_id = null
            this.seachQuery.page = 1
            this.seachQuery.limit = 10
          },
          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;
    }
    </style>
    