<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item :label="systemName+'号'" prop="usercode">
        <el-input
            v-model="queryParams.usercode"
            :placeholder="'请输入'+systemName+'号'"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="来源" prop="actionType">
        <el-select v-model="queryParams.actionType" placeholder="来源" clearable size="small">
          <el-option
              v-for="dict in pointChangeLogActionTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="链路号" prop="traceId">
        <el-input
            v-model="queryParams.traceId"
            placeholder="请输入链路号"
            clearable
            @keyup.enter.native="handleQuery"
        />
      </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="pointChangeLogList" @selection-change="handleSelectionChange">
      <el-table-column :label="systemName+'号'" align="center" prop="usercode" />
      <el-table-column label="来源" align="center" prop="actionType" >
        <template v-slot="scope">
          <cai-dict-tag :options="pointChangeLogActionTypeList" :value="scope.row.actionType"/>
        </template>
      </el-table-column>
      <el-table-column label="变动" align="center" prop="changeValue" >
        <template v-slot="scope" >
          <span :class="scope.row.changeValue >= 0 ?'font-red':'font-green'">{{scope.row.changeValue}}</span>
        </template>
      </el-table-column>
      <el-table-column label="说明" align="center" prop="message" min-width="200">
        <template v-slot="scope">
          <div class="context-avatar-center">
            <span>{{scope.row.message}}</span><image-preview v-if="scope.row.tarImg" :src="scope.row.tarImg" :width="32" :height="32"/>
          </div>
        </template>
      </el-table-column>
      <el-table-column label="后台操作" align="center" prop="isAdmin" >
        <template v-slot="scope">
          <cai-dict-tag :options="yesOrNoList" :value="scope.row.isAdmin?1:0"/>
        </template>
      </el-table-column>
      <el-table-column label="操作时间" align="center" prop="createTime" width="160" />
      <el-table-column label="链路号" align="center" prop="traceId" show-overflow-tooltip/>
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
              size="mini"
              type="text"
              icon="el-icon-info"
              v-if="scope.row.traceId"
              @click="handleInfo(scope.row)"
          >关联业务</el-button>
        </template>
      </el-table-column>-->
    </el-table>

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

  </div>
</template>

<script>
import {listPointChangeLog} from "@/api/cai/pointChangeLog";
import {pointChangeLogActionTypeList, yesOrNoList} from "@/constant/statusMap";

export default {
  name: "PointChangeLog",
  data() {
    return {
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      pointChangeLogActionTypeList,yesOrNoList,
      // 按钮loading
      buttonLoading: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 积分记录表格数据
      pointChangeLogList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        usercode: undefined,
        actionType: undefined,
        traceId:undefined
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询积分记录列表 */
    getList() {
      this.loading = true;
      listPointChangeLog(this.queryParams).then(response => {
        this.pointChangeLogList = 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>
