index.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. import {Setting} from '@/common/mock.js'
  135. // 订单操作
  136. const orderNavbar = [
  137. { id: 'all', name: '全部订单', icon: 'qpdingdan' },
  138. { id: 'payment', name: '待支付', icon: 'daifukuan', count: 0 },
  139. { id: 'delivery', name: '待发货', icon: 'daifahuo', count: 0 },
  140. { id: 'received', name: '待收货', icon: 'daishouhuo', count: 0 },
  141. ]
  142. /**
  143. * 我的服务
  144. * id: 标识; name: 标题名称; icon: 图标; type 类型(link和button); url: 跳转的链接
  145. */
  146. const service = [
  147. { id: 'address', name: '收货地址', icon: 'shouhuodizhi', type: 'link', url: 'pages/address/index' },
  148. { id: 'coupon', name: '领券中心', icon: 'lingquan', type: 'link', url: 'pages/coupon/index' },
  149. { id: 'myCoupon', name: '优惠券', icon: 'youhuiquan', type: 'link', url: 'pages/my-coupon/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. { id: 'help', name: '我的帮助', icon: 'bangzhu', type: 'link', url: 'pages/help/index' },
  155. ]
  156. export default {
  157. components: {
  158. AvatarImage
  159. },
  160. data() {
  161. return {
  162. // 枚举类
  163. SettingKeyEnum,
  164. // 正在加载
  165. isLoading: true,
  166. // 首次加载
  167. isFirstload: true,
  168. // 是否已登录
  169. isLogin: false,
  170. // 系统设置
  171. setting: {},
  172. // 当前用户信息
  173. userInfo: {},
  174. // 账户资产
  175. assets: { balance: '--', points: '--', coupon: '--' },
  176. // 我的服务
  177. service,
  178. // 订单操作
  179. orderNavbar,
  180. // 当前用户待处理的订单数量
  181. todoCounts: { payment: 0, deliver: 0, received: 0 }
  182. }
  183. },
  184. /**
  185. * 生命周期函数--监听页面显示
  186. */
  187. onShow(options) {
  188. this.onRefreshPage()
  189. },
  190. methods: {
  191. // 刷新页面
  192. onRefreshPage() {
  193. // 更新购物车角标
  194. setCartTabBadge()
  195. // 判断是否已登录
  196. this.isLogin = checkLogin()
  197. // 获取页面数据
  198. this.getPageData()
  199. },
  200. // 获取页面数据
  201. getPageData(callback) {
  202. const app = this
  203. app.isLoading = true
  204. // app.setting = Setting.data.setting
  205. // app.initService()
  206. // app.initOrderTabbar()
  207. // app.isLoading = false
  208. Promise.all([app.getSetting(), app.getUserInfo(), app.getUserAssets(), app.getTodoCounts()])
  209. .then(result => {
  210. app.isFirstload = false
  211. // 初始化我的服务数据
  212. app.initService()
  213. // 初始化订单操作数据
  214. app.initOrderTabbar()
  215. // 执行回调函数
  216. callback && callback()
  217. })
  218. .catch(err => console.log('catch', err))
  219. .finally(() => app.isLoading = false)
  220. },
  221. // 初始化我的服务数据
  222. initService() {
  223. const app = this
  224. const newService = []
  225. service.forEach(item => {
  226. if (item.id === 'points') {
  227. item.name = '我的' + app.setting[SettingKeyEnum.POINTS.value].points_name
  228. }
  229. // 数据角标
  230. if (item.count != undefined) {
  231. item.count = app.todoCounts[item.id]
  232. }
  233. newService.push(item)
  234. })
  235. app.service = newService
  236. },
  237. // 初始化订单操作数据
  238. initOrderTabbar() {
  239. const app = this
  240. const newOrderNavbar = []
  241. orderNavbar.forEach(item => {
  242. if (item.count != undefined) {
  243. item.count = app.todoCounts[item.id]
  244. }
  245. newOrderNavbar.push(item)
  246. })
  247. app.orderNavbar = newOrderNavbar
  248. },
  249. // 获取商城设置
  250. getSetting() {
  251. const app = this
  252. return app.setting = Setting.data.setting
  253. // return new Promise((resolve, reject) => {
  254. // SettingModel.data()
  255. // .then(setting => {
  256. // app.setting = setting
  257. // resolve(setting)
  258. // }).catch(reject)
  259. // })
  260. },
  261. // 获取当前用户信息
  262. getUserInfo() {
  263. const app = this
  264. return new Promise((resolve, reject) => {
  265. !app.isLogin ? resolve(null) : UserApi.info({}, { load: app.isFirstload })
  266. .then(result => {
  267. app.userInfo = result.data.userInfo
  268. resolve(app.userInfo)
  269. })
  270. .catch(err => {
  271. if (err.result && err.result.status == 401) {
  272. app.isLogin = false
  273. resolve(null)
  274. } else {
  275. reject(err)
  276. }
  277. })
  278. })
  279. },
  280. // 获取账户资产
  281. getUserAssets() {
  282. const app = this
  283. return new Promise((resolve, reject) => {
  284. !app.isLogin ? resolve(null) : UserApi.assets({}, { load: app.isFirstload })
  285. .then(result => {
  286. app.assets = result.data.assets
  287. resolve(app.assets)
  288. })
  289. .catch(err => {
  290. if (err.result && err.result.status == 401) {
  291. app.isLogin = false
  292. resolve(null)
  293. } else {
  294. reject(err)
  295. }
  296. })
  297. })
  298. },
  299. // 获取当前用户待处理的订单数量
  300. getTodoCounts() {
  301. const app = this
  302. return new Promise((resolve, reject) => {
  303. !app.isLogin ? resolve(null) : OrderApi.todoCounts({}, { load: app.isFirstload })
  304. .then(result => {
  305. app.todoCounts = result.data.counts
  306. resolve(app.todoCounts)
  307. })
  308. .catch(err => {
  309. if (err.result && err.result.status == 401) {
  310. app.isLogin = false
  311. resolve(null)
  312. } else {
  313. reject(err)
  314. }
  315. })
  316. })
  317. },
  318. // 跳转到登录页
  319. handleLogin() {
  320. !this.isLogin && this.$navTo('pages/login/index')
  321. },
  322. // 跳转到修改个人信息页
  323. handlePersonal() {
  324. this.$navTo('pages/user/personal/index')
  325. },
  326. // 退出登录
  327. handleLogout() {
  328. const app = this
  329. uni.showModal({
  330. title: '友情提示',
  331. content: '您确定要退出登录吗?',
  332. success(res) {
  333. if (res.confirm) {
  334. store.dispatch('Logout', {})
  335. .then(result => app.onRefreshPage())
  336. }
  337. }
  338. })
  339. },
  340. // 跳转到钱包页面
  341. onTargetWallet() {
  342. this.$navTo('pages/wallet/index')
  343. },
  344. // 跳转到订单页
  345. onTargetOrder(item) {
  346. this.$navTo('pages/order/index', { dataType: item.id })
  347. },
  348. // 跳转到我的积分页面
  349. onTargetPoints() {
  350. this.$navTo('pages/points/log')
  351. },
  352. // 跳转到我的优惠券页
  353. onTargetMyCoupon() {
  354. this.$navTo('pages/my-coupon/index')
  355. },
  356. // 跳转到服务页面
  357. handleService({ url }) {
  358. this.$navTo(url)
  359. },
  360. },
  361. /**
  362. * 下拉刷新
  363. */
  364. onPullDownRefresh() {
  365. // 获取首页数据
  366. this.getPageData(() => {
  367. uni.stopPullDownRefresh()
  368. })
  369. },
  370. }
  371. </script>
  372. <style lang="scss" scoped>
  373. // 页面头部
  374. .main-header {
  375. background-color: #fff;
  376. // background-image: url('/static/background/user-header.png');
  377. position: relative;
  378. width: 100%;
  379. height: 280rpx;
  380. background-size: 100% 100%;
  381. overflow: hidden;
  382. display: flex;
  383. align-items: center;
  384. // padding-top: 40rpx;
  385. padding-left: 30rpx;
  386. .bg-image {
  387. position: absolute;
  388. top: 0;
  389. left: 0;
  390. width: 100%;
  391. height: 100%;
  392. z-index: 0;
  393. }
  394. .user-info {
  395. display: flex;
  396. height: 100rpx;
  397. z-index: 1;
  398. .user-content {
  399. display: flex;
  400. flex-direction: column;
  401. justify-content: center;
  402. margin-left: 30rpx;
  403. color: #c59a46;
  404. .nick-name {
  405. font-size: 34rpx;
  406. font-weight: bold;
  407. max-width: 270rpx;
  408. }
  409. .mobile {
  410. margin-top: 15rpx;
  411. font-size: 28rpx;
  412. }
  413. .user-grade {
  414. align-self: baseline;
  415. display: flex;
  416. align-items: center;
  417. background: #3c3c3c;
  418. margin-top: 12rpx;
  419. border-radius: 10rpx;
  420. padding: 4rpx 12rpx;
  421. .user-grade_icon .image {
  422. display: block;
  423. width: 32rpx;
  424. height: 32rpx;
  425. }
  426. .user-grade_name {
  427. margin-left: 5rpx;
  428. font-size: 26rpx;
  429. color: #EEE0C3;
  430. }
  431. }
  432. .login-tips {
  433. margin-top: 12rpx;
  434. font-size: 30rpx;
  435. }
  436. }
  437. }
  438. }
  439. // 角标组件
  440. .item-badge {
  441. position: absolute;
  442. top: 0;
  443. right: 55rpx;
  444. background: #fa2209;
  445. color: #fff;
  446. border-radius: 100%;
  447. min-width: 38rpx;
  448. height: 38rpx;
  449. display: flex;
  450. justify-content: center;
  451. align-items: center;
  452. padding: 1rpx;
  453. font-size: 24rpx;
  454. }
  455. // 我的钱包
  456. .my-asset {
  457. display: flex;
  458. background: #fff;
  459. padding: 40rpx 0;
  460. .asset-right {
  461. width: 200rpx;
  462. border-left: 1rpx solid #eee;
  463. }
  464. .asset-right-item {
  465. text-align: center;
  466. color: #545454;
  467. .item-icon {
  468. font-size: 44rpx;
  469. }
  470. .item-name {
  471. margin-top: 14rpx;
  472. font-size: 28rpx;
  473. }
  474. }
  475. .asset-left-item {
  476. max-width: 183rpx;
  477. text-align: center;
  478. color: #666;
  479. padding: 0 16rpx;
  480. .item-value {
  481. font-size: 34rpx;
  482. color: red;
  483. }
  484. .item-name {
  485. margin-top: 6rpx;
  486. }
  487. .item-name {
  488. margin-top: 14rpx;
  489. font-size: 28rpx;
  490. }
  491. }
  492. }
  493. // 订单操作
  494. .order-navbar {
  495. display: flex;
  496. margin: 20rpx auto 20rpx auto;
  497. padding: 20rpx 0;
  498. width: 94%;
  499. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  500. font-size: 30rpx;
  501. border-radius: 5rpx;
  502. background: #fff;
  503. &-item {
  504. position: relative;
  505. width: 25%;
  506. .item-icon {
  507. text-align: center;
  508. margin: 0 auto;
  509. padding: 10rpx 0;
  510. color: #545454;
  511. font-size: 44rpx;
  512. }
  513. .item-name {
  514. font-size: 28rpx;
  515. color: #545454;
  516. text-align: center;
  517. margin-right: 10rpx;
  518. }
  519. }
  520. }
  521. // 我的服务
  522. .my-service {
  523. margin: 22rpx auto 22rpx auto;
  524. padding: 22rpx 0;
  525. width: 94%;
  526. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  527. border-radius: 5rpx;
  528. background: #fff;
  529. .service-title {
  530. padding-left: 24rpx;
  531. margin-bottom: 20rpx;
  532. font-size: 30rpx;
  533. }
  534. .service-content {
  535. margin-bottom: -20rpx;
  536. .service-item {
  537. position: relative;
  538. width: 25%;
  539. float: left;
  540. margin-bottom: 30rpx;
  541. .item-icon {
  542. text-align: center;
  543. margin: 0 auto;
  544. padding: 14rpx 0;
  545. color: #ff3800;
  546. font-size: 44rpx;
  547. }
  548. .item-name {
  549. font-size: 28rpx;
  550. color: #545454;
  551. text-align: center;
  552. margin-right: 10rpx;
  553. }
  554. }
  555. }
  556. }
  557. // 退出登录
  558. .my-logout {
  559. display: flex;
  560. justify-content: center;
  561. margin-top: 50rpx;
  562. .logout-btn {
  563. width: 60%;
  564. margin: 0 auto;
  565. font-size: 28rpx;
  566. color: #616161;
  567. border-radius: 20rpx;
  568. border: 1px solid #dcdcdc;
  569. padding: 16rpx 0;
  570. text-align: center;
  571. }
  572. }
  573. </style>