<template>
  <el-dialog title="账户明细" :close-on-click-modal="false" :visible.sync="open" width="1000px" append-to-body>
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="账户类型" prop="accountType">
        <el-select v-model="queryParams.accountType" placeholder="账户类型" clearable size="small">
          <el-option
              v-for="dict in accountTypeList"
              :key="dict.value"
              :label="dict.label"
              :value="dict.value"
              @keyup.enter.native="handleQuery"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="业务操作" prop="cateId">
        <el-select v-model="queryParams.cateId" placeholder="业务操作" clearable size="small">
          <el-option
              v-for="dict in changeTypeList"
              :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-row :gutter="10" class="mb8">
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="accountChangeLogList" >
      <el-table-column :label="systemName+'号'" align="center" prop="usercode" />
      <el-table-column label="账户类型" align="center" prop="accountType" >
        <template v-slot="scope">
          <cai-dict-tag :options="accountTypeList" :value="scope.row.accountType"/>
        </template>
      </el-table-column>
      <el-table-column label="业务操作" align="center" prop="cateAdminName" />
      <el-table-column label="变动" align="center" prop="changeValue" />
      <el-table-column label="说明" align="center" prop="remark" min-width="200">
        <template v-slot="scope">
          <div class="context-avatar-center">
            <span>{{scope.row.showMessage}}</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"/>
        </template>
      </el-table-column>
      <el-table-column label="操作时间" align="center" prop="createTime" min-width="120" />
<!--      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template v-slot="scope">
        </template>
      </el-table-column>-->
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />
    <div slot="footer" class="dialog-footer">
      <el-button @click="open = false">取 消</el-button>
    </div>
  </el-dialog>
</template>

<script>
import {getUserByUsercode, listUserByUserCode} from "@/api/cai/user";
import { listMemberPrice } from '@/api/cai/memberPrice'
import { addUserMember } from '@/api/cai/userMember'
import {updateAccountCoin} from "@/api/cai/account";
import {listGoods} from "@/api/cai/goods";
import {accountTypeList, yesOrNoList} from "@/constant/statusMap";
import {listAccountChangeLog, listChangeType} from "@/api/cai/accountChangeLog";

export default {
  components: {
  },
  data () {
    return {
      accountTypeList,yesOrNoList,
      systemName: process.env.VUE_APP_SYSTEM_HOME,
      open: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 账户明细表格数据
      accountChangeLogList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: undefined,
        accountType: undefined,
        cateId: undefined
      },
      changeTypeList:[],
    }
  },
  created() {
  },
  methods: {
    init (id) {
      this.open = true;
      this.queryParams.userId = id
      this.getList();
      listChangeType().then(res => {
        this.changeTypeList = res.data
      })
    },
    /** 查询账户明细列表 */
    getList() {
      this.loading = true;
      listAccountChangeLog(this.queryParams).then(response => {
        this.accountChangeLogList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
}
</script>
<style lang="scss" scoped>
.context-avatar-center {
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
}
</style>
