index.vue 6.6 KB

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