user.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556
  1. <template>
  2. <view class="container">
  3. <view class="vheigh"></view>
  4. <scroll-view class="content-box" scroll-y="true">
  5. <view class="user-section">
  6. <view class="bg"></view>
  7. <view class="user-info-box ">
  8. <view class="detail flex" @click="navTo('/pages/set/userinfo')">
  9. <view class="portrait-box"><image class="portrait" :src="userInfo.avatar || '/static/error/missing-face.png'"></image></view>
  10. <view class="info-box">
  11. <view class="username">{{ userInfo.nickname || '游客' }}</view>
  12. <view class="font-size-sm" v-if="userInfo.spread_uid">邀请码:{{ userInfo.spread_uid }}</view>
  13. </view>
  14. </view>
  15. <view class="config iconfont">
  16. <text class="setting iconsetting" @click="navTo('/pages/set/set')"></text>
  17. <text class="message iconmessage" @click="navTo('/pages/user/notice')"></text>
  18. </view>
  19. </view>
  20. <!-- 会员卡功能 -->
  21. <view class="vip-card-box">
  22. <image class="card-bg" src="/static/img/vip-card-bg.png" mode=""></image>
  23. <view class="b-btn">我要升级</view>
  24. <view class="tit">
  25. <text class="iconfont icon-iLinkapp-"></text>
  26. 升级专享优惠权益
  27. </view>
  28. <text class="e-m">DCloud Union</text>
  29. <text class="e-b">开通会员开发无bug 一测就上线</text>
  30. </view>
  31. </view>
  32. <view
  33. class="cover-container"
  34. :style="[
  35. {
  36. transform: coverTransform,
  37. transition: coverTransition
  38. }
  39. ]"
  40. @touchstart="coverTouchstart"
  41. @touchmove="coverTouchmove"
  42. @touchend="coverTouchend"
  43. >
  44. <image class="arc" src="/static/img/arc.png"></image>
  45. <view class="tj-sction">
  46. <view class="tj-item" @click="navTo('/pages/money/wallet')">
  47. <text class="num">{{ userInfo.now_money || '0.00' }}</text>
  48. <text>余额</text>
  49. </view>
  50. <view class="tj-item" @click="navTo('/pages/user/award')">
  51. <text class="num">{{ userInfo.brokerage_price || '0.00' }}</text>
  52. <text>佣金</text>
  53. </view>
  54. <view class="tj-item" @click="navTo('/pages/user/scoreAccumulate')">
  55. <text class="num">{{ userInfo.integral || '0.00' }}</text>
  56. <text>积分</text>
  57. </view>
  58. </view>
  59. <!-- 订单 -->
  60. <view class="item-box">
  61. <!-- <view class="box-title flex borde-b">
  62. <view class="title"><text>我的订单</text></view>
  63. <view class="link" @click="navTo('/pages/order/order?state=0')" hover-class="common-hover">
  64. <text>全部订单</text>
  65. <text class="iconfont iconenter"></text>
  66. </view>
  67. </view> -->
  68. <view class="order-section">
  69. <view class="order-item" @click="navTo('/pages/order/order?state=0')" hover-class="common-hover" :hover-stay-time="50">
  70. <view class=" icon position-relative">
  71. <image class="icon-img" src="/static/icon/i1.png" mode="aspectFit"></image>
  72. <view class="corner" v-if="orderInfo.unpaid_count > 0">
  73. <text>{{ orderInfo.unpaid_count }}</text>
  74. </view>
  75. </view>
  76. <text>待付款</text>
  77. </view>
  78. <view class="order-item" @click="navTo('/pages/order/order?state=1')" hover-class="common-hover" :hover-stay-time="50">
  79. <view class=" icon position-relative">
  80. <image class="icon-img" src="/static/icon/i2.png" mode="aspectFit"></image>
  81. <view class="corner" v-if="orderInfo.unshipped_count > 0">
  82. <text>{{ orderInfo.unshipped_count }}</text>
  83. </view>
  84. </view>
  85. <text>待发货</text>
  86. </view>
  87. <view class="order-item" @click="navTo('/pages/order/order?state=2')" hover-class="common-hover" :hover-stay-time="50">
  88. <view class="icon position-relative">
  89. <image class="icon-img" src="/static/icon/i3.png" mode="aspectFit"></image>
  90. <view class="corner" v-if="orderInfo.received_count > 0">
  91. <text>{{ orderInfo.received_count }}</text>
  92. </view>
  93. </view>
  94. <text>待收货</text>
  95. </view>
  96. <view class="order-item" @click="navTo('/pages/order/order?state=3')" hover-class="common-hover" :hover-stay-time="50">
  97. <view class="icon position-relative">
  98. <image class="icon-img" src="/static/icon/i4.png" mode="aspectFit"></image>
  99. <!-- <view class="corner" v-if="orderInfo.complete_count > 0">
  100. <text>{{ orderInfo.complete_count }}</text>
  101. </view> -->
  102. </view>
  103. <text>已完成</text>
  104. </view>
  105. </view>
  106. </view>
  107. <view class="item-box">
  108. <!-- <view class="box-title flex borde-b">
  109. <view class="title"><text>我的资产</text></view>
  110. </view> -->
  111. <view class="order-section">
  112. <view class="order-item" @click="navTo('/pages/money/wallet')" hover-class="common-hover" :hover-stay-time="50">
  113. <view class="icon"><image class="icon-img" src="/static/icon/u1.png" mode="aspectFit"></image></view>
  114. <text>我的钱包</text>
  115. </view>
  116. <view class="order-item" @click="navTo('/pages/user/award')" hover-class="common-hover" :hover-stay-time="50">
  117. <view class="icon"><image class="icon-img" src="/static/icon/u2.png" mode="aspectFit"></image></view>
  118. <text>奖励明细</text>
  119. </view>
  120. <view class="order-item" @click="navTo('/pages/user/award')" hover-class="common-hover" :hover-stay-time="50">
  121. <view class="icon"><image class="icon-img" src="/static/icon/u3.png" mode="aspectFit"></image></view>
  122. <text>积分明细</text>
  123. </view>
  124. <view class="order-item" @click="navTo('/pages/order/order?state=4')" hover-class="common-hover" :hover-stay-time="50">
  125. <view class="icon"><image class="icon-img" src="/static/icon/u4.png" mode="aspectFit"></image></view>
  126. <text>通用币</text>
  127. </view>
  128. </view>
  129. </view>
  130. <!-- 浏览历史 -->
  131. <view class="history-section icon">
  132. <view class="sec-header">
  133. <text class="iconfont iconfavor"></text>
  134. <text>浏览历史</text>
  135. </view>
  136. <scroll-view scroll-x class="h-list">
  137. <image
  138. class="h-list-image"
  139. @click="navTo('/pages/product/product')"
  140. src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1553105186633&di=c121a29beece4e14269948d990f9e720&imgtype=0&src=http%3A%2F%2Fimg004.hc360.cn%2Fm8%2FM04%2FDE%2FDE%2FwKhQplZ-QteEBvsbAAAAADUkobU751.jpg"
  141. mode="aspectFill"
  142. ></image>
  143. </scroll-view>
  144. <uni-list>
  145. <uni-list-item title="我的钱包" @click="navTo('/pages/money/wallet')" thumb="/static/icon/img11.png"></uni-list-item>
  146. <uni-list-item title="我的卡卷" @click="navTo('/pages/user/coupon')" thumb="/static/icon/img12.png"></uni-list-item>
  147. <uni-list-item title="我的收藏" @click="navTo('/pages/user/favorites')" thumb="/static/icon/img02.png"></uni-list-item>
  148. <uni-list-item title="商户入驻" @click="navTo('/pages/set/address')" thumb="/static/icon/img05.png"></uni-list-item>
  149. <uni-list-item title="邀请好友" @click="navTo('/pages/user/shareQrCode')" thumb="/static/icon/img10.png"></uni-list-item>
  150. <uni-list-item title="关于我们" @click="navTo('/pages/shareQrCode/index')" thumb="/static/icon/img09.png"></uni-list-item>
  151. </uni-list>
  152. </view>
  153. </view>
  154. </scroll-view>
  155. </view>
  156. </template>
  157. <script>
  158. import { mapState, mapMutations } from 'vuex';
  159. import uniList from '@/components/uni-list/uni-list.vue';
  160. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  161. import { orderData, userinfo } from '@/api/user.js';
  162. import { saveUrl, interceptor } from '@/utils/loginUtils.js';
  163. let startY = 0,
  164. moveY = 0,
  165. pageAtTop = true;
  166. export default {
  167. components: {
  168. uniList,
  169. uniListItem
  170. },
  171. data() {
  172. return {
  173. coverTransform: 'translateY(0px)',
  174. coverTransition: '0s',
  175. moving: false,
  176. userDowm: 0, //卡片升级专属高度
  177. userMaxDowm: 0 //卡片最高高度
  178. };
  179. },
  180. onShow() {
  181. // 判断是否已经登录
  182. if (this.hasLogin) {
  183. this.loadBaseData();
  184. }
  185. },
  186. onReady() {
  187. // 初始化获取页面宽度
  188. uni.createSelectorQuery()
  189. .select('.container')
  190. .fields(
  191. {
  192. size: true
  193. },
  194. data => {
  195. // 计算最多下拉的高度
  196. this.userDowm = Math.floor((data.width / 750) * 185);
  197. // 计算最大触发修改高度事件
  198. this.userMaxDowm = Math.floor((data.width / 750) * 250);
  199. }
  200. )
  201. .exec();
  202. },
  203. // #ifndef MP
  204. // onNavigationBarButtonTap(e) {
  205. // const index = e.index;
  206. // if (index === 0) {
  207. // this.navTo('/pages/set/set');
  208. // } else if (index === 1) {
  209. // // #ifdef APP-PLUS
  210. // const pages = getCurrentPages();
  211. // const page = pages[pages.length - 1];
  212. // const currentWebview = page.$getAppWebview();
  213. // currentWebview.hideTitleNViewButtonRedDot({
  214. // index
  215. // });
  216. // // #endif
  217. // uni.navigateTo({
  218. // url: '/pages/user/notice'
  219. // });
  220. // }
  221. // },
  222. // #endif
  223. computed: {
  224. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin'])
  225. },
  226. methods: {
  227. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  228. // 加载初始数据
  229. loadBaseData() {
  230. userinfo({})
  231. .then(({ data }) => {
  232. this.setUserInfo(data);
  233. // 获取用户数据完毕后在获取订单数据防止多次跳转到登录页
  234. orderData({})
  235. .then(({ data }) => {
  236. this.setOrderInfo(data);
  237. })
  238. .catch(e => {
  239. this.setOrderInfo({
  240. complete_count: 0, //完成
  241. received_count: 0, //待收货
  242. unshipped_count: 0, //待发货
  243. order_count: 0, //订单总数
  244. unpaid_count: 0 //待付款
  245. });
  246. });
  247. })
  248. .catch(e => {
  249. console.log(e);
  250. });
  251. },
  252. /**
  253. * 统一跳转接口,拦截未登录路由
  254. * navigator标签现在默认没有转场动画,所以用view
  255. */
  256. navTo(url) {
  257. if (!this.hasLogin) {
  258. // 保存地址
  259. saveUrl();
  260. // 登录拦截
  261. interceptor();
  262. } else {
  263. uni.navigateTo({
  264. url
  265. });
  266. }
  267. },
  268. /**
  269. * 会员卡下拉和回弹
  270. * 1.关闭bounce避免ios端下拉冲突
  271. * 2.由于touchmove事件的缺陷(以前做小程序就遇到,比如20跳到40,h5反而好很多),下拉的时候会有掉帧的感觉
  272. * transition设置0.1秒延迟,让css来过渡这段空窗期
  273. * 3.回弹效果可修改曲线值来调整效果,推荐一个好用的bezier生成工具 http://cubic-bezier.com/
  274. */
  275. coverTouchstart(e) {
  276. // console.log(e);
  277. if (pageAtTop === false) {
  278. return;
  279. }
  280. this.coverTransition = 'transform .1s linear';
  281. startY = e.touches[0].clientY;
  282. },
  283. coverTouchmove(e) {
  284. // console.log(e);
  285. moveY = e.touches[0].clientY;
  286. let moveDistance = moveY - startY;
  287. let maxDowm = this.userMaxDowm;
  288. let Dowm = this.userDowm;
  289. if (moveDistance < 0) {
  290. this.moving = false;
  291. return;
  292. }
  293. this.moving = true;
  294. if (moveDistance >= Dowm && moveDistance < maxDowm) {
  295. moveDistance = Dowm;
  296. }
  297. if (moveDistance > 0 && moveDistance <= Dowm) {
  298. this.coverTransform = `translateY(${moveDistance}px)`;
  299. }
  300. },
  301. coverTouchend() {
  302. if (this.moving === false) {
  303. return;
  304. }
  305. this.moving = false;
  306. this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
  307. this.coverTransform = 'translateY(0px)';
  308. }
  309. }
  310. };
  311. </script>
  312. <style lang="scss">
  313. page {
  314. height: 100%;
  315. }
  316. %flex-center {
  317. display: flex;
  318. flex-direction: column;
  319. justify-content: center;
  320. align-items: center;
  321. }
  322. %section {
  323. display: flex;
  324. justify-content: space-around;
  325. align-content: center;
  326. background: #fff;
  327. border-radius: 10rpx;
  328. }
  329. .container {
  330. height: 100%;
  331. background-color: $page-color-base;
  332. }
  333. .content-box {
  334. height: 100%;
  335. }
  336. .vheigh {
  337. height: var(--status-bar-height);
  338. background-color: $base-color;
  339. }
  340. .user-section {
  341. height: 435rpx;
  342. padding: 15rpx 30rpx 0;
  343. position: relative;
  344. .bg {
  345. position: absolute;
  346. left: 0;
  347. top: 0;
  348. width: 100%;
  349. height: 100%;
  350. background-color: $base-color;
  351. }
  352. }
  353. .user-info-box {
  354. height: 180rpx;
  355. color: white;
  356. display: flex;
  357. align-items: center;
  358. justify-content: space-between;
  359. position: relative;
  360. z-index: 1;
  361. .detail {
  362. height: 130rpx;
  363. .portrait-box {
  364. height: 100%;
  365. .portrait {
  366. width: 130rpx;
  367. height: 100%;
  368. border: 5rpx solid #fff;
  369. border-radius: 50%;
  370. }
  371. }
  372. .info-box {
  373. margin-left: 20rpx;
  374. line-height: 1.5;
  375. .username {
  376. font-size: $font-lg + 6rpx;
  377. height: 100%;
  378. }
  379. }
  380. }
  381. .config {
  382. font-size: 48rpx;
  383. height: 130rpx;
  384. .setting {
  385. margin-right: 51rpx;
  386. }
  387. }
  388. }
  389. .vip-card-box {
  390. display: flex;
  391. flex-direction: column;
  392. color: #f7d680;
  393. height: 240rpx;
  394. background: linear-gradient(left, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.8));
  395. border-radius: 16rpx 16rpx 0 0;
  396. overflow: hidden;
  397. position: relative;
  398. padding: 20rpx 24rpx;
  399. .card-bg {
  400. position: absolute;
  401. top: 20rpx;
  402. right: 0;
  403. width: 380rpx;
  404. height: 260rpx;
  405. }
  406. .b-btn {
  407. position: absolute;
  408. right: 20rpx;
  409. top: 16rpx;
  410. width: 132rpx;
  411. height: 40rpx;
  412. text-align: center;
  413. line-height: 40rpx;
  414. font-size: 22rpx;
  415. color: #36343c;
  416. border-radius: 20px;
  417. background: linear-gradient(left, #f9e6af, #ffd465);
  418. z-index: 1;
  419. }
  420. .tit {
  421. font-size: $font-base + 2rpx;
  422. color: #f7d680;
  423. margin-bottom: 28rpx;
  424. .iconfont {
  425. color: #f6e5a3;
  426. margin-right: 16rpx;
  427. }
  428. }
  429. .e-b {
  430. font-size: $font-sm;
  431. color: #d8cba9;
  432. margin-top: 10rpx;
  433. }
  434. }
  435. .cover-container {
  436. background: $page-color-base;
  437. margin-top: -150rpx;
  438. padding: 0 30rpx;
  439. position: relative;
  440. background: #f5f5f5;
  441. padding-bottom: 20rpx;
  442. .arc {
  443. position: absolute;
  444. left: 0;
  445. top: -34rpx;
  446. width: 100%;
  447. height: 36rpx;
  448. }
  449. }
  450. .tj-sction {
  451. @extend %section;
  452. .tj-item {
  453. @extend %flex-center;
  454. flex-direction: column;
  455. height: 140rpx;
  456. font-size: $font-sm;
  457. color: #75787d;
  458. }
  459. .num {
  460. font-size: $font-lg;
  461. color: $font-color-dark;
  462. margin-bottom: 8rpx;
  463. }
  464. }
  465. .item-box {
  466. border-radius: 10rpx;
  467. background-color: white;
  468. margin-top: 20rpx;
  469. .box-title {
  470. line-height: 1;
  471. padding: 30rpx;
  472. .title {
  473. font-size: $font-lg;
  474. font-weight: bold;
  475. }
  476. .link {
  477. font-size: $font-base - 2rpx;
  478. color: $font-color-light;
  479. }
  480. }
  481. .order-section {
  482. @extend %section;
  483. padding: 28rpx 0;
  484. .order-item {
  485. @extend %flex-center;
  486. width: 120rpx;
  487. height: 120rpx;
  488. border-radius: 10rpx;
  489. font-size: $font-sm;
  490. color: $font-color-dark;
  491. }
  492. .iconfont {
  493. font-size: 48rpx;
  494. margin-bottom: 18rpx;
  495. color: #fa436a;
  496. }
  497. .icon-shouhoutuikuan {
  498. font-size: 44rpx;
  499. }
  500. .icon {
  501. height: 50rpx;
  502. width: 48rpx;
  503. margin-bottom: 18rpx;
  504. background-size: 100%;
  505. background-repeat: no-repeat;
  506. background-position: center;
  507. .icon-img {
  508. width: 100%;
  509. height: 100%;
  510. }
  511. }
  512. }
  513. }
  514. .history-section {
  515. // padding: 30rpx 0 0;
  516. margin-top: 20rpx;
  517. background: #fff;
  518. border-radius: 10rpx;
  519. .sec-header {
  520. display: flex;
  521. align-items: center;
  522. font-size: $font-base;
  523. color: $font-color-dark;
  524. line-height: 40rpx;
  525. margin-left: 30rpx;
  526. padding-top: 30rpx;
  527. .iconfont {
  528. font-size: 44rpx;
  529. color: $color-red;
  530. margin-right: 16rpx;
  531. line-height: 40rpx;
  532. }
  533. }
  534. .h-list {
  535. white-space: nowrap;
  536. padding: 30rpx 30rpx 0;
  537. .h-list-image {
  538. display: inline-block;
  539. width: 160rpx;
  540. height: 160rpx;
  541. margin-right: 20rpx;
  542. border-radius: 10rpx;
  543. }
  544. }
  545. }
  546. </style>