index.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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">
  9. <avatar-image :url="userInfo.avatar_url" :width="100" />
  10. </view>
  11. <view class="user-content">
  12. <!-- 会员昵称 -->
  13. <view class="nick-name oneline-hide">{{ 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"
  18. 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==">
  19. </image>
  20. </view>
  21. <view class="user-grade_name">
  22. <text>{{ userInfo.grade.name }}</text>
  23. </view>
  24. </view>
  25. <!-- 会员无等级时显示手机号 -->
  26. <view v-else class="mobile">{{ userInfo.mobile }}</view>
  27. </view>
  28. </view>
  29. <!-- 未登录 -->
  30. <view v-else class="user-info" @click="handleLogin">
  31. <view class="user-avatar">
  32. <avatar-image :width="100" />
  33. </view>
  34. <view class="user-content">
  35. <view class="nick-name">未登录</view>
  36. <view class="login-tips">点击登录账号</view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- 我的钱包 -->
  41. <view class="my-asset">
  42. <view class="asset-left flex-box dis-flex flex-x-around">
  43. <view class="asset-left-item" @click="onTargetWallet">
  44. <view class="item-value dis-flex flex-x-center">
  45. <text>{{ isLogin ? assets.balance : '--' }}</text>
  46. </view>
  47. <view class="item-name dis-flex flex-x-center">
  48. <text>账户余额</text>
  49. </view>
  50. </view>
  51. <view class="asset-left-item" @click="onTargetPoints">
  52. <view class="item-value dis-flex flex-x-center">
  53. <text>{{ isLogin ? assets.points : '--' }}</text>
  54. </view>
  55. <view class="item-name dis-flex flex-x-center">
  56. <text>{{ setting[SettingKeyEnum.POINTS.value].points_name }}</text>
  57. </view>
  58. </view>
  59. <view class="asset-left-item" @click="onTargetMyCoupon">
  60. <view class="item-value dis-flex flex-x-center">
  61. <text>{{ isLogin ? assets.coupon : '--' }}</text>
  62. </view>
  63. <view class="item-name dis-flex flex-x-center">
  64. <text>优惠券</text>
  65. </view>
  66. </view>
  67. </view>
  68. <view class="asset-right">
  69. <view class="asset-right-item" @click="onTargetWallet">
  70. <view class="item-icon dis-flex flex-x-center">
  71. <text class="iconfont icon-qianbao"></text>
  72. </view>
  73. <view class="item-name dis-flex flex-x-center">
  74. <text>我的钱包</text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- 订单操作 -->
  80. <view class="order-navbar">
  81. <view class="order-navbar-item" v-for="(item, index) in orderNavbar" :key="index" @click="onTargetOrder(item)">
  82. <view class="item-icon">
  83. <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
  84. </view>
  85. <view class="item-name">{{ item.name }}</view>
  86. <view class="item-badge" v-if="item.count && item.count > 0">
  87. <text v-if="item.count <= 99" class="text">{{ item.count }}</text>
  88. <text v-else class="text">99+</text>
  89. </view>
  90. </view>
  91. </view>
  92. <!-- 我的服务 -->
  93. <view class="my-service">
  94. <view class="service-title">我的服务</view>
  95. <view class="service-content clearfix">
  96. <block v-for="(item, index) in service" :key="index">
  97. <view v-if="item.type == 'link'" class="service-item" @click="handleService(item)">
  98. <view class="item-icon">
  99. <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
  100. </view>
  101. <view class="item-name">{{ item.name }}</view>
  102. <view class="item-badge" v-if="item.count && item.count > 0">
  103. <text v-if="item.count <= 99" class="text">{{ item.count }}</text>
  104. <text v-else class="text">99+</text>
  105. </view>
  106. </view>
  107. <view v-if="item.type == 'button' && platform == 'MP-WEIXIN'" class="service-item">
  108. <button class="btn-normal" :open-type="item.openType">
  109. <view class="item-icon">
  110. <text class="iconfont" :class="[`icon-${item.icon}`]"></text>
  111. </view>
  112. <view class="item-name">{{ item.name }}</view>
  113. </button>
  114. </view>
  115. </block>
  116. </view>
  117. </view>
  118. <!-- 退出登录 -->
  119. <view v-if="isLogin" class="my-logout">
  120. <view class="logout-btn" @click="handleLogout()">
  121. <text>退出登录</text>
  122. </view>
  123. </view>
  124. </view>
  125. </template>
  126. <script>
  127. import store from '@/store'
  128. import AvatarImage from '@/components/avatar-image'
  129. import { setCartTabBadge } from '@/core/app'
  130. import SettingKeyEnum from '@/common/enum/setting/Key'
  131. import SettingModel from '@/common/model/Setting'
  132. import * as UserApi from '@/api/user'
  133. import * as OrderApi from '@/api/order'
  134. import { checkLogin } from '@/core/app'
  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: 'help', name: '我的帮助', icon: 'bangzhu', type: 'link', url: 'pages/help/index' },
  151. { id: 'contact', name: '在线客服', icon: 'kefu', type: 'button', openType: 'contact' },
  152. { id: 'points', name: '我的积分', icon: 'jifen', type: 'link', url: 'pages/points/log' },
  153. { id: 'refund', name: '退换/售后', icon: 'shouhou', type: 'link', url: 'pages/refund/index', count: 0 },
  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. handleLogout() {
  318. const app = this
  319. uni.showModal({
  320. title: '友情提示',
  321. content: '您确定要退出登录吗?',
  322. success(res) {
  323. if (res.confirm) {
  324. store.dispatch('Logout', {})
  325. .then(result => app.onRefreshPage())
  326. }
  327. }
  328. })
  329. },
  330. // 跳转到钱包页面
  331. onTargetWallet() {
  332. this.$navTo('pages/wallet/index')
  333. },
  334. // 跳转到订单页
  335. onTargetOrder(item) {
  336. this.$navTo('pages/order/index', { dataType: item.id })
  337. },
  338. // 跳转到我的积分页面
  339. onTargetPoints() {
  340. this.$navTo('pages/points/log')
  341. },
  342. // 跳转到我的优惠券页
  343. onTargetMyCoupon() {
  344. this.$navTo('pages/my-coupon/index')
  345. },
  346. // 跳转到服务页面
  347. handleService({ url }) {
  348. this.$navTo(url)
  349. },
  350. },
  351. /**
  352. * 下拉刷新
  353. */
  354. onPullDownRefresh() {
  355. // 获取首页数据
  356. this.getPageData(() => {
  357. uni.stopPullDownRefresh()
  358. })
  359. },
  360. }
  361. </script>
  362. <style lang="scss" scoped>
  363. // 页面头部
  364. .main-header {
  365. background-color: #fff;
  366. // background-image: url('/static/background/user-header.png');
  367. position: relative;
  368. width: 100%;
  369. height: 280rpx;
  370. background-size: 100% 100%;
  371. overflow: hidden;
  372. display: flex;
  373. align-items: center;
  374. // padding-top: 40rpx;
  375. padding-left: 30rpx;
  376. .bg-image {
  377. position: absolute;
  378. top: 0;
  379. left: 0;
  380. width: 100%;
  381. height: 100%;
  382. z-index: 0;
  383. }
  384. .user-info {
  385. display: flex;
  386. height: 100rpx;
  387. z-index: 1;
  388. .user-content {
  389. display: flex;
  390. flex-direction: column;
  391. justify-content: center;
  392. margin-left: 30rpx;
  393. color: #c59a46;
  394. .nick-name {
  395. font-size: 34rpx;
  396. font-weight: bold;
  397. max-width: 270rpx;
  398. }
  399. .mobile {
  400. margin-top: 15rpx;
  401. font-size: 28rpx;
  402. }
  403. .user-grade {
  404. align-self: baseline;
  405. display: flex;
  406. align-items: center;
  407. background: #3c3c3c;
  408. margin-top: 12rpx;
  409. border-radius: 10rpx;
  410. padding: 4rpx 12rpx;
  411. .user-grade_icon .image {
  412. display: block;
  413. width: 32rpx;
  414. height: 32rpx;
  415. }
  416. .user-grade_name {
  417. margin-left: 5rpx;
  418. font-size: 26rpx;
  419. color: #EEE0C3;
  420. }
  421. }
  422. .login-tips {
  423. margin-top: 12rpx;
  424. font-size: 30rpx;
  425. }
  426. }
  427. }
  428. }
  429. // 角标组件
  430. .item-badge {
  431. position: absolute;
  432. top: 0;
  433. right: 55rpx;
  434. background: #fa2209;
  435. color: #fff;
  436. border-radius: 100%;
  437. min-width: 38rpx;
  438. height: 38rpx;
  439. display: flex;
  440. justify-content: center;
  441. align-items: center;
  442. padding: 1rpx;
  443. font-size: 24rpx;
  444. }
  445. // 我的钱包
  446. .my-asset {
  447. display: flex;
  448. background: #fff;
  449. padding: 40rpx 0;
  450. .asset-right {
  451. width: 200rpx;
  452. border-left: 1rpx solid #eee;
  453. }
  454. .asset-right-item {
  455. text-align: center;
  456. color: #545454;
  457. .item-icon {
  458. font-size: 44rpx;
  459. }
  460. .item-name {
  461. margin-top: 14rpx;
  462. font-size: 28rpx;
  463. }
  464. }
  465. .asset-left-item {
  466. text-align: center;
  467. color: #666;
  468. padding: 0 42rpx;
  469. .item-value {
  470. font-size: 34rpx;
  471. color: red;
  472. }
  473. .item-name {
  474. margin-top: 6rpx;
  475. }
  476. .item-name {
  477. margin-top: 14rpx;
  478. font-size: 28rpx;
  479. }
  480. }
  481. }
  482. // 订单操作
  483. .order-navbar {
  484. display: flex;
  485. margin: 20rpx auto 20rpx auto;
  486. padding: 20rpx 0;
  487. width: 94%;
  488. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  489. font-size: 30rpx;
  490. border-radius: 5rpx;
  491. background: #fff;
  492. &-item {
  493. position: relative;
  494. width: 25%;
  495. .item-icon {
  496. text-align: center;
  497. margin: 0 auto;
  498. padding: 10rpx 0;
  499. color: #545454;
  500. font-size: 44rpx;
  501. }
  502. .item-name {
  503. font-size: 28rpx;
  504. color: #545454;
  505. text-align: center;
  506. margin-right: 10rpx;
  507. }
  508. }
  509. }
  510. // 我的服务
  511. .my-service {
  512. margin: 22rpx auto 22rpx auto;
  513. padding: 22rpx 0;
  514. width: 94%;
  515. box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
  516. border-radius: 5rpx;
  517. background: #fff;
  518. .service-title {
  519. padding-left: 24rpx;
  520. margin-bottom: 20rpx;
  521. font-size: 30rpx;
  522. }
  523. .service-content {
  524. margin-bottom: -20rpx;
  525. .service-item {
  526. position: relative;
  527. width: 25%;
  528. float: left;
  529. margin-bottom: 30rpx;
  530. .item-icon {
  531. text-align: center;
  532. margin: 0 auto;
  533. padding: 14rpx 0;
  534. color: #ff3800;
  535. font-size: 44rpx;
  536. }
  537. .item-name {
  538. font-size: 28rpx;
  539. color: #545454;
  540. text-align: center;
  541. margin-right: 10rpx;
  542. }
  543. }
  544. }
  545. }
  546. // 退出登录
  547. .my-logout {
  548. display: flex;
  549. justify-content: center;
  550. margin-top: 50rpx;
  551. .logout-btn {
  552. width: 60%;
  553. margin: 0 auto;
  554. font-size: 28rpx;
  555. color: #616161;
  556. border-radius: 20rpx;
  557. border: 1px solid #dcdcdc;
  558. padding: 16rpx 0;
  559. text-align: center;
  560. }
  561. }
  562. </style>