<template>
  <div class="p-2">
    <div v-show="show">
      <el-card shadow="hover" class="mb-[10px]">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px" size="default" class="ry_form">
          <el-form-item label="名称" prop="name">
            <el-input v-model.trim="queryParams.id" placeholder="请输入会员名称" clearable />
          </el-form-item>
          <el-form-item label="手机号码" prop="phone">
            <el-input v-model.trim="queryParams.phone" placeholder="请输入手机号码" clearable />
          </el-form-item>
          <el-form-item label="类型" prop="type">
            <!-- 1 用户 2 商家 3 代理 4 平台 -->
            <el-select v-model="queryParams.type" placeholder="请选择" clearable>
              <el-option label="用户" value="1" />
              <el-option label="商家" value="2" />
              <el-option label="代理" value="3" />
              <el-option label="平台" value="4" />
            </el-select>
          </el-form-item>
          <el-form-item class="flex_one tr">
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-card shadow="hover">
        <el-table v-loading="loading" :data="umsAccountList" border empty-text="暂无数据">
          <el-table-column label="昵称" prop="nickname" align="center" />
          <el-table-column label="手机号" prop="phone" align="center" />
          <el-table-column label="钱包" prop="wallet" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.wallet || '0.00' }} </template>
          </el-table-column>
          <el-table-column label="营收" prop="revenue" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.revenue || '0.00' }} </template>
          </el-table-column>
          <el-table-column label="积分余额" prop="integral" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.integral || '0.00' }} </template>
          </el-table-column>

          <el-table-column label="操作" align="center">
            <template v-slot="scope">
              <el-button v-hasPermi="['system:tenant:edit']" link type="primary" @click="showTenantBannedInfoModal(scope.row, true)">
                查看账户历史
              </el-button>
            </template>
          </el-table-column>
        </el-table>
        <pagination :total="total" v-model:page="queryParams.current" v-model:limit="queryParams.size" @pagination="getList" />
      </el-card>
    </div>
    <el-dialog v-model="isshow" title="明细" width="1200px" append-to-body>
      <el-card shadow="hover">
        <el-form :model="queryParams" ref="query" :inline="true" v-show="showSearch" label-width="100px" size="default" class="ry_form">
          <el-form-item label="时间:" prop="date">
            <el-date-picker
              v-model="query.date"
              value-format="YYYY-MM-DD HH:mm:ss"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              :default-time="[new Date(2000, 1, 1, 0, 0, 0), new Date(2000, 1, 1, 23, 59, 59)]"
            />
          </el-form-item>
          <el-form-item label="类型:" prop="changeType">
            <el-select v-model="query.changeType" placeholder="请选择类型" clearable size="default" style="width: 240px">
              <el-option label="收入" value="1" />
              <el-option label="支出" value="2" />
            </el-select>
          </el-form-item>
          <el-form-item class="flex_one tr">
            <el-button type="primary" icon="Search" @click="getFomg">搜索</el-button>
          </el-form-item>
        </el-form>
      </el-card>
      <el-table :data="tableData" border>
        <el-table-column label="变动类型" prop="accountType" align="center" />
        <el-table-column label="变动来源" prop="accountTypeDesc" align="center" />
        <el-table-column label="用户类型" prop="userType" align="center" />
        <el-table-column label="余额" prop="moneyBalance" align="center" />
        <el-table-column label="变动前余额" prop="beforeBalance" align="center" />
        <el-table-column label="变动后余额" prop="afterBalance" align="center" />
        <el-table-column label="变动金额" prop="changeAmount" align="center" />
        <el-table-column label="变动类型" prop="changeType" align="center" />
        <el-table-column label="创建时间" prop="createTime" align="center" />
        <el-table-column label="备注" prop="remark" align="center" />
      </el-table>
      <pagination :total="totals" v-model:page="query.current" v-model:limit="query.size" @pagination="getFomg" />
    </el-dialog>
  </div>
</template>

<script>
import { getUserAccountList, listCurrent } from '@/api/ums/member';

export default {
  name: 'UmeAccount',
  data() {
    return {
      tableData: [],
      isshow: false,
      show: false,
      // 遮罩层
      loading: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 会员账户数据
      umsAccountList: [],
      // 弹出层标题
      title: '',
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        name: null,
        phone: null,
        type: null
      },
      totals: 0,
      query: {
        current: 1,
        size: 10,
        accountld: null,
        date: null,
        changeType: null
      }
    };
  },
  created() {
    this.show = true;
    this.getList();
  },
  methods: {
    showTenantBannedInfoModal(row) {
      this.query.accountld = row.id;
      this.getFomg();
    },
    async getFomg() {
      const res = await listCurrent(this.query);
      if (res.code === 200) {
        this.tableData = res.data.records;
        this.totals = res.data.total;
        this.isshow = true;
      }
    },
    /** 查询会员信息列表 */
    getList() {
      //  type:账户类型  1 用户 2 商家 3 代理 4 平台
      this.loading = true;
      const { current: pageNum, size: pageSize } = this.queryParams;
      const query = { ...this.queryParams, pageNum: undefined, pageSize: undefined };
      const pageReq = { current: pageNum - 1, size: pageSize };
      getUserAccountList(query, pageReq).then((response) => {
        const { records = [], total = 0 } = response.data || {};
        this.umsAccountList = records;
        this.total = total;
        this.loading = false;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    }
  }
};
</script>
