user.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  1. <template>
  2. <view class="container">
  3. <!-- #ifdef APP-PLUS -->
  4. <view class="bar-height"></view>
  5. <!-- #endif -->
  6. <!-- <scroll-view class="content-box" scroll-y="true"> -->
  7. <view class="user-section">
  8. <view class="bg">
  9. <image src="../../static/user/ground.png" mode=""></image>
  10. </view>
  11. <!-- top -->
  12. <view class="user-info-box ">
  13. <view class="detail flex" @click="navTo('/pages/userinfo/userinfo')">
  14. <view class="portrait-box"><image class="portrait" :src="userInfo.avatar || '/static/error/missing-face.png'"></image></view>
  15. <view class="info-box">
  16. <view class="username">{{ userInfo.nickname || '游客' }}</view>
  17. <view class="font-size-sm" v-if="userInfo.uid">{{ userInfo.uid}}</view>
  18. </view>
  19. </view>
  20. <view class="config">
  21. <text class="setting " @click="navTo('/pages/userinfo/userinfo')">
  22. <image src="../../static/user/set.png" mode=""></image>
  23. </text>
  24. 设置
  25. </view>
  26. </view>
  27. <!-- 会员卡功能 -->
  28. </view>
  29. <view class="item-box">
  30. <image class="arc" src="/static/img/arc.png"></image>
  31. <view class="box-title flex borde-b">
  32. <view class="title"><text>我的订单</text></view>
  33. <view class="link" @click="navTo('/pages/order/order?state=5')" hover-class="common-hover">
  34. <text class="iconfont iconenter"></text>
  35. </view>
  36. </view>
  37. <view class="order-section">
  38. <view class="order-item" @click="navTo('/pages/order/order?state=1')" hover-class="common-hover" :hover-stay-time="50">
  39. <view class=" icon1 position-relative">
  40. <image class="icon-img" src="/static/icon/i2.png" mode="aspectFit"></image>
  41. <view class="corner" v-if="orderInfo.unshipped_count > 0">
  42. <text>{{ orderInfo.unshipped_count }}</text>
  43. </view>
  44. </view>
  45. <text>待发货</text>
  46. </view>
  47. <view class="order-item" @click="navTo('/pages/order/order?state=2')" hover-class="common-hover" :hover-stay-time="50">
  48. <view class="icon1 position-relative">
  49. <image class="icon-img" src="/static/icon/i3.png" mode="aspectFit"></image>
  50. <view class="corner" v-if="orderInfo.received_count > 0">
  51. <text>{{ orderInfo.received_count }}</text>
  52. </view>
  53. </view>
  54. <text>待收货</text>
  55. </view>
  56. <view class="order-item" @click="navTo('/pages/order/order?state=3')" hover-class="common-hover" :hover-stay-time="50">
  57. <view class="icon1 position-relative">
  58. <image class="icon-img" src="/static/icon/i4.png" mode="aspectFit"></image>
  59. <view class="corner" v-if="orderInfo.evaluated_count > 0">
  60. <text>{{ orderInfo.evaluated_count }}</text>
  61. </view>
  62. </view>
  63. <text>待评价</text>
  64. </view>
  65. <view class="order-item" @click="navTo('/pages/order/refundOrder?state=0')" hover-class="common-hover" :hover-stay-time="50">
  66. <view class=" icon1 position-relative">
  67. <image class="icon-img" src="/static/icon/i1.png" mode="aspectFit"></image>
  68. </view>
  69. <text>退款</text>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- <view class="cover-container"> -->
  74. <view class="vip" @click="navTo('/pages/wallet/openMember')" v-if="userInfo.level < 3">
  75. <image src="../../static/user/upgrade.png" mode=""></image>
  76. </view>
  77. <!-- 订单 -->
  78. <view class="item-box " v-if="isShowIllegality">
  79. <view class="order-section order">
  80. <view class="order-item" @click="navTo('/pages/wallet/wallet')" hover-class="common-hover" :hover-stay-time="50">
  81. <view class=" icon position-relative"><image class="icon-img" src="../../static/user/balance.png" mode="aspectFit"></image></view>
  82. <text>我的余额</text>
  83. </view>
  84. <view class="order-item" @click="navTo('/pages/award/award')" hover-class="common-hover" :hover-stay-time="50">
  85. <view class=" icon position-relative"><image class="icon-img" src="../../static/user/commission.png" mode="aspectFit"></image></view>
  86. <text>我的佣金</text>
  87. </view>
  88. <view class="order-item" @click="navTo('/pages/coupon/consumer')" hover-class="common-hover" :hover-stay-time="50">
  89. <view class=" icon position-relative"><image class="icon-img" src="../../static/user/coupon.png" mode="aspectFit"></image></view>
  90. <text>我的消费券</text>
  91. </view>
  92. </view>
  93. <!-- 浏览历史 -->
  94. <view class="history-section ">
  95. <uni-list>
  96. <uni-list-item v-if="isShowIllegality" title="我的推广" @click="navTo('/pages/myteam/myteam')" thumb="/static/user/tuiguang.png"></uni-list-item>
  97. <uni-list-item title="邀请海报" @click="navTo('/pages/shareQrCode/index')" thumb="/static/user/haibao.png"></uni-list-item>
  98. <uni-list-item title="我的收藏" @click="navTo('/pages/favorites/favorites')" thumb="/static/user/collect.png"></uni-list-item>
  99. <uni-list-item title="收货地址" @click="navTo('/pages/address/address')" thumb="/static/user/address.png"></uni-list-item>
  100. <uni-list-item title="商家入口" @click="navTo('/pages/merchant/merchant')" thumb="/static/user/shopping.png" v-if="userInfo.service == 1"></uni-list-item>
  101. </uni-list>
  102. </view>
  103. </view>
  104. <!-- </scroll-view> -->
  105. </view>
  106. </template>
  107. <script>
  108. import { mapState, mapMutations } from 'vuex';
  109. import uniList from '@/components/uni-list/uni-list.vue';
  110. import uniListItem from '@/components/uni-list-item/uni-list-item.vue';
  111. import { orderData, orderVerific } from '@/api/user.js';
  112. import { getUserInfo } from '@/api/login.js';
  113. let startY = 0,
  114. moveY = 0,
  115. pageAtTop = true;
  116. export default {
  117. components: {
  118. uniList,
  119. uniListItem
  120. },
  121. data() {
  122. return {
  123. coverTransform: 'translateY(0px)',
  124. coverTransition: '0s',
  125. moving: false,
  126. userDowm: 0, //卡片升级专属高度
  127. userMaxDowm: 0, //卡片最高高度
  128. orderinfo: {
  129. complete_count: 0,
  130. received_count: 0,
  131. unshipped_count: 0,
  132. order_count: 0
  133. },
  134. // 判断是否已经点击过一次取消关注公众号
  135. watchful: true
  136. };
  137. },
  138. onShow() {
  139. // 判断是否已经登录
  140. if (this.hasLogin) {
  141. this.loadBaseData();
  142. }
  143. },
  144. onReady() {
  145. // 初始化获取页面宽度
  146. uni.createSelectorQuery()
  147. .select('.container')
  148. .fields(
  149. {
  150. size: true
  151. },
  152. data => {
  153. // 计算最多下拉的高度
  154. this.userDowm = Math.floor((data.width / 750) * 200);
  155. // 计算最大触发修改高度事件
  156. this.userMaxDowm = Math.floor((data.width / 750) * 250);
  157. }
  158. )
  159. .exec();
  160. },
  161. computed: {
  162. ...mapState('user', ['userInfo', 'orderInfo', 'hasLogin']),
  163. // #ifdef H5
  164. ...mapState(['weichatObj']),
  165. // #endif
  166. ...mapState(['isShowIllegality'])
  167. },
  168. methods: {
  169. ...mapMutations('user', ['setUserInfo', 'setOrderInfo']),
  170. // 加载初始数据
  171. loadBaseData() {
  172. let obj = this;
  173. getUserInfo({})
  174. .then(({ data }) => {
  175. orderData({})
  176. .then(({ data }) => {
  177. obj.setOrderInfo(data);
  178. })
  179. .catch(e => {
  180. obj.setOrderInfo({
  181. complete_count: 0, //完成
  182. received_count: 0, //待收货
  183. unshipped_count: 0, //待发货
  184. order_count: 0, //订单总数
  185. unpaid_count: 0 //待付款
  186. });
  187. });
  188. obj.setUserInfo(data);
  189. // 判断是否已经关注公众号
  190. if (data.subscribe == 0 && obj.watchful) {
  191. uni.showModal({
  192. title: '温馨提醒',
  193. content: '为提供更好的服务,请关注公众号。',
  194. success: res => {
  195. obj.watchful = false;
  196. // 判断是否点击了确认
  197. if (res.confirm) {
  198. uni.navigateTo({
  199. url: '/pages/shareQrCode/wechatQr'
  200. });
  201. }
  202. }
  203. });
  204. }
  205. })
  206. .catch(e => {
  207. console.log(e);
  208. });
  209. },
  210. /**
  211. * 统一跳转接口,拦截未登录路由
  212. * navigator标签现在默认没有转场动画,所以用view
  213. */
  214. navTo(url) {
  215. if (!this.hasLogin) {
  216. url = '/pages/public/login';
  217. // #ifdef H5
  218. let weichatBrowser = uni.getStorageSync('weichatBrowser');
  219. // 判断是否为微信浏览器
  220. if (weichatBrowser) {
  221. url = '/pages/public/wxLogin';
  222. }
  223. // #endif
  224. // #ifdef MP-WEIXIN
  225. url = '/pages/public/wxLogin';
  226. // #endif
  227. }
  228. uni.navigateTo({
  229. url
  230. });
  231. },
  232. /**
  233. * 会员卡下拉和回弹
  234. * 1.关闭bounce避免ios端下拉冲突
  235. * 2.由于touchmove事件的缺陷(以前做小程序就遇到,比如20跳到40,h5反而好很多),下拉的时候会有掉帧的感觉
  236. * transition设置0.1秒延迟,让css来过渡这段空窗期
  237. * 3.回弹效果可修改曲线值来调整效果,推荐一个好用的bezier生成工具 http://cubic-bezier.com/
  238. */
  239. coverTouchstart(e) {
  240. // console.log(e);
  241. if (pageAtTop === false) {
  242. return;
  243. }
  244. this.coverTransition = 'transform .1s linear';
  245. startY = e.touches[0].clientY;
  246. },
  247. coverTouchmove(e) {
  248. // console.log(e);
  249. moveY = e.touches[0].clientY;
  250. let moveDistance = moveY - startY;
  251. let maxDowm = this.userMaxDowm;
  252. let Dowm = this.userDowm;
  253. if (moveDistance < 0) {
  254. this.moving = false;
  255. return;
  256. }
  257. this.moving = true;
  258. if (moveDistance >= Dowm && moveDistance < maxDowm) {
  259. moveDistance = Dowm;
  260. }
  261. if (moveDistance > 0 && moveDistance <= Dowm) {
  262. this.coverTransform = `translateY(${moveDistance}px)`;
  263. }
  264. },
  265. coverTouchend() {
  266. if (this.moving === false) {
  267. return;
  268. }
  269. this.moving = false;
  270. this.coverTransition = 'transform 0.3s cubic-bezier(.21,1.93,.53,.64)';
  271. this.coverTransform = 'translateY(0px)';
  272. },
  273. // 核销
  274. openQr() {
  275. let obj = this;
  276. // #ifndef H5
  277. uni.scanCode({
  278. success(e) {
  279. obj.orderVerific(e.result);
  280. }
  281. });
  282. // #endif
  283. // #ifdef H5
  284. this.weichatObj.scanQRCode({
  285. needResult: 1, // 默认为0,扫描结果由微信处理,1则直接返回扫描结果,
  286. scanType: ['qrCode', 'barCode'], // 可以指定扫二维码还是一维码,默认二者都有
  287. success: function(res) {
  288. obj.orderVerific(res.resultStr); // 当needResult 为 1 时,扫码返回的结果
  289. }
  290. });
  291. // #endif
  292. },
  293. // 核销请求
  294. orderVerific(data) {
  295. orderVerific({
  296. verify_code: data
  297. })
  298. .then(e => {
  299. uni.showModal({
  300. title: '核销',
  301. content: '已核销成功',
  302. showCancel: false
  303. });
  304. })
  305. .catch(e => {
  306. uni.showModal({
  307. title: '错误',
  308. content: JSON.stringify(e),
  309. showCancel: false
  310. });
  311. console.log(e);
  312. });
  313. }
  314. }
  315. };
  316. </script>
  317. <style lang="scss">
  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: #FFFFFF;
  334. /* #ifdef APP-PLUS */
  335. .bar-height {
  336. height: var(--status-bar-height);
  337. background-color: $base-color;
  338. }
  339. /* #endif */
  340. }
  341. .content-box {
  342. height: 100%;
  343. }
  344. .user-section {
  345. height: 435rpx;
  346. padding: 60rpx 0 0 30rpx;
  347. position: relative;
  348. .bg {
  349. position: absolute;
  350. height: 480rpx;
  351. width: 100%;
  352. left: 0;
  353. top: 0;
  354. image{
  355. width: 100%;
  356. height: 100%;
  357. }
  358. // background-color: $base-color;
  359. }
  360. }
  361. .user-info-box {
  362. height: 280rpx;
  363. color: white;
  364. display: flex;
  365. align-items: start;
  366. justify-content: space-between;
  367. position: relative;
  368. z-index: 1;
  369. .detail {
  370. height: 130rpx;
  371. .portrait-box {
  372. height: 100%;
  373. .portrait {
  374. width: 130rpx;
  375. height: 100%;
  376. border: 5rpx solid #fff;
  377. border-radius: 50%;
  378. }
  379. }
  380. .info-box {
  381. margin-left: 20rpx;
  382. line-height: 1.5;
  383. .username {
  384. font-size: $font-lg + 6rpx;
  385. height: 100%;
  386. }
  387. }
  388. }
  389. .config {
  390. font-size: 28rpx;
  391. font-family: PingFang SC;
  392. font-weight: 500;
  393. color: #52C696;
  394. display: flex;
  395. justify-content: center;
  396. align-items: center;
  397. width: 165rpx;
  398. height: 64rpx;
  399. background: #FFFFFF;
  400. border-radius: 32px 0px 0px 32px;
  401. .setting {
  402. width: 32rpx;
  403. height: 32rpx;
  404. image{
  405. width: 100%;
  406. height: 100%;
  407. }
  408. // margin-right: 51rpx;
  409. }
  410. }
  411. }
  412. .vip-card-box {
  413. display: flex;
  414. flex-direction: column;
  415. color: #f7d680;
  416. height: 240rpx;
  417. background: linear-gradient(left, rgba(0, 0, 0, 0.7), rgba(0, 0, 0, 0.8));
  418. border-radius: 16rpx 16rpx 0 0;
  419. overflow: hidden;
  420. position: relative;
  421. padding: 20rpx 24rpx;
  422. .card-bg {
  423. position: absolute;
  424. top: 20rpx;
  425. right: 0;
  426. width: 380rpx;
  427. height: 260rpx;
  428. }
  429. .b-btn {
  430. position: absolute;
  431. right: 20rpx;
  432. top: 16rpx;
  433. width: 132rpx;
  434. height: 40rpx;
  435. text-align: center;
  436. line-height: 40rpx;
  437. font-size: 22rpx;
  438. color: #36343c;
  439. border-radius: 20px;
  440. background: linear-gradient(left, #f9e6af, #ffd465);
  441. z-index: 1;
  442. }
  443. .tit {
  444. font-size: $font-base + 2rpx;
  445. color: #f7d680;
  446. margin-bottom: 28rpx;
  447. .iconfont {
  448. color: #f6e5a3;
  449. margin-right: 16rpx;
  450. font-size: 30rpx;
  451. }
  452. }
  453. .e-b {
  454. font-size: $font-sm;
  455. color: #d8cba9;
  456. margin-top: 10rpx;
  457. }
  458. }
  459. .vip{
  460. margin-top: -110rpx;
  461. margin-bottom: 110rpx;
  462. padding: 0 30rpx;
  463. height: 170rpx;
  464. image{
  465. height: 100%;
  466. width: 100%;
  467. }
  468. }
  469. .cover-container {
  470. display: flex;
  471. flex-direction: column;
  472. background: $page-color-base;
  473. padding: 0 30rpx;
  474. position: relative;
  475. background: #f5f5f5;
  476. padding-bottom: 20rpx;
  477. margin-top: -110rpx;
  478. .arc {
  479. position: absolute;
  480. left: 0;
  481. top: -34rpx;
  482. width: 100%;
  483. height: 36rpx;
  484. }
  485. }
  486. .tj-sction {
  487. @extend %section;
  488. .tj-item {
  489. @extend %flex-center;
  490. flex-direction: column;
  491. height: 140rpx;
  492. font-size: $font-sm;
  493. color: #75787d;
  494. }
  495. .num {
  496. font-size: $font-lg;
  497. color: $font-color-dark;
  498. margin-bottom: 8rpx;
  499. }
  500. }
  501. .item-box {
  502. position: relative;
  503. background-color: white;
  504. top: -150rpx;
  505. box-shadow: 0px 0px 20rpx 0px rgba(50, 50, 52, 0.06);
  506. .arc {
  507. position: absolute;
  508. left: 0;
  509. top: -34rpx;
  510. width: 100%;
  511. height: 36rpx;
  512. }
  513. .box-title {
  514. line-height: 1;
  515. padding: 30rpx;
  516. .title {
  517. font-size: $font-lg;
  518. font-weight: bold;
  519. }
  520. .link {
  521. font-size: $font-base - 2rpx;
  522. color: $font-color-light;
  523. }
  524. }
  525. // .order{
  526. // margin-top: 70rpx;
  527. // }
  528. .order-section {
  529. @extend %section;
  530. padding: 28rpx 0;
  531. .order-item {
  532. @extend %flex-center;
  533. // width: 120rpx;
  534. width: 25%;
  535. height: 120rpx;
  536. border-radius: 10rpx;
  537. font-size: $font-sm;
  538. color: $font-color-dark;
  539. }
  540. .iconfont {
  541. font-size: 48rpx;
  542. margin-bottom: 18rpx;
  543. color: #fa436a;
  544. }
  545. .icon-shouhoutuikuan {
  546. font-size: 44rpx;
  547. }
  548. .icon {
  549. height: 88rpx;
  550. width: 90rpx;
  551. margin-bottom: 18rpx;
  552. background-size: 100%;
  553. background-repeat: no-repeat;
  554. background-position: center;
  555. .icon-img {
  556. width: 100%;
  557. height: 100%;
  558. }
  559. }
  560. .icon1 {
  561. height: 50rpx;
  562. width: 48rpx;
  563. margin-bottom: 18rpx;
  564. background-size: 100%;
  565. background-repeat: no-repeat;
  566. background-position: center;
  567. .icon-img {
  568. width: 100%;
  569. height: 100%;
  570. }
  571. }
  572. }
  573. }
  574. .history-section {
  575. // padding: 30rpx 0 0;
  576. margin-top: 20rpx;
  577. background: #fff;
  578. border-radius: 10rpx;
  579. .sec-header {
  580. display: flex;
  581. align-items: center;
  582. font-size: $font-base;
  583. color: $font-color-dark;
  584. line-height: 40rpx;
  585. margin-left: 30rpx;
  586. padding-top: 30rpx;
  587. .iconfont {
  588. font-size: 44rpx;
  589. color: $color-red;
  590. margin-right: 16rpx;
  591. line-height: 40rpx;
  592. }
  593. }
  594. .h-list {
  595. white-space: nowrap;
  596. padding: 30rpx 30rpx 0;
  597. image {
  598. display: inline-block;
  599. width: 160rpx;
  600. height: 160rpx;
  601. margin-right: 20rpx;
  602. border-radius: 10rpx;
  603. }
  604. }
  605. }
  606. </style>