user.vue 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439
  1. <template>
  2. <view>
  3. <!-- 顶部内容 -->
  4. <view class="top-content" :style="top_content_style">
  5. <!-- 内容 -->
  6. <view class="content padding-horizontal-main">
  7. <view class="head-base pr oh">
  8. <!-- 左侧头像 -->
  9. <view class="padding-bottom-xxl oh tc fl">
  10. <image @tap="preview_event" @error="user_avatar_error" class="head-avatar circle bg-white va-m" :src="avatar" mode="widthFix"></image>
  11. <view class="va-m dis-inline-block cr-white margin-left-lg tl">
  12. <view data-value="/pages/personal/personal" @tap="url_event">
  13. <view>
  14. <text class="va-m">{{nickname}}</text>
  15. <view class="dis-inline-block va-m margin-left-sm">
  16. <uni-icons type="compose" size="14" color="#fff"></uni-icons>
  17. </view>
  18. </view>
  19. <view v-if="(user_id || null) != null" class="br round tc padding-left-lg padding-right-lg margin-top-xs dis-inline-block">ID {{user_id}}</view>
  20. </view>
  21. </view>
  22. </view>
  23. <!-- 右上角 -->
  24. <view class="head-right pa">
  25. <view v-if="(qrcode_page_url || null) != null" class="item pr dis-inline-block" :data-value="qrcode_page_url" @tap="url_event">
  26. <image class="icon" :src="common_static_url+'qrcode-icon.png'" mode="widthFix"></image>
  27. </view>
  28. <view class="item pr dis-inline-block margin-left-xxl" data-value="/pages/setup/setup" @tap="url_event">
  29. <image class="icon" :src="common_static_url+'gear-icon.png'" mode="widthFix"></image>
  30. </view>
  31. <view class="item pr dis-inline-block margin-left-xxl" data-value="/pages/message/message" @tap="url_event">
  32. <image class="icon" :src="common_static_url+'notification-icon.png'" mode="widthFix"></image>
  33. <view class="badge-icon pa">
  34. <component-badge :propNumber="message_total"></component-badge>
  35. </view>
  36. </view>
  37. </view>
  38. </view>
  39. <!-- 副导航 -->
  40. <view v-if="common_app_is_head_vice_nav == 1 && head_nav_list.length > 0" class="head-nav oh bg-white padding-main border-radius-main spacing-mb">
  41. <block v-for="(item, index) in head_nav_list" :key="index">
  42. <navigator :url="'/pages/' + item.url + '/' + item.url" hover-class="none">
  43. <view class="head-nav-item tc fl">
  44. <view class="nav-value fw-b text-size">{{item.count}}</view>
  45. <view class="nav-name cr-gray">{{item.name}}</view>
  46. </view>
  47. </navigator>
  48. </block>
  49. </view>
  50. <!-- 订单导航 -->
  51. <view v-if="(navigation_order || null) != null" class="nav-list bg-white bg-white padding-main border-radius-main spacing-mb">
  52. <!-- 主导航 -->
  53. <view :data-value="navigation_order.event_value" :data-type="navigation_order.event_type" @tap="navigation_event" class="nav-item br-b cp padding-main">
  54. <view class="arrow-right">
  55. <image :src="navigation_order.images_url" class="item-icon va-m" mode="widthFix"></image>
  56. <text class="item-name va-m cr-base margin-left-sm">{{navigation_order.name}}</text>
  57. <text v-if="(navigation_order.desc || null) != null" class="item-desc fr tr single-text cr-grey">{{navigation_order.desc}}</text>
  58. </view>
  59. </view>
  60. <!-- 订单自定义副导航 -->
  61. <view class="nav-list-sub oh margin-top-sm">
  62. <block v-for="(items, index) in user_order_status_list" :key="index">
  63. <navigator :url="items.url" hover-class="none">
  64. <view class="item pr fl tc">
  65. <view class="badge-icon pa">
  66. <component-badge :propNumber="items.count"></component-badge>
  67. </view>
  68. <image class="item-icon margin-bottom-xs" :src="static_url+'order-icon-' + items.status + '.png'" mode="aspectFill"></image>
  69. <view class="item-name cr-base">{{items.name}}</view>
  70. </view>
  71. </navigator>
  72. </block>
  73. </view>
  74. </view>
  75. <!-- 聚合导航 -->
  76. <view class="service-nav padding-main border-radius-main bg-white spacing-mb">
  77. <view class="padding-main pr">
  78. <text class="fw-b text-size">我的服务</text>
  79. <image class="show-type-submit pa cp" :src="common_static_url+'show-'+(nav_show_model_type == 0 ? 'list' : 'grid')+'-icon.png'" mode="aspectFill" @tap="nav_show_type_event"></image>
  80. </view>
  81. <!-- 列表模式 -->
  82. <view v-if="nav_show_model_type == 1" class="nav-list">
  83. <block v-for="(item, index) in navigation" :key="index">
  84. <!-- 这里不展示订单导航 -->
  85. <block v-if="item.event_value != '/pages/user-order/user-order'">
  86. <view :data-value="item.event_value" :data-type="item.event_type" @tap="navigation_event" class="nav-item br-t cp padding-main margin-top-sm">
  87. <view class="arrow-right">
  88. <image :src="item.images_url" class="item-icon va-m" mode="widthFix"></image>
  89. <text class="item-name va-m cr-base margin-left-sm">{{item.name}}</text>
  90. <text v-if="(item.desc || null) != null" class="item-desc fr tr single-text cr-grey">{{item.desc}}</text>
  91. </view>
  92. </view>
  93. </block>
  94. </block>
  95. <!-- 清除缓存 -->
  96. <view class="nav-item br-t cp padding-main" @tap="remove_user_cache_event">
  97. <view class="arrow-right">
  98. <image :src="common_static_url+nav_logout_data.icon+'-icon.png'" class="item-icon va-m" mode="widthFix"></image>
  99. <text class="item-name va-m cr-base margin-left-sm">{{nav_logout_data.name}}</text>
  100. </view>
  101. </view>
  102. <!-- 联系客服 -->
  103. <view v-if="(common_app_customer_service_tel || null) != null" class="nav-item br-t cp padding-main" @tap="call_event">
  104. <view class="arrow-right">
  105. <image :src="common_static_url+'customer-service-icon.png'" class="item-icon va-m" mode="widthFix"></image>
  106. <text class="item-name va-m cr-base margin-left-sm">联系客服</text>
  107. </view>
  108. </view>
  109. </view>
  110. <!-- 默认九方格模式 -->
  111. <view v-else class="nav-box oh br-t margin-top-sm">
  112. <block v-for="(item, index) in navigation" :key="index">
  113. <!-- 这里不展示订单导航 -->
  114. <block v-if="item.event_value != '/pages/user-order/user-order'">
  115. <view :data-value="item.event_value" :data-type="item.event_type" @tap="navigation_event" class="nav-item padding-main fl tc cp">
  116. <image :src="item.images_url" class="item-icon" mode="widthFix"></image>
  117. <view class="item-name single-text cr-base">{{item.name}}</view>
  118. </view>
  119. </block>
  120. </block>
  121. <!-- 清除缓存 -->
  122. <view class="nav-item padding-main fl tc cp" @tap="remove_user_cache_event">
  123. <image :src="common_static_url+nav_logout_data.icon+'-icon.png'" class="item-icon" mode="widthFix"></image>
  124. <view class="item-name single-text cr-base">{{nav_logout_data.name}}</view>
  125. </view>
  126. <!-- 联系客服 -->
  127. <view v-if="(common_app_customer_service_tel || null) != null" class="nav-item padding-main fl tc cp" @tap="call_event">
  128. <image :src="common_static_url+'customer-service-icon.png'" class="item-icon" mode="widthFix"></image>
  129. <view class="item-name single-text cr-base">联系客服</view>
  130. </view>
  131. </view>
  132. </view>
  133. </view>
  134. </view>
  135. <!-- 用户中心公告 -->
  136. <view v-if="(common_user_center_notice || null) != null" class="padding-horizontal-main padding-bottom-main">
  137. <view class="notice-content">{{common_user_center_notice}}</view>
  138. </view>
  139. <!-- 在线客服 -->
  140. <component-online-service :propIsNav="true" :propIsBar="true"></component-online-service>
  141. <!-- 快捷导航 -->
  142. <component-quick-nav :propIsNav="true" :propIsBar="true"></component-quick-nav>
  143. <!-- 版权信息 -->
  144. <component-copyright></component-copyright>
  145. </view>
  146. </template>
  147. <script>
  148. const app = getApp();
  149. import componentQuickNav from "../../components/quick-nav/quick-nav";
  150. import componentBadge from "../../components/badge/badge";
  151. import componentCopyright from "../../components/copyright/copyright";
  152. import componentOnlineService from "../../components/online-service/online-service";
  153. var common_static_url = app.globalData.get_static_url('common');
  154. var static_url = app.globalData.get_static_url('user');
  155. var client_value = app.globalData.application_client();
  156. export default {
  157. data() {
  158. return {
  159. common_static_url: common_static_url,
  160. static_url: static_url,
  161. avatar: app.globalData.data.default_user_head_src,
  162. user_id: '',
  163. nickname: "用户名",
  164. message_total: 0,
  165. nav_logout_data: {
  166. name: (client_value == 'mp') ? '清除缓存' : '退出账号',
  167. icon: (client_value == 'mp') ? 'cache' : 'logout',
  168. },
  169. head_nav_list: [
  170. { name: "订单总数", url: "user-order", count: 0 },
  171. { name: "商品收藏", url: "user-favor", count: 0 },
  172. { name: "我的足迹", url: "user-goods-browse", count: 0 },
  173. { name: "我的积分", url: "user-integral", count: 0 },
  174. ],
  175. user_order_status_list: [
  176. { name: "待付款", status: 1, count: 0, url: "/pages/user-order/user-order?status=1" },
  177. { name: "待发货", status: 2, count: 0, url: "/pages/user-order/user-order?status=2" },
  178. { name: "待收货", status: 3, count: 0, url: "/pages/user-order/user-order?status=3" },
  179. { name: "已完成", status: 4, count: 0, url: "/pages/user-order/user-order?status=4" },
  180. { name: "退款/售后", status: 101, count: 0, url: "/pages/user-orderaftersale/user-orderaftersale" },
  181. ],
  182. navigation_order: null,
  183. // 远程自定义导航
  184. navigation: [],
  185. // 基础配置
  186. common_app_customer_service_tel: null,
  187. common_user_center_notice: null,
  188. common_app_is_online_service: 0,
  189. common_app_is_head_vice_nav: 0,
  190. // 顶部样式配置
  191. top_content_style: 'background-image: url("'+static_url+'nav-top.png");'+'padding-top:'+(parseInt(app.globalData.get_system_info('statusBarHeight', 0))+5)+'px;',
  192. // 付款码地址
  193. qrcode_page_url: null,
  194. // 用户中心菜单展示模式
  195. nav_show_model_type: app.globalData.data.user_center_nav_show_model_type
  196. };
  197. },
  198. components: {
  199. componentQuickNav,
  200. componentBadge,
  201. componentCopyright,
  202. componentOnlineService
  203. },
  204. props: {},
  205. onShow() {
  206. // 数据加载
  207. this.init();
  208. // 初始化配置
  209. this.init_config();
  210. },
  211. // 下拉刷新
  212. onPullDownRefresh(e) {
  213. this.init();
  214. },
  215. methods: {
  216. // 初始化配置
  217. init_config(status) {
  218. if ((status || false) == true) {
  219. // 会员码及付款码入口
  220. var qrcode_page_url = null;
  221. if(app.globalData.get_config('plugins_base.wallet', null) != null) {
  222. qrcode_page_url = '/pages/plugins/wallet/payment-code/payment-code';
  223. }
  224. if(app.globalData.get_config('plugins_base.membershiplevelvip', null) != null) {
  225. qrcode_page_url = '/pages/plugins/membershiplevelvip/member-code/member-code';
  226. }
  227. this.setData({
  228. common_app_customer_service_tel: app.globalData.get_config('config.common_app_customer_service_tel'),
  229. common_user_center_notice: app.globalData.get_config('config.common_user_center_notice'),
  230. common_app_is_online_service: app.globalData.get_config('config.common_app_is_online_service'),
  231. common_app_is_head_vice_nav: app.globalData.get_config('config.common_app_is_head_vice_nav'),
  232. qrcode_page_url: qrcode_page_url
  233. });
  234. } else {
  235. app.globalData.is_config(this, 'init_config');
  236. }
  237. },
  238. // 获取数据
  239. init(e) {
  240. var user = app.globalData.get_user_info(this, "init");
  241. if (user != false) {
  242. // 用户未绑定用户则转到登录页面
  243. if (app.globalData.user_is_need_login(user)) {
  244. uni.stopPullDownRefresh();
  245. uni.showModal({
  246. title: '温馨提示',
  247. content: '绑定手机号码',
  248. confirmText: '确认',
  249. cancelText: '暂不',
  250. success: result => {
  251. uni.stopPullDownRefresh();
  252. if (result.confirm) {
  253. uni.navigateTo({
  254. url: "/pages/login/login?event_callback=init"
  255. });
  256. }
  257. this.set_user_base(user);
  258. }
  259. });
  260. // 分享菜单处理
  261. app.globalData.page_share_handle();
  262. } else {
  263. this.set_user_base(user);
  264. this.get_data();
  265. }
  266. } else {
  267. uni.stopPullDownRefresh();
  268. // 分享菜单处理
  269. app.globalData.page_share_handle();
  270. }
  271. },
  272. // 设置用户基础信息
  273. set_user_base(user) {
  274. if((user.id || null) != null) {
  275. this.setData({user_id: user.id});
  276. }
  277. if((user.avatar || null) != null) {
  278. this.setData({avatar: user.avatar});
  279. }
  280. if((user.user_name_view || null) != null) {
  281. this.setData({nickname: user.user_name_view});
  282. }
  283. },
  284. // 获取数据
  285. get_data() {
  286. uni.request({
  287. url: app.globalData.get_request_url("center", "user"),
  288. method: 'POST',
  289. data: {},
  290. dataType: 'json',
  291. success: res => {
  292. uni.stopPullDownRefresh();
  293. if (res.data.code == 0) {
  294. var data = res.data.data;
  295. // 订单状态
  296. var temp_user_order_status_list = this.user_order_status_list;
  297. if ((data.user_order_status || null) != null && data.user_order_status.length > 0) {
  298. for (var i in temp_user_order_status_list) {
  299. for (var t in data.user_order_status) {
  300. if (temp_user_order_status_list[i]['status'] == data.user_order_status[t]['status']) {
  301. temp_user_order_status_list[i]['count'] = data.user_order_status[t]['count'];
  302. break;
  303. }
  304. }
  305. }
  306. }
  307. // 头部导航总数
  308. var temp_head_nav_list = this.head_nav_list;
  309. temp_head_nav_list[0]['count'] = (data.user_order_count || 0) == 0 ? 0 : data.user_order_count;
  310. temp_head_nav_list[1]['count'] = (data.user_goods_favor_count || 0) == 0 ? 0 : data.user_goods_favor_count;
  311. temp_head_nav_list[2]['count'] = (data.user_goods_browse_count || 0) == 0 ? 0 : data.user_goods_browse_count;
  312. temp_head_nav_list[3]['count'] = (data.integral || 0) == 0 ? 0 : data.integral;
  313. // 数据设置
  314. var upd_data = {
  315. user_order_status_list: temp_user_order_status_list,
  316. message_total: parseInt(data.message_total || 0),
  317. head_nav_list: temp_head_nav_list,
  318. navigation: data.navigation || []
  319. }
  320. // 是否存在配置订单导航
  321. var temp_nav_order = null;
  322. if(upd_data.navigation.length > 0) {
  323. for(var i in upd_data.navigation) {
  324. var url = app.globalData.get_url_main_part(upd_data.navigation[i]['event_value']);
  325. if(url == '/pages/user-order/user-order') {
  326. temp_nav_order = upd_data.navigation[i];
  327. upd_data.navigation.splice(i, 1);
  328. break;
  329. }
  330. }
  331. }
  332. upd_data['navigation_order'] = temp_nav_order;
  333. // 用户基础信息处理
  334. if((data.avatar || null) != null) {
  335. upd_data['avatar'] = data.avatar;
  336. }
  337. if((data.user_name_view || null) != null) {
  338. upd_data['nickname'] = data.user_name_view;
  339. }
  340. this.setData(upd_data);
  341. // 导航购物车处理
  342. var cart_total = data.cart_total.buy_number || 0;
  343. if (cart_total <= 0) {
  344. app.globalData.set_tab_bar_badge(2, 0);
  345. } else {
  346. app.globalData.set_tab_bar_badge(2, 1, cart_total);
  347. }
  348. } else {
  349. if (app.globalData.is_login_check(res.data, this, 'get_data')) {
  350. app.globalData.showToast(res.data.msg);
  351. }
  352. }
  353. // 分享菜单处理、延时执行,确保基础数据已加载完成
  354. setTimeout(function() {
  355. app.globalData.page_share_handle();
  356. }, 3000);
  357. },
  358. fail: () => {
  359. uni.stopPullDownRefresh();
  360. app.globalData.showToast('服务器请求出错');
  361. }
  362. });
  363. },
  364. // 清除缓存
  365. remove_user_cache_event(e) {
  366. app.globalData.remove_user_cache_event();
  367. },
  368. // 客服电话
  369. call_event() {
  370. if (this.common_app_customer_service_tel == null) {
  371. app.globalData.showToast('客服电话有误');
  372. } else {
  373. app.globalData.call_tel(this.common_app_customer_service_tel);
  374. }
  375. },
  376. // 头像查看
  377. preview_event() {
  378. if (app.globalData.data.default_user_head_src != this.avatar) {
  379. uni.previewImage({
  380. current: this.avatar,
  381. urls: [this.avatar]
  382. });
  383. }
  384. },
  385. // 头像加载错误
  386. user_avatar_error(e) {
  387. this.setData({
  388. avatar: app.globalData.data.default_user_head_src
  389. });
  390. },
  391. // 远程自定义导航事件
  392. navigation_event(e) {
  393. app.globalData.operation_event(e);
  394. },
  395. // url事件
  396. url_event(e) {
  397. app.globalData.url_event(e);
  398. },
  399. // 数据展示类型
  400. nav_show_type_event(e) {
  401. this.setData({nav_show_model_type: this.nav_show_model_type == 0 ? 1 : 0});
  402. }
  403. }
  404. };
  405. </script>
  406. <style>
  407. @import './user.css';
  408. </style>