index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. <template>
  2. <view class="">
  3. <view v-if="msgList.length" class="margin-topW">
  4. <view class="flex padding-tb radius padding-lr-sm bg" @click="goMsg" v-for="(item,index) in msgList"
  5. :key='index'>
  6. <view>
  7. <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
  8. src="../../static/images/msg/msg.png"></image>
  9. </view>
  10. <view class="flex-sub margin-left-sm">
  11. <view class="flex justify-between">
  12. <view class="text-white">{{item.title?item.title: '系统消息'}}</view>
  13. <view v-if="messageCount>0"
  14. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  15. {{messageCount}}
  16. </view>
  17. </view>
  18. <view>
  19. <view class="text-grey">{{item.content}}</view>
  20. </view>
  21. </view>
  22. </view>
  23. </view>
  24. <view class="margin-topW">
  25. <view class="flex padding-tb radius padding-lr-sm bg" @click="goChat">
  26. <view>
  27. <image style="width: 80rpx;height: 80rpx;border-radius: 80rpx;"
  28. src="../../static/images/msg/msgs.png"></image>
  29. </view>
  30. <view class="flex-sub margin-left-sm">
  31. <view class="flex justify-between">
  32. <view class="text-white">在线客服</view>
  33. <view v-if="userCount>0"
  34. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  35. {{userCount}}
  36. </view>
  37. </view>
  38. <view>
  39. <view class="text-grey">联系在线客服</view>
  40. </view>
  41. </view>
  42. </view>
  43. </view>
  44. <view v-if="chatList.length" class="margin-top-sm content ">
  45. <view class="radius padding-lr-sm bg" style="margin-top: 4rpx;" @click="goIM(item)"
  46. v-for="(item,index) in chatList" :key='index'>
  47. <view class="flex padding-tb ">
  48. <view>
  49. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
  50. </view>
  51. <view class="flex-sub margin-left-sm">
  52. <view class="flex justify-between align-center">
  53. <view class="text-white flex align-center userNameleng">
  54. <view class="">
  55. {{item.userName}}
  56. </view>
  57. <text class="text-grey"
  58. style="font-size: 26rpx;margin-left: 20rpx;">{{item.stationName}}</text>
  59. </view>
  60. <view class="text-grey">{{item.messageTime?getMonthOrDay(item.messageTime):''}}</view>
  61. </view>
  62. <view class="flex justify-between" style="margin-top: 10rpx;">
  63. <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
  64. <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
  65. <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
  66. <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
  67. <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
  68. <view class="text-grey" v-else-if="item.messageType == 2">[图片]</view>
  69. <view class="text-grey" v-else-if="item.messageType == 4">[表情]</view>
  70. <view class="text-grey" v-else-if="item.messageType == 20">[视频通话]</view>
  71. <view class="text-grey" v-else-if="item.messageType == 21">[语音通话]</view>
  72. <view v-if="item.contentCount"
  73. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  74. {{item.contentCount}}
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. <!-- <view class="flex padding-tb" v-else>
  80. <view>
  81. <u-image shape="circle" width='80rpx' height="80rpx" :src="item.avatar"></u-image>
  82. </view>
  83. <view class="flex-sub margin-left-sm">
  84. <view class="flex justify-between">
  85. <view class="text-white">{{item.userName}}</view>
  86. <view class="text-grey">{{item.messageTime?item.messageTime:''}}</view>
  87. </view>
  88. <view class="flex justify-between">
  89. <view class="text-grey" v-if="item.messageType == 1">{{item.content}}</view>
  90. <view class="text-grey" v-else-if="item.messageType == 18">位置</view>
  91. <view class="text-grey" v-else-if="item.messageType == 9">简历请求</view>
  92. <view class="text-grey" v-else-if="item.messageType == 6">微信请求</view>
  93. <view class="text-grey" v-else-if="item.messageType == 5">手机号请求</view>
  94. <view class="text-grey" v-else>[图片]</view>
  95. <view v-if="item.contentCount"
  96. style="height: 32rpx;width: 32rpx;border-radius: 100rpx;background-color: red;color: #FFF;text-align: center;">
  97. {{item.contentCount}}
  98. </view>
  99. </view>
  100. </view>
  101. </view> -->
  102. </view>
  103. </view>
  104. <empty v-if="!chatList.length" content='暂无消息'></empty>
  105. </view>
  106. </template>
  107. <script>
  108. import empty from '../../components/empty.vue'
  109. export default {
  110. components: {
  111. empty
  112. },
  113. data() {
  114. return {
  115. page: 1,
  116. limit: 100,
  117. chatList: [],
  118. userId: '',
  119. msgList: [],
  120. time: '',
  121. messageCount: 0,
  122. userCount: 0,
  123. arr: [],
  124. showModal: true,
  125. }
  126. },
  127. onLoad() {
  128. if (uni.getStorageSync('userId')) {
  129. this.getChatList()
  130. }
  131. },
  132. //下拉刷新
  133. onPullDownRefresh() {
  134. let that = this
  135. if (uni.getStorageSync('token')) {
  136. that.getweiduMsg();
  137. that.getChatList()
  138. that.getMsgList()
  139. that.$nextTick(function() {
  140. that.messageCount = uni.getStorageSync('messageCount')
  141. })
  142. }
  143. },
  144. onShow() {
  145. let that = this
  146. that.userId = uni.getStorageSync('userId')
  147. if (that.userId) {
  148. that.time = setInterval(function() {
  149. that.getweiduMsg();
  150. that.getChatList()
  151. that.getMsgList()
  152. that.$nextTick(function() {
  153. that.messageCount = uni.getStorageSync('messageCount')
  154. })
  155. }, 3000)
  156. this.$Request.getT('/app/common/type/310').then(res => { //消息未读提醒
  157. if (res.code == 0) {
  158. if (res.data && res.data.value) {
  159. this.arr.push(res.data.value)
  160. }
  161. }
  162. })
  163. this.$Request.getT('/app/common/type/337').then(res => { //预约成功通知(通用)
  164. if (res.code == 0) {
  165. if (res.data && res.data.value) {
  166. this.arr.push(res.data.value)
  167. }
  168. }
  169. })
  170. this.$Request.getT('/app/common/type/338').then(res => { //订单状态通知
  171. if (res.code == 0) {
  172. if (res.data && res.data.value) {
  173. this.arr.push(res.data.value)
  174. }
  175. }
  176. })
  177. // #ifdef MP-WEIXIN
  178. if (this.showModal) {
  179. this.openMsg()
  180. }
  181. // #endif
  182. } else {
  183. that.chatList = []
  184. that.msgList = []
  185. }
  186. },
  187. onHide() {
  188. clearInterval(this.time)
  189. },
  190. methods: {
  191. //把时间转换为月日
  192. getMonthOrDay(time) {
  193. let date = new Date(time) // 获取时间
  194. // var year = date.getFullYear() // 获取年
  195. let month = date.getMonth() + 1 // 获取月
  196. let strDate = date.getDate() // 获取日
  197. return month + '月' + strDate + '日'
  198. },
  199. // 开启订阅消息
  200. openMsg() {
  201. console.log('订阅消息')
  202. var that = this
  203. uni.getSetting({
  204. withSubscriptions: true, //是否获取用户订阅消息的订阅状态,默认false不返回
  205. success(ret) {
  206. console.log(ret.subscriptionsSetting.itemSettings, '*************************************')
  207. // if (ret.subscriptionsSetting.itemSettings && Object.keys(ret.subscriptionsSetting.itemSettings).length == 2) {
  208. if (ret.subscriptionsSetting.itemSettings) {
  209. uni.setStorageSync('sendMsg', true)
  210. uni.openSetting({ // 打开设置页
  211. success(rea) {
  212. console.log(rea.authSetting)
  213. }
  214. });
  215. } else { // 用户没有点击“总是保持以上,不再询问”则每次都会调起订阅消息
  216. uni.setStorageSync('sendMsg', false)
  217. uni.showModal({
  218. title: '提示',
  219. content: '为了更好的体验,请绑定消息推送',
  220. confirmText: '确定',
  221. cancelText: '取消',
  222. confirmColor: '#00B88F',
  223. success: function(res) {
  224. if (res.confirm) {
  225. wx.requestSubscribeMessage({
  226. tmplIds: that.arr,
  227. success(re) {
  228. console.log(JSON.stringify(re),
  229. '++++++++++++++')
  230. var datas = JSON.stringify(re);
  231. if (datas.indexOf("accept") != -1) {
  232. console.log(re)
  233. // uni.setStorageSync('sendMsg', true)
  234. }
  235. },
  236. fail: (res) => {
  237. console.log(res)
  238. }
  239. })
  240. // uni.setStorageSync('sendMsg', true)
  241. console.log('确认')
  242. that.showModal = false
  243. } else if (res.cancel) {
  244. console.log('取消')
  245. // uni.setStorageSync('sendMsg', false)
  246. that.showModal = true
  247. }
  248. }
  249. })
  250. }
  251. }
  252. })
  253. },
  254. getweiduMsg() {
  255. this.$Request.get("/app/chats/userCount").then(res => {
  256. uni.stopPullDownRefresh()
  257. if (res.code == 0) {
  258. this.userCount = res.data
  259. }
  260. });
  261. },
  262. //在线客服
  263. goChat() {
  264. // uni.navigateTo({
  265. // url:'/my/setting/chat'
  266. // })
  267. // #ifdef MP-WEIXIN
  268. if (uni.getStorageSync('sendMsg')) {
  269. // console.log('授权+1')
  270. wx.requestSubscribeMessage({
  271. tmplIds: this.arr,
  272. success(re) {
  273. // console.log(JSON.stringify(re), 111111111111)
  274. var datas = JSON.stringify(re);
  275. if (datas.indexOf("accept") != -1) {
  276. // console.log(re)
  277. }
  278. },
  279. fail: (res) => {
  280. // console.log(res)
  281. }
  282. })
  283. }
  284. // #endif
  285. let that = this
  286. if (uni.getStorageSync('userType') == 1) { //用户端
  287. // #ifdef MP-WEIXIN
  288. wx.openCustomerServiceChat({
  289. extInfo: {
  290. url: that.$queue.getData('kefu')
  291. },
  292. corpId: that.$queue.getData('kefuAppid'),
  293. success(res) {
  294. console.log(res)
  295. },
  296. })
  297. // #endif
  298. // #ifdef H5
  299. window.location.href = that.$queue.getData('kefu');
  300. // #endif
  301. // #ifdef APP
  302. let kefu = that.$queue.getData('kefu')
  303. console.log(kefu)
  304. plus.runtime.openURL(kefu, function(res) {});
  305. // #endif
  306. } else { //企业端
  307. // #ifdef MP-WEIXIN
  308. wx.openCustomerServiceChat({
  309. extInfo: {
  310. url: that.$queue.getData('kefuq')
  311. },
  312. corpId: that.$queue.getData('kefuAppidq'),
  313. success(res) {
  314. console.log(res)
  315. },
  316. })
  317. // #endif
  318. // #ifdef H5
  319. window.location.href = that.$queue.getData('kefuq');
  320. // #endif
  321. // #ifdef APP
  322. let kefu = that.$queue.getData('kefuq')
  323. console.log(kefu)
  324. plus.runtime.openURL(kefu, function(res) {});
  325. // #endif
  326. }
  327. },
  328. getChatList() {
  329. this.$Request.get("/app/chat/selectChatConversationPage", {
  330. page: this.page,
  331. limit: this.limit
  332. }).then(res => {
  333. uni.stopPullDownRefresh()
  334. if (res.code == 0) {
  335. this.chatList = res.data.list
  336. }
  337. });
  338. },
  339. getMsgList() {
  340. this.$Request.get("/app/message/selectMessageByUserIdLimit1").then(res => {
  341. uni.stopPullDownRefresh()
  342. if (res.code == 0) {
  343. this.msgList = res.data.list
  344. }
  345. });
  346. },
  347. goIM(e) {
  348. // #ifdef MP-WEIXIN
  349. if (uni.getStorageSync('sendMsg')) {
  350. // console.log('授权+1')
  351. wx.requestSubscribeMessage({
  352. tmplIds: this.arr,
  353. success(re) {
  354. // console.log(JSON.stringify(re), 111111111111)
  355. var datas = JSON.stringify(re);
  356. if (datas.indexOf("accept") != -1) {
  357. // console.log(re)
  358. }
  359. },
  360. fail: (res) => {
  361. // console.log(res)
  362. }
  363. })
  364. }
  365. // #endif
  366. let userId = '';
  367. let userType = uni.getStorageSync('userType')
  368. console.log(e, 'aaaaaaaaa')
  369. if (userType == 2) { //当前登录用户为企业
  370. userId = e.userId
  371. } else { //当前登录用户为用户
  372. userId = e.focusedUserId
  373. }
  374. if (uni.getStorageSync('userType') == 1) {
  375. uni.navigateTo({
  376. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
  377. '&postPushId=' + e.postPushId + '&resumesId=' + e.resumesId
  378. })
  379. } else {
  380. uni.navigateTo({
  381. url: '/pages/msg/im?chatConversationId=' + e.chatConversationId + '&byUserId=' + userId +
  382. '&resumesId=' + e.resumesId + '&postPushId=' + e.postPushId
  383. })
  384. }
  385. },
  386. goMsg() {
  387. // #ifdef MP-WEIXIN
  388. if (uni.getStorageSync('sendMsg')) {
  389. // console.log('授权+1')
  390. wx.requestSubscribeMessage({
  391. tmplIds: this.arr,
  392. success(re) {
  393. // console.log(JSON.stringify(re), 111111111111)
  394. var datas = JSON.stringify(re);
  395. if (datas.indexOf("accept") != -1) {
  396. // console.log(re)
  397. }
  398. },
  399. fail: (res) => {
  400. // console.log(res)
  401. }
  402. })
  403. }
  404. // #endif
  405. uni.navigateTo({
  406. url: '/pages/msg/message'
  407. })
  408. }
  409. }
  410. }
  411. </script>
  412. <style>
  413. page {
  414. background-color: #F7F7F7;
  415. }
  416. .bg {
  417. background: #FFFFFF;
  418. }
  419. .userNameleng {
  420. width: 80%;
  421. overflow: hidden;
  422. white-space: nowrap;
  423. text-overflow: ellipsis;
  424. -o-text-overflow: ellipsis;
  425. }
  426. </style>