app-user-center-top.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  1. <template>
  2. <!-- 'background-image': 'url('+topPicUrl+')' -->
  3. <view class="app-user-center-top cross-center" :style="{'background-image': 'url('+topPicUrl+')'}">
  4. <!-- style 3 start -->
  5. <view class="style-3 box-grow-1 main-center" v-if="topStyle == '3'">
  6. <view class="style-3-container dir-left-nowrap cross-center"
  7. :style="userCenter.style_bg_pic_url?`background-image: url(${userCenter.style_bg_pic_url})`:``">
  8. <view class="box-grow-0 avatar-container">
  9. <image :src="avatar"
  10. :class="[is_vip_card_user && is_icon_super_vip == '1' ? 'avatar is_vip' : 'avatar']"></image>
  11. <image v-if="is_vip_card_user && is_icon_super_vip == '1'" src="/static/image/vip_icon.png"
  12. class="vip_icon"></image>
  13. </view>
  14. <view class="box-grow-1 info-container">
  15. <template v-if="isLogin">
  16. <view class="dir-left-nowrap cross-center">
  17. <view v-if="userInfo" class="nickname t-omit" :style="{'color':userNameColor}">
  18. {{userInfo.nickname}}
  19. </view>
  20. <!--#ifdef MP-WEIXIN -->
  21. <button class="u-refresh dir-left-nowrap main-between cross-center member-margin"
  22. scope="userInfo" @click="getUserInfo">
  23. <icon class="u-icon" type></icon>
  24. <text>刷新</text>
  25. </button>
  26. <!-- #endif-->
  27. <!--#ifdef H5 -->
  28. <button class="u-refresh dir-left-nowrap main-between cross-center member-margin"
  29. @click="getUserInfo" v-if="isWechat">
  30. <icon class="u-icon" type></icon>
  31. <text>刷新</text>
  32. </button>
  33. <!-- #endif-->
  34. </view>
  35. <app-form-id @click="goMember" v-if="mall.setting.is_icon_members_grade == 1">
  36. <view class="member-info inline-flex cross-center dir-left-nowrap">
  37. <view>
  38. <image :src="getMemberPicUrl" class="member-icon" mode="aspectFill"></image>
  39. </view>
  40. <view v-if="userInfo" class="t-omit">{{userInfo.identity.level_name}}</view>
  41. </view>
  42. </app-form-id>
  43. </template>
  44. <template v-else>
  45. <app-form-id>
  46. <view class="login-btn" @click="callLogin">点击登录</view>
  47. </app-form-id>
  48. </template>
  49. </view>
  50. <view class="box-grow-0 address-container">
  51. <app-jump-button v-if="userInfo && userInfo.is_show_pay_code" form
  52. url="/plugins/teller/index/index">
  53. <view class="address-btn-3 pay-code">
  54. <image class="pay-code-icon" src="/static/image/icon/pay-code.png"></image>
  55. <view>付款码</view>
  56. </view>
  57. </app-jump-button>
  58. <app-jump-button form url="/pages/address/address">
  59. <view class="address-btn-3">
  60. <image class="address-btn-icon" src="/static/image/icon/address-white.png"></image>
  61. <view>收货地址</view>
  62. </view>
  63. </app-jump-button>
  64. </view>
  65. </view>
  66. </view>
  67. <!-- style 3 end -->
  68. <!-- style 2 start -->
  69. <view class="style-2 box-grow-1" v-else-if="topStyle == '2'">
  70. <app-jump-button v-if="userInfo && userInfo.is_show_pay_code" form url="/plugins/teller/index/index">
  71. <view class="pay-code-btn">
  72. <image class="pay-code-icon" src="/static/image/icon/pay-code.png"></image>
  73. <view>付款码</view>
  74. </view>
  75. </app-jump-button>
  76. <view class="avatar-container">
  77. <image :src="avatar"
  78. :class="[is_vip_card_user && is_icon_super_vip == '1' ? 'avatar is_vip' : 'avatar']"></image>
  79. <image v-if="is_vip_card_user && is_icon_super_vip == '1'" src="/static/image/vip_icon.png"
  80. class="vip_icon"></image>
  81. </view>
  82. <view class="info-container">
  83. <template v-if="isLogin">
  84. <app-form-id @click="goMember" v-if="mall.setting.is_icon_members_grade == 1">
  85. <view class="member-info inline-flex cross-center dir-left-nowrap">
  86. <view>
  87. <image :src="getMemberPicUrl" class="member-icon" mode="aspectFill"></image>
  88. </view>
  89. <view v-if="userInfo" class="t-omit">{{userInfo.identity.level_name}}</view>
  90. </view>
  91. </app-form-id>
  92. <view class="dir-left-nowrap cross-center main-center">
  93. <view v-if="userInfo" class="nickname t-omit" :style="{'color':userNameColor}"
  94. :class="[mall.setting.is_icon_members_grade != 1 ? 'no-member-icon' : '',]">
  95. {{userInfo.nickname}}
  96. </view>
  97. <!--#ifdef MP-WEIXIN -->
  98. <button class="u-refresh dir-left-nowrap main-between cross-center"
  99. :class="[mall.setting.is_icon_members_grade != 1 ? 'no-member-icon' : '',]" scope="userInfo"
  100. @click="getUserInfo">
  101. <icon class="u-icon" type></icon>
  102. <text>刷新</text>
  103. </button>
  104. <!-- #endif-->
  105. <!--#ifdef H5 -->
  106. <button class="u-refresh dir-left-nowrap main-between cross-center" v-if="isWechat"
  107. :class="[mall.setting.is_icon_members_grade != 1 ? 'no-member-icon' : '',]"
  108. @click="getUserInfo">
  109. <icon class="u-icon" type></icon>
  110. <text>刷新</text>
  111. </button>
  112. <!-- #endif-->
  113. </view>
  114. </template>
  115. <template v-else>
  116. <app-form-id>
  117. <view class="login-btn" @click="callLogin">点击登录</view>
  118. </app-form-id>
  119. </template>
  120. </view>
  121. </view>
  122. <!-- style 2 end -->
  123. <!-- style 1 start -->
  124. <view class="style-1 dir-left-nowrap cross-center box-grow-1" v-else-if="topStyle == '1'">
  125. <view class="box-grow-0 avatar-container">
  126. <image :src="avatar"
  127. :class="[is_vip_card_user && is_icon_super_vip == '1' ? 'avatar is_vip' : 'avatar']"></image>
  128. <image v-if="is_vip_card_user && is_icon_super_vip == '1'" src="/static/image/vip_icon.png"
  129. class="vip_icon"></image>
  130. </view>
  131. <view class="box-grow-1 info-container">
  132. <template v-if="isLogin">
  133. <view class="dir-left-nowrap cross-center">
  134. <view v-if="userInfo" class="nickname t-omit" :style="{'color':userNameColor}">
  135. {{userInfo.nickname}}
  136. </view>
  137. <!--#ifdef MP-WEIXIN -->
  138. <button class="u-refresh dir-left-nowrap main-between cross-center member-margin"
  139. @click="getUserInfo">
  140. <icon class="u-icon" type></icon>
  141. <text>刷新</text>
  142. </button>
  143. <!-- #endif-->
  144. <!--#ifdef H5 -->
  145. <button class="u-refresh dir-left-nowrap main-between cross-center member-margin"
  146. v-if="isWechat" @click="getUserInfo">
  147. <icon class="u-icon" type></icon>
  148. <text>刷新</text>
  149. </button>
  150. <!-- #endif-->
  151. </view>
  152. <app-form-id @click="goMember" v-if="mall.setting.is_icon_members_grade == 1">
  153. <view class="member-info inline-flex cross-center dir-left-nowrap">
  154. <view>
  155. <image :src="getMemberPicUrl" class="member-icon" mode="aspectFill"></image>
  156. </view>
  157. <view v-if="userInfo" class="t-omit">{{userInfo.identity.level_name}}</view>
  158. </view>
  159. <view class="" v-if="userInfo.identity.member_level>0" style="font-size: 22rpx;color: #fff;">
  160. 会员剩余天数:{{userInfo.user_level_date.end_date}}天
  161. </view>
  162. </app-form-id>
  163. </template>
  164. <template v-else>
  165. <app-form-id>
  166. <view class="login-btn" @click="callLogin">点击登录</view>
  167. </app-form-id>
  168. </template>
  169. </view>
  170. <view class="box-grow-0 address-container">
  171. <app-jump-button v-if="userInfo && userInfo.is_show_pay_code" form url="/plugins/teller/index/index">
  172. <view class="pay-code">
  173. <image class="pay-code-icon" src="/static/image/icon/pay-code.png"></image>
  174. <view>付款码</view>
  175. </view>
  176. </app-jump-button>
  177. <app-jump-button form url="/pages/address/address">
  178. <view class="address-btn-1 dir-left-nowrap cross-center">
  179. <view>
  180. <image class="address-btn-icon" src="/static/image/icon/address-white.png"></image>
  181. </view>
  182. <view>收货地址</view>
  183. </view>
  184. </app-jump-button>
  185. </view>
  186. </view>
  187. <!-- style 1 end -->
  188. </view>
  189. </template>
  190. <script>
  191. import {
  192. mapState,
  193. mapGetters
  194. } from 'vuex';
  195. import Vue from "@dcloudio/vue-cli-plugin-uni/packages/h5-vue";
  196. export default {
  197. name: 'app-user-center-top',
  198. props: {
  199. topStyle: String,
  200. topPicUrl: String,
  201. memberPicUrl: String,
  202. userNameColor: String,
  203. is_icon_super_vip: {
  204. type: String,
  205. default () {
  206. return '0';
  207. }
  208. },
  209. },
  210. computed: {
  211. isLogin() {
  212. return this.$user.isLogin();
  213. },
  214. ...mapState({
  215. mall: state => state.mallConfig.mall,
  216. is_vip_card_user: function(state) {
  217. return state.user.info && state.user.info.is_vip_card_user ? 1 : 0;
  218. }
  219. }),
  220. ...mapGetters({
  221. userCenter: 'mallConfig/getUserCenter',
  222. userInfo: 'user/info',
  223. }),
  224. avatar() {
  225. if (this.isLogin && this.userInfo) {
  226. return this.userInfo.avatar;
  227. } else {
  228. return '/static/image/user-default-avatar.png';
  229. }
  230. },
  231. getMemberPicUrl() {
  232. return this.memberPicUrl;
  233. // todo 此处选哪个图标待确认
  234. if (this.memberPicUrl) {
  235. return this.memberPicUrl;
  236. } else {
  237. return this.userInfo.identity.member_pic_url;
  238. }
  239. },
  240. // #ifdef H5
  241. isWechat: function() {
  242. return this.$jwx.isWechat();
  243. }
  244. // #endif
  245. },
  246. // #ifdef MP
  247. created() {
  248. if (this.isLogin) {
  249. this.$store.dispatch('user/info', {
  250. refresh: true
  251. });
  252. }
  253. },
  254. // #endif
  255. methods: {
  256. callLogin() {
  257. this.$store.dispatch('user/accessToken');
  258. },
  259. goMember() {
  260. uni.navigateTo({
  261. url: '/pages/member/index/index',
  262. });
  263. },
  264. getUserInfo() {
  265. // #ifdef MP
  266. let _this = this;
  267. uni.login({
  268. scopes: 'auth_user',
  269. success: (loginResult) => {
  270. this.getuserinfodata(loginResult)
  271. }
  272. });
  273. // #endif
  274. // #ifdef H5
  275. this.$request({
  276. url: this.$api.registered.url,
  277. method: 'get',
  278. data: {
  279. scope: 'snsapi_userinfo',
  280. response_type: 'code',
  281. url: `${window.location.href}`
  282. }
  283. }).then(res => {
  284. if (res.code === 0) {
  285. this.$storage.setStorageSync('_USER_SIGN', true);
  286. window.location.replace(res.data.url);
  287. } else {
  288. uni.navigateTo({
  289. url: '/pages/registered/sign'
  290. });
  291. }
  292. });
  293. // #endif
  294. },
  295. getuserinfodata(code) {
  296. this.$request({
  297. url: this.$api.passport.login,
  298. method: 'post',
  299. data: {
  300. code: code.code
  301. }
  302. }).then(response => {
  303. uni.hideLoading();
  304. if (response.code === 0) {
  305. uni.showToast({
  306. title: '资料已更新',
  307. icon: 'none'
  308. });
  309. this.$storage.setStorageSync('_USER_ACCESS_TOKEN', response.data.access_token);
  310. } else {
  311. // return reject(response.msg);
  312. }
  313. });
  314. }
  315. }
  316. }
  317. </script>
  318. <style scoped lang="scss">
  319. .app-user-center-top {
  320. width: #{750rpx};
  321. height: #{360rpx};
  322. background-repeat: no-repeat;
  323. background-size: cover;
  324. background-position: center;
  325. overflow: hidden;
  326. }
  327. .avatar {
  328. width: #{132rpx};
  329. height: #{132rpx};
  330. border-radius: #{1000rpx};
  331. }
  332. .avatar.is_vip {
  333. border: #{8rpx} solid #ffe993;
  334. }
  335. .login-btn {
  336. display: inline-block;
  337. padding: #{12rpx} #{24rpx};
  338. font-size: $uni-font-size-import-one;
  339. }
  340. .avatar-container {
  341. padding: #{24rpx};
  342. position: relative;
  343. }
  344. .style-2 .vip_icon {
  345. left: 50%;
  346. margin-left: 29rpx;
  347. }
  348. .vip_icon {
  349. position: absolute;
  350. right: 0;
  351. top: 0;
  352. width: 58rpx;
  353. height: 57rpx;
  354. }
  355. .info-container {
  356. padding: #{0rpx};
  357. position: relative;
  358. z-index: 997;
  359. }
  360. .address-container {
  361. padding: #{24rpx};
  362. }
  363. .member-info {
  364. background: #3c3642;
  365. color: #fff;
  366. font-size: $uni-font-size-weak-two;
  367. padding: #{6rpx} #{12rpx};
  368. border-radius: #{1000rpx};
  369. height: #{36rpx};
  370. line-height: #{36rpx};
  371. .member-icon {
  372. display: block;
  373. width: #{44rpx};
  374. height: #{44rpx};
  375. margin-top: -#{6rpx};
  376. margin-bottom: -#{6rpx};
  377. margin-left: -#{12rpx};
  378. margin-right: #{6rpx};
  379. border-radius: #{1000rpx};
  380. overflow: hidden;
  381. }
  382. }
  383. .pay-code-btn {
  384. z-index: 998;
  385. position: absolute;
  386. right: 50rpx;
  387. top: 0;
  388. color: #fff;
  389. text-align: center;
  390. font-size: $uni-font-size-weak-two;
  391. .pay-code-icon {
  392. width: #{44rpx};
  393. height: #{44rpx};
  394. }
  395. }
  396. .address-btn-3 {
  397. text-align: center;
  398. font-size: $uni-font-size-general-two;
  399. color: #ffffff;
  400. &.pay-code {
  401. margin-bottom: #{20rpx};
  402. font-size: $uni-font-size-weak-two;
  403. .pay-code-icon {
  404. width: #{44rpx};
  405. height: #{44rpx};
  406. }
  407. }
  408. .address-btn-icon {
  409. width: #{44rpx};
  410. height: #{44rpx};
  411. }
  412. }
  413. .address-btn-1 {
  414. padding: #{16rpx} #{18rpx};
  415. border-radius: #{1000rpx} 0 0 #{1000rpx};
  416. margin-right: -#{48rpx};
  417. background: #ff4544;
  418. color: #ffffff;
  419. .address-btn-icon {
  420. width: #{44rpx};
  421. height: #{44rpx};
  422. margin-right: #{12rpx};
  423. display: block;
  424. }
  425. }
  426. .style-3 {
  427. .style-3-container {
  428. background-color: #fff;
  429. border-radius: #{12rpx};
  430. width: #{656rpx};
  431. height: #{220rpx};
  432. background-size: 100% 100%;
  433. .nickname {
  434. margin-bottom: #{12rpx};
  435. color: $uni-important-color-black;
  436. }
  437. }
  438. .u-refresh.member-margin {
  439. margin-bottom: 12upx;
  440. }
  441. }
  442. .style-2 {
  443. text-align: center;
  444. position: relative;
  445. .info-container {
  446. margin-top: -#{50rpx};
  447. }
  448. .nickname {
  449. color: #fff;
  450. }
  451. .nickname.no-member-icon {
  452. margin-top: #{30rpx};
  453. }
  454. .u-refresh.no-member-icon {
  455. margin-top: #{30rpx};
  456. }
  457. .login-btn {
  458. color: #fff;
  459. margin-top: #{40rpx};
  460. }
  461. }
  462. .style-1 {
  463. padding: 0 #{24rpx};
  464. .nickname {
  465. color: #fff;
  466. margin-bottom: #{12rpx};
  467. }
  468. .u-refresh.member-margin {
  469. margin-bottom: 12upx;
  470. }
  471. .pay-code {
  472. margin-bottom: #{20rpx};
  473. color: #fff;
  474. text-align: center;
  475. font-size: $uni-font-size-weak-two;
  476. margin-left: #{96rpx};
  477. .pay-code-icon {
  478. width: #{44rpx};
  479. height: #{44rpx};
  480. }
  481. }
  482. }
  483. .u-refresh {
  484. border-radius: 18upx;
  485. border: 1upx solid #ffffff;
  486. min-width: 69upx;
  487. margin: 0 0 0 10upx;
  488. box-sizing: content-box;
  489. height: 37upx;
  490. padding: 0 13upx;
  491. background-color: transparent;
  492. transform: rotateZ(360deg);
  493. .u-icon {
  494. width: 21upx;
  495. height: 21upx;
  496. background-image: url('../../../static/image/icon/refresh.png');
  497. background-size: 100% 100%;
  498. background-repeat: no-repeat;
  499. margin-right: 5upx;
  500. }
  501. text {
  502. line-height: 1;
  503. color: #ffffff;
  504. font-size: 21upx;
  505. }
  506. }
  507. </style>