my.vue 18 KB

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