index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. <template>
  2. <view v-if="!isFirstload" class="container">
  3. <!-- 页面头部 -->
  4. <view class="main-header" :style="{ height: platform == 'H5' ? '260rpx' : '320rpx', paddingTop: platform == 'H5' ? '0' : '80rpx' }">
  5. <image class="bg-image" src="/static/background/user-header2.png" mode="scaleToFill"></image>
  6. <!-- 用户信息 -->
  7. <view v-if="isLogin" class="user-info">
  8. <view class="user-avatar" @click="handlePersonal()">
  9. <avatar-image :url="userInfo.avatar_url" :width="100" />
  10. </view>
  11. <view class="user-content">
  12. <!-- 会员昵称 -->
  13. <view class="nick-name oneline-hide" @click="handlePersonal()">{{ userInfo.nick_name }}</view>
  14. <!-- 会员等级 -->
  15. <view v-if="userInfo.grade_id > 0 && userInfo.grade" class="user-grade">
  16. <view class="user-grade_icon">
  17. <image class="image" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAA0lBMVEUAAAD/tjL/tzH/uDP/uC7/tjH/tzH/tzL/tTH+tTL+tjP/tDD/tTD+tzD/tjL/szD/uDH/tjL/tjL+tjD/tjT/szb/tzL/tTL+uTH+tjL/tjL/tjL/tTT/tjL/tjL+tjH/uTL/vDD/tjL/tjH/tzL9uS//tTL/nBr/sS7/tjH/ujL/szD/uTv+rzf/tzL+tzH+vDP+uzL+tjP+ry7+tDL9ki/7szf/sEX/tTL/tjL+tjL/tTH/tTT/tzH/tzL/tjP/sTX/uTP/wzX+rTn/vDX9vC8m8ckhAAAAOXRSTlMAlnAMB/vjxKWGMh0S6drMiVxPRkEY9PLy0ru0sKagmo5+dGtgVCMgBP716eXWyMGxqJGRe2o5KSmFNjaYAAABP0lEQVQ4y8XS13KDMBAF0AWDDe4t7r3ETu9lVxJgJ/n/X8rKAzHG5TE+Twz3zki7I/g/KXdghIbGJewrU4yzn08Ebgl6TuZzzuOC6W5es3HX6qsSz3NFShRU0MpucytDmOSpu3yULx3CA9RD1HjVedc0jSjqm6ZzhUjDsFDQhSp/OKj5GQvg0+ZCOixsbtDLAeTTOm/yGi8GyIphIVsgH737FEDV44LJa88IRKK/SetrwT9G/GUIr6vXjoy4GXn7+RboVXnghuSjaoGecwQxL2su3CwAKlO+QFoqxI4FMctHQhQd2OhxTu184jWUlI+rMTBTn1/IQcJHQ6GQdZ7pWiDaNdhTt330efISeiqYwQEzQpTlsURJLhzkEmpCPsERfeIUVyXr6MNuIyp5uziW6xURtt7hhGwzmMNJExfO4Bd9X0ZPqAxdNwAAAABJRU5ErkJggg==">
  18. </image>
  19. </view>
  20. <view class="user-grade_name">
  21. <text>{{ userInfo.grade.name }}</text>
  22. </view>
  23. </view>
  24. <!-- 会员无等级时显示手机号 -->
  25. <view v-else class="mobile">{{ userInfo.mobile }}</view>
  26. </view>
  27. </view>
  28. <!-- 未登录 -->
  29. <view v-else class="user-info" @click="handleLogin">
  30. <view class="user-avatar">
  31. <avatar-image :width="100" />
  32. </view>
  33. <view class="user-content">
  34. <view class="nick-name">未登录</view>
  35. <view class="login-tips">点击登录账号</view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 我的钱包 -->
  40. <view class="my-asset">
  41. <view class="asset-left flex-box dis-flex flex-x-around">
  42. <view class="asset-left-item" style="max-width: 200rpx;" @click="onTargetWallet">
  43. <view class="item-value dis-flex flex-x-center">
  44. <text>{{ isLogin ? assets.balance : '--' }}</text>
  45. </view>
  46. <view class="item-name dis-flex flex-x-center">
  47. <text class="oneline-hide">账户余额</text>
  48. </view>
  49. </view>
  50. <view class="asset-left-item" @click="onTargetPoints">
  51. <view class="item-value dis-flex flex-x-center">
  52. <text>{{ isLogin ? assets.points : '--' }}</text>
  53. </view>
  54. <view class="item-name dis-flex flex-x-center">
  55. <text class="oneline-hide">{{ setting[SettingKeyEnum.POINTS.value].points_name }}</text>
  56. </view>
  57. </view>
  58. <view class="asset-left-item" @click="onTargetMyCoupon">
  59. <view class="item-value dis-flex flex-x-center">
  60. <text class="oneline-hide">{{ isLogin ? assets.coupon : '--' }}</text>
  61. </view>
  62. <view class="item-name dis-flex flex-x-center">
  63. <text>优惠券</text>
  64. </view>
  65. </view>
  66. </view>
  67. <view class="asset-right">
  68. <view class="asset-right-item" @click="onTargetWallet">
  69. <view class="item-icon dis-flex flex-x-center">
  70. <text class="iconfont icon-qianbao"></text>
  71. </view>
  72. <view class="item-name dis-flex flex-x-center">
  73. <text>我的钱包</text>
  74. </view>
  75. </view>
  76. </view>
  77. </view>
  78. <!-- 订单操作 -->
  79. <view class="order-navbar">
  80. <view class="order-navbar-item" v-for="(item, index) in orderNavbar" :key="index" @click="onTargetOrder(item)">
  81. <view class="item-icon">
  82. <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
  83. </view>
  84. <view class="item-name">{{ item.name }}</view>
  85. <view class="item-badge" v-if="item.count && item.count > 0">
  86. <text v-if="item.count <= 99" class="text">{{ item.count }}</text>
  87. <text v-else class="text">99+</text>
  88. </view>
  89. </view>
  90. </view>
  91. <!-- 我的服务 -->
  92. <view class="my-service">
  93. <view class="service-title">我的服务</view>
  94. <view class="service-content clearfix">
  95. <block v-for="(item, index) in service" :key="index">
  96. <view v-if="item.type == 'link'" class="service-item" @click="handleService(item)">
  97. <view class="item-icon">
  98. <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
  99. </view>
  100. <view class="item-name">{{ item.name }}</view>
  101. <view class="item-badge" v-if="item.count && item.count > 0">
  102. <text v-if="item.count <= 99" class="text">{{ item.count }}</text>
  103. <text v-else class="text">99+</text>
  104. </view>
  105. </view>
  106. <view v-if="item.type == 'button' && platform == 'MP-WEIXIN'" class="service-item">
  107. <button class="btn-normal" :open-type="item.openType">
  108. <view class="item-icon">
  109. <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
  110. </view>
  111. <view class="item-name">{{ item.name }}</view>
  112. </button>
  113. </view>
  114. </block>
  115. </view>
  116. </view>
  117. <!-- 退出登录 -->
  118. <view v-if="isLogin" class="my-logout">
  119. <view class="logout-btn" @click="handleLogout()">
  120. <text>退出登录</text>
  121. </view>
  122. </view>
  123. </view>
  124. </template>
  125. <script>
  126. import store from '@/store'
  127. import AvatarImage from '@/components/avatar-image'
  128. import { setCartTabBadge } from '@/core/app'
  129. import SettingKeyEnum from '@/common/enum/setting/Key'
  130. import SettingModel from '@/common/model/Setting'
  131. import * as UserApi from '@/api/user'
  132. import * as OrderApi from '@/api/order'
  133. import { checkLogin } from '@/core/app'
  134. // 订单操作
  135. const orderNavbar = [
  136. { id: 'all', name: '全部订单', icon: 'qpdingdan' },
  137. { id: 'payment', name: '待支付', icon: 'daifukuan', count: 0 },
  138. { id: 'delivery', name: '待发货', icon: 'daifahuo', count: 0 },
  139. { id: 'received', name: '待收货', icon: 'daishouhuo', count: 0 },
  140. ]
  141. /**
  142. * 我的服务
  143. * id: 标识; name: 标题名称; icon: 图标; type 类型(link和button); url: 跳转的链接
  144. */
  145. const service = [
  146. { id: 'address', name: '收货地址', icon: 'shouhuodizhi', type: 'link', url: 'pages/address/index' },
  147. { id: 'coupon', name: '领券中心', icon: 'lingquan', type: 'link', url: 'pages/coupon/index' },
  148. { id: 'myCoupon', name: '优惠券', icon: 'youhuiquan', type: 'link', url: 'pages/my-coupon/index' },
  149. { id: 'help', name: '我的帮助', icon: 'bangzhu', type: 'link', url: 'pages/help/index' },
  150. { id: 'contact', name: '在线客服', icon: 'kefu', type: 'button', openType: 'contact' },
  151. { id: 'points', name: '我的积分', icon: 'jifen', type: 'link', url: 'pages/points/log' },
  152. { id: 'refund', name: '退换/售后', icon: 'shouhou', type: 'link', url: 'pages/refund/index', count: 0 },
  153. { id: 'orderCenter', name: '订单中心', icon: 'order-c', type: 'link', url: 'pages/order/center' },
  154. ]
  155. export default {
  156. components: {
  157. AvatarImage
  158. },
  159. data() {
  160. return {
  161. // 枚举类
  162. SettingKeyEnum,
  163. // 正在加载
  164. isLoading: true,
  165. // 首次加载
  166. isFirstload: true,
  167. // 是否已登录
  168. isLogin: false,
  169. // 系统设置
  170. setting: {},
  171. // 当前用户信息
  172. userInfo: {},
  173. // 账户资产
  174. assets: { balance: '--', points: '--', coupon: '--' },
  175. // 我的服务
  176. service,
  177. // 订单操作
  178. orderNavbar,
  179. // 当前用户待处理的订单数量
  180. todoCounts: { payment: 0, deliver: 0, received: 0 }
  181. }
  182. },
  183. /**
  184. * 生命周期函数--监听页面显示
  185. */
  186. onShow(options) {
  187. this.onRefreshPage()
  188. },
  189. methods: {
  190. // 刷新页面
  191. onRefreshPage() {
  192. // 更新购物车角标
  193. setCartTabBadge()
  194. // 判断是否已登录
  195. this.isLogin = checkLogin()
  196. // 获取页面数据
  197. this.getPageData()
  198. },
  199. // 获取页面数据
  200. getPageData(callback) {
  201. const app = this
  202. app.isLoading = true
  203. Promise.all([app.getSetting(), app.getUserInfo(), app.getUserAssets(), app.getTodoCounts()])
  204. .then(result => {
  205. app.isFirstload = false
  206. // 初始化我的服务数据
  207. app.initService()
  208. // 初始化订单操作数据
  209. app.initOrderTabbar()
  210. // 执行回调函数
  211. callback && callback()
  212. })
  213. .catch(err => console.log('catch', err))
  214. .finally(() => app.isLoading = false)
  215. },
  216. // 初始化我的服务数据
  217. initService() {
  218. const app = this
  219. const newService = []
  220. service.forEach(item => {
  221. if (item.id === 'points') {
  222. item.name = '我的' + app.setting[SettingKeyEnum.POINTS.value].points_name
  223. }
  224. // 数据角标
  225. if (item.count != undefined) {
  226. item.count = app.todoCounts[item.id]
  227. }
  228. newService.push(item)
  229. })
  230. app.service = newService
  231. },
  232. // 初始化订单操作数据
  233. initOrderTabbar() {
  234. const app = this
  235. const newOrderNavbar = []
  236. orderNavbar.forEach(item => {
  237. if (item.count != undefined) {
  238. item.count = app.todoCounts[item.id]
  239. }
  240. newOrderNavbar.push(item)
  241. })
  242. app.orderNavbar = newOrderNavbar
  243. },
  244. // 获取商城设置
  245. getSetting() {
  246. const app = this
  247. return new Promise((resolve, reject) => {
  248. SettingModel.data()
  249. .then(setting => {
  250. app.setting = setting
  251. resolve(setting)
  252. }).catch(reject)
  253. })
  254. },
  255. // 获取当前用户信息
  256. getUserInfo() {
  257. const app = this
  258. return new Promise((resolve, reject) => {
  259. !app.isLogin ? resolve(null) : UserApi.info({}, { load: app.isFirstload })
  260. .then(result => {
  261. app.userInfo = result.data.userInfo
  262. resolve(app.userInfo)
  263. })
  264. .catch(err => {
  265. if (err.result && err.result.status == 401) {
  266. app.isLogin = false
  267. resolve(null)
  268. } else {
  269. reject(err)
  270. }
  271. })
  272. })
  273. },
  274. // 获取账户资产
  275. getUserAssets() {
  276. const app = this
  277. return new Promise((resolve, reject) => {
  278. !app.isLogin ? resolve(null) : UserApi.assets({}, { load: app.isFirstload })
  279. .then(result => {
  280. app.assets = result.data.assets
  281. resolve(app.assets)
  282. })
  283. .catch(err => {
  284. if (err.result && err.result.status == 401) {
  285. app.isLogin = false
  286. resolve(null)
  287. } else {
  288. reject(err)
  289. }
  290. })
  291. })
  292. },
  293. // 获取当前用户待处理的订单数量
  294. getTodoCounts() {
  295. const app = this
  296. return new Promise((resolve, reject) => {
  297. !app.isLogin ? resolve(null) : OrderApi.todoCounts({}, { load: app.isFirstload })
  298. .then(result => {
  299. app.todoCounts = result.data.counts
  300. resolve(app.todoCounts)
  301. })
  302. .catch(err => {
  303. if (err.result && err.result.status == 401) {
  304. app.isLogin = false
  305. resolve(null)
  306. } else {
  307. reject(err)
  308. }
  309. })
  310. })
  311. },
  312. // 跳转到登录页
  313. handleLogin() {
  314. !this.isLogin && this.$navTo('pages/login/index')
  315. },
  316. // 跳转到修改个人信息页
  317. handlePersonal() {
  318. this.$navTo('pages/user/personal/index')
  319. },
  320. // 退出登录
  321. handleLogout() {
  322. const app = this
  323. uni.showModal({
  324. title: '友情提示',
  325. content: '您确定要退出登录吗?',
  326. success(res) {
  327. if (res.confirm) {
  328. store.dispatch('Logout', {})
  329. .then(result => app.onRefreshPage())
  330. }
  331. }
  332. })
  333. },
  334. // 跳转到钱包页面
  335. onTargetWallet() {
  336. this.$navTo('pages/wallet/index')
  337. },
  338. // 跳转到订单页
  339. onTargetOrder(item) {
  340. this.$navTo('pages/order/index', { dataType: item.id })
  341. },
  342. // 跳转到我的积分页面
  343. onTargetPoints() {
  344. this.$navTo('pages/points/log')
  345. },
  346. // 跳转到我的优惠券页
  347. onTargetMyCoupon() {
  348. this.$navTo('pages/my-coupon/index')
  349. },
  350. // 跳转到服务页面
  351. handleService({ url }) {
  352. this.$navTo(url)
  353. },
  354. },
  355. /**
  356. * 下拉刷新
  357. */
  358. onPullDownRefresh() {
  359. // 获取首页数据
  360. this.getPageData(() => {
  361. uni.stopPullDownRefresh()
  362. })
  363. },
  364. }
  365. </script>
  366. <style lang="scss" scoped>
  367. // 页面头部
  368. .main-header {
  369. background-color: #fff;
  370. // background-image: url('/static/background/user-header.png');
  371. position: relative;
  372. width: 100%;
  373. height: 280rpx;
  374. background-size: 100% 100%;
  375. overflow: hidden;
  376. display: flex;
  377. align-items: center;
  378. // padding-top: 40rpx;
  379. padding-left: 30rpx;
  380. .bg-image {
  381. position: absolute;
  382. top: 0;
  383. left: 0;
  384. width: 100%;
  385. height: 100%;
  386. z-index: 0;
  387. }
  388. .user-info {
  389. display: flex;
  390. height: 100rpx;
  391. z-index: 1;
  392. .user-content {
  393. display: flex;
  394. flex-direction: column;
  395. justify-content: center;
  396. margin-left: 30rpx;
  397. color: #c59a46;
  398. .nick-name {
  399. font-size: 34rpx;
  400. font-weight: bold;
  401. max-width: 270rpx;
  402. }
  403. .mobile {
  404. margin-top: 15rpx;
  405. font-size: 28rpx;
  406. }
  407. .user-grade {
  408. align-self: baseline;
  409. display: flex;
  410. align-items: center;
  411. background: #3c3c3c;
  412. margin-top: 12rpx;
  413. border-radius: 10rpx;
  414. padding: 4rpx 12rpx;
  415. .user-grade_icon .image {
  416. display: block;
  417. width: 32rpx;
  418. height: 32rpx;
  419. }
  420. .user-grade_name {
  421. margin-left: 5rpx;
  422. font-size: 26rpx;
  423. color: #EEE0C3;
  424. }
  425. }
  426. .login-tips {
  427. margin-top: 12rpx;
  428. font-size: 30rpx;
  429. }
  430. }
  431. }
  432. }
  433. // 角标组件
  434. .item-badge {
  435. position: absolute;
  436. top: 0;
  437. right: 55rpx;
  438. background: #fa2209;
  439. color: #fff;
  440. border-radius: 100%;
  441. min-width: 38rpx;
  442. height: 38rpx;
  443. display: flex;
  444. justify-content: center;
  445. align-items: center;
  446. padding: 1rpx;
  447. font-size: 24rpx;
  448. }
  449. // 我的钱包
  450. .my-asset {
  451. display: flex;
  452. background: #fff;
  453. padding: 40rpx 0;
  454. .asset-right {
  455. width: 200rpx;
  456. border-left: 1rpx solid #eee;
  457. }
  458. .asset-right-item {
  459. text-align: center;
  460. color: #545454;
  461. .item-icon {
  462. font-size: 44rpx;
  463. }
  464. .item-name {
  465. margin-top: 14rpx;
  466. font-size: 28rpx;
  467. }
  468. }
  469. .asset-left-item {
  470. max-width: 183rpx;
  471. text-align: center;
  472. color: #666;
  473. padding: 0 16rpx;
  474. .item-value {
  475. font-size: 34rpx;
  476. color: red;
  477. }
  478. .item-name {
  479. margin-top: 6rpx;
  480. }
  481. .item-name {
  482. margin-top: 14rpx;
  483. font-size: 28rpx;
  484. }
  485. }
  486. }
  487. // 订单操作
  488. .order-navbar {
  489. display: flex;
  490. margin: 20rpx auto 20rpx auto;
  491. padding: 20rpx 0;
  492. width: 94%;
  493. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  494. font-size: 30rpx;
  495. border-radius: 5rpx;
  496. background: #fff;
  497. &-item {
  498. position: relative;
  499. width: 25%;
  500. .item-icon {
  501. text-align: center;
  502. margin: 0 auto;
  503. padding: 10rpx 0;
  504. color: #545454;
  505. font-size: 44rpx;
  506. }
  507. .item-name {
  508. font-size: 28rpx;
  509. color: #545454;
  510. text-align: center;
  511. margin-right: 10rpx;
  512. }
  513. }
  514. }
  515. // 我的服务
  516. .my-service {
  517. margin: 22rpx auto 22rpx auto;
  518. padding: 22rpx 0;
  519. width: 94%;
  520. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  521. border-radius: 5rpx;
  522. background: #fff;
  523. .service-title {
  524. padding-left: 24rpx;
  525. margin-bottom: 20rpx;
  526. font-size: 30rpx;
  527. }
  528. .service-content {
  529. margin-bottom: -20rpx;
  530. .service-item {
  531. position: relative;
  532. width: 25%;
  533. float: left;
  534. margin-bottom: 30rpx;
  535. .item-icon {
  536. text-align: center;
  537. margin: 0 auto;
  538. padding: 14rpx 0;
  539. color: #ff3800;
  540. font-size: 44rpx;
  541. }
  542. .item-name {
  543. font-size: 28rpx;
  544. color: #545454;
  545. text-align: center;
  546. margin-right: 10rpx;
  547. }
  548. }
  549. }
  550. }
  551. // 退出登录
  552. .my-logout {
  553. display: flex;
  554. justify-content: center;
  555. margin-top: 50rpx;
  556. .logout-btn {
  557. width: 60%;
  558. margin: 0 auto;
  559. font-size: 28rpx;
  560. color: #616161;
  561. border-radius: 20rpx;
  562. border: 1px solid #dcdcdc;
  563. padding: 16rpx 0;
  564. text-align: center;
  565. }
  566. }
  567. </style>