    <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('querylist.mobilephone')" >
                <div class="block">
                  <el-input style="width: 100%;" class="filter-item"
                      v-model="seachQuery.pd_phone" :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('booking.duedate')" >
                <div class="block">
                  <el-date-picker v-model="seachQuery.pd_duedate" value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions1" 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('booking.bookingdate')" >
                <div class="block">
                  <el-date-picker v-model="seachQuery.pd_date" value-format="yyyy-MM-dd" align="right" type="date" placeholder="选择日期" :picker-options="pickerOptions1" 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('promotion.name')" >
                <div class="block">
                    <el-select class="filter-item" v-model="seachQuery.pd_prom_id" default-first-optionplaceholder="请选活动" style="width: 100%;">
                    <el-option v-for="item in promotionOptions" :key="item.id" :label="item.pd_title" :value="item.id">
                    </el-option>
                  </el-select>
                </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')" >
                <div class="block">
                    <el-select v-if="mktEnable" class="filter-item" disabled v-model="seachQuery.pd_city" default-first-optionplaceholder="请选择城市" style="width:100%;">
                    <el-option v-for="item in branchesOptions" :key="item.branche_code" :label="item.branche_name" :value="item.branche_code">
                    </el-option>
                  </el-select>
                  <el-select v-else class="filter-item" v-model="seachQuery.pd_city" default-first-optionplaceholder="请选择城市" style="width:100%;">
                    <el-option v-for="item in branchesOptions" :key="item.branche_code" :label="item.branche_name" :value="item.branche_code">
                    </el-option>
                  </el-select>
                </div>
              </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.pd_phone}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('booking.duedate')">
            <template slot-scope="scope">
              <span>{{scope.row.pd_duedate}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('booking.bookingdate')">
            <template slot-scope="scope">
              <span>{{scope.row.pd_date}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('promotion.name')">
            <template slot-scope="scope">
              <span>{{scope.row.pd_prom_name}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('promotion.consultname')">
            <template slot-scope="scope">
              <span>{{scope.row.consultname}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('promotion.mkt')">
            <template slot-scope="scope">
              <span>{{scope.row.pd_cityname}}</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, getBranches } from '@/api/article'
      import { getPromotionDCUserInfos, getPromotionDCs } from '@/api/promotion'
      import waves from '@/directive/waves' // 水波纹指令
      import { parseTime } from '@/utils'
      // arr to obj ,such as { CN : "China", US : "USA" }
      export default {
        name: 'promotiondcbooking',
        directives: {
          waves
        },
        data() {
          return {
            userMkt: null,
            mktEnable: null,
            list: null,
            total: null,
            page: 1,
            limit: 10,
            queryType: 'list',
            listLoading: true,
            buttonloading: false,
            listQuery: {
              po_mkt: undefined,
              importance: undefined,
              pd_prom_id: undefined,
              title: undefined,
              type: undefined,
              sort: '+id'
            },
            seachQuery: {
              pd_phone: undefined,
              pd_duedate: undefined,
              pd_prom_id: undefined,
              pd_date: undefined,
              pd_city: undefined,
              page: null,
              limit: null
            },
            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)
                }
              }]
            },
            showReviewer: false,
            ethnicgroupptions: '',
            provinceoptions: '',
            dialogFormVisible: false,
            dialogStatus: '',
            dialogPvVisible: false,
            pvData: [],
            downloadLoading: false,
            branchesOptions: [],
            promotionOptions: []
          }
        },
        created() {
          this.userMkt = this.$store.getters.mkt
          if (this.userMkt !== 'ALL') {
            this.seachQuery.pd_city = this.userMkt
            this.listQuery.pd_city = this.userMkt
            this.mktEnable = true
          }
          this.list = []
          this.listLoading = false
          this.getList()
          getBranches().then(response5 => {
            this.branchesOptions = response5.data
          })
          getPromotionDCs().then(response6 => {
            this.promotionOptions = response6.data
            this.listQuery.pd_prom_id = response6.data[0].id
          })
        },
        methods: {
          getList() {
            this.listQuery.page = this.page
            this.listQuery.limit = this.limit
            this.queryType = 'list'
            this.listLoading = true
            getPromotionDCUserInfos(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
            getPromotionDCUserInfos(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
            getPromotionDCUserInfos(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()
            })
          },
          handleFetchPv(pv) {
            fetchPv(pv).then(response => {
              this.pvData = response.data.pvData
              this.dialogPvVisible = true
            })
          },
          handleref() {
            this.seachQuery.pd_phone = null
            this.seachQuery.pd_duedate = null
            this.seachQuery.pd_prom_id = null
            this.seachQuery.pd_date = null
            this.seachQuery.page = 1
            this.seachQuery.pd_city = null
            this.seachQuery.limit = 10
            if (this.userMkt !== 'ALL') {
              this.seachQuery.pd_city = this.userMkt
            }
          },
          handleDownload() {
            this.downloadLoading = true
            import('@/vendor/Export2Excel').then(excel => {
              const tHeader = ['手机号', '预产期', '预约日期', '活动名称', '门店']
              const filterVal = ['pd_phone', 'pd_duedate', 'pd_date', 'pd_prom_name', 'pd_cityname']
              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
            })
          },
          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>
    