trans_index.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. <template>
  2. <view class="page">
  3. <uni-search-bar ref="searchBar"
  4. placeholder="搜索聊天记录"
  5. :show="false"
  6. @confirm="search"
  7. @search="search"></uni-search-bar>
  8. <view class="uni-list"
  9. v-if="list.length">
  10. <uni-swipe-action >
  11. <uni-swipe-action-item class="uni-list-cell"
  12. v-for="(value,key) of list"
  13. :key="key" :right-options="swipeData(value,key)"
  14. :auto-close="false" @click="swipeAction">
  15. <view class="uni-media-list"
  16. @tap="goMessage(value.list_id,key,value.no_reader_num,value.chat_id,value.show_name)">
  17. <view class="uni-media-list-logo">
  18. <image :src="staticPhoto + value.photo_path + '?_=' + imgRan"
  19. :lazy-load="true"
  20. style="border-radius: 10px;"
  21. :data-index="key"
  22. @error="imageError" />
  23. </view>
  24. <view class="red_num">
  25. <uni-badge :text="value.no_reader_num"
  26. type="error" />
  27. </view>
  28. <view class="uni-media-list-body">
  29. <view class="uni-media-list-text-top">
  30. <text>{{msgHandle(value.show_name+'',12)}}</text>
  31. <view style="float: right;color: #8f8f94;font-size: 23upx;">
  32. {{timestampFormat(value.time)}}
  33. </view>
  34. </view>
  35. <view class="uni-media-list-text-bottom uni-ellipsis">{{value.last_msg}}</view>
  36. </view>
  37. </view>
  38. </uni-swipe-action-item>
  39. </uni-swipe-action>
  40. <!-- <view class="uni-list-cell"
  41. v-for="(value,key) of list"
  42. :key="key">
  43. <uni-swipe-action :options="swipeData(value.no_reader_num)"
  44. @click="swipeAction"
  45. @opened="openedAction(key)">
  46. <uni-swipe-action>
  47. <view class="uni-media-list"
  48. @tap="goMessage(value.list_id,key,value.no_reader_num,value.chat_id)">
  49. <view class="uni-media-list-logo">
  50. <image :src="staticPhoto + value.photo_path + '?_=' + imgRan"
  51. :lazy-load="true"
  52. style="border-radius: 10px;"
  53. :data-index="key"
  54. @error="imageError" />
  55. </view>
  56. <view class="red_num">
  57. <uni-badge :text="value.no_reader_num"
  58. type="error" />
  59. </view>
  60. <view class="uni-media-list-body">
  61. <view class="uni-media-list-text-top">
  62. <text>{{msgHandle(value.show_name+'',12)}}</text>
  63. <view style="float: right;color: #8f8f94;font-size: 23upx;">
  64. {{timestampFormat(value.time)}}
  65. </view>
  66. </view>
  67. <view class="uni-media-list-text-bottom uni-ellipsis">{{value.last_msg}}</view>
  68. </view>
  69. </view>
  70. </uni-swipe-action>
  71. </uni-swipe-action>
  72. </view> -->
  73. </view>
  74. <view :class="['action_main animated faster',(action_menu ? 'bounceInDown' : 'bounceOutUp')]"
  75. v-show="showActionMenu"
  76. @tap="actionMain">
  77. <view class="action_base">
  78. <view class="sj"></view>
  79. <view class="action_item"
  80. @tap="goAction(0)">
  81. <view class="uni-media-list-logo action_icon">
  82. <image :src="'../../static/theme/default/chat/chat.png'"
  83. :lazy-load="true" />
  84. </view>
  85. <text class="action_item_text">发起群聊</text>
  86. </view>
  87. <view class="action_item"
  88. @tap="goAction(1)">
  89. <view class="uni-media-list-logo action_icon">
  90. <image :src="'../../static/theme/default/chat/add_friend.png'"
  91. :lazy-load="true" />
  92. </view>
  93. <text class="action_item_text">添加好友</text>
  94. </view>
  95. <!-- #ifdef APP-PLUS -->
  96. <view class="action_item"
  97. @tap="goScanCode">
  98. <view class="uni-media-list-logo action_icon">
  99. <image :src="'../../static/theme/default/chat/scan_code.png'"
  100. :lazy-load="true" />
  101. </view>
  102. <text class="action_item_text">扫一扫</text>
  103. </view>
  104. <!-- #endif -->
  105. <view class="action_item"
  106. @tap="goPath('../my/pay/pay')">
  107. <view class="uni-media-list-logo action_icon">
  108. <image :src="'../../static/theme/default/chat/in_out.png'"
  109. :lazy-load="true" />
  110. </view>
  111. <text class="action_item_text">收付款</text>
  112. </view>
  113. </view>
  114. </view>
  115. <uni-popup ref="popup" type="confirm">
  116. <uni-popup-confirm title="转发消息" :content="popuMsg" @confirm = "confirm"> </uni-popup-confirm>
  117. </uni-popup>
  118. </view>
  119. </template>
  120. <script>
  121. import uniIcon from '../../components/uni-icons/uni-icons.vue';
  122. import uniBadge from '../../components/uni-badge/uni-badge.vue';
  123. import uniSwipeAction from '../../components/uni-swipe-action/uni-swipe-action.vue'
  124. import uniSwipeActionItem from '../../components/uni-swipe-action-item/uni-swipe-action-item.vue'
  125. import _get from '../../common/_get';
  126. import _hook from '../../common/_hook';
  127. import _action from '../../common/_action';
  128. import _data from '../../common/_data';
  129. import _page from '../../common/common';
  130. import uniSearchBar from '@/components/mehaotian-search/mehaotian-search.vue';
  131. import uniPopup from '../../components/uni-popup/uni-popup.vue';
  132. import uniPopupConfirm from '../../components/uni-popup/uni-popup-confirm.vue';
  133. export default {
  134. components: {
  135. uniIcon,
  136. uniBadge,
  137. uniSwipeAction,
  138. uniSwipeActionItem,
  139. uniSearchBar,
  140. uniPopup,
  141. uniPopupConfirm
  142. },
  143. data () {
  144. return {
  145. trans_id:'',
  146. popuMsg:'',
  147. list: [],
  148. search_list: [],
  149. list_index: '',
  150. action_menu: false,
  151. action_menu_num: 0,
  152. options: [
  153. {
  154. text: '取消',
  155. style: {
  156. backgroundColor: '#007aff'
  157. }
  158. }, {
  159. text: '删除',
  160. style: {
  161. backgroundColor: '#dd524d'
  162. }
  163. }
  164. ]
  165. }
  166. },
  167. onShow () {
  168. _hook.routeTabBarHook();
  169. uni.$off('data_chat_list');
  170. let _this = this,
  171. chat_list = _data.localData('chat_list');
  172. console.log(chat_list)
  173. /** 监听最新数据 */
  174. uni.$on('data_chat_list', function (data) {
  175. console.log("success");
  176. console.log(data);
  177. _this.list = data;
  178. _this.search_list = _this.list;
  179. console.log("接收到新数据....");
  180. });
  181. //有缓存则监听是否有数据更新,有则重新获取
  182. // uni.$once('update_chat_list', function () {
  183. // _get.getChatList();
  184. // })
  185. /** 加载本地缓存数据,让页面秒速渲染出来 */
  186. if (chat_list) {
  187. _this.list = chat_list;
  188. } else {
  189. _get.getChatList();
  190. }
  191. _this.action_menu = false;
  192. },
  193. onLoad (options) {
  194. if('id' in options){
  195. this.trans_id = options.id
  196. }
  197. },
  198. onUnload () {
  199. uni.$off('data_chat_list');
  200. },
  201. onPullDownRefresh () {
  202. _get.getChatList();
  203. setTimeout(function () {
  204. uni.stopPullDownRefresh();
  205. }, 300);
  206. },
  207. onHide () {
  208. //清空search框
  209. if (this.keyword) {
  210. this.$refs.searchBar.clear();
  211. this.list = this.search_list;
  212. }
  213. },
  214. computed: {
  215. showActionMenu () {
  216. return this.action_menu;
  217. },
  218. staticPhoto () {
  219. return _data.staticPhoto();
  220. },
  221. imgRan () {
  222. return Math.random();
  223. },
  224. },
  225. methods: {
  226. search (chat_msg) {
  227. chat_msg = chat_msg.trim();
  228. let _this = this;
  229. _this.keyword = chat_msg;
  230. console.log(!chat_msg)
  231. if (!chat_msg) {
  232. _this.list = _this.search_list;
  233. return true;
  234. }
  235. _get.serchChatMsg({ 'chat_msg': chat_msg,'list_id': '' }, function (data) {
  236. _this.list = data;
  237. })
  238. },
  239. goPath (path) {
  240. if (path) {
  241. uni.navigateTo({
  242. url: path
  243. })
  244. }
  245. },
  246. imageError (e) {
  247. let index = e.currentTarget.dataset.index
  248. //替换index对应的图片
  249. this.list[index].photo_path = '/default_photo_path.png';
  250. },
  251. msgHandle (msg, num) {
  252. if (num == undefined) num = 16;
  253. if (!msg) return '';
  254. msg = msg.replace(/&lt;/g, '<');
  255. return msg.length > num ? msg.substr(0, num) + '...' : msg;
  256. },
  257. timestampFormat (time) {
  258. return _action.timestampFormat(time);
  259. },
  260. goAction (type) {
  261. let path = '';
  262. switch (type) {
  263. case 0:
  264. path = '../friend/index_list?list_id=0';
  265. break;
  266. case 1:
  267. path = '../friend/add';
  268. break;
  269. default:
  270. return;
  271. break;
  272. }
  273. uni.navigateTo({
  274. url: path,
  275. animationType: 'slide-in-bottom',
  276. });
  277. },
  278. actionMain () {
  279. this.action_menu = !this.action_menu;
  280. this.action_menu_num++;
  281. },
  282. openedAction (key) {
  283. this.list_index = key;
  284. },
  285. swipeAction (e) {
  286. let list_index = e.content.number
  287. let _this = this,
  288. list_id = _this.list[list_index].list_id;
  289. if (!list_id) {
  290. return;
  291. }
  292. let top = _this.list[list_index].top;
  293. console.log("top",top)
  294. let value = top == 1 ? 0 : 1;
  295. console.log("value",value)
  296. switch (e.index) {
  297. case 0:
  298. //置顶 /取消置顶
  299. _this.$httpSend({
  300. path: '/im/message/chatTop ',
  301. data: { list_id:list_id, value: value},
  302. success: () => {
  303. _get.getChatList();
  304. }
  305. });
  306. break;
  307. case 1:
  308. /** 删除这条对话 */
  309. _this.$httpSend({
  310. path: '/im/chat/deleteChat',
  311. data: { list_id, },
  312. success: (data) => {
  313. _get.getChatList();
  314. }
  315. });
  316. break;
  317. default:
  318. break;
  319. }
  320. },
  321. swipeData (value,index) {
  322. console.log(value)
  323. return [
  324. {
  325. text: value.top == 1 ? '取消置顶':'置顶',
  326. number:index,
  327. style: {
  328. },
  329. },
  330. {
  331. text: '删除',
  332. number:index,
  333. style: {
  334. backgroundColor: 'rgb(255,58,49)',
  335. }
  336. }
  337. ];
  338. },
  339. goMessage (list_id, key, no_reader_num, chat_id,show_name) {
  340. if (no_reader_num > 0) {
  341. _get.getChatData({
  342. send_data: {
  343. list_id: list_id,
  344. time: 0,
  345. is_up: 1,
  346. },
  347. is_action_data: 1,
  348. });
  349. this.list[key].no_reader_num = 0;
  350. _data.localData('chat_list', this.list);
  351. _action.updataNoReader(list_id);
  352. _action.setStatusTips();
  353. }
  354. console.log("chat_id", chat_id);
  355. _data.localData('message_list_id', list_id);
  356. // './message?list_id=' + list_id + "&chat_id="+chat_id,
  357. //TODO 弹窗发送消息
  358. this.popuMsg = "确认转发给:"+show_name
  359. this.$refs.popup.open()
  360. },
  361. goScanCode () {
  362. let _this = this;
  363. _this.action_menu = false;
  364. _page.scanCode();
  365. },
  366. confirm(callback){
  367. if(typeof callback === "function"){
  368. let list_id = _data.localData('message_list_id');
  369. _get.transMsg({list_id:list_id,trans_id:this.trans_id},function (ret) {
  370. uni.redirectTo({
  371. url:'/pages/chat/message?trans=1&list_id='+list_id,
  372. success:function (res) {
  373. }
  374. })
  375. });
  376. }
  377. }
  378. },
  379. watch: {
  380. },
  381. onNavigationBarButtonTap (e) {
  382. this.action_menu = !this.action_menu;
  383. },
  384. }
  385. </script>
  386. <style>
  387. @import '../../static/css/chat/animate.css';
  388. .uni-list-cell{
  389. overflow: hidden;
  390. }
  391. .uni-media-list-logo {
  392. height: 100upx;
  393. width: 100upx;
  394. }
  395. .search .content {
  396. padding-left: 20upx;
  397. height: 60upx;
  398. }
  399. .header {
  400. display: flex;
  401. flex-direction: row;
  402. padding: 10px 15px;
  403. align-items: center;
  404. }
  405. .input-view {
  406. display: flex;
  407. align-items: center;
  408. flex-direction: row;
  409. background-color: #e7e7e7;
  410. height: 30px;
  411. border-radius: 5px;
  412. padding: 0 10px;
  413. flex: 1;
  414. }
  415. .input {
  416. flex: 1;
  417. padding: 0 5px;
  418. height: 24px;
  419. line-height: 24px;
  420. font-size: 16px;
  421. }
  422. .red_num {
  423. position: absolute;
  424. height: 34upx;
  425. top: 7upx;
  426. left: 120upx;
  427. font-size: 23upx !important;
  428. }
  429. /**
  430. .uni-media-list-body {
  431. height: auto;
  432. }
  433. */
  434. .uni-swipe-action,.uni-swipe,.uni-view,.uni-media-list{
  435. width: 750upx !important;
  436. }
  437. .action_main {
  438. position: fixed;
  439. top: 55px;
  440. /* #ifndef H5 */
  441. top: 15px;
  442. /* #endif */
  443. width: 750upx;
  444. height: 1080upx;
  445. z-index: 10000;
  446. }
  447. .action_base {
  448. position: absolute;
  449. right: 15upx;
  450. width: 300upx;
  451. top: -15upx;
  452. background: #36363d;
  453. border-radius: 10upx;
  454. }
  455. .sj {
  456. position: fixed;
  457. top: -28upx;
  458. right: 26upx;
  459. /* #ifdef APP-PLUS */
  460. top: 3upx;
  461. right: 20upx;
  462. /* #endif */
  463. width: 0;
  464. height: 0;
  465. border-left: 20upx solid transparent;
  466. border-right: 20upx solid transparent;
  467. border-bottom: 20upx solid #36363d;
  468. }
  469. .action_item {
  470. color: #e5e5e5;
  471. height: 100upx;
  472. line-height: 100upx;
  473. margin-left: 45upx;
  474. border-bottom: 1px solid #3e3e3e;
  475. }
  476. .action_icon {
  477. width: 45upx;
  478. height: 45upx;
  479. display: inline-block;
  480. vertical-align: middle;
  481. }
  482. .action_item:last-child {
  483. border: none;
  484. }
  485. .action_item_text {
  486. font-size: 30upx;
  487. }
  488. </style>