my.vue 17 KB

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