index.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  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 {
  95. userOrWorker
  96. } from '@/api/login';
  97. const show = ref(false); // 是否显示二维码
  98. const userInfo = ref({
  99. avatar: '/static/serverImg/mine/user.png',
  100. nickName: '登陆/注册',
  101. })
  102. const authentication = ref(false);//是否认证
  103. const globalData = ref({
  104. statusBarHeight: 47,
  105. navBarHeight: 91,
  106. })
  107. const data = ref({
  108. balance: 0.0,
  109. reservationCount: 0,
  110. doingCount: 0,
  111. finishedCount: 0,
  112. cancelCount: 0,
  113. orderCount: 0,
  114. orderFrozenBalance: 0,
  115. browsing: 0,
  116. collect: 0,
  117. comment: 0
  118. })
  119. const rateValue = ref(5)
  120. const orderMainList = [
  121. {
  122. name: '浏览记录',
  123. key: 'browsing',
  124. },
  125. {
  126. name: '收藏',
  127. key: 'collect',
  128. },
  129. {
  130. name: '评论',
  131. key: 'comment',
  132. },
  133. ]
  134. const priceUser = [
  135. {
  136. name: '我的钱包(元)',
  137. key: 'balance',
  138. decimals: 2,
  139. balance: 'orderFrozenBalance',
  140. page: '/pages_mine/pages/wallet/index',
  141. },
  142. {
  143. name: '我的积分',
  144. key: 'orderCount',
  145. decimals: 0,
  146. page: '/pages_mine/pages/integral/index',
  147. },
  148. ]
  149. const priceAdmin = [
  150. {
  151. name: '我的余额',
  152. key: 'balance',
  153. decimals: 2,
  154. balance: 'orderFrozenBalance',
  155. page: '/pages_mine/pages/wallet/index',
  156. },
  157. {
  158. name: '预约单数',
  159. key: 'orderCount',
  160. decimals: 0,
  161. switchPage: '/pages/classify',
  162. value: 1,
  163. },
  164. ]
  165. const priceList = computed(() => {
  166. if (userType === 1) {
  167. return priceUser
  168. }
  169. return priceAdmin
  170. })
  171. const userType = uni.getStorageSync('userType') //读取本地存储
  172. const adminList = [
  173. {
  174. name: '我的地址',
  175. img: '/static/serverImg/mine/adress.png',
  176. key: 'map',
  177. text: '',
  178. page: '/pages_mine/pages/selectAddress/index',
  179. },
  180. {
  181. name: '帮助与客服',
  182. img: '/static/serverImg/mine/kf.png',
  183. key: 'map',
  184. text: '',
  185. operate: () => {
  186. uni.navigateTo({
  187. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true&conversationType=3`
  188. })
  189. },
  190. },
  191. {
  192. name: '我的评论',
  193. key: 'share',
  194. img: '/static/serverImg/mine/yq.png',
  195. text: '查看所有订单',
  196. switchPage: '/pages/classify',
  197. value: 3,
  198. },
  199. // {
  200. // name: '修改个人信息',
  201. // img: '/static/serverImg/mine/xg.png',
  202. // key: 'map',
  203. // text: '去认证资质',
  204. // operate: () => {
  205. // handLsetTing();
  206. // },
  207. // },
  208. {
  209. name: '邀请二维码',
  210. key: 'share',
  211. img: '/static/img/Iconly@1x.png',
  212. text: '推荐好友得好礼',
  213. operate: () => {
  214. show.value = true
  215. },
  216. },
  217. {
  218. name: '切换为用户',
  219. img: '/static/serverImg/mine/sf.png',
  220. key: 'map',
  221. text: '切换身份',
  222. operate: () => {
  223. switchUserType(1)
  224. },
  225. },
  226. ]
  227. const userList = [
  228. {
  229. name: '我的地址',
  230. img: '/static/serverImg/mine/adress.png',
  231. key: 'map',
  232. text: '',
  233. page: '/pages_mine/pages/selectAddress/index',
  234. },
  235. {
  236. name: '帮助与客服',
  237. img: '/static/serverImg/mine/kf.png',
  238. key: 'map',
  239. text: '',
  240. operate: () => {
  241. uni.navigateTo({
  242. url: `/pages_orderuser/pages/talk/pages/index/index?customerService=true&conversationType=3`
  243. })
  244. },
  245. },
  246. {
  247. name: '邀请二维码',
  248. key: 'share',
  249. img: '/static/img/Iconly@1x.png',
  250. text: '推荐好友得好礼',
  251. operate: () => {
  252. show.value = true
  253. },
  254. },
  255. // {
  256. // name: '修改个人信息',
  257. // img: '/static/serverImg/mine/xg.png',
  258. // key: 'map',
  259. // text: '去实名认证',
  260. // operate: () => {
  261. // handLsetTing();
  262. // },
  263. // },
  264. {
  265. name: '切换为志愿者',
  266. img: '/static/serverImg/mine/sf.png',
  267. key: 'map',
  268. text: '切换身份',
  269. operate: () => {
  270. switchUserType(2)
  271. },
  272. },
  273. ]
  274. const switchUserType = (userType) => {
  275. uni.setStorageSync('userType', userType)
  276. store.dispatch('GetInfo').then((res) => {
  277. userInfo.value = store.state.user
  278. userOrWorker({ userType: userType })
  279. .then(res => {
  280. console.log("TCL: loginSuccess -> res", res)
  281. uni.reLaunch({
  282. url: '/pages/index',
  283. })
  284. })
  285. })
  286. .catch(err => {
  287. console.error('设置失败:', err);
  288. });
  289. }
  290. const list = computed(() => {
  291. if (userType === 1) {
  292. return userList
  293. }
  294. return adminList
  295. })
  296. function open() { //弹框打开逻辑
  297. // 打开逻辑,比如设置 show 为 true
  298. show.value = true;
  299. }
  300. function close() {
  301. // 关闭逻辑,设置 show 为 false
  302. show.value = false;
  303. }
  304. const onLogin = () => {
  305. const token = getToken()
  306. !token &&
  307. showConfirm('您还未登陆系统,是否前往登陆?').then((res) => {
  308. if (res.confirm) {
  309. store.dispatch('LogOut').then((res) => {
  310. uni.navigateTo({ url: '/pages/login' })
  311. })
  312. }
  313. })
  314. }
  315. const onLogou = () => {
  316. showConfirm('确认退出登陆吗?').then((res) => {
  317. if (res.confirm) {
  318. store.dispatch('LogOut').then((res) => {
  319. uni.reLaunch({
  320. url: '/pages/index',
  321. })
  322. })
  323. }
  324. })
  325. }
  326. const onClick = (record) => {
  327. console.log('record', record, record.page)
  328. if (record.page) {
  329. uni.navigateTo({
  330. url: record.page,
  331. })
  332. }
  333. if (record.operate) {
  334. record.operate()
  335. }
  336. if (record.switchPage && record.value) {
  337. const app = getApp()
  338. app.globalData.switchTabParams = {
  339. tabKey: record.value,
  340. }
  341. // JS跳转
  342. uni.switchTab({
  343. url: record.switchPage,
  344. })
  345. return
  346. }
  347. }
  348. const getDetails = async () => {
  349. try {
  350. // const res = await getVolunteerAccount();
  351. // console.log('res',res);
  352. } catch (error) {
  353. console.log('error', error)
  354. }
  355. }
  356. const handLsetTing = () => {
  357. uni.navigateTo({
  358. url: '/pages_mine/pages/setupUser/index',
  359. })
  360. }
  361. const geUserInfo = () => {
  362. console.log(store.state.user, '>>>>99')
  363. userInfo.value = store.state.user
  364. // store.dispatch('GetInfo').then((res) => {
  365. // userInfo.value = store.state.user
  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. data.value = {
  397. ...data.value,
  398. ...res.data,
  399. };
  400. }
  401. } catch (error) {
  402. console.log('error', error)
  403. uni.showToast({
  404. title: error.msg,
  405. icon: 'error',
  406. })
  407. } finally {
  408. // uni.hideLoading()
  409. }
  410. }
  411. const getNav = async () => {
  412. try {
  413. const res = await getNavBarHeight();
  414. globalData.value = res;
  415. console.log("TCL: getNav -> res", res)
  416. } catch (error) {
  417. console.log("TCL: getNav -> error", error)
  418. }
  419. }
  420. </script>
  421. <style lang="scss" scoped>
  422. @import "./index.scss";
  423. </style>