user.vue 15 KB

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