index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  1. <template>
  2. <view>
  3. <!-- ===================================== tabbar ===================================== -->
  4. <u-navbar
  5. title-color="#fff"
  6. :custom-back="customBack"
  7. :border-bottom="false"
  8. back-icon-color="#CCE8FF"
  9. :background="{ background: '#008CFF' }"
  10. title="我的"
  11. />
  12. <!-- ===================================== 头像 ===================================== -->
  13. <view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30 u-p-t-30">
  14. <view class="u-m-r-24" @click="clickHead">
  15. <u-avatar :src="userInfo.headImgUrl || userInfo.avatar || pic" size="140"></u-avatar>
  16. </view>
  17. <view class="u-flex-1">
  18. <view class="u-font-18 u-p-b-20">{{ userInfo.nickname || userInfo.mobile }}</view>
  19. <view class="u-font-14">手机号:{{ userInfo.mobile || '暂无' }}</view>
  20. </view>
  21. </view>
  22. <view class="u-m-t-20">
  23. <u-cell-group>
  24. <u-cell-item title="我的车辆" @click="openPage('pages/myCars/myCars', true)">
  25. <u-icon slot="icon" custom-prefix="custom-icon" size="35" name="wodecheliang"></u-icon>
  26. </u-cell-item>
  27. <u-cell-item title="停车记录" @click="openPage('pages/center/order/order')">
  28. <u-icon slot="icon" custom-prefix="custom-icon" size="35" name="tingchejilu"></u-icon>
  29. </u-cell-item>
  30. </u-cell-group>
  31. </view>
  32. <view class="u-m-t-20">
  33. <u-cell-group>
  34. <u-cell-item title="包月" @click="openPage('pages/center/monthly/monthly')">
  35. <u-icon slot="icon" custom-prefix="custom-icon" size="35" name="baoyue"></u-icon>
  36. </u-cell-item>
  37. </u-cell-group>
  38. </view>
  39. <view class="u-m-t-20">
  40. <u-cell-group>
  41. <u-cell-item title="消息中心" @click="openPage('pages/message/message', true)">
  42. <u-icon slot="icon" custom-prefix="custom-icon" size="35" name="xiaoxi"></u-icon>
  43. <u-badge type="success" :count="messageNum" :offset="[38, 80]"></u-badge>
  44. </u-cell-item>
  45. </u-cell-group>
  46. </view>
  47. <view class="u-m-t-20 u-m-b-40">
  48. <u-cell-group>
  49. <u-cell-item title="拨打客服电话" @click="callPhoneShow = true">
  50. <u-icon slot="icon" custom-prefix="custom-icon" size="35" name="dianhua"></u-icon>
  51. </u-cell-item>
  52. </u-cell-group>
  53. </view>
  54. <u-select v-model="callPhoneShow" :list="callPhoneList" @confirm="phoneCall"></u-select>
  55. <view class="u-m-t-20">
  56. <u-cell-group>
  57. <u-cell-item icon="coupon" title="我的优惠券" @click="openPage('/pages/center/coupon/myCoupon/myCoupon')"></u-cell-item>
  58. </u-cell-group>
  59. </view>
  60. <!-- ===================================== 登出提示 ===================================== -->
  61. <u-modal
  62. v-model="logoutPop"
  63. :title-style="{ color: '#404040' }"
  64. title="登出提示"
  65. :show-confirm-button="true"
  66. confirm-text="确认"
  67. :confirm-style="{ backgroundColor: '#3397FA', color: '#fff' }"
  68. :show-cancel-button="true"
  69. cancel-text="取消"
  70. @cancel="logoutPop = false"
  71. :cancel-style="{ backgroundColor: '#EBF1FF', color: '#3397FA' }"
  72. @confirm="loginOut"
  73. >
  74. <view class="slot-content">
  75. <view class="pay-tips">你确认退出登录吗?</view>
  76. </view>
  77. </u-modal>
  78. <u-toast ref="uToast" />
  79. </view>
  80. </template>
  81. <script>
  82. export default {
  83. data() {
  84. return {
  85. // 默认头像
  86. pic: '/static/img/default-avatar.png',
  87. // 用户信息
  88. userInfo: {},
  89. logoutPop: false,
  90. messageNum: 0,
  91. callPhoneShow: false,
  92. callPhoneList: []
  93. };
  94. },
  95. onLoad() {},
  96. onShow() {
  97. this.getMsgNum();
  98. this.getDict();
  99. if (this.vuex_hasLogin) {
  100. this.userInfo = this.vuex_user;
  101. if (this.vuex_wxinfo) {
  102. this.userInfo = Object.assign(this.userInfo, this.vuex_wxinfo);
  103. }
  104. } else {
  105. this.userInfo = {};
  106. }
  107. },
  108. methods: {
  109. /**
  110. * 获取客服电话字典
  111. */
  112. getDict() {
  113. this.$u.api
  114. .getDictApi({
  115. type: 'customer_service_phone'
  116. })
  117. .then((res) => {
  118. if (res.code === 200) {
  119. this.callPhoneList = res.data.map((item) => {
  120. return {
  121. value: item.dictValue,
  122. label: item.dictLabel
  123. };
  124. });
  125. }
  126. });
  127. },
  128. /**
  129. * 打开新页面
  130. * @param {String} path 跳转路径
  131. * @param {flag} flag 返回存储标识
  132. * */
  133. openPage(path, flag) {
  134. this.$u.route({
  135. url: path
  136. });
  137. if (flag) {
  138. uni.setStorage({
  139. key: 'messageBack',
  140. data: 'pages/center/index'
  141. });
  142. }
  143. },
  144. // 获取消息未读条数
  145. getMsgNum() {
  146. this.$u.api.getIndexData().then((res) => {
  147. if (res.code === 200) {
  148. let num = 0;
  149. if (res.data.news) {
  150. res.data.news.forEach((item) => {
  151. if (item.readFlag == 0) {
  152. num += 1;
  153. }
  154. });
  155. }
  156. this.messageNum = num;
  157. } else {
  158. this.$refs.uToast.show({
  159. title: res.msg,
  160. type: 'error'
  161. });
  162. }
  163. });
  164. },
  165. // tabbar 返回
  166. customBack() {
  167. this.$u.route({
  168. type: 'switchTab',
  169. url: 'pages/index/index'
  170. });
  171. },
  172. // 拨打电话
  173. phoneCall(phone) {
  174. uni.makePhoneCall({
  175. phoneNumber: phone[0].value || '0851-38222696'
  176. });
  177. },
  178. // 登出
  179. loginOut() {
  180. this.$u.api.codeV2Api.logoutApi().then((res) => {
  181. if (res.code === 200) {
  182. this.$u.vuex('vuex_hasLogin', false);
  183. this.$u.vuex('vuex_token', '');
  184. this.$u.vuex('vuex_user', null);
  185. uni.removeStorage({
  186. key: 'jumpUrl'
  187. });
  188. uni.removeStorage({
  189. key: 'backUrl'
  190. });
  191. setTimeout(() => {
  192. this.logoutPop = false;
  193. uni.navigateTo({
  194. url: '/pages/center/phoneLogin/phoneLogin'
  195. });
  196. }, 500);
  197. } else {
  198. this.$refs.uToast.show({
  199. title: res.msg || '登出失败',
  200. type: 'error'
  201. });
  202. }
  203. });
  204. },
  205. // 点击头像
  206. clickHead() {
  207. if (this.$store.state.vuex_hasLogin) {
  208. this.logoutPop = true;
  209. }
  210. }
  211. }
  212. };
  213. </script>
  214. <style lang="scss" scoped>
  215. page {
  216. background-color: $my-page-bg-color;
  217. }
  218. .user-box {
  219. position: relative;
  220. background-color: $my-main-color;
  221. color: #fff;
  222. &:after {
  223. position: absolute;
  224. right: 0;
  225. bottom: 0;
  226. content: '';
  227. background: url('/static/img/center-top-bg.png') no-repeat;
  228. background-position: -90rpx 0;
  229. width: 305rpx;
  230. height: 145rpx;
  231. z-index: 999;
  232. }
  233. }
  234. .u-avatar {
  235. border: 10rpx solid #4caeff;
  236. }
  237. .u-cell-box /deep/ .u-cell__left-icon-wrap,
  238. .u-cell-box /deep/ .custom-icon {
  239. color: $my-main-color;
  240. margin-right: 10rpx;
  241. }
  242. .pay-tips {
  243. text-align: center;
  244. margin: 30rpx 0;
  245. }
  246. </style>