my.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  1. <template>
  2. <view class="my">
  3. <MyNav title="我的" bgColor="" :backIcon="false"></MyNav>
  4. <view class="topCard" :style="{backgroundImage:'url('+imgurl+')'}">
  5. <!-- 用户名 -->
  6. <view class="user">
  7. <view v-if="admin.avatar">
  8. <button class="avatar" open-type="chooseAvatar" @click="handleGetWechatUserInfo">
  9. <image class="user-avatar" style="height: 176rpx;width: 176rpx;border-radius: 50%;"
  10. :src="admin.avatar? admin.avatar : '/static/icon/avatar.png'" />
  11. </button>
  12. <view class="userinfo" @click="goPersonData">
  13. <text class="unlogin">{{admin.nickname}}</text>
  14. </view>
  15. </view>
  16. <view v-else>
  17. <image class="user-avatar" src="/static/icon/avatar.png" style="height: 176rpx;width: 176rpx;">
  18. </image>
  19. <view class="userinfo">
  20. <text class="unlogin" v-if="!islogin" @click="login">请点击登录</text>
  21. </view>
  22. </view>
  23. <image src="/static/icon/setting.png" @click="goSetting"
  24. style="width: 44rpx;height: 44rpx; position: absolute;top:0rpx;right: 24rpx;"></image>
  25. </view>
  26. <!-- 会员 -->
  27. <view class="membership" @click="goJoin">
  28. <view class="flex">
  29. <view style="display: flex;align-items: center;">
  30. <image style="width: 68rpx ;height: 62rpx;" src="../../static/icon/vip.png"></image>
  31. <text class="join">加入会员</text>
  32. </view>
  33. <view style="display: flex;align-items: center;">
  34. <text class="gojoin">去加入</text>
  35. <image style="width: 12rpx ;height: 20rpx;" src="../../static/icon/right05.png"></image>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 订单 -->
  40. <view class="orders">
  41. <view class="nav">
  42. <view class="myorder">我的订单</view>
  43. <view class="more">
  44. <text style="margin-right: 8rpx;" @click="goMyorders(0)">查看更多</text>
  45. <image style="width: 12rpx ;height: 20rpx;" src="../../static/icon/right05.png"></image>
  46. </view>
  47. </view>
  48. <view class="content">
  49. <view class="flexbox" @click="goMyorders(1)">
  50. <view
  51. style="width: 56rpx; height: 56rpx; display: flex;align-items: center;justify-content: center; ">
  52. <image style="width: 56rpx ;height: 42rpx;" src="../../static/icon/exchange.png"></image>
  53. </view>
  54. <text>待兑换</text>
  55. </view>
  56. <view class="flexbox" @click="goMyorders(2)">
  57. <view
  58. style="width: 56rpx; height: 56rpx;display: flex;align-items: center;justify-content: center; ">
  59. <image style="width: 54rpx ;height: 52rpx;" src="../../static/icon/shipments.png"></image>
  60. </view>
  61. <text>待发货</text>
  62. </view>
  63. <view class="flexbox" @click="goMyorders(3)">
  64. <view
  65. style="width: 56rpx; height: 56rpx;display: flex;align-items: center;justify-content: center; ">
  66. <image style="width: 56rpx ;height: 56rpx;" src="../../static/icon/Receipt.png"></image>
  67. </view>
  68. <text>待收货</text>
  69. </view>
  70. <view class="flexbox" @click="goMyorders(4)">
  71. <view
  72. style="width: 56rpx; height: 56rpx;display: flex;align-items: center;justify-content: center; ">
  73. <image style="width: 54rpx ;height: 54rpx;" src="../../static/icon/finish.png"></image>
  74. </view>
  75. <text>已完成</text>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <!-- 列表 -->
  81. <view style="padding:0 30rpx;">
  82. <view class="list" v-for="(item,index) in list" :key="index" @click="goDetail(index)">
  83. <view class="title">{{item.title}}</view>
  84. <view class="container">{{item.content}}</view>
  85. <image src="../../static/icon/right.png"></image>
  86. </view>
  87. </view>
  88. <u-modal @close="closeMask" closeOnClickOverlay="true" :show="modal.show" :title="modal.title"
  89. :show-confirm-button="false">
  90. <view>
  91. <button class="avatar" open-type="chooseAvatar" @chooseavatar="handleChooseAvatar">
  92. <image class="user-avatar" style="height: 176rpx;width: 176rpx;border-radius: 50%;"
  93. :src="modal.avatar?modal.avatar:'/static/icon/avatar.png'" />
  94. </button>
  95. <input class="avatar" type="nickname" :value="modal.nickname" placeholder="填写昵称"
  96. @change="handleChangeNickname">
  97. <button class="confirm" @click="handleConfirmWechatUserInfo">提交</button>
  98. </view>
  99. </u-modal>
  100. <!-- 底部导航栏 -->
  101. <view style="height: 140rpx; width: 100%;"></view>
  102. <tab-bar checked="my"></tab-bar>
  103. </view>
  104. </template>
  105. <script>
  106. // 引入组件
  107. import TabBar from '../../components/TabBar/tabbar.vue'
  108. import MyNav from "@/components/my-nav/my-nav.vue"
  109. export default {
  110. // 注册组件
  111. components: {
  112. TabBar,
  113. MyNav
  114. },
  115. data() {
  116. return {
  117. modal: {
  118. show: false,
  119. title: '用户信息获取',
  120. nickname: '',
  121. avatar: ''
  122. },
  123. admin: '',
  124. // 顶部背景图
  125. imgurl: 'http://t9.9026.com/imgs/bg@2x.png',
  126. // 是否登录
  127. islogin: false,
  128. // 列表内容
  129. list: [{
  130. title: '积分',
  131. content: '积分兑换奖品'
  132. }, {
  133. title: '奖品',
  134. content: '查看所有奖品'
  135. }, {
  136. title: '点赞',
  137. content: '查看所有点赞'
  138. }]
  139. };
  140. },
  141. onShow() {
  142. this.admin = this.$store.getters.userInfo
  143. },
  144. methods: {
  145. //关闭遮罩层
  146. closeMask() {
  147. this.modal.show = false
  148. },
  149. // 微信获取头像
  150. handleGetWechatUserInfo() {
  151. console.log(1111);
  152. this.modal.show = true
  153. this.modal.nickname = this.admin.nickname
  154. this.modal.avatar = this.admin.avatar
  155. },
  156. //提交微信名称和头像
  157. handleConfirmWechatUserInfo() {
  158. if (!this.modal.avatar) {
  159. this.$u.toast('请上传头像')
  160. return
  161. }
  162. if (!this.modal.nickname) {
  163. this.$u.toast('请填写昵称')
  164. return
  165. }
  166. this.$loading('数据提交中...')
  167. this.$api.my.update({
  168. avatar: this.modal.avatar,
  169. nickname: this.modal.nickname
  170. }).then(res => {
  171. this.$hideLoading()
  172. this.$store.dispatch('user/info', res.data)
  173. this.admin = this.$store.getters.userInfo
  174. this.modal.show = false
  175. })
  176. },
  177. // 微信获取头像
  178. handleChooseAvatar({detail}) {
  179. // console.log(e.detail);
  180. // this.modal.avatar = e.detail.avatarUrl
  181. let _this = this
  182. uni.getFileSystemManager().readFile({
  183. filePath:detail.avatarUrl, // 选择图片返回的相对路径
  184. encoding: 'base64', // 编码格式
  185. success: res => { // 成功的回调
  186. uni.uploadFile({
  187. url: _this.$setting.BASE_URL + '/v1/user/uploadFile',
  188. // filePath: 'data:image/png;base64,' + res.data,
  189. filePath: detail.avatarUrl,
  190. name: 'file',
  191. success({ data }) {
  192. const res = JSON.parse(data)
  193. const { url } = res.data
  194. _this.modal.avatar = url
  195. console.log('-->data', _this.modal.avatar)
  196. }
  197. })
  198. // this.modal.avatar = detail.avatarUrl
  199. // console.log('data:image/png;base64,' + res.data)
  200. }
  201. })
  202. },
  203. handleChangeNickname(res) {
  204. this.modal.nickname = res.detail.value
  205. },
  206. // 跳转登录页
  207. login() {
  208. uni.navigateTo({
  209. url: '/pages/login/login'
  210. })
  211. },
  212. // 跳转个人信息
  213. goPersonData() {
  214. uni.navigateTo({
  215. url: '/pages/my/PersonalData/personalData'
  216. })
  217. },
  218. // 跳转设置页面
  219. goSetting() {
  220. if (this.admin == undefined) {
  221. uni.navigateTo({
  222. url: '/pages/login/login'
  223. })
  224. } else {
  225. uni.navigateTo({
  226. url: '/pages/my/setting/setting'
  227. })
  228. }
  229. },
  230. // 跳转积分页
  231. goDetail(index) {
  232. if (this.admin == undefined) {
  233. uni.navigateTo({
  234. url: '/pages/login/login'
  235. })
  236. } else {
  237. if (index == 0) {
  238. uni.navigateTo({
  239. url: '/pages/my/integral/integral'
  240. })
  241. } else if (index == 1) {
  242. uni.navigateTo({
  243. url: '/pages/my/prize/prize'
  244. })
  245. } else {
  246. uni.navigateTo({
  247. url: '/pages/my/Kudos/Kudos'
  248. })
  249. }
  250. }
  251. },
  252. // 跳转订单页
  253. goMyorders(index) {
  254. if (this.admin == undefined) {
  255. uni.navigateTo({
  256. url: '/pages/login/login'
  257. })
  258. } else {
  259. switch (index) {
  260. case 0:
  261. uni.navigateTo({
  262. url: '/pages/my/myorders/orders'
  263. })
  264. break;
  265. case 1:
  266. uni.navigateTo({
  267. url: '/pages/my/myorders/orders?isActive=' + 1
  268. })
  269. break;
  270. case 2:
  271. uni.navigateTo({
  272. url: '/pages/my/myorders/orders?isActive=' + 2
  273. })
  274. break;
  275. case 3:
  276. uni.navigateTo({
  277. url: '/pages/my/myorders/orders?isActive=' + 3
  278. })
  279. break;
  280. case 4:
  281. uni.navigateTo({
  282. url: '/pages/my/myorders/orders?isActive=' + 4
  283. })
  284. break;
  285. }
  286. }
  287. },
  288. //获取当前页面路径
  289. getPageUrl() {
  290. const pages = getCurrentPages();
  291. console.log(pages,'--------->pages')
  292. if(pages.length==1){
  293. const currentPage = pages[0];
  294. let pageUrl = `/${currentPage.route}`;
  295. return pageUrl
  296. console.log('当前页面url:', pageUrl);
  297. }else{
  298. const currentPage = pages[pages.length - 1];
  299. let pageUrl = `/${currentPage.route}`;
  300. return pageUrl
  301. console.log('当前页面url:', pageUrl);
  302. }
  303. },
  304. // 跳转其他小程序
  305. goJoin() {
  306. let _this = this
  307. wx.navigateToMiniProgram({
  308. appId: 'wx255b58f0992b3c53', //appid
  309. path: 'newUIMain/enrollment/enrollment', //path
  310. extraData: { //参数
  311. foo: 'bar'
  312. },
  313. // envVersion: 'develop', //开发版develop 开发版 trial 体验版 release 正式版
  314. success(res) {
  315. let page = _this.getPageUrl()
  316. let user_id = ''
  317. if (_this.admin != null) {
  318. user_id = _this.admin.id
  319. } else {
  320. user_id = 0
  321. }
  322. console.log('成功', page)
  323. _this.$api.my.userMemberAdd({
  324. user_id,
  325. page,
  326. }).then(res => {
  327. console.log(res.data);
  328. })
  329. // 打开成功
  330. },
  331. fail(e) {
  332. console.log(e, '失败')
  333. }
  334. })
  335. },
  336. // 上传头像
  337. uploadAvatar() {
  338. // let img = []
  339. // uni.chooseImage({
  340. // count: 1, //默认9
  341. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  342. // sourceType: ['album'], //从相册选择
  343. // success: function (res) {
  344. // console.log(JSON.stringify(res.tempFilePaths));
  345. // img = res.tempFilePaths[0]
  346. // uni.uploadFile({
  347. // //后端接口地址
  348. // url: `${baseUrl}` + '/api/attachment/upload',
  349. // //图片临时地址
  350. // filePath: img,
  351. // // 上传文件类型
  352. // formData: {
  353. // tag: 'avatar'
  354. // },
  355. // success: (res) => {
  356. // //后端返回的图片名称
  357. // let data = JSON.parse(res.data)
  358. // // _this.formData.avatar = data.data.file
  359. // },
  360. // })
  361. // },
  362. // });
  363. }
  364. }
  365. }
  366. </script>
  367. <style lang="scss" scoped>
  368. $pageColor:#F9F9F9;
  369. $bgColor:#FFFFFF;
  370. .my {
  371. height: 100%;
  372. background-color: $pageColor;
  373. }
  374. .avatar {
  375. width: 176rpx;
  376. height: 176rpx;
  377. border-radius: 50%;
  378. }
  379. .topCard {
  380. width: 100%;
  381. border-radius: 0rpx 0rpx 16rpx 16rpx;
  382. padding: 40rpx 30rpx 38rpx 30rpx;
  383. box-sizing: border-box;
  384. background-position: center;
  385. background-repeat: no-repeat;
  386. background-size: cover;
  387. .user {
  388. width: 690rpx;
  389. height: 176rpx;
  390. position: relative;
  391. margin-bottom: 38rpx;
  392. .user-avatar {
  393. object-fit: cover;
  394. object-position: center;
  395. }
  396. .userinfo {
  397. position: absolute;
  398. top: 38rpx;
  399. left: 200rpx;
  400. .unlogin {
  401. width: 360rpx;
  402. font-size: 44rpx;
  403. font-family: PingFang-SC-Heavy, PingFang-SC;
  404. font-weight: 500;
  405. color: #FFFFFF;
  406. display: block;
  407. margin-top: 20rpx;
  408. }
  409. .username {
  410. width: 184rpx;
  411. height: 44rpx;
  412. font-size: 44rpx;
  413. font-family: PingFang-SC-Heavy, PingFang-SC;
  414. font-weight: 500;
  415. color: #FFFFFF;
  416. line-height: 44rpx;
  417. display: block;
  418. margin-bottom: 24rpx;
  419. }
  420. .userId {
  421. font-size: 32rpx;
  422. font-family: PingFang-SC-Medium, PingFang-SC;
  423. font-weight: 400;
  424. color: #FFFFFF;
  425. line-height: 32rpx;
  426. }
  427. }
  428. }
  429. .membership {
  430. width: 690rpx;
  431. height: 110rpx;
  432. background: $bgColor;
  433. border-radius: 8rpx;
  434. display: flex;
  435. align-items: center;
  436. padding-left: 28rpx;
  437. padding-right: 24rpx;
  438. box-sizing: border-box;
  439. margin-bottom: 24rpx;
  440. .flex {
  441. display: flex;
  442. align-items: center;
  443. justify-content: space-between;
  444. height: 68rpx;
  445. width: 650rpx;
  446. .join {
  447. font-size: 36rpx;
  448. font-family: PingFang-SC-Bold, PingFang-SC;
  449. font-weight: 600;
  450. color: #627885;
  451. margin-left: 8rpx;
  452. }
  453. .gojoin {
  454. font-size: 30rpx;
  455. font-family: PingFang-SC-Bold, PingFang-SC;
  456. font-weight: 600;
  457. color: #627885;
  458. margin-right: 8rpx;
  459. }
  460. }
  461. }
  462. .orders {
  463. width: 690rpx;
  464. background: $bgColor;
  465. border-radius: 8rpx;
  466. padding: 40rpx 30rpx 36rpx 36rpx;
  467. box-sizing: border-box;
  468. .nav {
  469. height: 50rpx;
  470. width: 633rpx;
  471. display: flex;
  472. align-items: center;
  473. justify-content: space-between;
  474. .myorder {
  475. font-size: 28rpx;
  476. font-family: PingFang-SC-Heavy, PingFang-SC;
  477. font-weight: 800;
  478. color: #333333;
  479. }
  480. .more {
  481. font-size: 28rpx;
  482. font-family: PingFang-SC-Bold, PingFang-SC;
  483. font-weight: bold;
  484. color: #627885;
  485. }
  486. }
  487. .content {
  488. display: flex;
  489. align-items: center;
  490. justify-content: space-between;
  491. padding: 0 20rpx;
  492. margin-top: 72rpx;
  493. .flexbox {
  494. display: flex;
  495. flex-direction: column;
  496. align-items: center;
  497. text {
  498. margin-top: 16rpx;
  499. font-size: 28rpx;
  500. font-family: PingFang-SC-Medium, PingFang-SC;
  501. font-weight: 500;
  502. color: #627885;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. .list {
  509. width: 100%;
  510. padding-top: 32rpx;
  511. padding-bottom: 32rpx;
  512. border-bottom: 2rpx solid #F0F0F0;
  513. display: flex;
  514. flex-direction: column;
  515. justify-content: center;
  516. position: relative;
  517. &:first-child {
  518. padding-top: 50rpx;
  519. }
  520. .title {
  521. font-size: 36rpx;
  522. font-family: PingFang-SC-Bold, PingFang-SC;
  523. font-weight: bold;
  524. color: #333333;
  525. margin-bottom: 16rpx;
  526. }
  527. .container {
  528. font-size: 28rpx;
  529. font-family: PingFang-SC-Medium, PingFang-SC;
  530. font-weight: 500;
  531. color: #333333;
  532. }
  533. image {
  534. width: 12rpx;
  535. height: 20rpx;
  536. position: absolute;
  537. top: 70rpx;
  538. right: 0rpx;
  539. }
  540. }
  541. </style>