chat.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936
  1. <template>
  2. <view>
  3. <view class="flex_c page" @touchmove="touchmove">
  4. <scroll-view class="flex1 scroll-Y" @tap.stop="onPage" id="scroll-view" lower-threshold="100" scroll-y
  5. scroll-with-animation :scroll-top="scroll_top" @scroll="scroll" @scrolltoupper="scrolltoupper"
  6. @scrolltolower="scrolltolower">
  7. <view class="scroll-view-str" :style="{height: `${reserveHeight}px`}" v-if="reserveHeight>0"></view>
  8. <view class="messageList_">
  9. <template v-for="(item, index) in history.messages">
  10. <!-- #ifdef APP || H5 -->
  11. <view class="z_index2" :class="`oneheight_${index}`" style="transform: rotate(-180deg)"
  12. :key="item.messageId + index" v-if="!item.isHide">
  13. <view class="icon_ text_26 color__ time">
  14. {{ renderMessageDate(item, index) }}
  15. </view>
  16. <view :key="item.messageId + index" v-if="!item.recalled">
  17. <item :isMy="isSelf(item.senderId)" :myid="myid" :item="item" @onClick="onItem"
  18. @onLongpress="onLongpress" @mention="mention" @imgLoad="imgLoad"></item>
  19. </view>
  20. <view class="icon_ text_26 recalled" v-else>
  21. <view class="">
  22. <text v-if="isSelf(item.senderId)">你</text>
  23. <text v-else>{{ item.senderData.name }}</text>
  24. 撤回了一条消息
  25. </view>
  26. <view class="recalled-edit" v-if="item.type === 'text' && isSelf(item.senderId)"
  27. @click="recalledEdit(item)">重新编辑</view>
  28. </view>
  29. </view>
  30. <!-- #endif -->
  31. <!-- #ifdef MP -->
  32. <view class="z_index2" style="transform: rotate(-180deg)" :key="item.messageId"
  33. v-if="!item.isHide">
  34. <view class="icon_ text_26 color__ time">
  35. {{ renderMessageDate(item, index) }}
  36. </view>
  37. <view :key="item.messageIds" v-if="!item.recalled">
  38. <item :isMy="isSelf(item.senderId)" :myid="myid" :item="item" @onClick="onItem"
  39. @onLongpress="onLongpress" @mention="mention"></item>
  40. </view>
  41. <view class="icon_ text_26 recalled" v-else>
  42. <view class="">
  43. <text v-if="isSelf(item.senderId)">你</text>
  44. <text v-else>{{ item.senderData.name }}</text>
  45. 撤回了一条消息
  46. </view>
  47. <view class="recalled-edit" v-if="item.type === 'text' && isSelf(item.senderId)"
  48. @click="recalledEdit(item)">重新编辑</view>
  49. </view>
  50. </view>
  51. <!-- #endif -->
  52. </template>
  53. </view>
  54. </scroll-view>
  55. <view class="bottomOperationRef">
  56. <view class="bottom-btn-group">
  57. <!-- <view class="btn-item">
  58. <image src="https://jymini.oss-cn-guangzhou.aliyuncs.com/mini/star.svg"></image>
  59. <view class="name">评价服务</view>
  60. </view> -->
  61. <view class="btn-item" @click="showOrder(1)">
  62. <image src="https://jymini.oss-cn-guangzhou.aliyuncs.com/mini/order.svg"></image>
  63. <view class="name">我的订单</view>
  64. </view>
  65. </view>
  66. <view class="bottom-operation-box">
  67. <view class="input-text">
  68. <textarea class="input" placeholder="输入点什么呢..." auto-height="true" confirm-type="send" type="text" :focus="isFocus"
  69. :maxlength="-1" :adjust-position="false" v-model="text" confirm-hold
  70. :show-confirm-bar="false" @input="input" @confirm="sendingText" @focus="focus"
  71. @blur="blured" @keyboardheightchange="keyboardheightchange" />
  72. </view>
  73. <view class="check-img">
  74. <view class="check-icon" @click="tapEmoji"><image src="@/static/image/face.svg" mode="aspectFill"></image></view>
  75. <view class="check-icon" @click="tapMore"><image src="@/static/image/more.svg" mode="aspectFill"></image></view>
  76. </view>
  77. </view>
  78. <view class="safe-box"></view>
  79. <view class="keyboardheight" :style="{ height: keyboardHeight + 'px' }"></view>
  80. </view>
  81. <view>
  82. <emoji v-model="isEmoji" @onEmoji="onEmoji" @deleteFn="deleteFn" @sendingText="sendingText"
  83. @sendingEmojiPack="sendingEmojiPack"></emoji>
  84. </view>
  85. <view>
  86. <more v-model="isMore" @onMore="onMore"></more>
  87. </view>
  88. </view>
  89. <uni-popup ref="addresspopup" type="bottom" border-radius="10px 10px 0 0" background-color="#ffffff" :mask-click="false">
  90. <view class="order-popup address">
  91. <view class="order-title bb1">
  92. <view class="name">补充会员信息</view>
  93. <view class="close" @click="showAddress(2)"><image src="/static/image/close.png"></image></view>
  94. </view>
  95. <view class="order-body">
  96. <view class="form-feedbak">
  97. <view class="title"><text>*</text>姓名</view>
  98. <view class="form-textarea">
  99. <input v-model="addressForm.nickname" placeholder="请输入" class="u-input" />
  100. </view>
  101. </view>
  102. <view class="form-feedbak">
  103. <view class="title"><text>*</text>手机号码</view>
  104. <view class="form-textarea">
  105. <input v-model="addressForm.mobile" placeholder="请填写手机号码" class="u-input" />
  106. </view>
  107. </view>
  108. <view class="form-feedbak">
  109. <view class="title"><text>*</text>所属地区</view>
  110. <view class="form-textarea">
  111. <uni-data-picker placeholder="请选择地址" popup-title="请选择城市" :localdata="cityData" @change="addressChange" @nodeclick="addressChange">
  112. </uni-data-picker>
  113. </view>
  114. </view>
  115. <view class="form-feedbak">
  116. <view class="title"><text>*</text>详细地址</view>
  117. <view class="form-textarea">
  118. <input v-model="addressForm.address" placeholder="请输入" class="u-input" />
  119. </view>
  120. </view>
  121. </view>
  122. <view class="submit-btn">
  123. <button class="btn" @click="submitForm" :loading="submitState" :disabled="submitState">{{submitState?'提交中':'提交'}}</button>
  124. </view>
  125. </view>
  126. </uni-popup>
  127. <uni-popup ref="orderpopup" type="bottom" border-radius="10px 10px 0 0" background-color="#ffffff" :mask-click="false">
  128. <view class="order-popup">
  129. <view class="order-title">
  130. <view class="name">我的订单</view>
  131. <view class="close" @click="showOrder(2)"><image src="/static/image/close.png"></image></view>
  132. </view>
  133. <view class="order-body" v-if="orderData.length > 0">
  134. <view class="m-order-s" v-for="(items,index) in orderData" :key="index">
  135. <view class="order-img"><image :src="items.img" mode="widthFix"></image></view>
  136. <view class="order-info">
  137. <view class="title">{{items.product.product_name}}</view>
  138. <view class="desc">{{items.out_order_no}}</view>
  139. <view class="price">{{ $dialog.formatMoney(items.price,true) }}</view>
  140. </view>
  141. <view class="status-btn-group">
  142. <view class="status danger" @click="sendOrder(items)">发送</view>
  143. <view class="status info" v-if="items.status=='0'">未支付</view>
  144. <view class="status primary" v-if="items.status=='1'">待使用</view>
  145. <view class="status success" v-if="items.status=='2'">已完成</view>
  146. <view class="status danger" v-if="items.status=='3'">已退款</view>
  147. <view class="status warn" v-if="items.status=='4'">退款中</view>
  148. <view class="status info" v-if="items.status=='5'">已关闭</view>
  149. </view>
  150. </view>
  151. </view>
  152. <view class="order-body" v-else>
  153. <view class="empty-body">暂无数据...</view>
  154. </view>
  155. <view class="view-more" v-if="orderMore" @click="showOrder(1)">{{orderLoading?'加载中...':'展开更多'}}</view>
  156. </view>
  157. </uni-popup>
  158. </view>
  159. </template>
  160. <script>
  161. var app;
  162. let getSelectedTextRangeSetInterval = null;
  163. let inputValue = '';
  164. let cursor = 0; //输入框光标
  165. let scroll_top = 0;
  166. import emoji from '@/components/bottom-operation/emoji.vue';
  167. import more from '@/components/bottom-operation/more.vue';
  168. import item from '@/components/item/index';
  169. // 浏览照片数组
  170. let imageList = [];
  171. // 是否是手动触发的列表滑动
  172. let isBottomOperationScrollToBottom = false;
  173. import {
  174. show,
  175. formatDate,
  176. throttle,
  177. openimg,
  178. getLocation,
  179. to as tofn
  180. } from '@/utils/index.js';
  181. import {
  182. mapState
  183. } from 'vuex';
  184. var {Push} = require("@/static/js/push.js")
  185. import * as Api from "@/static/api/service.js";
  186. import form from "@/static/js/form.js";
  187. export default {
  188. components: {
  189. emoji,
  190. more,
  191. item
  192. },
  193. data() {
  194. return {
  195. submitState:false,
  196. serviceId:null, // 客服ID
  197. reserveHeight:0,
  198. isFocus: false, //键盘焦点
  199. isEmoji:false,
  200. isMore:false,
  201. keyboardHeight:0,
  202. optionsData:null,
  203. testData:null,
  204. text:"",
  205. // 历史数据
  206. history: {
  207. messages: [],
  208. allLoaded: false
  209. },
  210. showOrderState:false,
  211. orderMore:false,
  212. orderLoading:false,
  213. storeData:null,
  214. sendId:null,
  215. myid:"",
  216. pushObj:null,
  217. wsAuth:"https://tran.jsshuita.cn/plugin/webman/push/auth",
  218. wsUrl: 'wss://tran.jsshuita.cn/ws',
  219. // wsAuth:"http://127.0.0.1:9881/plugin/webman/push/auth",
  220. // wsUrl: 'ws://127.0.0.1:3131',
  221. page:2,
  222. size:10,
  223. orderPage:1,
  224. orderData:[],
  225. noService:false,
  226. addressData:null,
  227. addressForm:{},
  228. cityData:[],
  229. userAvatar:null
  230. }
  231. },
  232. computed: mapState({
  233. //显示时间
  234. renderMessageDate() {
  235. return (message, index) => {
  236. if (message.timestamp - this.history.messages[index + 1]?.timestamp > 3 * 60 * 1000) {
  237. return formatDate(message.timestamp, 'timestamp');
  238. }
  239. return '';
  240. };
  241. },
  242. // 是否本人isMy
  243. isSelf() {
  244. return (senderId) => {
  245. const {
  246. member_id = this.myid
  247. } = {"member_id":this.myid};
  248. return senderId === `${member_id}`;
  249. };
  250. },
  251. }),
  252. onLoad(options) {
  253. var app = this;
  254. app.optionsData = options;
  255. uni.setNavigationBarTitle({
  256. title:"加载中..."
  257. });
  258. app.getService(options)
  259. },
  260. beforeDestroy() {
  261. cursor = 0;
  262. this.pushObj.disconnect()
  263. },
  264. onPageScroll(e) {
  265. // this.$refs.bottomOperationRef.closeAll();
  266. },
  267. onReady() {
  268. // this.videoPlayer.context = uni.createVideoContext('videoPlayer', this);
  269. },
  270. methods: {
  271. initPush(){
  272. var _this = this;
  273. this.pushObj = new Push({
  274. "url":this.wsUrl,
  275. "app_key":"265c33b73d5c04f918978577df2c48d2",
  276. "auth":this.wsAuth
  277. });
  278. var user_channel = this.pushObj.subscribe('user-' + this.myid);
  279. user_channel.on('message', function (data) {
  280. // console.log(data);
  281. _this.formatMsg(data);
  282. })
  283. },
  284. addressChange(data){
  285. if (data.detail) {
  286. this.addressForm.city = JSON.stringify(data.detail.value);
  287. }
  288. },
  289. submitForm(){
  290. var formData = this.addressForm;
  291. var validation = form.validation(formData,[
  292. {name:"nickname",rule:["required"],msg:["请输入姓名"]},
  293. {name:"mobile",rule:["required","isMobile"],msg:["请填写手机号码","手机号码格式错误"]},
  294. {name:"city",rule:["required"],msg:["请选择地区"]},
  295. {name:"address",rule:["required"],msg:["请输入"]},
  296. ]);
  297. if(validation){
  298. this.$dialog.showSuccess(validation);
  299. return false;
  300. }
  301. formData.order = JSON.stringify(this.addressData);
  302. this.submitState = true;
  303. Api.address(formData).then((res)=>{
  304. if (res.code == 0) {
  305. return this.$dialog.showSuccess(res.msg);
  306. }
  307. this.$dialog.showSuccess(res.msg);
  308. this.showAddress(2)
  309. return
  310. })
  311. },
  312. imgLoad(data){},
  313. onItem(data,index){
  314. switch(data.type) {
  315. case "address":
  316. var order = data.payload.address;
  317. order.msgId = data.messageId;
  318. this.addressData = order;
  319. Api.city().then((res)=>{
  320. this.cityData = res.data;
  321. this.showAddress(1)
  322. })
  323. break;
  324. case "order":
  325. var order = data.payload.order;
  326. break;
  327. case "image":
  328. uni.previewImage({
  329. urls:[data.payload.url]
  330. })
  331. break;
  332. case "pay":
  333. var payInfo = data.payload.pay;
  334. if (payInfo.status == 1) {
  335. return this.$dialog.showSuccess("已完成支付")
  336. }
  337. uni.navigateToMiniProgram({
  338. appId:payInfo.appid,
  339. path:payInfo.path,
  340. success(){},
  341. fail(){}
  342. })
  343. break;
  344. default:
  345. break;
  346. }
  347. },
  348. onLongpress(data){
  349. },
  350. // 滚动中
  351. scroll(e) {
  352. scroll_top = e.detail.scrollTop;
  353. // this.$refs.operateRef.close();
  354. if (isBottomOperationScrollToBottom) return;
  355. // this.$refs.bottomOperationRef.closeAll();
  356. },
  357. // 滚动到底部
  358. scrolltolower() {
  359. if (this.history.allLoaded) return;
  360. console.log('触底')
  361. this.getMoreMsg()
  362. // this.loadHistoryMessage();
  363. },
  364. // 滚动到顶部
  365. scrolltoupper() {
  366. console.log('滚动到顶部')
  367. },
  368. showAddress(type){
  369. if (type == 2) {
  370. this.$refs.addresspopup.close()
  371. return ;
  372. }
  373. this.$refs.addresspopup.open()
  374. },
  375. showOrder(type){
  376. if (type == 2) {
  377. this.$refs.orderpopup.close()
  378. return ;
  379. }
  380. this.orderLoading = true;
  381. Api.order({"size":this.size,"page":this.orderPage}).then((res)=>{
  382. this.orderLoading = false;
  383. if (res.code == 0) {
  384. return this.$dialog.showSuccess(res.msg)
  385. }
  386. this.orderData = this.orderData.concat(res.data.rows);
  387. this.$refs.orderpopup.open()
  388. this.orderPage = res.data.page + 1;
  389. this.orderMore = true;
  390. })
  391. },
  392. getMoreMsg(){
  393. this.history.allLoaded = true;
  394. var formData = this.optionsData;
  395. formData.page = this.page;
  396. Api.msg(formData).then((res)=>{
  397. if(res.code == 0) {
  398. return this.$dialog.showSuccess(res.msg)
  399. }
  400. if (res.data.rows.length > 0) {
  401. this.page ++;
  402. var msgData = []
  403. var list = res.data.rows
  404. // 同步混入数据
  405. list.forEach((item, ix) => {
  406. var payload = {};
  407. if (item.type == 'text') {
  408. payload.text = item.content
  409. }
  410. if (item.type == 'order') {
  411. var order = JSON.parse(item.content)
  412. payload.order = order
  413. }
  414. if (item.type == 'pay') {
  415. var order = JSON.parse(item.content)
  416. payload.pay = order
  417. }
  418. if (item.type == 'address') {
  419. var order = JSON.parse(item.content)
  420. payload.address = order
  421. }
  422. if (item.type == 'image') {
  423. payload = {
  424. contentType: 'image/png',
  425. name: 'uni-image.png',
  426. size: 82942,
  427. url: item.content,
  428. width: 2732,
  429. height: 2732,
  430. thumbnail: item.content
  431. };
  432. }
  433. const message = {
  434. groupId: item.poi_id,
  435. senderData: {
  436. avatar:item.avatar
  437. },
  438. senderId: (item.source==1?item.openid:item.service_id),
  439. messageId: item.msgId,
  440. payload: payload,
  441. timestamp: item.time,
  442. type: item.type,
  443. recalled: false,
  444. status: 'success',
  445. isHide: 0
  446. };
  447. msgData[ix] = message
  448. });
  449. // console.log(msgData)
  450. // 模拟只有少量数据
  451. // this.history.messages = [list[0],list[1],list[2]];
  452. this.history.messages = [...this.history.messages, ...msgData];
  453. this.history.allLoaded = false;
  454. // if (this.history.messages.length > 20) return;
  455. // msgData.forEach((item,index)=>{
  456. // this.formatMsg(item);
  457. // })
  458. } else {
  459. this.history.allLoaded = true;
  460. }
  461. })
  462. },
  463. getService(options){
  464. Api.shareout(options).then((res)=>{
  465. if (res.code && res.code == 0) {
  466. return app.$dialog.showSuccess(res.msg)
  467. }
  468. console.log(res.data)
  469. uni.setNavigationBarTitle({
  470. title:"与"+res.data.store.poi_name+"对话中"
  471. })
  472. this.storeData = res.data.store;
  473. this.sendId = res.data.sendId;
  474. this.serviceId = res.data.serviceId;
  475. this.myid = res.data.sendId;
  476. this.userAvatar = res.data.avatar;
  477. if (res.data.msg.rows.length > 0) {
  478. var msgData = res.data.msg.rows
  479. msgData.forEach((item,index)=>{
  480. this.formatMsg(item);
  481. })
  482. }
  483. if (res.data.code == 3) { // 无客服在线
  484. this.noService = true;
  485. this.emptyService()
  486. }
  487. this.initPush()
  488. })
  489. },
  490. emptyService(){
  491. const message = {
  492. groupId: this.storeData.poi_id,
  493. senderData: {
  494. avatar:"https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png"
  495. },
  496. senderId: this.serviceId,
  497. messageId: Date.now(),
  498. payload: {
  499. text:"亲!当前无客服在线,请咨询商家电话客服哦!"
  500. },
  501. timestamp: Date.now(),
  502. type: "text",
  503. recalled: false,
  504. status: 'success',
  505. isHide: 0
  506. };
  507. this.pushList(message);
  508. },
  509. formatMsg(item){
  510. var payload = {};
  511. if (item.type == 'text') {
  512. payload.text = item.content
  513. }
  514. if (item.type == 'order') {
  515. var order = JSON.parse(item.content)
  516. payload.order = order
  517. }
  518. if (item.type == 'pay') {
  519. var order = JSON.parse(item.content)
  520. payload.pay = order
  521. }
  522. if (item.type == 'address') {
  523. var order = JSON.parse(item.content)
  524. payload.address = order
  525. }
  526. if (item.type == 'image') {
  527. payload = {
  528. contentType: 'image/png',
  529. name: 'uni-image.png',
  530. size: 82942,
  531. url: item.content,
  532. width: 2732,
  533. height: 2732,
  534. thumbnail: item.content
  535. };
  536. }
  537. const message = {
  538. groupId: item.poi_id,
  539. senderData: {
  540. avatar:item.avatar
  541. },
  542. senderId: (item.source==1?item.openid:item.service_id),
  543. messageId: item.msgId,
  544. payload: payload,
  545. timestamp: item.time,
  546. type: item.type,
  547. recalled: false,
  548. status: 'success',
  549. isHide: 0
  550. };
  551. this.pushList(message);
  552. },
  553. // 更多操作相关===============
  554. onMore(item) {
  555. // console.log(item)
  556. switch (item.type) {
  557. case 'img':
  558. this.sendImageMessage();
  559. break;
  560. case 'video':
  561. this.sendVideoMessage();
  562. break;
  563. case 'order':
  564. this.showOrder(1);
  565. break;
  566. }
  567. },
  568. sendOrder(items){
  569. var orderData = {};
  570. orderData.img = items.img;
  571. orderData.name = items.product.product_name;
  572. orderData.goods_id = items.life_goods_id;
  573. orderData.order = items.out_order_no;
  574. orderData.price = (parseInt(items.pay_money) / 100).toFixed(2);
  575. orderData.status = items.status;
  576. Api.send({type:"order",content: JSON.stringify(orderData),sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  577. if (res.code == 0) {
  578. return this.$dialog.showSuccess(res.msg)
  579. }
  580. this.showOrder(2);
  581. this.sendMessage({
  582. payload: {
  583. order: orderData
  584. },
  585. type: 'order'
  586. });
  587. })
  588. },
  589. // 创建发送照片内容
  590. sendImageMessage() {
  591. uni.chooseImage({
  592. count: 1,
  593. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  594. success: async (res) => {
  595. res.tempFiles.forEach((file) => {
  596. console.log(file);
  597. this.createImageMessage(file);
  598. });
  599. },
  600. fail(e) {
  601. console.log("选择失败",e)
  602. }
  603. });
  604. },
  605. // 创建发送照片内容
  606. createImageMessage(file) {
  607. Api.upload(file.path,{type:"image",sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  608. var respData = JSON.parse(res);
  609. if (respData.code == 0) {
  610. return this.$dialog.showSuccess(respData.msg)
  611. }
  612. this.sendMessage({
  613. payload: {
  614. contentType: 'image/png',
  615. name: 'uni-image.png',
  616. size: 82942,
  617. url: respData.data.path,
  618. width: 2732,
  619. height: 2732,
  620. thumbnail: respData.data.path
  621. },
  622. type: 'image'
  623. });
  624. })
  625. },
  626. // 创建发送视频内容
  627. sendVideoMessage() {
  628. uni.chooseVideo({
  629. success: async (res) => {
  630. console.log(res);
  631. this.createVideoMessage(res);
  632. }
  633. });
  634. },
  635. createVideoMessage(file) {
  636. this.sendMessage({
  637. payload: {
  638. video: {
  639. name: '3003009356267921_uni-video.mp4',
  640. url: file.tempFilePath,
  641. width: 640,
  642. height: 352,
  643. contentType: 'video/mp4',
  644. size: 501774,
  645. duration: 8.32
  646. },
  647. thumbnail: {
  648. name: 'uni-thumbnail.jpg',
  649. url: '封面路径',
  650. width: 364,
  651. height: 200,
  652. contentType: 'image/jpg'
  653. }
  654. },
  655. type: 'video'
  656. });
  657. },
  658. sendMessage({payload,type}){
  659. const message = {
  660. groupId: this.storeData.poi_id,
  661. senderData: {
  662. avatar:this.userAvatar
  663. },
  664. senderId: this.sendId,
  665. messageId: Date.now(),
  666. payload: payload,
  667. timestamp: Date.now(),
  668. type: type,
  669. recalled: false,
  670. status: 'success',
  671. isHide: 0
  672. };
  673. this.pushList(message);
  674. },
  675. // 组装item
  676. initMessageItem(message, index) {
  677. message['isHide'] = 0;
  678. if (index === 0 && (message.type === 'text' || message.type === 'text_quote')) {
  679. this.onSetText(message.payload.text);
  680. }
  681. },
  682. // 文本触发效果相关========
  683. onSetText(text) {
  684. // 触发礼花
  685. throttle(() => {
  686. if (text.includes('[彩带]')) {
  687. this.$refs.mScreenAnimationLihua.show();
  688. uni.vibrateLong();
  689. }
  690. }, 4000);
  691. },
  692. sendingEmojiPack(){
  693. },
  694. // 删除表情
  695. deleteFn() {
  696. const str = this.text.charAt(this.text.length - 1);
  697. if (str === ']') {
  698. let metaChars = /\[.*?(\u4e00*\u597d*)\]/g;
  699. let xstr = '';
  700. this.text.replace(metaChars, (match) => {
  701. xstr = match;
  702. });
  703. var text = this.text;
  704. function del(str) {
  705. return text.slice(0, text.length - str.length);
  706. }
  707. this.text = del(xstr);
  708. } else {
  709. this.text = this.text.substring(0, this.text.length - 1);
  710. }
  711. },
  712. onEmoji(key) {
  713. const text = `${this.text.slice(0, cursor)}${key}${this.text.slice(cursor)}`;
  714. this.text = text;
  715. },
  716. tapEmoji() {
  717. this.isEmoji = !this.isEmoji;
  718. if (this.isEmoji) {
  719. this.isKeyboard = true;
  720. }
  721. this.isMore = false;
  722. },
  723. tapMore() {
  724. this.isMore = !this.isMore;
  725. this.isEmoji = false;
  726. },
  727. touchmove(){
  728. this.isFocus = false;
  729. this.isFocisEmojius = false;
  730. this.isMore = false;
  731. this.isKeyboard = false;
  732. this.keyboardHeight = 0
  733. },
  734. onPage(){},
  735. // 监听输入
  736. input() {
  737. // if (inputValue.length > this.text.length) {} else {
  738. // const str = this.text.charAt(this.text.length - 1);
  739. // }
  740. // inputValue = this.text;
  741. },
  742. blured(){
  743. this.isFocus = false;
  744. this.keyboardHeight = 0
  745. },
  746. // 获取焦点
  747. focus(e) {
  748. this.testData = JSON.stringify(e.detail);
  749. this.isFocus = true;
  750. this.isEmoji = false;
  751. this.isMore = false;
  752. this.keyboardHeight = (e.detail.height==100)?0:e.detail.height
  753. },
  754. keyboardheightchange(e){
  755. // app.$dialog.showSuccess('asdasdasd')
  756. console.log(e)
  757. },
  758. sendingText() {
  759. if (this.text === '')
  760. return ;
  761. let body = this.text;
  762. if (this.text.length >= 50) {
  763. body = this.text.substring(0, 30) + '...';
  764. }
  765. Api.send({type:"text",content: this.text,sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  766. if (res.code == 0) {
  767. return this.$dialog.showSuccess(res.msg)
  768. }
  769. this.sendMessage({
  770. payload: {
  771. text: this.text
  772. },
  773. type: 'text'
  774. });
  775. this.text = '';
  776. })
  777. },
  778. async pushList(message) {
  779. this.initMessageItem(message);
  780. this.history.messages.unshift(message);
  781. // 是否触发文字动效果
  782. if (message.type === 'text' || message.type === 'text_quote') {
  783. this.onSetText(message.payload.text);
  784. }
  785. // 缓存照片地址,
  786. if (message.type === 'image' || message.type === 'image_transmit') {
  787. imageList.push(message.payload.url);
  788. }
  789. },
  790. }
  791. }
  792. </script>
  793. <style lang="scss">
  794. @import '@/static/index.scss';
  795. .order-popup .order-title{display: flex;align-items: center;justify-content: space-between;font-size: 28upx;padding: 20upx;}
  796. .order-popup .input-value-border{border: 0;}
  797. .order-popup .order-title.bb1{border-bottom: 2upx solid #efefef;}
  798. .order-popup .order-title image{width: 40upx;height: 40upx;}
  799. .order-popup .order-body{height: 40vh;overflow: auto;padding: 20upx;}
  800. .order-popup.address .order-body{height: 60vh;overflow: auto;padding: 20upx;}
  801. .view-more{text-align: center;font-size: 24upx;color: #666;padding: 20upx;}
  802. .order-popup .u-input {height: 60upx;}
  803. .order-popup .submit-btn{
  804. border-top: 2upx solid #efefef;
  805. border-radius: 0;
  806. }
  807. .submit-btn{
  808. background-color: #fff;
  809. border-radius: 20upx 0;
  810. padding: 20upx;
  811. }
  812. .submit-btn .btn{
  813. text-align: center;
  814. width: 100%;
  815. height: 80upx;
  816. line-height: 80upx;
  817. background-color: #956937;
  818. color: #fff;
  819. font-size: 30upx;
  820. border-radius: 40upx;
  821. }
  822. .submit-btn .btn::after{
  823. border: 0;
  824. }
  825. .form-feedbak{
  826. background-color: #fff;
  827. border-radius: 20upx;
  828. }
  829. .form-feedbak .title{
  830. line-height: 80upx;
  831. font-size: 28upx;
  832. }
  833. .form-feedbak .title text{
  834. color: #f00;
  835. margin-right: 10upx;
  836. }
  837. .form-feedbak .form-textarea{
  838. background-color: #f8f8f8;
  839. padding: 20upx;
  840. }
  841. .u-textarea{
  842. font-size: 24upx;
  843. }
  844. .u-input{
  845. font-size: 24upx;
  846. }
  847. .m-order-s{background-color: #f8f8f8;border-radius: 10upx;display: flex;font-size: 28upx;position: relative;margin-bottom: 20upx;}
  848. .m-order-s .order-img {display: flex;align-items: center;justify-content: center;}
  849. .m-order-s .order-img image{width: 150upx;height: 150upx;}
  850. .m-order-s .order-info {padding: 15upx;flex:1;overflow: hidden;}
  851. .m-order-s .order-info .title{font-size: 28upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
  852. .m-order-s .order-info .desc{font-size: 24upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #999;}
  853. .m-order-s .order-info .price{font-size: 28upx;color: #f00;}
  854. .m-order-s .status-btn-group{position: absolute;right: 0;bottom: 0;display: flex;align-items: center;gap: 15upx;}
  855. .m-order-s .status{border-radius: 10upx 0 10upx 0;background-color: #909399;font-size: 24upx;color: #fff;padding: 10upx;}
  856. .m-order-s .status.info{background-color: #909399;}
  857. .m-order-s .status.primary{background-color: #409eff;}
  858. .m-order-s .status.success{background-color: #67c23a;}
  859. .m-order-s .status.danger{background-color: #f56c6c;}
  860. .m-order-s .status.warn{background-color: #e6a23c;}
  861. .bottomOperationRef{background-color: #f6f6f6;}
  862. .bottom-btn-group{display: flex;gap: 20upx;padding: 10rpx 14rpx;}
  863. .bottom-btn-group .btn-item{display: flex;align-items: center;gap: 10upx;font-size: 24upx;background-color: #f6f6f6;padding: 10rpx 14rpx;border-radius: 10upx;}
  864. .bottom-btn-group .btn-item image{width: 30upx;height: 30upx;}
  865. .bottom-operation-box{display: flex;padding: 20rpx 20rpx 0 20rpx;gap: 20rpx;align-items: flex-end;}
  866. .bottom-operation-box .check-img{display: flex;align-items: center;justify-content: center;}
  867. .bottom-operation-box .check-img .check-icon{width: 84rpx;height: 84rpx;display: flex;align-items: center;justify-content: center;}
  868. .bottom-operation-box .check-img image{width: 75%;height: 75%;}
  869. .bottom-operation-box .input-text{flex: 1;width: 100%;
  870. box-sizing: border-box;
  871. padding: 10rpx 14rpx;
  872. min-height: 84rpx;
  873. max-height: 300rpx;
  874. overflow: auto;
  875. border-radius: 10rpx;
  876. background-color: #fff}
  877. .bottom-operation-box .input{margin: 10rpx 0;width: 100%;font-size: 24upx;height: 100%;background-color: transparent;min-height: 48rpx;
  878. max-height: 300rpx;}
  879. .safe-box{width: 100%;height: env(safe-area-inset-bottom);background-color: #f6f6f6;}
  880. .page {
  881. position: fixed;
  882. z-index: 1;
  883. top: 0;
  884. left: 0;
  885. bottom: 0;
  886. right: 0;
  887. background-color: #ededed;
  888. }
  889. .scroll-Y {
  890. width: 100%;
  891. height: 0;
  892. transition: all 0.2s;
  893. transform: rotate(180deg);
  894. background-color: #ededed;
  895. padding: 20upx 0;
  896. ::-webkit-scrollbar {
  897. display: none;
  898. }
  899. }
  900. .scroll-view-str {
  901. width: 100%;
  902. }
  903. .time {
  904. width: 100%;
  905. color: #a3a3a3;
  906. line-height: 100rpx;
  907. }
  908. .recalled {
  909. width: 100%;
  910. height: 50rpx;
  911. margin: 20rpx 0;
  912. color: #a3a3a3;
  913. .recalled-edit {
  914. color: #5a6693;
  915. margin-left: 14rpx;
  916. }
  917. }
  918. </style>