<template>
  <div class="app-container">
    <!-- 搜索工作栏 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="140px">
      <el-form-item label="推广人姓名" prop="oldUserName">
        <el-input v-model="queryParams.oldUserName" placeholder="请输入推广人姓名" clearable @keyup.enter.native="handleQuery"/>
      </el-form-item>
      <el-form-item label="推广人角色" prop="userType">
        <el-select v-model="queryParams.userType" placeholder="请选择推广人角色" clearable size="small">
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.SYSTEM_USER_TYPE)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
<!--      <el-form-item label="推广人推广码" prop="uniqueCode">-->
<!--        <el-input v-model="queryParams.uniqueCode" placeholder="请输入推广人推广码" clearable @keyup.enter.native="handleQuery"/>-->
<!--      </el-form-item>-->
      <el-form-item label="被推广人姓名" prop="newUserName">
        <el-input v-model="queryParams.newUserName" placeholder="请输入被推广人姓名" clearable
                  @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="推广渠道" prop="promotionChannel">
        <el-select v-model="queryParams.promotionChannel" placeholder="请选择推广渠道" clearable size="small">
          <el-option
            v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_CHANNEL)"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="被推广人注册时间" prop="registerTimeArray">
        <el-date-picker v-model="queryParams.registerTimeArray" style="width: 240px" value-format="yyyy-MM-dd HH:mm:ss"
                        type="daterange"
                        range-separator="-" start-placeholder="开始日期" end-placeholder="结束日期"
                        :default-time="['00:00:00', '23:59:59']"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="list" :stripe="true" :show-overflow-tooltip="true">
      <el-table-column label="序号" align="center">
        <template scope="scope">
          <span>{{ scope.$index + 1 }}</span>
        </template>
      </el-table-column>
      <el-table-column label="推广人姓名" align="center" prop="oldUserName" width="180" />
      <el-table-column label="推广人电话" align="center" prop="oldUser.mobile" width="180" />
      <el-table-column label="推广人角色" align="center" prop="oldUser.userType" width="180">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.SYSTEM_USER_TYPE" :value="scope.row.oldUser.userType"/>
        </template>
      </el-table-column>
      <el-table-column label="推广人推广码" align="center" prop="uniqueCode" width="180">
        <template v-slot="scope">
          <qriously :value="scope.row.uniqueCode" :options="{ width: 100, height: 100 }"/>
        </template>
      </el-table-column>
      <el-table-column label="推广渠道" align="center" prop="promotionChannel" width="180">
        <template v-slot="scope">
          <dict-tag :type="DICT_TYPE.PROMOTION_CHANNEL" :value="scope.row.promotionChannel"/>
        </template>
      </el-table-column>
      <el-table-column label="被推广人姓名" align="center" prop="newUserName" width="180" />
      <el-table-column label="被推广人电话" align="center" prop="newUser.mobile" width="180" />
      <el-table-column label="被推广人注册时间" align="center" prop="registerTime" width="180" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right" width="180">
        <template v-slot="scope">
          <el-button size="mini" type="text" icon="el-icon-search" @click="openForm(scope.row)"
          >列表查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNo" :limit.sync="queryParams.pageSize"
                @pagination="getList"
    />

    <PromotionData ref="promotionData" @success="getList" />
  </div>
</template>

<script>

import * as PromotionApi from '@/api/company/promotion'
import PromotionData from '@/views/company/promotion/form/PromotionData'

export default {
  name: 'Promotion',
  components: {
    PromotionData
  },
  data() {
    return {
      // 查询参数
      queryParams: {
        pageNo: 1,
        pageSize: 10,
        oldUserName: null,
        promotionChannel: null,
        newUserName: null,
        registerTimeArray: null,
        uniqueCode: null,
        userType: null
      },
      // 显示搜索条件
      showSearch: true,
      total: 0,
      // 遮罩层
      loading: true,
      list:[],
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询列表 */
    async getList() {
      try {
        this.loading = true
        const res = await PromotionApi.getBasePromotionPage(this.queryParams)
        this.list = res.data.records
        this.total = res.data.total
      } finally {
        this.loading = false
      }
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNo = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm')
      this.handleQuery()
    },
    /** 列表查看操作 */
    openForm(row) {
      this.$refs['promotionData'].open(row)
    },
  }
}
</script>

<style scoped>

</style>
