index.vue 18 KB

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