my.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  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. //跳转h5,小程序,其他页面
  118. jump_type: '',
  119. jump_config: {},
  120. //加入会员广告配置
  121. advise: '',
  122. modal: {
  123. show: false,
  124. title: '用户信息获取',
  125. nickname: '',
  126. avatar: ''
  127. },
  128. admin: '',
  129. // 顶部背景图
  130. imgurl: 'http://t9.9026.com/imgs/bg@2x.png',
  131. // 是否登录
  132. islogin: false,
  133. // 列表内容
  134. list: [{
  135. title: '积分',
  136. content: '积分兑换奖品'
  137. }, {
  138. title: '奖品',
  139. content: '查看所有奖品'
  140. }, {
  141. title: '点赞',
  142. content: '查看所有点赞'
  143. }]
  144. };
  145. },
  146. onShow() {
  147. this.admin = this.$store.getters.userInfo
  148. },
  149. onLoad() {
  150. this.advise = this.$store.getters.allset.add_member
  151. this.jump_type = this.advise.value.me_jump_type
  152. if (this.jump_type == 1) {
  153. this.jump_config = this.advise.value.me_h5_url
  154. } else if (this.jump_type == 2) {
  155. this.jump_config.appid = this.advise.value.me_appid
  156. this.jump_config.path = this.advise.value.me_path
  157. } else if (this.jump_type == 3) {
  158. this.jump_config = this.advise.value.me_other_path
  159. }
  160. },
  161. methods: {
  162. //关闭遮罩层
  163. closeMask() {
  164. this.modal.show = false
  165. },
  166. // 微信获取头像
  167. handleGetWechatUserInfo() {
  168. console.log(1111);
  169. this.modal.show = true
  170. this.modal.nickname = this.admin.nickname
  171. this.modal.avatar = this.admin.avatar
  172. },
  173. //提交微信名称和头像
  174. handleConfirmWechatUserInfo() {
  175. if (!this.modal.avatar) {
  176. this.$u.toast('请上传头像')
  177. return
  178. }
  179. if (!this.modal.nickname) {
  180. this.$u.toast('请填写昵称')
  181. return
  182. }
  183. this.$loading('数据提交中...')
  184. this.$api.my.update({
  185. avatar: this.modal.avatar,
  186. nickname: this.modal.nickname
  187. }).then(res => {
  188. this.$hideLoading()
  189. this.$store.dispatch('user/info', res.data)
  190. this.admin = this.$store.getters.userInfo
  191. this.modal.show = false
  192. })
  193. },
  194. // 微信获取头像
  195. handleChooseAvatar({
  196. detail
  197. }) {
  198. // console.log(e.detail);
  199. // this.modal.avatar = e.detail.avatarUrl
  200. let _this = this
  201. uni.getFileSystemManager().readFile({
  202. filePath: detail.avatarUrl, // 选择图片返回的相对路径
  203. encoding: 'base64', // 编码格式
  204. success: res => { // 成功的回调
  205. uni.uploadFile({
  206. url: _this.$setting.BASE_URL + '/v1/user/uploadFile',
  207. // filePath: 'data:image/png;base64,' + res.data,
  208. filePath: detail.avatarUrl,
  209. name: 'file',
  210. success({
  211. data
  212. }) {
  213. const res = JSON.parse(data)
  214. const {
  215. url
  216. } = res.data
  217. _this.modal.avatar = url
  218. console.log('-->data', _this.modal.avatar)
  219. }
  220. })
  221. // this.modal.avatar = detail.avatarUrl
  222. // console.log('data:image/png;base64,' + res.data)
  223. }
  224. })
  225. },
  226. handleChangeNickname(res) {
  227. this.modal.nickname = res.detail.value
  228. },
  229. // 跳转登录页
  230. login() {
  231. uni.navigateTo({
  232. url: '/pages/login/login'
  233. })
  234. },
  235. // 跳转个人信息
  236. goPersonData() {
  237. uni.navigateTo({
  238. url: '/pages/my/PersonalData/personalData'
  239. })
  240. },
  241. // 跳转设置页面
  242. goSetting() {
  243. if (this.admin == undefined) {
  244. uni.navigateTo({
  245. url: '/pages/login/login'
  246. })
  247. } else {
  248. uni.navigateTo({
  249. url: '/pages/my/setting/setting'
  250. })
  251. }
  252. },
  253. // 跳转积分页
  254. goDetail(index) {
  255. if (this.admin == undefined) {
  256. uni.navigateTo({
  257. url: '/pages/login/login'
  258. })
  259. } else {
  260. if (index == 0) {
  261. uni.navigateTo({
  262. url: '/pages/my/integral/integral'
  263. })
  264. } else if (index == 1) {
  265. uni.navigateTo({
  266. url: '/pages/my/prize/prize'
  267. })
  268. } else {
  269. uni.navigateTo({
  270. url: '/pages/my/Kudos/Kudos'
  271. })
  272. }
  273. }
  274. },
  275. // 跳转订单页
  276. goMyorders(index) {
  277. if (this.admin == undefined) {
  278. uni.navigateTo({
  279. url: '/pages/login/login'
  280. })
  281. } else {
  282. switch (index) {
  283. case 0:
  284. uni.navigateTo({
  285. url: '/pages/my/myorders/orders'
  286. })
  287. break;
  288. case 1:
  289. uni.navigateTo({
  290. url: '/pages/my/myorders/orders?isActive=' + 1
  291. })
  292. break;
  293. case 2:
  294. uni.navigateTo({
  295. url: '/pages/my/myorders/orders?isActive=' + 2
  296. })
  297. break;
  298. case 3:
  299. uni.navigateTo({
  300. url: '/pages/my/myorders/orders?isActive=' + 3
  301. })
  302. break;
  303. case 4:
  304. uni.navigateTo({
  305. url: '/pages/my/myorders/orders?isActive=' + 4
  306. })
  307. break;
  308. }
  309. }
  310. },
  311. //获取当前页面路径
  312. getPageUrl() {
  313. const pages = getCurrentPages();
  314. console.log(pages, '--------->pages')
  315. if (pages.length == 1) {
  316. const currentPage = pages[0];
  317. let pageUrl = `/${currentPage.route}`;
  318. return pageUrl
  319. console.log('当前页面url:', pageUrl);
  320. } else {
  321. const currentPage = pages[pages.length - 1];
  322. let pageUrl = `/${currentPage.route}`;
  323. return pageUrl
  324. console.log('当前页面url:', pageUrl);
  325. }
  326. },
  327. // 跳转其他小程序
  328. jumpHAppID(id, urls) {
  329. if (id == 1) {
  330. const url = urls; // 跳转的外链
  331. const navtitle = 'H5'; // 这个标题是你自己可以设置的
  332. uni.navigateTo({
  333. // 跳转到webview页面
  334. url: `/pages/webview/webview?url=${url}&nav=${navtitle}`,
  335. success: () => {
  336. console.log('成功')
  337. },
  338. fail: (e) => {
  339. console.log(e, "失败")
  340. }
  341. });
  342. } else if (id == 2) {
  343. let _this = this
  344. let obj = urls;
  345. console.log(obj, '----->obj');
  346. wx.navigateToMiniProgram({
  347. appId: `${obj.appid}`, //appid
  348. path: `${obj.path}`, //path
  349. extraData: { //参数
  350. foo: 'bar'
  351. },
  352. // envVersion: 'develop', //开发版develop 开发版 trial 体验版 release 正式版
  353. success(res) {
  354. let page = _this.getPageUrl()
  355. let user_id = ''
  356. if (_this.admin != null) {
  357. user_id = _this.admin.id
  358. } else {
  359. user_id = 0
  360. }
  361. _this.$api.my.userMemberAdd({
  362. user_id,
  363. page,
  364. }).then(res => {
  365. console.log(res.data);
  366. })
  367. // 打开成功
  368. },
  369. fail(e) {
  370. console.log(e, '失败')
  371. }
  372. })
  373. } else if (id == 3) {
  374. uni.redirectTo({
  375. url: urls,
  376. fail: (err) => {
  377. uni.reLaunch({
  378. url: urls
  379. })
  380. }
  381. })
  382. }
  383. },
  384. // 跳转其他小程序
  385. goJoin() {
  386. let _this = this
  387. this.jumpHAppID(this.jump_type, this.jump_config)
  388. },
  389. // 上传头像
  390. uploadAvatar() {
  391. // let img = []
  392. // uni.chooseImage({
  393. // count: 1, //默认9
  394. // sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  395. // sourceType: ['album'], //从相册选择
  396. // success: function (res) {
  397. // console.log(JSON.stringify(res.tempFilePaths));
  398. // img = res.tempFilePaths[0]
  399. // uni.uploadFile({
  400. // //后端接口地址
  401. // url: `${baseUrl}` + '/api/attachment/upload',
  402. // //图片临时地址
  403. // filePath: img,
  404. // // 上传文件类型
  405. // formData: {
  406. // tag: 'avatar'
  407. // },
  408. // success: (res) => {
  409. // //后端返回的图片名称
  410. // let data = JSON.parse(res.data)
  411. // // _this.formData.avatar = data.data.file
  412. // },
  413. // })
  414. // },
  415. // });
  416. }
  417. }
  418. }
  419. </script>
  420. <style lang="scss" scoped>
  421. $pageColor:#F9F9F9;
  422. $bgColor:#FFFFFF;
  423. .my {
  424. height: 100%;
  425. background-color: $pageColor;
  426. }
  427. .avatar {
  428. width: 176rpx;
  429. height: 176rpx;
  430. border-radius: 50%;
  431. }
  432. .topCard {
  433. width: 100%;
  434. border-radius: 0rpx 0rpx 16rpx 16rpx;
  435. padding: 40rpx 30rpx 38rpx 30rpx;
  436. box-sizing: border-box;
  437. background-position: center;
  438. background-repeat: no-repeat;
  439. background-size: cover;
  440. .user {
  441. width: 690rpx;
  442. height: 176rpx;
  443. position: relative;
  444. margin-bottom: 38rpx;
  445. .user-avatar {
  446. object-fit: cover;
  447. object-position: center;
  448. }
  449. .userinfo {
  450. position: absolute;
  451. top: 38rpx;
  452. left: 200rpx;
  453. .unlogin {
  454. width: 360rpx;
  455. font-size: 44rpx;
  456. font-family: PingFang-SC-Heavy, PingFang-SC;
  457. font-weight: 500;
  458. color: #FFFFFF;
  459. display: block;
  460. margin-top: 20rpx;
  461. }
  462. .username {
  463. width: 184rpx;
  464. height: 44rpx;
  465. font-size: 44rpx;
  466. font-family: PingFang-SC-Heavy, PingFang-SC;
  467. font-weight: 500;
  468. color: #FFFFFF;
  469. line-height: 44rpx;
  470. display: block;
  471. margin-bottom: 24rpx;
  472. }
  473. .userId {
  474. font-size: 32rpx;
  475. font-family: PingFang-SC-Medium, PingFang-SC;
  476. font-weight: 400;
  477. color: #FFFFFF;
  478. line-height: 32rpx;
  479. }
  480. }
  481. }
  482. .membership {
  483. width: 690rpx;
  484. height: 110rpx;
  485. background: $bgColor;
  486. border-radius: 8rpx;
  487. display: flex;
  488. align-items: center;
  489. padding-left: 28rpx;
  490. padding-right: 24rpx;
  491. box-sizing: border-box;
  492. margin-bottom: 24rpx;
  493. .flex {
  494. display: flex;
  495. align-items: center;
  496. justify-content: space-between;
  497. height: 68rpx;
  498. width: 650rpx;
  499. .join {
  500. font-size: 36rpx;
  501. font-family: PingFang-SC-Bold, PingFang-SC;
  502. font-weight: 600;
  503. color: #627885;
  504. margin-left: 8rpx;
  505. }
  506. .gojoin {
  507. font-size: 30rpx;
  508. font-family: PingFang-SC-Bold, PingFang-SC;
  509. font-weight: 600;
  510. color: #627885;
  511. margin-right: 8rpx;
  512. }
  513. }
  514. }
  515. .orders {
  516. width: 690rpx;
  517. background: $bgColor;
  518. border-radius: 8rpx;
  519. padding: 40rpx 30rpx 36rpx 36rpx;
  520. box-sizing: border-box;
  521. .nav {
  522. height: 50rpx;
  523. width: 633rpx;
  524. display: flex;
  525. align-items: center;
  526. justify-content: space-between;
  527. .myorder {
  528. font-size: 28rpx;
  529. font-family: PingFang-SC-Heavy, PingFang-SC;
  530. font-weight: 800;
  531. color: #333333;
  532. }
  533. .more {
  534. font-size: 28rpx;
  535. font-family: PingFang-SC-Bold, PingFang-SC;
  536. font-weight: bold;
  537. color: #627885;
  538. }
  539. }
  540. .content {
  541. display: flex;
  542. align-items: center;
  543. justify-content: space-between;
  544. padding: 0 20rpx;
  545. margin-top: 72rpx;
  546. .flexbox {
  547. display: flex;
  548. flex-direction: column;
  549. align-items: center;
  550. text {
  551. margin-top: 16rpx;
  552. font-size: 28rpx;
  553. font-family: PingFang-SC-Medium, PingFang-SC;
  554. font-weight: 500;
  555. color: #627885;
  556. }
  557. }
  558. }
  559. }
  560. }
  561. .list {
  562. width: 100%;
  563. padding-top: 32rpx;
  564. padding-bottom: 32rpx;
  565. border-bottom: 2rpx solid #F0F0F0;
  566. display: flex;
  567. flex-direction: column;
  568. justify-content: center;
  569. position: relative;
  570. &:first-child {
  571. padding-top: 50rpx;
  572. }
  573. .title {
  574. font-size: 36rpx;
  575. font-family: PingFang-SC-Bold, PingFang-SC;
  576. font-weight: bold;
  577. color: #333333;
  578. margin-bottom: 16rpx;
  579. }
  580. .container {
  581. font-size: 28rpx;
  582. font-family: PingFang-SC-Medium, PingFang-SC;
  583. font-weight: 500;
  584. color: #333333;
  585. }
  586. image {
  587. width: 12rpx;
  588. height: 20rpx;
  589. position: absolute;
  590. top: 70rpx;
  591. right: 0rpx;
  592. }
  593. }
  594. </style>