index.vue 9.2 KB

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