<template>
  <div v-loading="loading">
    <div class="heior_box">
      <el-button
        size="small"
        type="primary"
        icon="el-icon-sold-out"
         v-if="$local.isRoot()"
        @click="dataExport"
      >导出</el-button>
      <!-- <el-button size="small" type="primary" icon="el-icon-sold-out" @click="dataExport" v-if="$local.isRoot()">导出</el-button> -->
      <div class="search-box">
        <el-date-picker
          size="small"
          v-model="dateRange1"
          type="daterange"
          range-separator="至"
          start-placeholder="A开始日期"
          end-placeholder="A结束日期"
        ></el-date-picker>
        <el-date-picker
          size="small"
          v-model="dateRange2"
          type="daterange"
          range-separator="至"
          start-placeholder="B开始日期"
          end-placeholder="B结束日期"
        ></el-date-picker>
        <el-select
          v-model="searchModel.profile"
          clearable
          size="small"
          placeholder="状态"
        >
          <el-option v-for="item in types" :key="item.label" :label="item.label" :value="item.value"></el-option>
        </el-select>
        <el-input v-model="searchModel.keyWord" placeholder="请输入会员号" clearable size="small">
          <el-button slot="append" icon="el-icon-search" @click="search"></el-button>
        </el-input>
      </div>
    </div>
    <el-table :data="retData.Data" size="medium" :height="$getHeight(300)"
     @sort-change="sort"
     row-key="Id" border>
      <el-table-column prop="Profile" label="状态" width="240">
         <template slot-scope="scope">
          <el-dropdown size="small" split-button type="primary">
            {{scope.row.UserInfo.Profile}}
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="changeProfile(scope.row,'已完成')">已完成</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'高意向客户')">高意向客户</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'待跟进-消费减少')">待跟进-消费减少</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'待跟进-未购买')">待跟进-未购买</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'跟进超时-消费减少')">跟进超时-消费减少</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'跟进超时-未购买')">跟进超时-未购买</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'流失-需求减少')">流失-需求减少</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'流失-暂时不用')">流失-暂时不用</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'流失-价格问题')">流失-价格问题</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'流失-产品问题')">流失-产品问题</el-dropdown-item>
              <el-dropdown-item @click.native="changeProfile(scope.row,'跟进超时')">跟进超时</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
        </template>
      </el-table-column>
      <el-table-column prop="UserName" label="用户">
        <template slot-scope="scope">
          <phoneHide :text="scope.row.UserName"></phoneHide>
        </template>
      </el-table-column>
      <el-table-column prop="UserName" label="联系信息">
        <template slot-scope="scope">
          <p v-if="scope.row.UserInfo.Wx">微信:{{scope.row.UserInfo.Wx}}</p>
          <p v-if="scope.row.UserInfo.QQ">QQ:{{scope.row.UserInfo.QQ}}</p>
          <p v-if="scope.row.UserInfo.TaoBao">淘宝:{{scope.row.UserInfo.TaoBao}}</p>
          <p v-if="scope.row.UserInfo.WangWang">旺旺:{{scope.row.UserInfo.WangWang}}</p>
        </template>
      </el-table-column>
       <el-table-column prop="CreateTime" label="注册时间"></el-table-column>
      <el-table-column prop="PrevMonthAmount" label="消费金额A" sortable="custom"></el-table-column>
      <el-table-column prop="MonthAmount" label="消费金额B" sortable="custom"></el-table-column>
       <el-table-column prop="AddAmount" label="对比增长金额" sortable="custom">
        <!-- <template slot-scope="scope">
             {{scope.row.MonthAmount-scope.row.PrevMonthAmount}}
        </template> -->
       </el-table-column>
      <el-table-column prop="TotalAccountCount" label="账户总数" sortable="custom"></el-table-column>
      <el-table-column prop="UsingAccountCount" label="使用中个数" sortable="custom"></el-table-column>
      <el-table-column prop="ExpirdAccountCount" label="过期个数" sortable="custom"></el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        v-if="retData.Data.length>0"
        @current-change="get"
        :page-size="50"
        :current-page.sync="searchModel.PageIndex"
        layout="total,prev, pager, next"
        :total="retData.TotalCount"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import * as dateUtil from '@/extend/js/dateFormatUtil'
export default {
  name: 'userIndex',
  components: {
    phoneHide: () => import('@/components/common/phonehide')
  },
  data () {
    return {
      loading: false,
      retData: { TotalCount: 0, Data: [] },
      dateRange1: [],
      dateRange2: [],
      searchModel: {
        PageIndex: 1,
        keyWord: '',
        sortLable: '',
        sortOrder: 0,
        profile: ''
      },
      types: [
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '已完成', label: '已完成'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '高意向客户', label: '高意向客户'},
        // eslint-disable-next-line indent
      // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '待跟进-消费减少', label: '待跟进-消费减少'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '待跟进-未购买', label: '待跟进-未购买'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '跟进超时-消费减少', label: '跟进超时-消费减少'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '跟进超时-未购买', label: '跟进超时-未购买'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '流失-需求减少', label: '流失-需求减少'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '流失-暂时不用', label: '流失-暂时不用'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '流失-价格问题', label: '流失-价格问题'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '流失-产品问题', label: '流失-产品问题'},
        // eslint-disable-next-line standard/object-curly-even-spacing
        { value: '跟进超时', label: '跟进超时'}
      ]
    }
  },
  created () {
    this.$store.commit('setCurrentNav', '用户管理>>消费统计')
    this.dateRange1[0] = dateUtil.getLastMonthStartDate()
    this.dateRange1[1] = dateUtil.getLastMonthCurrentDate()

    this.dateRange2[0] = dateUtil.getMonthStartDate()
    this.dateRange2[1] = dateUtil.getMonthCurrentDate()
    this.get()
  },
  methods: {
    // eslint-disable-next-line standard/object-curly-even-spacing
    sort ({column, prop, order }) {
      console.log(column)
      console.log(prop)
      console.log(order)
      this.searchModel.sortLable = prop
      // eslint-disable-next-line eqeqeq
      this.searchModel.sortOrder = order == 'ascending' ? 0 : 1
      this.search()
    },
    changeProfile (row, command) {
      row.UserInfo.Profile = command
      this.$api
        .post('baseinfo/v1/user/UpdateProfile', {UserId: row.UserInfo.Id, Profile: command})
        .then(res => {})
    },
    search () {
      this.searchModel.PageIndex = 1
      this.get()
    },
    get () {
      this.loading = true
      if (this.dateRange1 && this.dateRange1.length === 2) {
        this.searchModel.bTime1 = this.dateRange1[0]
        this.searchModel.eTime1 = this.dateRange1[1]
      }
      if (this.dateRange2 && this.dateRange2.length === 2) {
        this.searchModel.bTime2 = this.dateRange2[0]
        this.searchModel.eTime2 = this.dateRange2[1]
      }
      this.$api
        .get('course/v1/order/UserConsumeStatistics', this.searchModel)
        .then(res => {
          this.retData = res
          this.loading = false
        })
    },
    dataExport () {
      this.$api.getDownloadFile('/course/v1/order/ExportUserConsumeStatistics', this.searchModel)
    }
  }
}
</script>
<style scoped>
</style>
