    <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="12" :xl="12">
              <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('dc.dates')" >
                  <div class="block">
                  <el-date-picker
                    style="width:100%;"
                    v-model="seachQuery.date"
                    type="daterange"
                    range-separator="至"
                    start-placeholder="开始日期"
                    end-placeholder="结束日期">
                  </el-date-picker>
                  </div>
                </el-form-item>
              </div>
          </el-col>
          <el-col :xs="23" :sm="23" :md="11" :lg="11" :xl="11">
            <div class="grid-content bg-purple" >
                <el-form-item  :label="$t('dc.event')" >
                  <div class="block">
                    <el-select class="filter-item" v-model="reportQuery.xul_event" filterable  style="width: 100%;">
                    <el-option v-for="item in eventType" :key="item.key" :label="item.label" :value="item.key">
                    </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('dc.dc_xul_introducer_phone')" >
                  <div class="block">
                    <el-input style="width: 100%;" class="filter-item"
                      v-model="reportQuery.xul_introducer_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('dc.dc_xul_phone')" >
                  <div class="block">
                    <el-input style="width: 100%;" class="filter-item"
                      v-model="reportQuery.xul_phone" :maxlength = "20">
                  </el-input>
                  </div>
                </el-form-item>
              </div>
          </el-col>
          </el-row>
          <el-row :gutter="24" style="margin-bottom:15px;">
          <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="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>
          <el-button class="filter-item" type="primary" icon="document" @click="handleDownload" :loading="downloadLoading">{{$t('excel.export')}} excel</el-button>
          </div>
          </el-col>
          </el-row>
        </el-form>
        <el-table :key='tableKey' :data="list" v-loading="listLoading" element-loading-text="加载中......" border fit
                  highlight-current-row :span-method="objectSpanMethod"
                  style="width: 100%">
          <el-table-column align="center" :label="$t('dc.dc_xul_introducer_phone')">
            <template slot-scope="scope">
              <span>{{scope.row.xul_introducer_phone}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('dc.dc_xul_phone')">
              <template slot-scope="scope" align="right">
              <span>{{scope.row.xul_phone}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('dc.dc_event_date')" >
            <template slot-scope="scope">
              <span>{{scope.row.xul_date}}</span>
            </template>
          </el-table-column>
          <el-table-column align="center" :label="$t('order.orderno')">
              <template slot-scope="scope">
                <span>{{scope.row.xul_orderno}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('order.amount')">
              <template slot-scope="scope">
                <span id="moeny">{{scope.row.od_order_amount|numFilter}}</span>
              </template>
            </el-table-column>
            <el-table-column align="center" :label="$t('dc.od_rebate_amount')">
              <template slot-scope="scope">
                <span id="moeny">{{scope.row.od_rebate_amount|numFilter}}</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 } from '@/api/article'
      import { getDcReport } from '@/api/dc'
      import waves from '@/directive/waves' // 水波纹指令
      import { parseTime } from '@/utils'
      import config from '@/utils/config'
      // arr to obj ,such as { CN : "China", US : "USA" }
      export default {
        name: 'introducerdcreport',
        directives: {
          waves
        },
        computed: {
          uploadDisabled() {
            return this.fileListvoucher.length > 0
          }
        },
        filters: {
          numFilter(value) {
            return parseFloat(value).toFixed(2)
          }
        },
        data() {
          return {
            tableKey: 0,
            url: config.BASE_URL + '/getAccountNumber',
            fileListvoucher: [],
            channelOptions: [],
            list: null,
            dis: 1,
            total: null,
            page: 1,
            limit: 10,
            queryType: 'list',
            listLoading: true,
            spanArr: [],
            pos: 0,
            buttonloading: false,
            dialogbuttonloading: false,
            dialogImageUrl: undefined,
            listQuery: {
              importance: undefined,
              title: undefined,
              type: undefined,
              sort: '+id'
            },
            checkdate: {
              servant_code: undefined,
              stock_status: undefined,
              start_date: undefined,
              end_date: undefined
            },
            datavoucher: {
              phone: null
            },
            seachQuery: {
              date: null
            },
            idcardquery: {
              idcard: null
            },
            ordertemepdel: {
              id: undefined
            },
            checksalt: {
              salt: undefined
            },
            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)
                }
              }]
            },
            eventType: [{ label: '已注册', key: 2 }, { label: '定金支付', key: 5 }, { label: '尾款支付', key: 6 }, { label: '订单完成', key: 7 }, { label: '返现', key: 8 }],
            showReviewer: false,
            dialogVisible: false,
            tips: null,
            ethnicgroupptions: '',
            provinceoptions: '',
            dialogFormVisible: false,
            checkidcard: {
              idcard: undefined
            },
            dialogStatus: '',
            textMap: {
              update: 'Edit',
              create: '添加月嫂'
            },
            reportQuery: {
              start_date: null,
              end_date: null,
              xul_event: 2,
              xul_phone: null,
              xul_introducer_phone: null,
              page: 1,
              limit: 10
            },
            dialogPvVisible: false,
            pvData: [],
            updateStatus: {
              id: undefined,
              status: undefined
            },
            downloadLoading: false
          }
        },
        created() {
          this.reportQuery.xul_event = 2
          this.getList()
        },
        methods: {
          getList() {
            this.listQuery.page = this.page
            this.listQuery.limit = this.limit
            this.queryType = 'list'
            this.listLoading = true
            getDcReport(this.reportQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.spanArr = []
              this.pos = 0
              for (var i = 0; i < response.data.items.length; i++) {
                if (i === 0) {
                  this.spanArr.push(1)
                  this.pos = 0
                } else {
                  if (response.data.items[i].xul_introducer_phone === response.data.items[i - 1].xul_introducer_phone) {
                    this.spanArr[this.pos] += 1
                    this.spanArr.push(0)
                  } else {
                    this.spanArr.push(1)
                    this.pos = i
                  }
                }
              }
              this.listLoading = false
            })
          },
          objectSpanMethod({ row, column, rowIndex, columnIndex }) {
            if (columnIndex === 0) {
              const _row = this.spanArr[rowIndex]
              const _col = _row > 0 ? 1 : 0
              return {
                rowspan: _row,
                colspan: _col
              }
            }
          },
          handleFilter() {
            this.reportQuery.page = this.page
            this.reportQuery.limit = this.limit
            this.queryType = 'query'
            this.listLoading = true
            if (this.seachQuery.date !== null) {
              var startdate = new Date(this.seachQuery.date[0])
              var enddate = new Date(this.seachQuery.date[1])
              this.reportQuery.start_date = startdate.getFullYear() + '-' + (startdate.getMonth() + 1) + '-' + startdate.getDate()
              this.reportQuery.end_date = enddate.getFullYear() + '-' + (enddate.getMonth() + 1) + '-' + enddate.getDate()
            } else {
              this.reportQuery.start_date = null
              this.reportQuery.end_date = null
            }
            getDcReport(this.reportQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.spanArr = []
              this.pos = 0
              for (var i = 0; i < response.data.items.length; i++) {
                if (i === 0) {
                  this.spanArr.push(1)
                  this.pos = 0
                } else {
                  if (response.data.items[i].xul_introducer_phone === response.data.items[i - 1].xul_introducer_phone) {
                    this.spanArr[this.pos] += 1
                    this.spanArr.push(0)
                  } else {
                    this.spanArr.push(1)
                    this.pos = i
                  }
                }
              }
              this.listLoading = false
            })
          },
          handleFilterfirst() {
            this.reportQuery.page = 1
            this.reportQuery.limit = 10
            this.page = 1
            this.limit = 10
            this.queryType = 'query'
            this.listLoading = true
            this.buttonloading = true
            if (this.seachQuery.date !== null) {
              var startdate = new Date(this.seachQuery.date[0])
              var enddate = new Date(this.seachQuery.date[1])
              this.reportQuery.start_date = startdate.getFullYear() + '-' + (startdate.getMonth() + 1) + '-' + startdate.getDate()
              this.reportQuery.end_date = enddate.getFullYear() + '-' + (enddate.getMonth() + 1) + '-' + enddate.getDate()
            } else {
              this.reportQuery.start_date = null
              this.reportQuery.end_date = null
            }
            getDcReport(this.reportQuery).then(response => {
              this.list = response.data.items
              this.total = response.data.total
              this.spanArr = []
              this.pos = 0
              for (var i = 0; i < response.data.items.length; i++) {
                if (i === 0) {
                  this.spanArr.push(1)
                  this.pos = 0
                } else {
                  if (response.data.items[i].xul_introducer_phone === response.data.items[i - 1].xul_introducer_phone) {
                    this.spanArr[this.pos] += 1
                    this.spanArr.push(0)
                  } else {
                    this.spanArr.push(1)
                    this.pos = i
                  }
                }
              }
              this.listLoading = false
              this.buttonloading = false
            })
          },
          handleSizeChange(val) {
            this.limit = val
            this.reportQuery.limit = val
            this.reportQuery.page = this.page
            this.handleFilter()
          },
          handleCurrentChange(val) {
            this.page = val
            this.reportQuery.limit = this.limit
            this.reportQuery.page = val
            this.handleFilter()
          },
          handleClose(done) {
            this.$confirm('确认关闭？').then(_ => {
              done()
            }).catch(_ => {})
          },
          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 = ['xul_introducer_phone', 'xul_phone', 'xul_date', 'orderno', 'amount', 'od_rebate_amount']
              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.date = null
            this.reportQuery.start_date = null
            this.reportQuery.end_date = null
            this.reportQuery.xul_introducer_phone = null
            this.reportQuery.xul_phone = null
            this.reportQuery.page = 1
            this.reportQuery.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;
    }
    .disabled .el-upload--picture-card {
        display: none;
    }
    </style>
    