<template>
  <div class="p-2">
    <div>
      <el-card shadow="hover" class="mb-[10px]">
        <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="100px" size="default" class="ry_form">
          <el-form-item label="订单ID" prop="orderId">
            <el-input v-model.trim="queryParams.orderId" placeholder="请输入订单ID" clearable />
          </el-form-item>
          <el-form-item label="订单编号" prop="orderSn">
            <el-input v-model.trim="queryParams.orderSn" placeholder="请输入订单编号" clearable />
          </el-form-item>
          <el-form-item label="分账状态" prop="status">
            <el-select v-model="queryParams.status">
              <el-option v-for="item in userStatusMap" :key="item.value" :label="item.label" :value="item.value" />
            </el-select>
          </el-form-item>
          <el-form-item label="分账类型" prop="type">
            <el-select v-model="queryParams.type">
              <el-option v-for="item in userTypeMap" :key="item.value" :label="item.label" :value="item.value" />
            </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="tableLoading" :data="userDataInfo.data" border empty-text="暂无数据">
          <el-table-column label="订单id" prop="orderId" align="center" />
          <el-table-column label="分账规则" prop="ruleName" align="center" />
          <el-table-column label="订单总金额" prop="orderMoney" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.orderMoney || '0.00' }} </template>
          </el-table-column>
          <el-table-column label="手续费" prop="fee" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.fee || '0.00' }} </template>
          </el-table-column>

          <el-table-column label="实际分账金额" prop="actualMoney" align="center">
            <template v-slot="scope"> ￥ {{ scope.row.actualMoney || '0.00' }} </template>
          </el-table-column>
          <el-table-column label="分账类型" prop="type" align="center">
            <template v-slot="scope">
              {{ getEmulistLabelById(scope.row.type, userTypeMap) }}
            </template>
          </el-table-column>
          <el-table-column label="状态" prop="status" align="center">
            <template v-slot="scope">
              {{ getEmulistLabelById(scope.row.status, userStatusMap) }}
            </template>
          </el-table-column>
          <el-table-column label="创建部门" prop="createDept" width="100" align="center" />
          <el-table-column label="创建人" prop="createBy" width="100" align="center" />
          <el-table-column label="创建时间" prop="auditTime" width="100" align="center" />
        </el-table>
        <pagination
          v-if="userDataInfo.total"
          :total="userDataInfo.total"
          v-model:page="dataParams.current"
          v-model:limit="dataParams.size"
          @pagination="getList"
        />
      </el-card>
    </div>
  </div>
</template>
<script>
import { getUserDivideList } from '@/api/trade/index';

export default {
  name: 'DivideManage',
  data() {
    return {
      userDataInfo: {
        total: 0,
        data: [],
        record: {}
      },
      // 查询参数
      queryParams: {
        current: 1,
        size: 10,
        orderId: null,
        orderSn: null,
        type: undefined,
        status: undefined
      },
      tableLoading: false,
      dataParams: {
        current: 1,
        size: 10
      },
      userTypeMap: [],
      userStatusMap: []
    };
  },
  created() {
    this.getList();
    this.getPageEmu();
  },
  methods: {
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderId: null,
        orderSn: null,
        type: undefined,
        status: undefined
      };
      this.resetForm('form');
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm('queryForm');
      this.handleQuery();
    },

    /** 查询会员信息列表 */
    getList() {
      this.tableLoading = true;
      const { current: pageNum, size: pageSize } = this.queryParams;
      const query = { ...this.queryParams, pageNum: undefined, pageSize: undefined };
      const pageReq = { current: pageNum - 1, size: pageSize };
      getUserDivideList(query, pageReq)
        .then((response) => {
          const { records = [], total = 0 } = response.data || {};
          this.userDataInfo = {
            total: total,
            data: records || []
          };
          this.tableLoading = false;
        })
        .catch(() => {
          this.tableLoading = false;
        });
    },

    async getPageEmu() {
      const userTypeMap = await this.getDictionaryByKey('trans_divide_type');
      const userStatusMap = await this.getDictionaryByKey('trans_divide_status');

      this.userTypeMap = userTypeMap;
      this.userStatusMap = userStatusMap;
    }
  }
};
</script>
