index.vue
7.03 KB
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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
<!--
* @Date: 2023-12-13 11:13:13
* @LastEditors: hookehuyr hookehuyr@gmail.com
* @LastEditTime: 2023-12-27 14:37:22
* @FilePath: /meihuaApp/src/pages/my/index.vue
* @Description: 我的页面
-->
<template>
<view class="my-page">
<view id="avatar" class="user-wrapper">
<view class="user-info">
<nut-avatar size="60" style="border: 1px solid #fff;">
<img style="border-radius: 50%;" :src="userInfo.avatar ? userInfo.avatar : avatar" />
</nut-avatar>
<text style="margin-left: 30rpx;">{{ userInfo.name }}</text>
</view>
<view class="edit">
<IconFont name="edit" @tap="goToEdit"></IconFont>
</view>
<view class="wrapper-bottom"></view>
</view>
<view class="list-wrapper">
<view id="title" class="title">我的订单</view>
<nut-tabs v-model="tab_index" @click="onTabClick" title-scroll title-gutter="0" background="#FFF" color="#6A4925" animated-time="0">
<nut-tab-pane v-for="item in tabList" :title="item.title" :pane-key="item.key" />
</nut-tabs>
<view v-if="showContent" class="book-list">
<scroll-view ref="refScrollView" :style="scrollStyle" :scroll-y="true" :scroll-with-animation="true" @scrolltolower="onScrollToLower">
<view v-for="(item, index) in orderList" :key="index">
<order-card :key="index" :data="item" @onPay="onPay"></order-card>
<view v-if="index === orderList.length-1" style="height: 2rem;"></view>
</view>
</scroll-view>
<nut-empty
v-if="orderList.length === 0"
image="https://static-ftcms.jd.com/p/files/61a9e3313985005b3958672e.png"
description="暂无数据"
></nut-empty>
</view>
</view>
<nav-bar activated="my" />
<payCard :visible="show_pay" :data="payData" @close="onPayClose"/>
</view>
</template>
<script setup>
import Taro from '@tarojs/taro'
import { ref, onMounted, computed } from "vue";
import { IconFont } from '@nutui/icons-vue-taro';
import navBar from '@/components/navBar.vue'
import orderCard from '@/components/orderCard.vue'
import payCard from '@/components/payCard.vue'
import avatar from '@/assets/images/avatar.png'
import { showMyInfoAPI } from '@/api/index'
import { getCurrentPageParam } from "@/utils/weapp";
const refScrollView = ref(null);
const tab_index = ref('0');
const tabList = ref([{
title: '全部订单',
key: '0',
value: 'all'
}, {
title: '待入住',
key: '1',
value: 'a'
}, {
title: '待支付',
key: '2',
value: 'b'
}, {
title: '已取消',
key: '3',
value: 'c'
}]);
const orderList = ref([
{
id: 1,
name: '阿忆妞妞1',
phone: '138****8888',
price: 1200,
remain_time: 1000,
status: 'no-pay',
},
{
id: 2,
name: '阿忆妞妞2',
phone: '138****8888',
price: 1200,
remain_time: 100,
status: 'apply',
},
{
id: 3,
name: '阿忆妞妞3',
phone: '138****8888',
price: 1200,
remain_time: 100,
status: 'enable',
},
{
id: 4,
name: '阿忆妞妞4',
phone: '138****8888',
price: 1200,
remain_time: 100,
status: 'cancel',
},
])
const show_pay = ref(false);
const payData = ref({});
const userInfo = ref({
name: '',
avatar: '',
phone: ''
});
const tab_status = computed(() => {
switch (tab_index.value) {
case '0':
return 'all'
case '1':
return 'in';
case '2':
return 'pp';
case '3':
return 'ca';
}
});
onMounted(async () => {
// 获取用户信息
const { code, data } = await showMyInfoAPI();
if (code) {
userInfo.value = {
name: data.wxapp_user_name ? data.wxapp_user_name : '默认用户',
avatar: data.wxapp_user_avatar,
phone: data.wxapp_user_phone
}
}
// 默认勾选栏目
let params = getCurrentPageParam();
if (params.tab_index) {
tab_index.value = params.tab_index;
}
//
console.warn('tab_status', tab_status.value);
});
const onPay = ({ id, remain_time }) => {
console.warn(id);
// Taro.showToast({
// title: '支付已超时',
// icon: 'error',
// duration: 2000
// });
show_pay.value = true;
payData.value.id = '123';
payData.value.price = 1200;
payData.value.remain_time = remain_time;
}
const onPayClose = () => {
show_pay.value = false;
}
const goToEdit = async () => {
if (userInfo.value.phone) {
Taro.navigateTo({
url: '/pages/myInfo/index',
});
} else {
Taro.navigateTo({
url: '/pages/login/index?page=my',
});
}
}
const onTabClick = ({ title, paneKey, disabled }) => {
tab_index.value = paneKey;
// console.warn(title, paneKey, tabList.value[paneKey]);
// console.warn(tab_index.value);
console.warn(tab_status.value);
}
</script>
<script>
import "./index.less";
import { $ } from '@tarojs/extend'
import mixin from '@/utils/mixin';
export default {
name: "myPage",
mixins: [mixin.init],
computed: {
scrollStyle() {
return {
height: this.indexCoverHeight + 'px',
// paddingBottom: 50 + 'px',
};
},
},
onHide () { // 离开当前页面
this.page = 0;
this.flag = true;
},
mounted () {
Taro.showLoading({
title: '加载中',
});
// 设置首页封面高度
const windowHeight = wx.getSystemInfoSync().windowHeight;
// 处理切换显示白屏问题
setTimeout(() => {
this.showContent = true;
}, 100);
// setTimeout(async () => {
// const navHeight = await $('#navbar-page').height();
// const avatarHeight = await $('#avatar').height();
// const titleHeight = await $('#title').height();
// this.indexCoverHeight = windowHeight - navHeight - avatarHeight - titleHeight - 50;
// }, 500);
this.$nextTick(async () => {
const navHeight = await $('#navbar-page').height();
const avatarHeight = await $('#avatar').height();
const titleHeight = await $('#title').height();
this.indexCoverHeight = windowHeight - navHeight - avatarHeight - titleHeight - 50;
if (this.$refs.refScrollView) {
Taro.hideLoading();
console.warn('加载完成');
}
});
},
data() {
return {
showContent: false,
indexCoverHeight: 0,
flag: true,
page: 0,
limit: 10,
};
},
methods: {
onScrollToLower () {
// if(!this.flag){
// return
// }
// this.flag = false;
// this.getList();
console.warn('onScrollToLower');
},
async getList () {
// // 获取推荐活动列表
// const { code, data } = await activityHomeAPI({ page: this.page, limit: this.limit });
// if (code) {
// if (data.activity_list.length) {
// // 绑定服务器时间,判断状态
// data.activity_list.forEach(item => {
// item.server_time = data.server_time;
// });
// this.activity_list = this.activity_list.concat(data.activity_list);
// this.page = this.page + 1;
// this.flag = true;
// } else {
// Toast('没有数据')
// }
// }
// }
},
}
};
</script>