mine.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492
  1. <template>
  2. <view class="content">
  3. <view class="top hflex acenter jbetween">
  4. <view class="hflex acenter" @click="toLogin">
  5. <u-avatar :src="user.headimg"></u-avatar>
  6. <view class="user_name">{{user.nickname?user.nickname:'请先登录'}}</view>
  7. </view>
  8. <view class="message hflex acenter jcenter" @click="toMessage">
  9. <image src="/static/images/mine/message.png" style="width: 48rpx;height: 48rpx;"></image>
  10. <u-badge max="99" :absolute="true" :offset="[1,1]" :value="message_num" v-if="message_num>0"></u-badge>
  11. </view>
  12. </view>
  13. <view class="box">
  14. <view class="amount hflex acenter jbetween" @click="toMoney">
  15. <view class="amount_left">我的余额</view>
  16. <view class="amount_right">¥{{user.money}}</view>
  17. </view>
  18. <view class="order">
  19. <view class="order_top hflex acenter jbetween">
  20. <view class="order_title">商城订单</view>
  21. <view class="order_right" @click="toOrder(1)">查看全部</view>
  22. </view>
  23. <view class="order_list hflex acenter jcenter">
  24. <block v-for="(item,index) in orderList" :key="index">
  25. <view class="order_item vflex acenter jcenter" @click="toOrder(item.id)">
  26. <image :src="item.img" style="width: 52rpx;height: 52rpx;"></image>
  27. <u-badge :absolute="true" :offset="[1,20]" max="99" :value="item.number" v-if="item.number>0"></u-badge>
  28. <view class="order_text">{{item.name}}</view>
  29. </view>
  30. </block>
  31. </view>
  32. </view>
  33. <view class="cell">
  34. <view class="cell_item hflex acenter jbetween" @click="toService(1)">
  35. <view class="hflex acenter">
  36. <image src="/static/images/mine/cell1.png" style="width: 40rpx;height: 40rpx;"></image>
  37. <view class="cell_text">采购订单</view>
  38. </view>
  39. <u-icon name="arrow-right" color="#888888" size="12"></u-icon>
  40. </view>
  41. <view class="cell_item hflex acenter jbetween" @click="toService(2)">
  42. <view class="hflex acenter">
  43. <image src="/static/images/mine/cell2.png" style="width: 40rpx;height: 40rpx;"></image>
  44. <view class="cell_text">商家详情</view>
  45. </view>
  46. <u-icon name="arrow-right" color="#888888" size="12"></u-icon>
  47. </view>
  48. <view class="cell_item hflex acenter jbetween" @click="toService(3)">
  49. <view class="hflex acenter">
  50. <image src="/static/images/mine/cell3.png" style="width: 40rpx;height: 40rpx;"></image>
  51. <view class="cell_text">意见反馈</view>
  52. </view>
  53. <u-icon name="arrow-right" color="#888888" size="12"></u-icon>
  54. </view>
  55. <view class="cell_item hflex acenter jbetween" @click="toService(4)">
  56. <view class="hflex acenter">
  57. <image src="/static/images/mine/cell4.png" style="width: 40rpx;height: 40rpx;"></image>
  58. <view class="cell_text">平台规则</view>
  59. </view>
  60. <u-icon name="arrow-right" color="#888888" size="12"></u-icon>
  61. </view>
  62. <view class="cell_item hflex acenter jbetween" @click="toService(5)">
  63. <view class="hflex acenter">
  64. <image src="/static/images/mine/cell5.png" style="width: 40rpx;height: 40rpx;"></image>
  65. <view class="cell_text">设置</view>
  66. </view>
  67. <u-icon name="arrow-right" color="#888888" size="12"></u-icon>
  68. </view>
  69. </view>
  70. </view>
  71. <custom-tab-bar :current="3" />
  72. </view>
  73. </template>
  74. <script>
  75. import $api from '@/static/js/api.js'
  76. let disp = require("@/utils/broadcast");
  77. var WebIM = require("@/utils/WebIM")["default"];
  78. let isfirstTime = true;
  79. var that = ''
  80. export default {
  81. data() {
  82. return {
  83. user: {
  84. },
  85. message_num: 0,
  86. login: false,
  87. orderList: [
  88. {
  89. id: 2,
  90. img: '/static/images/mine/order1.png',
  91. name: '待付款',
  92. number: 0
  93. },
  94. {
  95. id: 3,
  96. img: '/static/images/mine/order2.png',
  97. name: '待发货',
  98. number: 0
  99. },
  100. {
  101. id: 4,
  102. img: '/static/images/mine/order3.png',
  103. name: '待收货',
  104. number: 0
  105. },
  106. {
  107. id: 5,
  108. img: '/static/images/mine/order4.png',
  109. name: '退款/售后',
  110. number: 0
  111. }
  112. ]
  113. }
  114. },
  115. onLoad() {
  116. that = this
  117. },
  118. onShow() {
  119. that.isLogin()
  120. that.getUser()
  121. if(that.login) {
  122. that.getChatList()
  123. }
  124. that.getNum()
  125. },
  126. onPullDownRefresh() {
  127. that.getUser()
  128. },
  129. methods: {
  130. getUser() {
  131. $api.req({
  132. url: '/data/api.business.User/user_info'
  133. }, function(res) {
  134. uni.stopPullDownRefresh()
  135. if(res.code == 1) {
  136. that.user = res.data
  137. uni.setStorageSync('id',res.data.id)
  138. var options = {
  139. user: res.data.huanxinID,
  140. pwd: '12345678',
  141. appKey: uni.WebIM.config.appkey,
  142. success: function (res2) {
  143. wx.setStorageSync("myUsername",res.data.huanxinID)
  144. },
  145. error: function(error){
  146. console.log(error);
  147. }
  148. };
  149. uni.WebIM.conn.open(options);
  150. setTimeout(()=> {
  151. let option = {
  152. nickname: res.data.nickname,
  153. avatarurl: res.data.headimg,
  154. }
  155. uni.WebIM.conn.updateOwnUserInfo(option);
  156. },3000)
  157. } else {
  158. uni.removeStorageSync('token')
  159. that.login = false
  160. that.user = {}
  161. }
  162. })
  163. },
  164. getNum() {
  165. $api.req({
  166. url: '/data/api.business.Order/order_statistics'
  167. }, function(res) {
  168. if(res.code == 1) {
  169. console.log('怎么可能',res);
  170. for(var i=0;i<that.orderList.length;i++) {
  171. that.$set(that.orderList[i],'number',res.data[i])
  172. }
  173. }
  174. })
  175. },
  176. getMessage() {
  177. },
  178. getChatList() {
  179. var myName = uni.getStorageSync("myUsername");
  180. var array = [];
  181. const me = this;
  182. uni.getStorageInfo({
  183. success: function(res) {
  184. let storageKeys = res.keys;
  185. let newChatMsgKeys = [];
  186. let historyChatMsgKeys = [];
  187. let len = myName.length;
  188. storageKeys.forEach((item) => {
  189. if (item.slice(-len) == myName && item.indexOf("rendered_") == -1) {
  190. newChatMsgKeys.push(item);
  191. } else if (
  192. item.slice(-len) == myName &&
  193. item.indexOf("rendered_") > -1
  194. ) {
  195. historyChatMsgKeys.push(item);
  196. } else if (item === "INFORM") {
  197. newChatMsgKeys.push(item);
  198. }
  199. });
  200. cul.call(me, newChatMsgKeys, historyChatMsgKeys);
  201. },
  202. });
  203. function cul(newChatMsgKeys, historyChatMsgKeys) {
  204. let array = [];
  205. let lastChatMsg;
  206. for (let i = historyChatMsgKeys.length; i > 0, i--;) {
  207. let index = newChatMsgKeys.indexOf(historyChatMsgKeys[i].slice(9));
  208. if (index > -1) {
  209. let newChatMsgs = uni.getStorageSync(newChatMsgKeys[index]) || [];
  210. if (newChatMsgKeys.includes()) {}
  211. if (newChatMsgs.length) {
  212. lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
  213. lastChatMsg.unReadCount = newChatMsgs.length;
  214. if (lastChatMsg.unReadCount > 99) {
  215. lastChatMsg.unReadCount = "99+";
  216. }
  217. let dateArr = lastChatMsg.time.split(" ")[0].split("-");
  218. let timeArr = lastChatMsg.time.split(" ")[1].split(":");
  219. let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
  220. lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
  221. lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
  222. newChatMsgKeys.splice(index, 1);
  223. } else {
  224. let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
  225. if (historyChatMsgs.length) {
  226. lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
  227. let dateArr = lastChatMsg.time.split(" ")[0].split("-");
  228. let timeArr = lastChatMsg.time.split(" ")[1].split(":");
  229. let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
  230. lastChatMsg.dateTimeNum =
  231. `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
  232. lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
  233. }
  234. }
  235. } else {
  236. let historyChatMsgs = uni.getStorageSync(historyChatMsgKeys[i]);
  237. if (historyChatMsgs.length) {
  238. lastChatMsg = historyChatMsgs[historyChatMsgs.length - 1];
  239. let dateArr = lastChatMsg.time.split(" ")[0].split("-");
  240. let timeArr = lastChatMsg.time.split(" ")[1].split(":");
  241. let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
  242. lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
  243. lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
  244. }
  245. }
  246. if (
  247. lastChatMsg &&
  248. (lastChatMsg.chatType == "groupchat" ||
  249. lastChatMsg.chatType == "chatRoom")
  250. ) {
  251. lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
  252. }
  253. lastChatMsg && lastChatMsg.username != myName &&
  254. array.push(lastChatMsg);
  255. }
  256. for (let i = newChatMsgKeys.length; i > 0, i--;) {
  257. let newChatMsgs = uni.getStorageSync(newChatMsgKeys[i]) || [];
  258. if (newChatMsgs.length) {
  259. lastChatMsg = newChatMsgs[newChatMsgs.length - 1];
  260. lastChatMsg.unReadCount = newChatMsgs.length;
  261. if (lastChatMsg.unReadCount > 99) {
  262. lastChatMsg.unReadCount = "99+";
  263. }
  264. let dateArr = lastChatMsg.time.split(" ")[0].split("-");
  265. let timeArr = lastChatMsg.time.split(" ")[1].split(":");
  266. let month = dateArr[2] < 10 ? "0" + dateArr[2] : dateArr[2];
  267. lastChatMsg.dateTimeNum = `${dateArr[1]}${month}${timeArr[0]}${timeArr[1]}${timeArr[2]}`;
  268. lastChatMsg.time = `${dateArr[1]}月${dateArr[2]}日 ${timeArr[0]}:${timeArr[1]}`;
  269. if (
  270. lastChatMsg.chatType == "groupchat" ||
  271. lastChatMsg.chatType == "chatRoom"
  272. ) {
  273. lastChatMsg.groupName = me.groupName[lastChatMsg.info.to];
  274. }
  275. lastChatMsg.username != myName && array.push(lastChatMsg);
  276. }
  277. }
  278. array.sort((a, b) => {
  279. return b.dateTimeNum - a.dateTimeNum;
  280. });
  281. that.message_num = 0
  282. for(var i=0;i<array.length;i++) {
  283. that.message_num += array[i].unReadCount
  284. }
  285. $api.req({
  286. url: '/data/api.business.User/messagenoread',
  287. method: 'POST',
  288. }, function(res) {
  289. if(res.code == 1) {
  290. console.log(res)
  291. let message_count = res.data.message_count
  292. let order_count = res.data.order_count
  293. that.message_num += message_count + order_count
  294. }
  295. })
  296. console.log('未读消息数量',that.message_num);
  297. }
  298. },
  299. isLogin() {
  300. var token = uni.getStorageSync('token')
  301. if(token) {
  302. that.login = true
  303. } else {
  304. that.login = false
  305. }
  306. },
  307. toLogin() {
  308. if(!that.login) {
  309. $api.jump('/pages/login/login/login')
  310. }
  311. },
  312. toMessage() {
  313. if(that.login) {
  314. $api.jump('/pages/mine/message/index')
  315. } else {
  316. $api.info('请先登录')
  317. $api.jump('/pages/login/login/login')
  318. }
  319. },
  320. toMoney() {
  321. if(that.login) {
  322. $api.jump('/pages/mine/wallet/wallet')
  323. } else {
  324. $api.info('请先登录')
  325. $api.jump('/pages/login/login/login')
  326. }
  327. },
  328. toOrder(id) {
  329. if(!that.login) {
  330. $api.info('请先登录')
  331. $api.jump('/pages/login/login/login')
  332. return
  333. }
  334. if(id != 5) {
  335. $api.jump('/pages/order/list?status=' + id)
  336. } else {
  337. $api.jump('/pages/order/refund')
  338. }
  339. },
  340. toService(index) {
  341. var url = ''
  342. switch(index) {
  343. case 1 :
  344. url = '/pages/mine/service/purOrder/list';
  345. break;
  346. case 2 :
  347. url = '/pages/mine/service/detail';
  348. break;
  349. case 3 :
  350. url = '/pages/mine/service/feed/feed';
  351. break;
  352. case 4 :
  353. url = '/pages/mine/service/rule';
  354. break;
  355. case 5 :
  356. url = '/pages/mine/service/setting/setting';
  357. break;
  358. }
  359. if(that.login) {
  360. $api.jump(url)
  361. } else {
  362. $api.info('请先登录')
  363. $api.jump('/pages/login/login/login')
  364. }
  365. },
  366. },
  367. }
  368. </script>
  369. <style lang="scss" scoped>
  370. .content {
  371. background: url('/static/images/mine/bg.png') no-repeat;
  372. background-size: 100%;
  373. // padding: 0 30rpx;
  374. .top {
  375. width: 100%;
  376. padding: 188rpx 0 0 30rpx;
  377. .user_name {
  378. font-size: 36rpx;
  379. font-weight: 500;
  380. color: #222222;
  381. line-height: 50rpx;
  382. padding-left: 16rpx;
  383. }
  384. .message {
  385. width: 104rpx;
  386. height: 68rpx;
  387. background: rgba(255,255,255,0.6);
  388. border-radius: 28rpx 0px 0px 28rpx;
  389. position: relative;
  390. }
  391. }
  392. .box {
  393. width: 100%;
  394. box-sizing: border-box;
  395. padding: 0 30rpx;
  396. margin-bottom: 80rpx;
  397. .amount {
  398. width: 100%;
  399. height: 144rpx;
  400. box-sizing: border-box;
  401. padding: 0 24rpx;
  402. margin: 36rpx 0 20rpx;
  403. background: url('/static/images/mine/amount_bg.png') no-repeat;
  404. background-size: 100%;
  405. .amount_left {
  406. font-size: 30rpx;
  407. font-weight: 400;
  408. color: #FFFFFF;
  409. line-height: 42rpx;
  410. }
  411. .amount_right {
  412. font-size: 48rpx;
  413. font-weight: 400;
  414. color: #FFFFFF;
  415. line-height: 58rpx;
  416. }
  417. }
  418. .order {
  419. width: 100%;
  420. height: 240rpx;
  421. background: #FFFFFF;
  422. border-radius: 20rpx;
  423. .order_top {
  424. padding: 24rpx 30rpx 0;
  425. .order_title {
  426. font-size: 28rpx;
  427. font-weight: 500;
  428. color: #0A0A0A;
  429. line-height: 40rpx;
  430. }
  431. .order_right {
  432. font-size: 22rpx;
  433. font-weight: 400;
  434. color: #B4B4B4;
  435. line-height: 32rpx;
  436. }
  437. }
  438. .order_list {
  439. padding: 32rpx 0;
  440. .order_item {
  441. width: 25%;
  442. position: relative;
  443. .order_text {
  444. font-size: 24rpx;
  445. font-weight: 400;
  446. color: #0A0A0A;
  447. line-height: 34rpx;
  448. padding-top: 26rpx;
  449. }
  450. }
  451. }
  452. }
  453. .cell {
  454. margin: 20rpx 0 110rpx;
  455. width: 100%;
  456. height: 588rpx;
  457. background: #FFFFFF;
  458. border-radius: 20px;
  459. box-sizing: border-box;
  460. padding: 0 30rpx;
  461. .cell_item {
  462. height: 116rpx;
  463. padding: 34rpx 0;
  464. border-bottom: 1rpx solid #F4F4F4;
  465. .cell_text {
  466. padding-left: 20rpx;
  467. font-size: 26rpx;
  468. font-weight: 400;
  469. color: #222222;
  470. line-height: 36rpx;
  471. }
  472. }
  473. .cell_item:nth-last-child(1) {
  474. border-bottom: none;
  475. }
  476. }
  477. }
  478. }
  479. </style>