index.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. });
  136. } else {
  137. res = await that.$api(`/orderDetail`, 'GET', {
  138. status: val.status,
  139. customer: user._id
  140. });
  141. }
  142. if (res.errcode == '0') {
  143. val.num = res.total
  144. that.$forceUpdate()
  145. }
  146. }
  147. }
  148. // 订单图标菜单
  149. that.$set(that, `orderList`, config.my_orderList);
  150. // 菜单
  151. that.$set(that, `menuList`, config.my_menu);
  152. }
  153. let res;
  154. res = await that.$api(`/serviceContact`, 'GET');
  155. if (res.errcode == '0' && res.total > 0) {
  156. that.$set(that, `serviceContactInfo`, res.data[0])
  157. }
  158. },
  159. // 公共跳转
  160. toCommon(e) {
  161. uni.getStorage({
  162. key: 'token',
  163. success: function(res) {
  164. uni.navigateTo({
  165. url: `/${e}`
  166. })
  167. },
  168. fail: function(err) {
  169. uni.navigateTo({
  170. url: `/pages/login/index`
  171. })
  172. }
  173. });
  174. },
  175. // 订单跳转页面
  176. toOrder(e) {
  177. const that = this;
  178. uni.getStorage({
  179. key: 'token',
  180. success: function(res) {
  181. if (e.type == 'order') {
  182. uni.navigateTo({
  183. url: `/${e.route}?status=${e.status}`
  184. })
  185. } else if (e.type == 'after') {
  186. uni.navigateTo({
  187. url: `/${e.route}`
  188. })
  189. }
  190. },
  191. fail: function(err) {
  192. uni.navigateTo({
  193. url: `/pages/login/index`
  194. })
  195. }
  196. });
  197. },
  198. // 拨打电话
  199. makePhone(e) {
  200. uni.makePhoneCall({
  201. phoneNumber: e
  202. });
  203. },
  204. // 底部菜单跳转
  205. toPath(e) {
  206. let url = `/${e.route}`;
  207. if (e.type == '0') uni.redirectTo({
  208. url
  209. })
  210. else {
  211. uni.navigateTo({
  212. url
  213. })
  214. }
  215. },
  216. }
  217. }
  218. </script>
  219. <style lang="scss">
  220. .main {
  221. display: flex;
  222. flex-direction: column;
  223. width: 100vw;
  224. height: 100vh;
  225. .one {
  226. text-align: center;
  227. padding: 4vw 0;
  228. background-color: var(--fFB1Color);
  229. color: var(--mainColor);
  230. .one_1 {
  231. margin: 0 0 5vw 0;
  232. image {
  233. width: 25vw;
  234. height: 25vw;
  235. border-radius: 25vw;
  236. }
  237. .iconfont {
  238. font-size: 80px;
  239. }
  240. .name {
  241. display: flex;
  242. justify-content: space-evenly;
  243. margin: 2vw 0;
  244. font-size: var(--font18Szie);
  245. }
  246. .image {
  247. border: 1px solid var(--f1Color);
  248. }
  249. }
  250. .one_2 {
  251. display: flex;
  252. flex-direction: row;
  253. justify-content: space-around;
  254. font-size: var(--font16Szie);
  255. .one_2_1 {
  256. display: flex;
  257. flex-direction: column;
  258. }
  259. .link {
  260. font-weight: bold;
  261. }
  262. }
  263. }
  264. .two {
  265. background-color: var(--f1Color);
  266. .two_1 {
  267. display: flex;
  268. justify-content: space-between;
  269. padding: 4vw;
  270. background-color: var(--mainColor);
  271. margin: 0 0 0.1vw 0;
  272. border-bottom: 1px solid var(--f1Color);
  273. .title {
  274. font-size: var(--font16Szie);
  275. text:first-child {
  276. margin: 0 1vw 0 0;
  277. }
  278. }
  279. .title:last-child {
  280. color: var(--f85Color);
  281. font-size: var(--font14Size);
  282. }
  283. }
  284. .two_1:nth-last-child(2) {
  285. margin: 0 0 2vw 0;
  286. }
  287. .two_1:nth-last-child(4) {
  288. margin: 0 0 2vw 0;
  289. }
  290. .two_2 {
  291. display: flex;
  292. justify-content: space-between;
  293. padding: 5vw;
  294. background-color: var(--mainColor);
  295. margin: 0 0 2vw 0;
  296. .orderList {
  297. text-align: center;
  298. .icon {
  299. .iconfont {
  300. font-size: 25px;
  301. }
  302. }
  303. .title {
  304. display: inline-block;
  305. margin: 2vw 0 0 0;
  306. font-size: var(--font12Size);
  307. }
  308. }
  309. }
  310. }
  311. }
  312. </style>