<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item :label="'消费方'+systemName+'号'" prop="sourceUsercode">
        <el-input
            v-model="queryParams.sourceUsercode"
            :placeholder="'请输入'+systemName+'号'"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item :label="'邀请方'+systemName+'号'" prop="oneUsercode">
        <el-input
            v-model="queryParams.oneUsercode"
            :placeholder="'请输入邀请方'+systemName+'号'"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="分销" prop="status">
        <el-select v-model="queryParams.status" clearable size="small">
          <el-option
              v-for="dict in consumeLogStatusList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="loading" :data="pointRecordLogList" @selection-change="handleSelectionChange">
      <el-table-column label="状态" align="center" prop="status" width="80" >
        <template v-slot="scope">
          <cai-dict-tag :options="consumeLogStatusList" :value="scope.row.status"/>
        </template>
      </el-table-column>
      <el-table-column label="消费方" align="center" prop="sourceUser" width="200">
        <template v-slot="scope">
          <span style="font-weight: bold">{{systemName}}号:</span><span>{{scope.row.sourceUsercode}}</span> <br>
          <span style="font-weight: bold">手机号:</span><span>{{scope.row.sourcePhone}}</span><br>
        </template>
      </el-table-column>
      <el-table-column label="发生积分" align="center" prop="points" />
      <el-table-column label="邀请方" align="center" prop="invite" min-width="200" >
        <template v-slot="scope">
          <div v-if="scope.row.oneUsercode">
            <span style="font-weight: bold">邀请人:</span><span>{{scope.row.oneUsercode}}({{scope.row.onePhone}})</span> <br>
            <span style="font-weight: bold">分销:</span><span :class="joinColor(scope.row.oneJoin)">{{scope.row.oneJoin ? '参与' : '不参与'}}</span><br>
            <span style="font-weight: bold">费率/金额:</span>
            <span>
                <span class="font-green">{{scope.row.oneRate}}</span>
              /
              <span class="font-red">{{scope.row.onePoints}}</span>
              </span> <br>
          </div>
          <span v-if="!scope.row.oneUsercode">-</span>
        </template>
      </el-table-column>
      <el-table-column label="创建时间" align="center" prop="createTime" />
      <el-table-column label="来源" align="center" prop="sourceType" />
      <el-table-column label="来源ID" align="center" prop="sourceId" />
      <el-table-column label="备注" align="center" prop="remark" />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {listPointRecordLog} from "@/api/cai/pointRecordLog";
import {consumeLogCalculateStatusList, consumeLogStatusList, consumeLogTypeList} from "@/constant/statusMap";

export default {
  name: "PointRecordLog",
  data() {
    return {
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      consumeLogTypeList,consumeLogStatusList,consumeLogCalculateStatusList,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户积分分销表格数据
      pointRecordLogList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sourceUsercode: undefined,
        oneUsercode: undefined,
        status: undefined,
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    joinColor(join){
      return join ? 'font-blue' : 'font-red'
    },
    /** 查询用户积分分销列表 */
    getList() {
      this.loading = true;
      listPointRecordLog(this.queryParams).then(response => {
        this.pointRecordLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
  }
};
</script>
<style lang="scss" scoped>
.font-red {
  color: red;
}
.font-green {
  color: green;
}
.font-blue {
  color: blue;
}
</style>
