wupengfei
1 天以前 ddddcf83e7deb9d0a674d2bbead300089530d87e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<template>
  <InfiniteLoading
    scrollViewClassName="life-page-infinite-scroll-list"
    v-bind="infiniteLoadingProps"
  >
    <template #renderItem="{ item }">
      <UserAccountCard
        :title="TitleMap[item.lifePayType]"
        :icon="TitleIconMap[item.lifePayType]"
        :content="
          item.lifePayType === LifeRechargeConstants.LifePayOrderTypeEnum.话费订单
            ? `${
                BlLifeRecharge.constants.IspCodeText[
                  JSON.parse(item?.extraProperties)?.ispCode ?? ''
                ]
              }-${item.content}`
            : `${item.city}-${item.content}`
        "
        :remark="item.remark"
        :style="{
          marginBottom: Taro.pxTransform(32),
          backgroundColor: '#ffffff',
        }"
      >
        <template #action>
          <div class="user-account-card-action" @click="handleEditUserAccount(item)">
            <img :src="IconAccountEdit" class="user-account-card-action-icon" />
            <span class="user-account-card-action-text">编辑</span>
          </div>
          <div class="user-account-card-action" @click="handleDeleteUserAccount(item)">
            <img :src="IconAccountDelete" class="user-account-card-action-icon" />
            <span class="user-account-card-action-text">删除</span>
          </div>
        </template>
      </UserAccountCard>
    </template>
  </InfiniteLoading>
</template>
 
<script setup lang="ts">
import InfiniteLoading from '../../components/InfiniteLoading/InfiniteLoading.vue';
import {
  BlLifeRecharge,
  useLifeRechargeContext,
  QueryUserAccountListInput,
  LifeRechargeConstants,
  UserAccountListOutput,
} from '@life-payment/core-vue';
import { useInfiniteLoading } from '../../hooks/infiniteLoading';
import { OrderInputType } from '../../constants';
import UserAccountCard from '../../components/Card/UserAccountCard.vue';
import IconAccountDelete from '../../assets/account/icon-account-delete.png';
import IconAccountEdit from '../../assets/account/icon-account-edit.png';
import { OssAssets } from '../../constants';
import Taro from '@tarojs/taro';
 
defineOptions({
  name: 'UserAccountListView',
});
 
const emit = defineEmits<{
  (e: 'goEdit', row: UserAccountListOutput): void;
}>();
 
const { blLifeRecharge } = useLifeRechargeContext();
 
const TitleMap = {
  [LifeRechargeConstants.LifePayOrderTypeEnum.话费订单]: '话费',
  [LifeRechargeConstants.LifePayOrderTypeEnum.电费订单]: '电费',
  [LifeRechargeConstants.LifePayOrderTypeEnum.燃气订单]: '燃气费',
};
 
const TitleIconMap = {
  [LifeRechargeConstants.LifePayOrderTypeEnum.话费订单]: OssAssets.accountCard.Phone,
  [LifeRechargeConstants.LifePayOrderTypeEnum.电费订单]: OssAssets.accountCard.Electric,
  [LifeRechargeConstants.LifePayOrderTypeEnum.燃气订单]: OssAssets.accountCard.Gas,
};
 
const { infiniteLoadingProps, invalidateQueries } = useInfiniteLoading(
  ({ pageParam }) => {
    let params: QueryUserAccountListInput = {
      pageModel: {
        rows: 20,
        page: pageParam,
        orderInput: [{ property: 'creationTime', order: OrderInputType.Desc }],
      },
      userId: blLifeRecharge.accountModel.userId,
    };
 
    return blLifeRecharge.services.getUserAccountList(params, {
      showLoading: false,
    });
  },
  {
    queryKey: ['blLifeRecharge/getUserAccountList', blLifeRecharge.accountModel.userId],
  }
);
 
function handleEditUserAccount(row: UserAccountListOutput) {
  emit('goEdit', row);
}
 
async function handleDeleteUserAccount(row: UserAccountListOutput) {
  try {
    const res = await Taro.showModal({
      title: '提示',
      content: '确定要删除该数据吗?',
      confirmColor: '#028CFF',
    });
    if (res.confirm) {
      await blLifeRecharge.services.deleteUserAccount({
        id: row.id,
      });
      invalidateQueries();
    }
  } catch (error) {}
}
</script>