index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <mobile-frame :frameStyle="frameStyle" @toPath="toPath">
  3. <view class="main">
  4. <view class="one">
  5. <view class="one_1" v-if="user&&user._id==null">
  6. <text class="iconfont icon-geren2" @click="toCommon('pages/login/index')"></text>
  7. <view class="name">未登录</view>
  8. </view>
  9. <view class="one_1" v-else>
  10. <view class="one_1_1" @tap="toNotice()">
  11. <uni-badge :text="notice_total" absolute="rightTop" size="normal">
  12. <text class="iconfont icon-xiaoxitongzhi"></text>
  13. </uni-badge>
  14. </view>
  15. <image class="image" :src="user.icon&&user.icon.length>0?user.icon[0].url:''"></image>
  16. <view class="name">
  17. <text>{{user&&user.name||'暂无名称'}}</text>
  18. <text>{{user&&user.is_leader=='0'?'团购会员':'普通会员'}}</text>
  19. </view>
  20. </view>
  21. <!-- <view class="one_2">
  22. <view class="one_2_1" @click="toCommon('pagesMy/collection/market')">
  23. <text v-if="user._id">{{market_num||0}}</text>
  24. <text>收藏的商品</text>
  25. </view>
  26. <text class="link">|</text>
  27. <view class="one_2_1" @click="toCommon('pagesMy/collection/shop')">
  28. <text v-if="user._id">{{shop_num||0}}</text>
  29. <text>收藏的店铺</text>
  30. </view>
  31. </view> -->
  32. </view>
  33. <view class="two">
  34. <view class="two_1">
  35. <view class="title">我的订单</view>
  36. <view class="title">
  37. <text @click="toCommon('pagesMy/order/all')">全部订单</text>
  38. <text class="iconfont icon-jiantouyou"></text>
  39. </view>
  40. </view>
  41. <view class="two_2">
  42. <view class="orderList" v-for="(item, index) in orderList" :key="index" @click="toOrder(item)">
  43. <uni-badge :text="item.num" absolute="rightTop" size="normal">
  44. <view class="icon">
  45. <text class="iconfont" :class="[item.icon]"></text>
  46. </view>
  47. <text class="title">{{item.title}}</text>
  48. </uni-badge>
  49. </view>
  50. </view>
  51. <view class="two_1" v-for="(item, index) in menuList" :key="index" @click="toCommon(item.route)">
  52. <view class="title">{{item.title}}</view>
  53. <view class="title">
  54. <text v-if="user.id&&item.title=='我的尊荣'">{{integral||0}}分</text>
  55. <text v-if="user.id&&item.title=='我的收藏'">{{market_num||0}}个</text>
  56. <text v-if="item.title=='客服电话'"
  57. @tap="makePhone(serviceContactInfo.phone)">{{serviceContactInfo.phone||''}}</text>
  58. <text class="iconfont icon-jiantouyou"></text>
  59. </view>
  60. </view>
  61. </view>
  62. </view>
  63. </mobile-frame>
  64. </template>
  65. <script>
  66. export default {
  67. data() {
  68. return {
  69. frameStyle: {
  70. useBar: true
  71. },
  72. // 用户信息
  73. user: {},
  74. // 客服信息
  75. serviceContactInfo: {},
  76. // 订单图标菜单
  77. orderList: [],
  78. // 菜单
  79. menuList: [],
  80. // 收藏商品
  81. market_num: '',
  82. // 收藏店铺
  83. shop_num: '',
  84. // 积分
  85. integral: '',
  86. // 未读消息
  87. notice_total: 0,
  88. };
  89. },
  90. onShow: async function() {
  91. const that = this;
  92. // 查询其他信息
  93. await that.searchOther();
  94. // 监听用户登录
  95. await that.watchLogin();
  96. // 监听用户登录
  97. await that.notice();
  98. },
  99. methods: {
  100. // 监听用户登录
  101. watchLogin() {
  102. const that = this;
  103. uni.getStorage({
  104. key: 'token',
  105. success: async (res) => {
  106. let user = that.$jwt(res.data);
  107. if (user && user._id) {
  108. let arr;
  109. // 查询用户信息
  110. arr = await that.$api(`/user/${user._id}`, 'GET');
  111. if (arr.errcode == '0') that.$set(that, `user`, arr.data);
  112. // 查询收藏商品
  113. arr = await that.$api(`/storeGoods/userView`, 'GET', {
  114. customer: user._id,
  115. limit: 1
  116. })
  117. if (arr.errcode == '0') that.$set(that, `market_num`, arr.total);
  118. // // 查询收藏店铺
  119. // arr = await that.$api(`/storeShop/userView`, 'GET', {
  120. // customer: user._id
  121. // })
  122. // if (arr.errcode == '0') that.$set(that, `shop_num`, arr.total);
  123. arr = await that.$api(`/point/computedTotal`, 'GET', {
  124. customer: user._id
  125. })
  126. if (arr.errcode == '0') that.$set(that, `integral`, Math.trunc(arr.data));
  127. that.searchOther();
  128. }
  129. },
  130. fail: (err) => {}
  131. })
  132. },
  133. // 消息通知
  134. notice() {
  135. const that = this;
  136. uni.getStorage({
  137. key: 'token',
  138. success: async (res) => {
  139. let user = that.$jwt(res.data);
  140. if (user && user._id) {
  141. let res = await that.$api(`/notice`, 'GET', {
  142. customer: user._id,
  143. shop: that.$config.shop,
  144. status: '0'
  145. });
  146. if (res.errcode == '0') that.$set(that, `notice_total`, res.total);
  147. }
  148. }
  149. })
  150. },
  151. // 查询其他信息
  152. async searchOther() {
  153. const that = this;
  154. let config = that.$config;
  155. let user = that.user;
  156. if (config) {
  157. if (user && user._id) {
  158. let res = await that.$api(`/viewUser/toDeal`, 'GET');
  159. if (res.errcode == '0') {
  160. for (let val of config.my_orderList) {
  161. if (val.type == "order") {
  162. if (val.status == '0') val.num = res.data.notPay
  163. if (val.status == '1') val.num = res.data.isPay
  164. if (val.status == '2') val.num = res.data.allSend
  165. } else {
  166. val.num = res.data.afterSale;
  167. }
  168. }
  169. }
  170. if (user.is_leader == '0') {
  171. config.my_menu = config.my_menu.filter((i) => {
  172. return i.route != 'pagesMy/apply/add';
  173. });
  174. }
  175. }
  176. // 订单图标菜单
  177. that.$set(that, `orderList`, config.my_orderList);
  178. // 菜单
  179. that.$set(that, `menuList`, config.my_menu);
  180. }
  181. // 客服联系方式
  182. const arr = await that.$api(`/serviceContact`, 'GET', {
  183. shop: that.$config.shop
  184. });
  185. if (arr.errcode == '0' && arr.total > 0) {
  186. that.$set(that, `serviceContactInfo`, arr.data[0])
  187. }
  188. },
  189. // 公共跳转
  190. toCommon(e) {
  191. uni.getStorage({
  192. key: 'token',
  193. success: function(res) {
  194. uni.navigateTo({
  195. url: `/${e}`
  196. })
  197. },
  198. fail: function(err) {
  199. uni.navigateTo({
  200. url: `/pages/login/index`
  201. })
  202. }
  203. });
  204. },
  205. // 系统消息页
  206. toNotice() {
  207. uni.navigateTo({
  208. url: `/pagesHome/notice/index`
  209. })
  210. },
  211. // 订单跳转页面
  212. toOrder(e) {
  213. const that = this;
  214. uni.getStorage({
  215. key: 'token',
  216. success: function(res) {
  217. if (e.type == 'order') {
  218. uni.navigateTo({
  219. url: `/${e.route}?status=${e.status}`
  220. })
  221. } else if (e.type == 'after') {
  222. uni.navigateTo({
  223. url: `/${e.route}`
  224. })
  225. }
  226. },
  227. fail: function(err) {
  228. uni.navigateTo({
  229. url: `/pages/login/index`
  230. })
  231. }
  232. });
  233. },
  234. // 拨打电话
  235. makePhone(e) {
  236. uni.makePhoneCall({
  237. phoneNumber: e
  238. });
  239. },
  240. // 底部菜单跳转
  241. toPath(e) {
  242. let url = `/${e.route}`;
  243. if (e.type == '0') uni.redirectTo({
  244. url
  245. })
  246. else {
  247. uni.navigateTo({
  248. url
  249. })
  250. }
  251. },
  252. }
  253. }
  254. </script>
  255. <style lang="scss">
  256. .main {
  257. display: flex;
  258. flex-direction: column;
  259. width: 100vw;
  260. height: 100vh;
  261. .one {
  262. text-align: center;
  263. padding: 4vw 0;
  264. background-color: var(--fFB1Color);
  265. color: var(--mainColor);
  266. .one_1 {
  267. margin: 0 0 5vw 0;
  268. .one_1_1 {
  269. position: absolute;
  270. left: 55vw;
  271. .iconfont {
  272. font-size: 20px;
  273. }
  274. }
  275. image {
  276. width: 25vw;
  277. height: 25vw;
  278. border-radius: 25vw;
  279. }
  280. .iconfont {
  281. font-size: 80px;
  282. }
  283. .name {
  284. display: flex;
  285. justify-content: space-evenly;
  286. margin: 2vw 0;
  287. font-size: var(--font18Szie);
  288. }
  289. .image {
  290. border: 1px solid var(--f1Color);
  291. }
  292. }
  293. .one_2 {
  294. display: flex;
  295. flex-direction: row;
  296. justify-content: space-around;
  297. font-size: var(--font16Szie);
  298. .one_2_1 {
  299. display: flex;
  300. flex-direction: column;
  301. }
  302. .link {
  303. font-weight: bold;
  304. }
  305. }
  306. }
  307. .two {
  308. background-color: var(--f1Color);
  309. .two_1 {
  310. display: flex;
  311. justify-content: space-between;
  312. padding: 4vw;
  313. background-color: var(--mainColor);
  314. margin: 0 0 0.1vw 0;
  315. border-bottom: 1px solid var(--f1Color);
  316. .title {
  317. font-size: var(--font16Szie);
  318. text:first-child {
  319. margin: 0 1vw 0 0;
  320. }
  321. }
  322. .title:last-child {
  323. color: var(--f85Color);
  324. font-size: var(--font14Size);
  325. }
  326. }
  327. .two_1:nth-last-child(2) {
  328. margin: 0 0 2vw 0;
  329. }
  330. .two_1:nth-last-child(4) {
  331. margin: 0 0 2vw 0;
  332. }
  333. .two_2 {
  334. display: flex;
  335. justify-content: space-between;
  336. padding: 5vw;
  337. background-color: var(--mainColor);
  338. margin: 0 0 2vw 0;
  339. .orderList {
  340. text-align: center;
  341. .icon {
  342. .iconfont {
  343. font-size: 25px;
  344. }
  345. }
  346. .title {
  347. display: inline-block;
  348. margin: 2vw 0 0 0;
  349. font-size: var(--font12Size);
  350. }
  351. }
  352. }
  353. }
  354. }
  355. </style>