index.vue 6.8 KB

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