index.vue 22 KB

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