index.vue 7.5 KB

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