user.vue 16 KB

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