index.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. ></u-navbar>
  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. import getUrlParams from '../../utils/getUrlParams.js';
  83. export default {
  84. data() {
  85. return {
  86. // 默认头像
  87. pic: '/static/img/default-avatar.png',
  88. // 用户信息
  89. userInfo: [],
  90. logoutPop: false,
  91. messageNum: 0,
  92. callPhoneShow: false,
  93. callPhoneList: []
  94. };
  95. },
  96. onLoad() {},
  97. onShow() {
  98. this.getMsgNum();
  99. this.getDict();
  100. if (this.vuex_hasLogin) {
  101. this.userInfo = this.vuex_user;
  102. if (this.vuex_wxinfo) {
  103. this.userInfo = Object.assign(this.userInfo, this.vuex_wxinfo);
  104. }
  105. } else {
  106. this.userInfo = [];
  107. }
  108. },
  109. methods: {
  110. /**
  111. * 获取客服电话字典
  112. */
  113. getDict() {
  114. this.$u.api
  115. .getDictApi({
  116. type: 'customer_service_phone'
  117. })
  118. .then((res) => {
  119. if (res.code === 200) {
  120. this.callPhoneList = res.data.map((item) => {
  121. return {
  122. value: item.dictValue,
  123. label: item.dictLabel
  124. };
  125. });
  126. }
  127. });
  128. },
  129. /**
  130. * 打开新页面
  131. * @param {String} path 跳转路径
  132. * @param {flag} flag 返回存储标识
  133. * */
  134. openPage(path, flag) {
  135. this.$u.route({
  136. url: path
  137. });
  138. if (flag) {
  139. uni.setStorage({
  140. key: 'messageBack',
  141. data: 'pages/center/index'
  142. });
  143. }
  144. },
  145. // 获取消息未读条数
  146. getMsgNum() {
  147. this.$u.api.getIndexData().then((res) => {
  148. if (res.code === 200) {
  149. let num = 0;
  150. if (res.data.news) {
  151. res.data.news.forEach((item) => {
  152. if (item.readFlag == 0) {
  153. num += 1;
  154. }
  155. });
  156. }
  157. this.messageNum = num;
  158. } else {
  159. this.$refs.uToast.show({
  160. title: res.msg,
  161. type: 'error'
  162. });
  163. }
  164. });
  165. },
  166. // tabbar 返回
  167. customBack() {
  168. this.$u.route({
  169. type: 'switchTab',
  170. url: 'pages/index/index'
  171. });
  172. },
  173. // 拨打电话
  174. phoneCall(phone) {
  175. uni.makePhoneCall({
  176. phoneNumber: phone[0].value || '0851-38222696'
  177. });
  178. },
  179. // 登出
  180. loginOut() {
  181. this.$u.api.codeV2Api.logoutApi().then((res) => {
  182. if (res.code === 200) {
  183. this.$u.vuex('vuex_hasLogin', false);
  184. this.$u.vuex('vuex_token', '');
  185. this.$u.vuex('vuex_user', null);
  186. uni.removeStorage({
  187. key: 'jumpUrl'
  188. });
  189. uni.removeStorage({
  190. key: 'backUrl'
  191. });
  192. setTimeout(() => {
  193. this.logoutPop = false;
  194. uni.navigateTo({
  195. url: '/pages/center/phoneLogin/phoneLogin'
  196. });
  197. }, 500);
  198. } else {
  199. this.$refs.uToast.show({
  200. title: res.msg || '登出失败',
  201. type: 'error'
  202. });
  203. }
  204. });
  205. },
  206. // 点击头像
  207. clickHead() {
  208. if (this.$store.state.vuex_hasLogin) {
  209. this.logoutPop = true;
  210. }
  211. }
  212. }
  213. };
  214. </script>
  215. <style lang="scss" scoped>
  216. page {
  217. background-color: $my-page-bg-color;
  218. }
  219. .user-box {
  220. position: relative;
  221. background-color: $my-main-color;
  222. color: #fff;
  223. &:after {
  224. position: absolute;
  225. right: 0;
  226. bottom: 0;
  227. content: '';
  228. background: url(../../static/img/center-top-bg.png) no-repeat;
  229. background-position: -90rpx 0;
  230. width: 305rpx;
  231. height: 145rpx;
  232. z-index: 999;
  233. }
  234. }
  235. .u-avatar {
  236. border: 10rpx solid #4caeff;
  237. }
  238. .u-cell-box /deep/ .u-cell__left-icon-wrap,
  239. .u-cell-box /deep/ .custom-icon {
  240. color: $my-main-color;
  241. margin-right: 10rpx;
  242. }
  243. .pay-tips {
  244. text-align: center;
  245. margin: 30rpx 0;
  246. }
  247. </style>