userCenter.vue 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="userPage">
  3. <view class="userTop">
  4. <view class="topbg">
  5. <image src="../static/usercenter/bg.png" mode="aspectFill"></image>
  6. </view>
  7. <view class="userTop-content" v-if="loginShow">
  8. <view class="avatar" @click="goEndit">
  9. <image :src="userMsg.avatarUrl" mode="aspectFill" v-if="userMsg.avatarUrl"></image>
  10. <image src="/static/bghesd.png" mode="aspectFill" v-else></image>
  11. </view>
  12. <view class="userinfo" v-if="userMsg.nickName">
  13. <view class="getnewname">
  14. <text>{{userMsg.nickName}}</text>
  15. <text class="getnew" @click="getUserProfile()">刷新</text>
  16. </view>
  17. <view class="phonenumber">
  18. {{phone}}
  19. </view>
  20. </view>
  21. <view class="userinfo" v-if="!userMsg.nickName" @click="getUserProfile()">
  22. <text>点击获取头像昵称</text>
  23. <text style="padding-top: 10rpx;">{{phone}}</text>
  24. </view>
  25. </view>
  26. <view class="login" v-if="!loginShow">
  27. <view class="">
  28. 日月峡森林康养旅行
  29. </view>
  30. <view class="btn" @click="gologin">
  31. 登录
  32. </view>
  33. </view>
  34. </view>
  35. <view class="userOrder">
  36. <view class="flex-item" @click="goOrder(1)">
  37. <image mode="aspectFit" src="../static/usercenter/Tobepaid.png" style="width: 45%;margin-bottom: -5px;">
  38. </image>
  39. <view>待付款</view>
  40. <view class="cuicle" v-if="ordernum.unpaid"><text>{{ordernum.unpaid}}</text></view>
  41. </view>
  42. <view class="line">
  43. </view>
  44. <view class="flex-item" @click="goOrder(2)">
  45. <image mode="aspectFit" src="../static/usercenter/Aftersales.png"
  46. style="width: 45%;margin-bottom: -5px;"></image>
  47. <view>待出行</view>
  48. <view class="cuicle" v-if="ordernum.paid"><text>{{ordernum.paid}}</text></view>
  49. </view>
  50. <view class="line">
  51. </view>
  52. <view class="flex-item" @click="goOrder(3)">
  53. <image mode="aspectFit" src="../static/usercenter/Tobepaid1.png"
  54. style="width: 45%;margin-bottom: -5px;"></image>
  55. <view>已完成</view>
  56. <view class="cuicle" v-if="ordernum.completed"><text>{{ordernum.completed}}</text></view>
  57. </view>
  58. <view class="line">
  59. </view>
  60. <view class="flex-item " @click="goOrder(0)">
  61. <image mode="aspectFit" src="../static/usercenter/all.png" style="width: 45%;margin-bottom: -5px;">
  62. </image>
  63. <view>全部订单</view>
  64. <!-- <view class="cuicle" v-if="ordernum.total"><text>{{ordernum.total}}</text></view> -->
  65. </view>
  66. </view>
  67. <view class="" style="background-color: #FFFFFF; margin: 0 30rpx;border-radius: 8rpx;">
  68. <u-cell-group :border="false">
  69. <u-cell title="出行人" isLink size="large" :border="false" @click="goaddpeople"></u-cell>
  70. <u-cell title="发票" isLink size="large" :border="false" @click="goinvoice"></u-cell>
  71. </u-cell-group>
  72. </view>
  73. <view class="" style="background-color: #FFFFFF; margin: 20rpx 30rpx;border-radius: 8rpx 8rpx 8rpx 56rpx;">
  74. <u-cell-group :border="false">
  75. <u-cell title="客服" size="large" isLink :border="false" @click="gomes"></u-cell>
  76. <u-cell title="关于日月峡" size="large" isLink :border="false" @click="goaboutus"></u-cell>
  77. </u-cell-group>
  78. </view>
  79. <view class="signout" @click="signout" v-if="loginShow">
  80. 退出登录
  81. </view>
  82. <view class="kefuicon">
  83. <button open-type="contact" type="default"
  84. style="background-color: transparent;border-style:none;border:0;">
  85. <image src="../static/usercenter/service.png" mode="widthFix"></image>
  86. </button>
  87. </view>
  88. </view>
  89. </template>
  90. <script>
  91. let that
  92. export default {
  93. data() {
  94. return {
  95. loginShow: this.$store.state.login,
  96. getuser: this.$store.state.getuser,
  97. userMsg: {},
  98. phone: '',
  99. ordernum: ''
  100. }
  101. },
  102. onLoad() {
  103. that = this
  104. this.init()
  105. },
  106. onShow() {
  107. this.init()
  108. this.initvist()
  109. },
  110. // watch:{
  111. // "this.$store.state.token": {
  112. // handler(newValue, oldValue) {
  113. // console.log("单个属性监听", newValue, oldValue);
  114. // }
  115. // },
  116. // },
  117. methods: {
  118. initvist(){
  119. let curPage = getCurrentPages();
  120. let route = curPage[curPage.length - 1].route; //获取当前页面的路由
  121. let code=uni.getStorageSync("code")
  122. let obj={
  123. page:route,
  124. code:code
  125. }
  126. if(code){
  127. uni.$u.http.post('/api/visit/add',obj,{
  128. custom: {
  129. auth: true
  130. }
  131. }).then((res) => {
  132. }).catch((err) => {
  133. })
  134. }
  135. },
  136. init() {
  137. let token = uni.getStorageSync("token")
  138. if (token) {
  139. this.loginShow = true
  140. uni.$u.http.post('/api/order/count', {
  141. token: token
  142. }, {
  143. custom: {
  144. auth: true
  145. }
  146. }).then((res) => {
  147. that.ordernum = res
  148. }).catch((err) => {
  149. })
  150. }
  151. let userMsg = uni.getStorageSync("userMsg")
  152. if (userMsg) {
  153. this.userMsg = userMsg
  154. }
  155. let phone = uni.getStorageSync("phone")
  156. this.phone = phone
  157. },
  158. // 登录
  159. gologin() {
  160. uni.navigateTo({
  161. url: "/pages/login"
  162. })
  163. },
  164. // 跳转完善个人信息
  165. goEndit() {
  166. uni.navigateTo({
  167. url: "/pages/userCenter/userEdit"
  168. })
  169. },
  170. // 跳转订单列表
  171. goOrder(state) {
  172. uni.navigateTo({
  173. url: "/pages/order/order?state="+state
  174. })
  175. },
  176. //跳转出行人
  177. goaddpeople() {
  178. uni.navigateTo({
  179. url: "/pages/peopleList/peopleList?id=0"
  180. })
  181. },
  182. // 跳转发票
  183. goinvoice() {
  184. uni.navigateTo({
  185. url: "/pages/userCenter/invoice"
  186. })
  187. },
  188. // 客服
  189. gomes() {
  190. uni.navigateTo({
  191. url: "/pages/customerService"
  192. })
  193. },
  194. // 关于我们
  195. goaboutus() {
  196. uni.navigateTo({
  197. url: "/pages/userCenter/aboutus"
  198. })
  199. },
  200. // 获取用户头像
  201. getUserProfile() {
  202. var that = this;
  203. wx.getUserProfile({
  204. desc: "用于完善用户资料", // 声明获取用户个人信息后的用途,后续会展示在弹窗中,请谨慎填写
  205. success: (res) => {
  206. that.$toast("获取成功")
  207. // that.userMsg = res.userInfo; //这个我有时候获取不到,所以没管它,但先写着
  208. uni.setStorageSync("userMsg", res.userInfo);
  209. that.init()
  210. let setNowTime = Date.now() + 3600 * 1000 * 24 * 30;
  211. uni.setStorageSync("userInfoStorageTime", setNowTime);
  212. },
  213. fail: function(err) {
  214. console.log(err);
  215. },
  216. });
  217. },
  218. // setUserInfoStorageTime() {
  219. // let nowTime = Date.now();
  220. // let oldTime = uni.getStorageSync("userInfoStorageTime");
  221. // let userInfo = uni.getStorageSync("userMsg");
  222. // if ( userInfo.nickName != undefined && userInfo.nickName != null && userInfo.nickName != "" ) {
  223. // if (oldTime && nowTime < oldTime) {
  224. // that.userMsg=userInfo
  225. // return;
  226. // } else {
  227. // that.getUserProfile();
  228. // }
  229. // } else {
  230. // that.getUserProfile();
  231. // }
  232. // },
  233. // })
  234. // 退出登录
  235. signout() {
  236. uni.showModal({
  237. title: "提示",
  238. content: "是否退出?",
  239. success: (res) => {
  240. if (res.confirm) {
  241. this.$toast("退出成功")
  242. this.ordernum = ''
  243. uni.removeStorageSync('token')
  244. uni.removeStorageSync('code')
  245. uni.removeStorageSync('phone')
  246. uni.removeStorageSync('userMsg')
  247. this.userMsg = {}
  248. this.$store.commit("setToken", "")
  249. this.$store.commit('getUserInfo', {})
  250. this.$store.commit('loginState', null)
  251. this.loginShow = this.$store.state.login
  252. this.init()
  253. }
  254. }
  255. })
  256. },
  257. }
  258. }
  259. </script>
  260. <style lang="less">
  261. page {
  262. background-color: #F4F4F4;
  263. font-size: 32rpx;
  264. font-family: PingFang-SC-Bold, PingFang-SC;
  265. position: relative;
  266. }
  267. .userPage {
  268. height: 100vh;
  269. position: relative;
  270. .userTop {
  271. position: relative;
  272. width: 100%;
  273. box-sizing: border-box;
  274. padding: 50rpx 30rpx 65rpx;
  275. .topbg {
  276. image {
  277. width: 100%;
  278. height: 288rpx;
  279. position: absolute;
  280. left: 0;
  281. top: 0;
  282. z-index: -1;
  283. }
  284. }
  285. .userTop-content {
  286. display: flex;
  287. align-items: center;
  288. }
  289. .userinfo {
  290. display: flex;
  291. flex-direction: column;
  292. }
  293. .getnewname {
  294. display: flex;
  295. align-items: center;
  296. }
  297. .getnew {
  298. font-size: 22rpx;
  299. display: block;
  300. margin-left: 40rpx;
  301. padding: 5rpx 10rpx;
  302. border: 1rpx solid #555555;
  303. border-radius: 8rpx;
  304. }
  305. .phonenumber {
  306. padding-top: 10rpx;
  307. }
  308. .avatar {
  309. width: 172rpx;
  310. height: 172rpx;
  311. border-radius: 50%;
  312. // background-color: pink;
  313. margin-right: 30rpx;
  314. border: 5rpx solid rgba(216, 227, 224, 0.5);
  315. image {
  316. width: 100%;
  317. height: 100%;
  318. border-radius: 50%;
  319. }
  320. }
  321. .login {
  322. text-align: center;
  323. }
  324. .btn {
  325. width: 324rpx;
  326. height: 62rpx;
  327. line-height: 62rpx;
  328. background: #1E9F6A;
  329. border-radius: 8rpx 32rpx 8rpx 32rpx;
  330. color: #FFFFFF;
  331. margin: 40rpx auto;
  332. }
  333. }
  334. .userOrder {
  335. margin: 20rpx 30rpx;
  336. padding: 40rpx 0;
  337. border-radius: 8rpx 56rpx 8rpx 8rpx;
  338. background-color: #ffffff;
  339. display: flex;
  340. font-size: 22rpx;
  341. font-weight: bold;
  342. color: #141328;
  343. text-align: center;
  344. .flex-item {
  345. position: relative;
  346. .cuicle {
  347. top: 20rpx;
  348. right: 40rpx;
  349. position: absolute;
  350. width: 35rpx;
  351. height: 35rpx;
  352. line-height: 35rpx;
  353. border-radius: 50%;
  354. display: flex;
  355. align-items: center;
  356. justify-content: center;
  357. font-size: 18rpx;
  358. color: #fff;
  359. background-color: #1E9F6A;
  360. }
  361. flex: 1;
  362. image {
  363. width: 120rpx;
  364. height: 120rpx;
  365. }
  366. }
  367. .line {
  368. width: 1px;
  369. height: 48rpx;
  370. line-height: 48rpx;
  371. background: #141328;
  372. opacity: 0.29;
  373. margin: auto 0;
  374. }
  375. }
  376. .signout {
  377. margin: 46rpx auto 0;
  378. padding: 24rpx 0;
  379. width: 438rpx;
  380. text-align: center;
  381. background: #E6E5E5;
  382. border-radius: 8rpx 56rpx 8rpx 56rpx;
  383. }
  384. .kefuicon {
  385. button::after {
  386. border: none;
  387. }
  388. position: absolute;
  389. right: 30rpx;
  390. bottom: 0;
  391. image {
  392. width: 136rpx;
  393. height: 136rpx;
  394. }
  395. }
  396. }
  397. </style>