<template>
  <div class="p-2 auto-overflow-y">
    <transition :enter-active-class="proxy?.animate.searchAnimate.enter" :leave-active-class="proxy?.animate.searchAnimate.leave">
      <div v-show="showSearch" class="search">
        <el-form ref="queryFormRef" :model="queryParams" :inline="true" label-width="68px" class="-mb-15px">
          <el-form-item label="学/工号" prop="userNumb">
            <el-input v-model="queryParams.userNumb" placeholder="请输入学/工号" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="用户姓名" prop="realName">
            <el-input v-model="queryParams.realName" placeholder="请输入用户姓名" clearable style="width: 240px" @keyup.enter="handleQuery" />
          </el-form-item>
          <el-form-item label="交易时间" style="width: 308px">
            <el-date-picker
                v-model="dateRangeCreditTime"
                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="creditType">
            <el-select v-model="queryParams.creditType" placeholder="请选择交易类型" clearable>
              <el-option v-for="dict in CREDITTYPE" :key="dict.value" :label="dict.label" :value="dict.value" />
            </el-select>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="Search" @click="handleQuery">搜索</el-button>
            <el-button icon="Refresh" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </div>
    </transition>

    <el-card shadow="never">
      <template #header>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button v-hasPermi="['consumption:xfCreditaccount:export']" type="warning" plain icon="Download" @click="handleExport">导出</el-button>
          </el-col>
          <right-toolbar v-model:showSearch="showSearch" :columns="columns"  @query-table="getList"></right-toolbar>
        </el-row>
      </template>

      <el-table v-loading="loading" :data="xfCreditaccountList" max-height="400" @selection-change="handleSelectionChange">
        <!-- <el-table-column type="selection" width="55" align="center" /> -->
        <el-table-column v-if="false" label="收支Id" align="center" prop="creditId" />
        <el-table-column v-if="columns[1].visible" label="学/工号" align="center" prop="userNumb" />
        <el-table-column v-if="columns[2].visible" label="用户姓名" align="center" prop="realName" />
        <el-table-column v-if="columns[3].visible" label="部门名称" align="center" prop="deptName" />
        <el-table-column v-if="columns[11].visible" label="交易时间" align="center" prop="creditTime" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.creditTime, '{y}-{m}-{d} {h}:{m}') }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[12].visible" label="交易类型" align="center" prop="creditType">
          <template #default="scope">
            <dict-tag :options="CREDITTYPE" :value="scope.row.creditType"/>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[14].visible" label="交易金额" align="center" prop="receiptMoney" />
        <el-table-column v-if="columns[13].visible" label="支付方式" align="center" prop="payStyle">
          <template #default="scope">
            <dict-tag :options="PAYSTYLE" :value="scope.row.payStyle"/>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[6].visible" label="卡上余额" align="center" prop="cardValue" />
        <el-table-column v-if="columns[8].visible" label="钱包类型" align="center" prop="bagType">
          <template #default="scope">
            <dict-tag :options="CARDBAGTYPE" :value="scope.row.bagType"/>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[7].visible" label="卡片类型名称" align="center" prop="cardTypeName" />
        <el-table-column v-if="columns[4].visible" label="设备机号" align="center" prop="termNo" />
        <el-table-column v-if="columns[5].visible" label="设备名称" align="center" prop="termName" />
        <!-- <el-table-column v-if="columns[9].visible" label="工作站名称" align="center" prop="stationName" /> -->
        <el-table-column v-if="columns[10].visible" label="营业员名称" align="center" prop="operatorName" />
       
        <!-- <el-table-column v-if="columns[15].visible" label="核对状态" align="center" prop="auditStatus">
          <template #default="scope">
            <dict-tag :options="sys_yes_no" :value="scope.row.auditStatus"/>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[16].visible" label="核对时间" align="center" prop="auditDate" width="180">
          <template #default="scope">
            <span>{{ parseTime(scope.row.auditDate, '{y}-{m}-{d}') }}</span>
          </template>
        </el-table-column>
        <el-table-column v-if="columns[17].visible" label="消费记录标志位?" align="center" prop="recordStatus" />
        <el-table-column v-if="columns[18].visible" label="备注" align="center" prop="remark" /> -->
       
      </el-table>
      <!-- 翻页组件 -->
      <pagination v-show="total > 0" v-model:page="queryParams.pageNum" v-model:limit="queryParams.pageSize" :total="total" @pagination="getList" />
    </el-card>
    <!-- 添加或修改资金收支明细对话框 -->
    <detail-form ref="detailFormRef" apped-to-body @success="getList" />
  </div>
</template>

