index.vue 6.7 KB

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