zhengyiming
3 天以前 e75076815db5ab6870353d0760b962b671e7c56f
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
<template>
  <InfiniteLoading
    scrollViewClassName="common-infinite-scroll-list home-list"
    v-bind="infiniteLoadingProps"
  >
    <nut-address-list
      :data="infiniteLoadingProps.flattenListData"
      @del-icon="delClick"
      @edit-icon="editClick"
      :show-bottom-button="false"
      :data-options="dataOptions"
      style="padding-bottom: 0"
    >
    </nut-address-list>
  </InfiniteLoading>
  <PageFooter>
    <PageFooterBtn type="primary" @click="goAddress()">添加地址</PageFooterBtn>
  </PageFooter>
</template>
 
<script setup lang="ts">
import { useInfiniteLoading, useTaskList } from '@12333/hooks';
import Taro from '@tarojs/taro';
import * as enterpriseServices from '@12333/services/apiV2/enterprise';
import { Message } from '@12333/utils';
 
defineOptions({
  name: 'InnerPage',
});
 
const dataOptions = reactive({
  id: 'id',
  addressDetail: 'addressDetail',
  addressName: 'name',
  phone: 'contactPhoneNumber',
  defaultAddress: 'isDefault',
});
 
const delClick = async (_, item: API.GetEnterpriseAddressesQueryResultItem) => {
  try {
    await Message.confirm({
      message: '确定要删除吗?',
    });
    let params: API.DeleteEnterpriseAddressCommand = {
      ids: [item.id],
    };
    let res = await enterpriseServices.deleteEnterpriseAddress(params);
 
    if (res) {
      Message.success('删除成功');
      invalidateQueries();
    }
  } catch (error) {}
};
const editClick = (_, item: API.GetEnterpriseAddressesQueryResultItem) => {
  goAddress(item.id);
};
 
const { infiniteLoadingProps, invalidateQueries } = useInfiniteLoading(
  ({ pageParam }) => {
    let params: API.GetEnterpriseAddressesQuery = {
      pageModel: {
        rows: 20,
        page: pageParam,
      },
    };
 
    return enterpriseServices.getEnterpriseAddresses(params, {
      showLoading: false,
    });
  },
  {
    queryKey: ['enterpriseServices/getEnterpriseAddresses'],
  }
);
 
function goAddress(id?: string) {
  Taro.navigateTo({
    url: id ? `${RouterPath.editAddress}?id=${id}` : RouterPath.editAddress,
  });
}
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
</style>