index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467
  1. <template>
  2. <view>
  3. <view class="mine-container">
  4. <view class="mine-header" :style="{ paddingTop: globalData.navBarHeight + 'px' }">
  5. <view class="flex_c_s mine-header-info">
  6. <img :show-loading="true" :src="userInfo.avatar" class="header-avatar" />
  7. <view class="header-info flex_c_s">
  8. <view class="info-top ">
  9. <view class="user-info flex_c_c">
  10. <view class="info-name" @click="onLogin">{{
  11. userInfo.nickName
  12. }}</view>
  13. <view class="info-tag flex_c_c" v-if="userType">{{ userType === 1 ? '用户' : '志愿者' }}
  14. </view>
  15. </view>
  16. <view class="info-real-name flex_c_c">
  17. <view class="real-name">{{ authentication ? '已实名' : '暂未实名' }}</view>
  18. <img src="/static/serverImg/mine/suce.png" alt="" style="width: 24rpx; height: 24rpx;"
  19. v-if="authentication">
  20. <img src="/static/serverImg/mine/left.png" alt="" style="width: 24rpx; height: 24rpx;" v-else>
  21. </view>
  22. </view>
  23. <img src="/static/serverImg/mine/setting.png" alt="" style="width: 60rpx; height: 60rpx;"
  24. @click="handLsetTing">
  25. </view>
  26. </view>
  27. <view class="applause-rate flex_c_c" v-if="userType === 2">
  28. <view class="rate-lable">好评率:</view>
  29. <view class="rate-value">{{ rateValue }}星</view>
  30. <view v-for="(item, index) in new Array(5)" :key="item">
  31. <img src="/static/serverImg/mine/flower.png" v-if="rateValue <= index" alt="" class="flower" />
  32. <img src="/static/serverImg/mine/flower_active.png" v-else alt="" class="flower" />
  33. </view>
  34. </view>
  35. <view class="order-main flex_c_s" v-if="userType === 1">
  36. <view v-for="item in orderMainList" :key="item.iconName" class="order-item flex_c_c_f">
  37. <view class="order-num">
  38. {{ data[item.key] }}
  39. </view>
  40. <view>
  41. {{ item.name }}
  42. </view>
  43. </view>
  44. </view>
  45. </view>
  46. <view class="price-main ">
  47. <view class="price-card flex_c_c">
  48. <view v-for="item in priceList" :key="item.key" class="price-item flex_c_c" @click="onClick(item)">
  49. <view class="flex_c_c_f">
  50. <view class="price-balance">{{ data[item.key] }}</view>
  51. <view class="price-name flex_c_c">
  52. <view class="price-name-text">{{ item.name }}</view>
  53. </view>
  54. </view>
  55. <img src="/static/serverImg/mine/rigth.png" alt="" class="price-rigth"
  56. style="width: 24rpx;height: 24rpx;" />
  57. </view>
  58. </view>
  59. </view>
  60. <view class="list-main">
  61. <view class="list-box">
  62. <view v-for="item in list" :key="item.key" class="list-item flex_c_s" @click="onClick(item)">
  63. <view class="list-left flex_c_l">
  64. <img :src="item.img" alt="" style="width: 56rpx;height: 56rpx;">
  65. <view class="list-name">{{ item.name }}</view>
  66. </view>
  67. <view class="list-rigth flex_c_r">
  68. <view class="list-text">{{ item.text }}</view>
  69. <up-icon name="arrow-right"></up-icon>
  70. </view>
  71. </view>
  72. </view>
  73. </view>
  74. </view>
  75. <CustomTabBar page="mine" />
  76. <up-popup :show="show" mode="center" @close="close" @open="open">
  77. <view v-if="show">
  78. <QRCode scene="123" page="/pages/index/index" width="430" auto-color line-color="#000000" is-hyaline>
  79. </QRCode>
  80. </view>
  81. </up-popup>
  82. </view>
  83. </template>
  84. <script setup>
  85. import { onMounted, ref, computed } from 'vue'
  86. import { onLoad, onShow } from '@dcloudio/uni-app'
  87. import store from '@/store'
  88. import { getVolunteerAccountInfo, volunteerOrderStatistics, getAccountInfo } from '@/api/mine'
  89. import CustomTabBar from '@/components/CustomTabBar/index.vue'
  90. import QRCode from '@/components/QRCode/index.vue'
  91. import { getNavBarHeight } from '@/utils/index.js'
  92. import { getToken } from '@/utils/auth'
  93. import { showConfirm } from '@/utils/common'
  94. import { getInfo } from '@/api/login'
  95. import {
  96. userOrWorker
  97. } from '@/api/login';
  98. const show = ref(false); // 是否显示二维码
  99. const userInfo = ref({
  100. avatar: '/static/serverImg/mine/user.png',
  101. nickName: '登陆/注册',
  102. })
  103. const authentication = ref(false);//是否认证
  104. const globalData = ref({
  105. statusBarHeight: 47,
  106. navBarHeight: 91,
  107. })
  108. const data = ref({
  109. balance: 0.0,
  110. reservationCount: 0,
  111. doingCount: 0,
  112. finishedCount: 0,
  113. cancelCount: 0,
  114. orderCount: 0,
  115. orderFrozenBalance: 0,
  116. browsing: 0,
  117. collect: 0,
  118. comment: 0
  119. })
  120. const rateValue = ref(5)
  121. const orderMainList = [
  122. {
  123. name: '浏览记录',
  124. key: 'browsing',
  125. },
  126. {
  127. name: '收藏',
  128. key: 'collect',
  129. },
  130. {
  131. name: '评论',
  132. key: 'comment',
  133. },
  134. ]
  135. const priceUser = [
  136. {
  137. name: '我的钱包(元)',
  138. key: 'balance',
  139. decimals: 2,
  140. balance: 'orderFrozenBalance',
  141. page: '/pages_mine/pages/wallet/index',
  142. },
  143. {
  144. name: '我的积分',
  145. key: 'orderCount',
  146. decimals: 0,
  147. page: '/pages_mine/pages/integral/index',
  148. },
  149. ]
  150. const priceAdmin = [
  151. {
  152. name: '我的余额',
  153. key: 'balance',
  154. decimals: 2,
  155. balance: 'orderFrozenBalance',
  156. page: '/pages_mine/pages/wallet/index',
  157. },
  158. {
  159. name: '预约单数',
  160. key: 'orderCount',
  161. decimals: 0,
  162. switchPage: '/pages/classify',
  163. value: 1,
  164. },
  165. ]
  166. const priceList = computed(() => {
  167. if (userType === 1) {
  168. return priceUser
  169. }
  170. return priceAdmin
  171. })
  172. const userType = uni.getStorageSync('userType') //读取本地存储
  173. const adminList = [
  174. {
  175. name: '我的地址',
  176. img: '/static/serverImg/mine/adress.png',
  177. key: 'map',
  178. text: '',
  179. page: '/pages_mine/pages/selectAddress/index',
  180. },
  181. {
  182. name: '帮助与客服',
  183. img: '/static/serverImg/mine/kf.png',
  184. key: 'map',
  185. text: '',
  186. operate: () => {
  187. uni.navigateTo({
  188. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true&conversationType=3`
  189. })
  190. },
  191. },
  192. {
  193. name: '我的评论',
  194. key: 'share',
  195. img: '/static/serverImg/mine/yq.png',
  196. text: '查看所有订单',
  197. switchPage: '/pages/classify',
  198. value: 3,
  199. },
  200. // {
  201. // name: '修改个人信息',
  202. // img: '/static/serverImg/mine/xg.png',
  203. // key: 'map',
  204. // text: '去认证资质',
  205. // operate: () => {
  206. // handLsetTing();
  207. // },
  208. // },
  209. {
  210. name: '邀请二维码',
  211. key: 'share',
  212. img: '/static/img/Iconly@1x.png',
  213. text: '推荐好友得好礼',
  214. operate: () => {
  215. show.value = true
  216. },
  217. },
  218. {
  219. name: '志愿者',
  220. img: '/static/serverImg/mine/sf.png',
  221. key: 'map',
  222. text: '切换为用户',
  223. operate: () => {
  224. switchUserType(1)
  225. },
  226. },
  227. ]
  228. const userList = [
  229. {
  230. name: '我的地址',
  231. img: '/static/serverImg/mine/adress.png',
  232. key: 'map',
  233. text: '',
  234. page: '/pages_mine/pages/selectAddress/index',
  235. },
  236. {
  237. name: '帮助与客服',
  238. img: '/static/serverImg/mine/kf.png',
  239. key: 'map',
  240. text: '',
  241. operate: () => {
  242. uni.navigateTo({
  243. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true&conversationType=3`
  244. })
  245. },
  246. },
  247. {
  248. name: '邀请二维码',
  249. key: 'share',
  250. img: '/static/img/Iconly@1x.png',
  251. text: '推荐好友得好礼',
  252. operate: () => {
  253. show.value = true
  254. },
  255. },
  256. {
  257. name: '用户',
  258. img: '/static/serverImg/mine/sf.png',
  259. key: 'map',
  260. text: '切换为志愿者',
  261. operate: () => {
  262. switchUserType(2)
  263. },
  264. },
  265. ]
  266. const switchUserType = (userType) => {
  267. uni.setStorageSync('userType', userType)
  268. store.dispatch('GetInfo').then((res) => {
  269. uni.$u.closeSoket();
  270. userInfo.value = store.state.user
  271. userOrWorker({ userType: userType })
  272. .then(res => {
  273. console.log("TCL: loginSuccess -> res", res)
  274. uni.$u.connectSoket(userInfo.value.userId)
  275. uni.reLaunch({
  276. url: '/pages/index',
  277. })
  278. })
  279. })
  280. .catch(err => {
  281. console.error('设置失败:', err);
  282. });
  283. }
  284. const list = computed(() => {
  285. if (userType === 1) {
  286. return userList
  287. }
  288. return adminList
  289. })
  290. function open() { //弹框打开逻辑
  291. // 打开逻辑,比如设置 show 为 true
  292. show.value = true;
  293. }
  294. function close() {
  295. // 关闭逻辑,设置 show 为 false
  296. show.value = false;
  297. }
  298. const onLogin = () => {
  299. const token = getToken()
  300. !token &&
  301. showConfirm('您还未登陆系统,是否前往登陆?').then((res) => {
  302. if (res.confirm) {
  303. store.dispatch('LogOut').then((res) => {
  304. uni.navigateTo({ url: '/pages/login' })
  305. })
  306. }
  307. })
  308. }
  309. const onLogou = () => {
  310. showConfirm('确认退出登陆吗?').then((res) => {
  311. if (res.confirm) {
  312. store.dispatch('LogOut').then((res) => {
  313. uni.reLaunch({
  314. url: '/pages/index',
  315. })
  316. })
  317. }
  318. })
  319. }
  320. const onClick = (record) => {
  321. console.log('record', record, record.page)
  322. if (record.page) {
  323. uni.navigateTo({
  324. url: record.page,
  325. })
  326. }
  327. if (record.operate) {
  328. record.operate()
  329. }
  330. if (record.switchPage && record.value) {
  331. const app = getApp()
  332. app.globalData.switchTabParams = {
  333. tabKey: record.value,
  334. }
  335. // JS跳转
  336. uni.switchTab({
  337. url: record.switchPage,
  338. })
  339. return
  340. }
  341. }
  342. const getDetails = async () => {
  343. try {
  344. // const res = await getVolunteerAccount();
  345. // console.log('res',res);
  346. } catch (error) {
  347. console.log('error', error)
  348. }
  349. }
  350. const handLsetTing = () => {
  351. console.log('uni.$u.closeSoket',uni.$u);
  352. uni.navigateTo({
  353. url: '/pages_mine/pages/setupUser/index',
  354. })
  355. }
  356. const geUserInfo = () => {
  357. // userInfo.value = store.state.user
  358. getInfo().then(res => {
  359. console.log("TCL: geUserInfo -> res", res)
  360. userInfo.value = res.user;
  361. // showConfirm('您未完成实名认证,是否前往实名?').then(res => {
  362. // if (res.confirm) {
  363. // handLsetTing();
  364. // }
  365. // })
  366. })
  367. }
  368. onShow(() => {
  369. const token = getToken()
  370. // console.log("TCL: token", token)
  371. if (token) {
  372. geUserInfo()
  373. init()
  374. }
  375. })
  376. onMounted(() => {
  377. getNav()
  378. })
  379. const init = async () => {
  380. try {
  381. // uni.hideLoading();
  382. // uni.showLoading({
  383. // title: '数据加载中...',
  384. // })
  385. if (userType === 2) {
  386. const res1 = await getVolunteerAccountInfo()
  387. const res2 = await volunteerOrderStatistics()
  388. data.value = {
  389. ...res1.data,
  390. ...res2.data,
  391. }
  392. console.log(11, res1, res2, data.value, userType)
  393. }
  394. if (userType === 1) {
  395. const res = await getAccountInfo();
  396. // 从本地存储读取积分
  397. const totalPoint = uni.getStorageSync('totalPoint') || 0;
  398. data.value = {
  399. ...data.value,
  400. ...res.data,
  401. orderCount: totalPoint, // 使用存储的可用积分
  402. };
  403. }
  404. } catch (error) {
  405. console.log('error', error)
  406. uni.showToast({
  407. title: error.msg,
  408. icon: 'error',
  409. })
  410. } finally {
  411. // uni.hideLoading()
  412. }
  413. }
  414. const getNav = async () => {
  415. try {
  416. const res = await getNavBarHeight();
  417. globalData.value = res;
  418. console.log("TCL: getNav -> res", res)
  419. } catch (error) {
  420. console.log("TCL: getNav -> error", error)
  421. }
  422. }
  423. </script>
  424. <style lang="scss" scoped>
  425. @import "./index.scss";
  426. </style>