index.vue 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962
  1. <style>
  2. .view-pop {
  3. position: fixed;
  4. width: 100%;
  5. height: 100%;
  6. top: 0;
  7. left: 0;
  8. z-index: 999;
  9. }
  10. .view-pop .bg {
  11. background: rgba(0, 0, 0, 0.5);
  12. width: 100%;
  13. height: 100%;
  14. top: 0;
  15. left: 0;
  16. position: absolute;
  17. }
  18. .view-pop .pop-view {
  19. background: #fff;
  20. padding: 10px;
  21. display: inline-block;
  22. position: absolute;
  23. right: 10px;
  24. top: 40px;
  25. border-radius: 6px;
  26. }
  27. .view-pop .pop-view .item {
  28. padding: 10px;
  29. }
  30. .view-pop .pop-view image {
  31. width: 20px;
  32. height: 20px;
  33. margin-right: 4px;
  34. }
  35. .view-pop .pop-view .pop-lv {
  36. width: 0;
  37. height: 0;
  38. border-left: 10px solid transparent;
  39. border-right: 10px solid transparent;
  40. border-bottom: 10px solid #fff;
  41. position: absolute;
  42. top: -9px;
  43. right: 3px;
  44. }
  45. </style>
  46. <template>
  47. <view class="app">
  48. <view id="app-top">
  49. <uni-nav-bar statusBar backgroundColor="#f8f8f8" title="聊天">
  50. <view slot="right" @tap="isPop = true" v-if="sysData.is_audit == 0">
  51. <image style="width: 20px;" src="/static/chat/chat-add.png" mode="widthFix"></image>
  52. </view>
  53. <view class="fx-r fx-bc fx-ac" style="width: 100%;">
  54. <view class="fx-r fx-bc fx-ac" v-if="isNetwork">
  55. <u-loading-icon size="18"></u-loading-icon>
  56. <text style="font-size: 14px;margin-left: 4px;">链接中..</text>
  57. </view>
  58. <text v-else style="text-overflow: ellipsis;white-space: nowrap;overflow: hidden;font-size: 14px;">
  59. 聊天
  60. </text>
  61. </view>
  62. </uni-nav-bar>
  63. <view class="lists fx-r" v-if="sysData.is_audit == 0">
  64. <view class="item fx-h fx-bc" @tap="tapOpen" data-url="apply/list">
  65. <image src="/static/chat/ic_add_friend.png" mode="widthFix"></image>
  66. <view class="info fx-h fx-ac">
  67. <view class="title">申请列表</view>
  68. </view>
  69. <view class="flg" v-if="txbagenum != null && txbagenum.applyCount > 0">{{txbagenum.applyCount}}
  70. </view>
  71. </view>
  72. <view class="item fx-h fx-bc" @tap="$refs.customer.open()">
  73. <image src="/static/chat/ic_customer_chat.png" mode="widthFix"></image>
  74. <view class="info fx-h fx-ac">
  75. <view class="title">我的客服</view>
  76. </view>
  77. </view>
  78. <view class="item fx-h fx-bc" @tap="tapOpen" data-url="group/list">
  79. <image src="/static/chat/ic_me_group_chat.png" mode="widthFix"></image>
  80. <view class="info fx-h fx-ac">
  81. <view class="title">我的群聊</view>
  82. </view>
  83. </view>
  84. <view class="item fx-h fx-bc" @tap="tapOpen" data-url="friend/index">
  85. <image src="/static/chat/ic_customer_chat.png" mode="widthFix"></image>
  86. <view class="info fx-h fx-ac">
  87. <view class="title">我的好友</view>
  88. </view>
  89. </view>
  90. </view>
  91. <view v-if="data.length > 0" class="tb-search fx-r fx-bc" @tap="tapOpen" data-url="search">
  92. <image src="/static/chat/tb-seach.png"></image>
  93. <view>搜索联系人</view>
  94. </view>
  95. </view>
  96. <view class="view-pop" v-if="isPop">
  97. <view class="bg" @tap="isPop = false"></view>
  98. <view class="pop-view">
  99. <view class="pop-lv"></view>
  100. <view class="item fx-r fx-bc" @tap="tapOpen" data-url="group/add">
  101. <image src="/static/chat/news_icon_initiategroupchat.png"></image>创建群聊
  102. </view>
  103. <view class="item fx-r fx-bc" @tap="tapOpen" data-url="./friend/add">
  104. <image src="/static/chat/news_icon_addfriend.png"></image>
  105. 添加好友
  106. </view>
  107. <view class="item fx-r fx-bc" @tap="tapSan">
  108. <image src="/static/chat/news_icon_saoyisao.png"></image>
  109. 扫一扫
  110. </view>
  111. </view>
  112. </view>
  113. <scroll-view v-if="user != null" scroll-y
  114. :style="'height: calc(100vh - 50px - ' + barheight + 'px - ' + footHeight + 'px);'">
  115. <view v-if="data.length > 0">
  116. <view @tap.stop="tapOpenChat(item)" @longtap="taploogView" :data-id="index"
  117. :class="{topchat : item.is_top == 1}" class="chat-list fx-r fx-bc" v-for="(item,index) in data">
  118. <view class="dot" v-if="item.read_count > 0">{{item.read_count}}</view>
  119. <view class="hot" v-if="item.type == 'group_chat'">群</view>
  120. <view class="avatar">
  121. <image mode="aspectFill" :src="utils.getAvatar(item.img,item.type)"></image>
  122. </view>
  123. <view class="chat-info fx-r">
  124. <view class="info fx-h">
  125. <view class="fx-r">
  126. <text class="nickname">{{item.name}}</text>
  127. <view class="fx-g1"></view>
  128. <view class="time" v-if="item.time != ''">{{utils.timeLastdate(item.msg_time,true)}}
  129. </view>
  130. </view>
  131. <view class="tag_value" v-if="item.type == 'chat'"
  132. style=" white-space: nowrap;overflow:hidden;height: 50rpx;line-height: 50rpx;">
  133. <text class="value" v-if="item.msg_type == 'tip'">
  134. {{item.msg_data}}
  135. </text>
  136. <!-- //消息红包 -->
  137. <text class="value" v-if="item.msg_type == 'red_envelope'">
  138. <rich-text class="title" :nodes="unDataChat(item,'red_envelope')"></rich-text>
  139. </text>
  140. <!-- //红包领取情况 -->
  141. <text class="value" v-if="item.msg_type == 'red_envelope_tip'">
  142. <rich-text class="title" :nodes="unDataChat(item,'red_envelope_tip')"></rich-text>
  143. </text>
  144. <!-- //文字聊天 -->
  145. <text class="value" v-if="item.msg_type == 'voice'">
  146. [语音文件]
  147. </text>
  148. <!-- //红包转账 -->
  149. <text class="value" v-if="item.msg_type == 'red_envelope_transfer'">
  150. <rich-text class="title"
  151. :nodes="unDataChat(item,'red_envelope_transfer')"></rich-text>
  152. </text>
  153. <!-- //文字聊天 -->
  154. <text class="value" v-if="item.msg_type == 'withdraw'">
  155. 撤回消息
  156. </text>
  157. <!-- //红包退回 -->
  158. <text class="value" v-if="item.msg_type == 'red_envelope_transfer_back'">
  159. <rich-text class="title"
  160. :nodes="unDataChat(item,'red_envelope_transfer_back')"></rich-text>
  161. </text>
  162. <!-- //文字聊天 -->
  163. <text class="value" v-if="item.msg_type == 'text'">
  164. {{item.msg_text}}
  165. </text>
  166. <!-- //语音聊天 -->
  167. <text class="value" v-if="item.msg_type == 'voice'">
  168. <rich-text class="title" :nodes="unDataChat(item,'voice')"></rich-text>
  169. </text>
  170. <!-- //图片 -->
  171. <text class="value" v-if="item.msg_type == 'img'">[图片]</text>
  172. </view>
  173. <view class="tag_value" v-if="item.type == 'group_chat'"
  174. style=" white-space: nowrap;overflow:hidden;height: 50rpx;line-height: 50rpx;">
  175. <text class="value" v-if="item.msg_type == 'tip'">
  176. {{item.msg_data}}
  177. </text>
  178. <!-- //消息红包 -->
  179. <text class="value" v-if="item.msg_type == 'red_envelope'">
  180. <rich-text class="title" :nodes="unDataGroupChat(item,'red_envelope')"></rich-text>
  181. </text>
  182. <!-- //红包领取情况 -->
  183. <text class="value" v-if="item.msg_type == 'red_envelope_tip'">
  184. <rich-text class="title"
  185. :nodes="unDataGroupChat(item,'red_envelope_tip')"></rich-text>
  186. </text>
  187. <!-- //红包转账 -->
  188. <text class="value" v-if="item.msg_type == 'red_envelope_transfer'">
  189. <rich-text class="title"
  190. :nodes="unDataGroupChat(item,'red_envelope_transfer')"></rich-text>
  191. </text>
  192. <!-- //红包退回 -->
  193. <text class="value" v-if="item.msg_type == 'red_envelope_transfer_back'">
  194. <rich-text class="title"
  195. :nodes="unDataGroupChat(item,'red_envelope_transfer_back')"></rich-text>
  196. </text>
  197. <!-- //文字聊天 -->
  198. <text class="value" v-if="item.msg_type == 'text'">
  199. {{item.msg_text}}
  200. </text>
  201. <!-- //文字聊天 -->
  202. <text class="value" v-if="item.msg_type == 'withdraw'">
  203. 撤回消息
  204. </text>
  205. <!-- //文字聊天 -->
  206. <text class="value" v-if="item.msg_type == 'group_text'">
  207. [群公告]{{item.msg_data}}
  208. </text>
  209. <!-- //语音聊天 -->
  210. <text class="value" v-if="item.msg_type == 'voice'">
  211. <rich-text class="title" :nodes="unDataGroupChat(item,'voice')"></rich-text>
  212. </text>
  213. <!-- //图片 -->
  214. <text class="value" v-if="item.msg_type == 'img'">[图片]</text>
  215. <view class="tipat" v-if="item.is_remind > 0">[有人@你]</view>
  216. </view>
  217. <view class="item-tip" v-if="item.not_red > 0">未领{{item.not_red}}个</view>
  218. </view>
  219. </view>
  220. </view>
  221. <view style="height: 10px;"></view>
  222. </view>
  223. <view class="user-hg fx-h fx-bc fx-ac" v-else>
  224. <image src="/static/chat/default_img_bud.png" mode="widthFix"></image>
  225. <view class="text">暂无消息内容</view>
  226. </view>
  227. </scroll-view>
  228. <view v-else :style="'height: calc(100vh - 50px - ' + barheight + 'px);'" class="user-bann fx-h fx-bc fx-ac">
  229. <view class="tips">你还未登录,请点击登录查看</view>
  230. <view class="btn" @tap="tapLogin" style="margin-top: 10px;">立即登录</view>
  231. </view>
  232. <view class="mb2-tip" v-if="showIndex >= 0">
  233. <view class="bg" @tap="showIndex = -1"></view>
  234. <view class="pop-view" :style="'left:' + showLeft+ 'px;top:' + showTop + 'px'">
  235. <view class="pop-lv"></view>
  236. <view class="item fx-r fx-bc" @tap="tapZding">{{ data[showIndex].is_top == 1 ? '取消置顶' : '置顶该聊天' }}
  237. </view>
  238. <view class="item fx-r fx-bc" @tap="tapRead">标记已读</view>
  239. <view class="item fx-r fx-bc" @tap="tapDel">删除该聊天</view>
  240. </view>
  241. </view>
  242. <customer-wiget ref="customer"></customer-wiget>
  243. </view>
  244. </template>
  245. <style lang="scss">
  246. .mb2-tip {
  247. position: fixed;
  248. width: 100%;
  249. height: 100%;
  250. top: 0;
  251. left: 0;
  252. z-index: 999;
  253. }
  254. .mb2-tip .bg {
  255. width: 100%;
  256. height: 100%;
  257. top: 0;
  258. left: 0;
  259. position: absolute;
  260. }
  261. .mb2-tip .pop-view {
  262. position: absolute;
  263. background: #fff;
  264. border-radius: 6px;
  265. border: 1px solid #f1f1f1;
  266. padding: 10px 20px;
  267. top: 56px;
  268. z-index: 9;
  269. left: 20px;
  270. }
  271. .mb2-tip .pop-view .item {
  272. padding: 10px 0;
  273. }
  274. .mb2-tip .pop-view .item:active {
  275. background: #f1f1f1;
  276. }
  277. .tb-search {
  278. margin: 10px;
  279. background: #fff;
  280. padding: 5px 10px;
  281. border-radius: 8px;
  282. color: $ic-default-text;
  283. font-size: 14px;
  284. }
  285. .tb-search image {
  286. width: 30px;
  287. height: 30px;
  288. }
  289. .user-hg {
  290. height: 100%;
  291. }
  292. .user-hg image {
  293. width: 200px;
  294. }
  295. .user-hg .text {
  296. font-size: 14px;
  297. margin: 10px;
  298. }
  299. .lists {
  300. margin-top: 10px;
  301. background: #fff;
  302. }
  303. .lists .item {
  304. padding: 10px 0;
  305. position: relative;
  306. width: 25%;
  307. }
  308. .lists .item:active {
  309. background: #f1f1f1;
  310. }
  311. .lists .item image {
  312. width: 50px;
  313. height: 50px;
  314. border-radius: 50%;
  315. }
  316. .lists .item .info {
  317. font-size: 12px;
  318. color: #787878;
  319. margin-top: 5px;
  320. }
  321. .lists .item .flg {
  322. background: #ff5857;
  323. width: 20px;
  324. height: 20px;
  325. border-radius: 50%;
  326. font-size: 10px;
  327. text-align: center;
  328. line-height: 20px;
  329. color: #fff;
  330. right: 14px;
  331. top: 0;
  332. position: absolute;
  333. }
  334. .chat-list {
  335. background: #fff;
  336. padding: 10px 15px;
  337. position: relative;
  338. }
  339. .chat-list .hot {
  340. position: absolute;
  341. border: 1px solid #faac06;
  342. border-radius: 6px;
  343. font-size: 10px;
  344. padding: 0px;
  345. color: #faac06;
  346. background: #fff;
  347. width: 15px;
  348. text-align: center;
  349. z-index: 9;
  350. top: 12px;
  351. }
  352. .chat-list:active {
  353. background: #f1f1f1;
  354. }
  355. .chat-list.topchat {
  356. background: #f1f1f1;
  357. }
  358. .chat-list .avatar {
  359. width: 45px;
  360. height: 45px;
  361. border-radius: 6px;
  362. background: #f1f1f1;
  363. }
  364. .chat-list .avatar image {
  365. width: 100%;
  366. height: 100%;
  367. border-radius: 6px;
  368. }
  369. .chat-list .chat-info {
  370. width: calc(100% - 55px);
  371. margin-left: 10px;
  372. height: 45px;
  373. padding-bottom: 4px;
  374. }
  375. .chat-list:last-child .chat-info {
  376. border-bottom: 0;
  377. }
  378. .chat-list .dot {
  379. overflow: hidden;
  380. text-overflow: ellipsis;
  381. -webkit-line-clamp: 1;
  382. position: absolute;
  383. z-index: 9;
  384. text-align: center;
  385. width: 20px;
  386. height: 20px;
  387. font-size: 10px;
  388. color: #fff;
  389. background: orangered;
  390. border-radius: 20px;
  391. line-height: 20px;
  392. top: 2px;
  393. left: 45px;
  394. }
  395. .chat-list text.nickname {
  396. color: #3b4144;
  397. font-size: 14px;
  398. }
  399. .chat-list .tag_value {
  400. margin-top: 3px;
  401. overflow: hidden;
  402. text-overflow: ellipsis;
  403. display: flex;
  404. -webkit-line-clamp: 1;
  405. -webkit-box-orient: vertical;
  406. }
  407. .chat-list text.value {
  408. color: #999;
  409. font-size: 12px;
  410. font-weight: normal;
  411. }
  412. .chat-list .chat-info .info {
  413. width: 100%;
  414. }
  415. .chat-list .chat-info .time {
  416. font-size: 12px;
  417. color: #999;
  418. }
  419. .tips {
  420. font-size: 14px;
  421. color: #787878;
  422. }
  423. .btn {
  424. background: $ic-appcolor;
  425. font-size: 14px;
  426. color: #fff;
  427. width: 160px;
  428. border-radius: 20px;
  429. height: 40px;
  430. text-align: center;
  431. line-height: 40px;
  432. }
  433. .item-tip {
  434. position: absolute;
  435. font-size: 12px;
  436. bottom: 16px;
  437. right: 10px;
  438. color: orange;
  439. }
  440. .tipat {
  441. font-size: 12px;
  442. color: orange;
  443. }
  444. </style>
  445. <script>
  446. let reqrcode = require("@/components/scancode/reqrcode.js");
  447. import customerWiget from '@/components/ui-public/customer-wiget.vue';
  448. import {
  449. mapState,
  450. mapMutations
  451. } from 'vuex';
  452. export default {
  453. computed: mapState(['user', 'sysData', 'txbagenum']),
  454. components: {
  455. customerWiget
  456. },
  457. data() {
  458. return {
  459. isNetwork: false,
  460. data: [],
  461. barheight: 0,
  462. isPop: false,
  463. showIndex: -1,
  464. showLeft: 0,
  465. showTop: 0,
  466. footHeight: 0,
  467. clickItem: {}, //点击栏目的项目
  468. customer: {},
  469. isLoad: false
  470. }
  471. },
  472. onLoad(option) {
  473. this.$nextTick(() => {
  474. uni.createSelectorQuery().select("#app-top").boundingClientRect(res => {
  475. this.barheight = res.height + 20;
  476. }).exec();
  477. });
  478. // #ifdef H5
  479. this.footHeight = 60;
  480. // #endif
  481. uni.$on('socketMessage', this.socketMessage);
  482. uni.$on('h5San', this.h5San);
  483. uni.$on('chatClear', this.chatClear);
  484. uni.$on('chatRead', this.chatRead);
  485. uni.$on('socketOpen', this.socketOpen);
  486. uni.$on('socketClose', this.socketClose);
  487. },
  488. onShow() {
  489. if (this.user != null) {
  490. this.getData();
  491. }
  492. },
  493. onUnload() {
  494. uni.$off('socketMessage', this.socketMessage);
  495. uni.$off('h5San', this.h5San);
  496. uni.$off('chatClear', this.chatClear);
  497. uni.$off('socketOpen', this.socketOpen);
  498. uni.$off('socketClose', this.socketClose);
  499. },
  500. methods: {
  501. ...mapMutations(['checkUserLogin', 'setSys', 'setTxbagenum']),
  502. getData: function() {
  503. if (this.user == null) {
  504. return;
  505. }
  506. if (this.isLoad) {
  507. return;
  508. }
  509. this.isLoad = true;
  510. this
  511. .request
  512. .get("chatList")
  513. .then(res => {
  514. this.isLoad = false;
  515. if (res.code == 200) {
  516. this.data = res.data;
  517. this.inBagr();
  518. }
  519. });
  520. },
  521. /**
  522. * 扫二维码
  523. */
  524. tapSan: function() {
  525. this.isPop = false;
  526. // #ifdef H5
  527. uni.navigateTo({
  528. url: "../scan/h5scan?type=chat"
  529. });
  530. // #endif
  531. // #ifndef H5
  532. const that = this;
  533. let p = uni.getSystemInfoSync().platform;
  534. if (p === "ios") {
  535. uni.scanCode({
  536. success: (res) => {
  537. that.h5San({
  538. type: 'chat',
  539. text: res.result
  540. });
  541. }
  542. });
  543. } else {
  544. that.$store.dispatch('permission/requestPermissions', 'WRITE_EXTERNAL_STORAGE').then(res => {
  545. uni.scanCode({
  546. success: (res) => {
  547. console.log(res, "res")
  548. that.h5San({
  549. type: 'chat',
  550. text: res.result
  551. });
  552. }
  553. });
  554. });
  555. }
  556. // #endif
  557. },
  558. h5San: function(data) {
  559. if (data.type == 'chat') {
  560. if (data.text.toLowerCase().indexOf("/api/pub/chat_invitation") >= 0) {
  561. var strCode = data.text.substr(data.text.indexOf("/api/pub/chat_invitation"), data.text
  562. .length);
  563. strCode = strCode.replace("/api/pub/chat_invitation?token=", "");
  564. console.log(strCode, 'strCode111A');
  565. uni.navigateTo({
  566. url: "group/groupInvite?code=" + encodeURIComponent(strCode),
  567. fail(res) {
  568. console.log(res, 'ress')
  569. }
  570. })
  571. return;
  572. }
  573. if (data.text.toLowerCase().indexOf("cb:") >= 0) {
  574. var strCode = data.text.substr(3, data.text.length);
  575. console.log(strCode);
  576. uni.showLoading({
  577. title: "加载中.."
  578. });
  579. this
  580. .request
  581. .post("FriendFindCode", {
  582. usercode: strCode
  583. })
  584. .then(res => {
  585. if (res.code == 200) {
  586. uni.navigateTo({
  587. url: "../book/friend/info?usercode=" + res.msg
  588. })
  589. } else {
  590. uni.showModal({
  591. title: '系统提示',
  592. content: res.msg,
  593. showCancel: false
  594. });
  595. }
  596. });
  597. }
  598. }
  599. },
  600. /**
  601. * 处理数据
  602. * @param {Object} item
  603. * @param {Object} type
  604. */
  605. unDataChat: function(item, type) {
  606. let dataAr = JSON.parse(item.msg_data);
  607. //红包转账
  608. if (type == 'red_envelope_transfer') {
  609. return `<font style="color:#ec7259">${dataAr['name']}</font>`;
  610. }
  611. //普通红包
  612. if (type == 'red_envelope') {
  613. return `<font style="color:#ec7259">[红包]${dataAr['name']}</font>`;
  614. }
  615. //普通红包
  616. if (type == 'red_envelope_transfer_back') {
  617. return `来${dataAr['send']['name']}[转账]`;
  618. }
  619. //领取状态
  620. if (type == 'red_envelope_tip') {
  621. if (dataAr.send.uid == this.user.uid) {
  622. return dataAr.lq.name + "领取您的红包";
  623. } else {
  624. return "你领取" + dataAr.send.name + "红包";
  625. }
  626. }
  627. },
  628. /**
  629. * 群聊数据
  630. * @param {Object} item
  631. * @param {Object} type
  632. */
  633. unDataGroupChat: function(item, type) {
  634. //红包转账
  635. if (type == 'red_envelope_transfer') {
  636. let dataAr = JSON.parse(item.msg_data);
  637. return `<font style="color:#ec7259">${dataAr['name']}</font>`;
  638. }
  639. //普通红包
  640. if (type == 'red_envelope') {
  641. let dataAr = JSON.parse(item.msg_data);
  642. return `<font style="color:#ec7259">[红包]${dataAr['name']}</font>`;
  643. }
  644. //普通红包
  645. if (type == 'red_envelope_transfer_back') {
  646. let dataAr = JSON.parse(item.msg_data);
  647. return `来${dataAr['send']['name']}[转账]`;
  648. }
  649. //领取状态
  650. if (type == 'red_envelope_tip') {
  651. let dataAr = JSON.parse(item.msg_data);
  652. if (dataAr.send.uid == this.user.uid) {
  653. return dataAr.lq.name + "领取您的红包";
  654. } else {
  655. return "你领取" + dataAr.send.name + "红包";
  656. }
  657. }
  658. if (type == 'voice') {
  659. return '<font style="color:#ec7259">[语音文件]</font>';
  660. }
  661. },
  662. /**
  663. * 打开
  664. * @param {Object} ev
  665. */
  666. tapOpen: function(ev) {
  667. if (this.user == null) {
  668. this.tapLogin();
  669. return;
  670. }
  671. let url = ev.currentTarget.dataset.url;
  672. console.log(url);
  673. this.isPop = false;
  674. this.utils.navigateTo(url);
  675. },
  676. taploogView: function(ev) {
  677. var index = ev.currentTarget.dataset.id;
  678. var left = ev.touches[0].pageX;
  679. var top = ev.touches[0].clientY;
  680. this.showIndex = index;
  681. var leftW = this.$device.screenWidth - left;
  682. var topW = this.$device.screenHeight - top;
  683. this.showLeft = leftW < 190 ? (left - (190 - leftW)) : left;
  684. this.showTop = topW < 250 ? (top - (250 - topW)) : top;
  685. },
  686. /**
  687. * 置顶设置
  688. */
  689. tapZding: function() {
  690. var item = this.data[this.showIndex];
  691. this
  692. .request
  693. .post("chatUpdateChat", {
  694. groupId: item.group_id,
  695. code: "is_top",
  696. val: item.is_top == 1 ? 0 : 1
  697. })
  698. .then(res => {
  699. if (res.code == 200) {
  700. this.getData();
  701. this.utils.Tip("操作成功");
  702. } else {
  703. uni.showModal({
  704. title: '系统提示',
  705. content: res.msg,
  706. showCancel: false
  707. });
  708. }
  709. });
  710. this.showIndex = -1;
  711. },
  712. /**
  713. * 数据阅读
  714. */
  715. tapRead: function() {
  716. var item = this.data[this.showIndex];
  717. this
  718. .request
  719. .post("chatRead", {
  720. groupId: item.group_id
  721. })
  722. .then(res => {
  723. if (res.code == 200) {
  724. this.getData();
  725. this.utils.Tip("操作成功");
  726. } else {
  727. uni.showModal({
  728. title: '系统提示',
  729. content: res.msg,
  730. showCancel: false
  731. });
  732. }
  733. });
  734. this.showIndex = -1;
  735. },
  736. //删除
  737. tapDel: function() {
  738. var item = this.data[this.showIndex];
  739. this
  740. .request
  741. .post("chatDel", {
  742. groupId: item.group_id
  743. })
  744. .then(res => {
  745. if (res.code == 200) {
  746. this.getData();
  747. this.utils.Tip("操作成功");
  748. } else {
  749. uni.showModal({
  750. title: '系统提示',
  751. content: res.msg,
  752. showCancel: false
  753. });
  754. }
  755. });
  756. this.showIndex = -1;
  757. },
  758. /**
  759. * 打开chat
  760. * @param {Object} ev
  761. */
  762. tapOpenChat: function(item) {
  763. this.clickItem = item;
  764. if (item.type == 'chat') {
  765. uni.navigateTo({
  766. url: 'chat?groupId=' + item.group_id + '&usercode=' + item.f_uid
  767. })
  768. }
  769. if (item.type == 'group_chat') {
  770. uni.navigateTo({
  771. url: 'chatGroup?groupId=' + item.group_id + '&usercode=' + item.f_uid
  772. })
  773. }
  774. },
  775. /**
  776. * 通讯数据
  777. * @param {Object} res
  778. */
  779. socketMessage: function(res) {
  780. if (res.code == null) return;
  781. var uData = JSON.parse(res.data);
  782. var bool = false;
  783. for (var i in this.data) {
  784. var data = this.data[i];
  785. if (data.group_id == uData.group_id) {
  786. bool = true;
  787. data.msg_data = uData['data'];
  788. data.msg_type = uData['type'];
  789. data.msg_time = uData['time'];
  790. data.read_count += 1;
  791. this.$set(this.data, i, data);
  792. }
  793. }
  794. this.getData();
  795. },
  796. socketOpen: function() {
  797. this.isNetwork = false;
  798. this.getData();
  799. },
  800. /**
  801. * 网络关闭 | 需重新链接
  802. */
  803. socketClose: function() {
  804. this.isNetwork = true;
  805. },
  806. /**
  807. * 【清理】预读消息
  808. */
  809. chatRead: function(data) {
  810. let txbagenum = this.txbagenum;
  811. var read_count = 0;
  812. for (var i in this.data) {
  813. var inAr = this.data[i];
  814. if (inAr.group_id == data.groupId) {
  815. read_count = inAr.read_count;
  816. inAr.read_count = 0;
  817. this.$set(this.data, i, inAr);
  818. break;
  819. }
  820. }
  821. txbagenum.chatCount -= read_count;
  822. if (txbagenum.chatCount <= 0) txbagenum.chatCount = 0;
  823. console.log(txbagenum);
  824. this.setTxbagenum(txbagenum);
  825. },
  826. chatClear: function(group_id) {
  827. for (var i in this.data) {
  828. var data = this.data[i];
  829. if (data.group_id == group_id) {
  830. data.data = "";
  831. this.$set(this.data, i, data);
  832. }
  833. }
  834. },
  835. tapLogin: function() {
  836. uni.navigateTo({
  837. url: "../login/index"
  838. });
  839. },
  840. inBagr: function() {
  841. //消息提示值
  842. this.request.get("chatBagenum").then(res => {
  843. if (res.code == 200) {
  844. this.setTxbagenum(res.data);
  845. }
  846. }).catch(err => {});
  847. },
  848. tapKf: function() {
  849. if (this.user == null) {
  850. this.tapLogin();
  851. return;
  852. }
  853. if (this.customer != null) {
  854. if (this.customer.group_id > 0) {
  855. uni.navigateTo({
  856. url: 'chat?groupId=' + this.customer.group_id + '&usercode=' + this.customer.uid
  857. })
  858. } else {
  859. uni.navigateTo({
  860. url: "friend/info?usercode=" + this.customer.uid
  861. });
  862. }
  863. }
  864. }
  865. }
  866. }
  867. </script>