<script setup name="XfCreditaccount" lang="ts">
/** 模块导入 */
import { listXfCreditaccount, delXfCreditaccount } from '@/api/cardCenter/report/xfCreditaccount';
import { XfCreditaccountVO } from '@/api/cardCenter/report/xfCreditaccount/types';


defineOptions({ name: 'XfCreditaccount' });

const { proxy } = getCurrentInstance() as ComponentInternalInstance;
/** 当前页面引用的数据字典 */
const { PAYSTYLE, CARDBAGTYPE, CREDITTYPE, sys_yes_no } = toRefs<any>(proxy?.useDict('PAYSTYLE', 'CARDBAGTYPE', 'CREDITTYPE', 'sys_yes_no'));
// 是否加载遮罩层
const loading = ref(true);
// 是否显示查询项
const showSearch = ref(true);
const xfCreditaccountList = ref<XfCreditaccountVO[]>([]);
// 列表选中的记录Id
const ids = ref<Array<number | string>>([]);
// 单选
const single = ref(true);
// 多选
const multiple = ref(true);
// 总记录数
const total = ref(0);

// 日期范围
const dateRangeCreditTime = ref<[DateModelType, DateModelType]>(['', '']);
// 查询窗体Ref
const queryFormRef = ref<ElFormInstance>();

const columns = ref<FieldOption[]>([
      { key: 0, label: `收支Id`, visible: true, children: [] },
      { key: 1, label: `学/工号`, visible: true, children: [] },
      { key: 2, label: `用户姓名`, visible: true, children: [] },
      { key: 3, label: `部门名称`, visible: true, children: [] },
      { key: 4, label: `设备机号`, visible: true, children: [] },
      { key: 5, label: `设备名称`, visible: true, children: [] },
      { key: 6, label: `卡上余额`, visible: true, children: [] },
      { key: 7, label: `卡片类型名称`, visible: true, children: [] },
      { key: 8, label: `钱包类型`, visible: true, children: [] },
      { key: 9, label: `工作站名称`, visible: true, children: [] },
      { key: 10, label: `营业员名称`, visible: true, children: [] },
      { key: 11, label: `交易时间`, visible: true, children: [] },
      { key: 12, label: `交易类型`, visible: true, children: [] },
      { key: 13, label: `支付方式`, visible: true, children: [] },
      { key: 14, label: `交易金额`, visible: true, children: [] },
      { key: 15, label: `核对状态`, visible: true, children: [] },
      { key: 16, label: `核对时间`, visible: true, children: [] },
      { key: 17, label: `消费记录标志位?`, visible: true, children: [] },
      { key: 18, label: `备注`, visible: true, children: [] },
]);

// 查询参数
const queryParams = reactive({
  pageNum: 1,
  pageSize: 10,
  userNumb: '',
  realName: '',
  creditTime: undefined,
  creditType: '',
  payStyle: '',
  params: {}
});

/** 查询资金收支明细列表 */
const getList = async () => {
  loading.value = true;
  // queryParams.value.params = {};
  proxy?.addDateRange(queryParams, dateRangeCreditTime.value, 'CreditTime');
  const res = await listXfCreditaccount(queryParams);
  xfCreditaccountList.value = res.rows;
  total.value = res.total;
  loading.value = false;
};


/** 搜索按钮操作 */
const handleQuery = () => {
  queryParams.pageNum = 1;
  getList();
};

/** 重置按钮操作 */
const resetQuery = () => {
  dateRangeCreditTime.value = ['', ''];
  queryFormRef.value?.resetFields();
  handleQuery();
};

/** 多选框选中数据 */
const handleSelectionChange = (selection: XfCreditaccountVO[]) => {
  ids.value = selection.map((item) => item.creditId);
  single.value = selection.length != 1;
  multiple.value = !selection.length;
};

/** 删除按钮操作 */
const handleDelete = async (row?: XfCreditaccountVO) => {
  const _creditIds = row?.creditId || ids.value;
  await proxy?.$modal.confirm('是否确认删除资金收支明细编号为"' + _creditIds + '"的数据项？').finally(() => (loading.value = false));
  await delXfCreditaccount(_creditIds);
  await getList();
  proxy?.$modal.msgSuccess('删除成功');
};

/** 导出按钮操作 */
const handleExport = () => {
  proxy?.download(
    'backstage/consumption/xfCreditaccount/export',
    {
      ...queryParams
    },
    `xfCreditaccount_${new Date().getTime()}.xlsx`);
};
/** 弹出框(增加、修改) */
const detailFormRef = ref();
const openForm = (type: string, row?: XfCreditaccountVO) => {
  const id = row?.creditId || ids.value[0];
  detailFormRef?.value.open(type, id);
};
onMounted(() => {
  getList();
});
</script>
