my.vue 18 KB

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