user.vue 12 KB

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