chat.vue 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  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 :value="addressForm.nickname" @blur="handleBlur" data-field="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 :value="addressForm.mobile" @blur="handleBlur" data-field="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 :value="addressForm.address" @blur="handleBlur" data-field="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. handleBlur(event){
  272. // 通过 data-field 获取字段名
  273. const field = event.currentTarget.dataset.field;
  274. // 在失焦时,将输入框的最终值赋给数据
  275. this.addressForm[field] = event.detail.value;
  276. // 可以在这里执行校验等后续操作
  277. console.log(`字段 ${field} 的最终值为:`, this.addressForm[field]);
  278. },
  279. initPush(){
  280. var _this = this;
  281. this.pushObj = new Push({
  282. "url":this.wsUrl,
  283. "app_key":"265c33b73d5c04f918978577df2c48d2",
  284. "auth":this.wsAuth
  285. });
  286. var user_channel = this.pushObj.subscribe('user-' + this.myid);
  287. user_channel.on('message', function (data) {
  288. // console.log(data);
  289. _this.formatMsg(data);
  290. })
  291. },
  292. addressChange(data){
  293. if (data.detail) {
  294. this.addressForm.city = JSON.stringify(data.detail.value);
  295. }
  296. },
  297. submitForm(){
  298. var formData = this.addressForm;
  299. var validation = form.validation(formData,[
  300. {name:"nickname",rule:["required"],msg:["请输入姓名"]},
  301. {name:"mobile",rule:["required","isMobile"],msg:["请填写手机号码","手机号码格式错误"]},
  302. {name:"city",rule:["required"],msg:["请选择地区"]},
  303. {name:"address",rule:["required"],msg:["请输入"]},
  304. ]);
  305. if(validation){
  306. this.$dialog.showSuccess(validation);
  307. return false;
  308. }
  309. formData.order = JSON.stringify(this.addressData);
  310. this.submitState = true;
  311. Api.address(formData).then((res)=>{
  312. this.submitState = false;
  313. if (res.code == 0) {
  314. return this.$dialog.showSuccess(res.msg);
  315. }
  316. this.$dialog.showSuccess(res.msg);
  317. this.showAddress(2)
  318. return
  319. })
  320. },
  321. imgLoad(data){},
  322. onItem(data,index){
  323. switch(data.type) {
  324. case "address":
  325. var order = data.payload.address;
  326. order.msgId = data.messageId;
  327. this.addressData = order;
  328. Api.city().then((res)=>{
  329. this.cityData = res.data;
  330. this.showAddress(1)
  331. })
  332. break;
  333. case "order":
  334. var order = data.payload.order;
  335. break;
  336. case "image":
  337. uni.previewImage({
  338. urls:[data.payload.url]
  339. })
  340. break;
  341. case "pay":
  342. var payInfo = data.payload.pay;
  343. if (payInfo.status == 1) {
  344. return this.$dialog.showSuccess("已完成支付")
  345. }
  346. uni.navigateToMiniProgram({
  347. appId:payInfo.appid,
  348. path:payInfo.path,
  349. success(){},
  350. fail(){}
  351. })
  352. break;
  353. default:
  354. break;
  355. }
  356. },
  357. onLongpress(data){
  358. },
  359. // 滚动中
  360. scroll(e) {
  361. scroll_top = e.detail.scrollTop;
  362. // this.$refs.operateRef.close();
  363. if (isBottomOperationScrollToBottom) return;
  364. // this.$refs.bottomOperationRef.closeAll();
  365. },
  366. // 滚动到底部
  367. scrolltolower() {
  368. if (this.history.allLoaded) return;
  369. console.log('触底')
  370. this.getMoreMsg()
  371. // this.loadHistoryMessage();
  372. },
  373. // 滚动到顶部
  374. scrolltoupper() {
  375. console.log('滚动到顶部')
  376. },
  377. showAddress(type){
  378. if (type == 2) {
  379. this.$refs.addresspopup.close()
  380. return ;
  381. }
  382. this.$refs.addresspopup.open()
  383. },
  384. showOrder(type){
  385. if (type == 2) {
  386. this.$refs.orderpopup.close()
  387. return ;
  388. }
  389. this.orderLoading = true;
  390. Api.order({"size":this.size,"page":this.orderPage,"status":2}).then((res)=>{
  391. this.orderLoading = false;
  392. if (res.code == 0) {
  393. return this.$dialog.showSuccess(res.msg)
  394. }
  395. this.orderData = this.orderData.concat(res.data.rows);
  396. this.$refs.orderpopup.open()
  397. this.orderPage = res.data.page + 1;
  398. this.orderMore = true;
  399. })
  400. },
  401. getMoreMsg(){
  402. this.history.allLoaded = true;
  403. var formData = this.optionsData;
  404. formData.page = this.page;
  405. Api.msg(formData).then((res)=>{
  406. if(res.code == 0) {
  407. return this.$dialog.showSuccess(res.msg)
  408. }
  409. if (res.data.rows.length > 0) {
  410. this.page ++;
  411. var msgData = []
  412. var list = res.data.rows
  413. // 同步混入数据
  414. list.forEach((item, ix) => {
  415. var payload = {};
  416. if (item.type == 'text') {
  417. payload.text = item.content
  418. }
  419. if (item.type == 'order') {
  420. var order = JSON.parse(item.content)
  421. payload.order = order
  422. }
  423. if (item.type == 'pay') {
  424. var order = JSON.parse(item.content)
  425. payload.pay = order
  426. }
  427. if (item.type == 'address') {
  428. var order = JSON.parse(item.content)
  429. payload.address = order
  430. }
  431. if (item.type == 'image') {
  432. payload = {
  433. contentType: 'image/png',
  434. name: 'uni-image.png',
  435. size: 82942,
  436. url: item.content,
  437. width: 2732,
  438. height: 2732,
  439. thumbnail: item.content
  440. };
  441. }
  442. const message = {
  443. groupId: item.poi_id,
  444. senderData: {
  445. avatar:item.avatar
  446. },
  447. senderId: (item.source==1?item.openid:item.service_id),
  448. messageId: item.msgId,
  449. payload: payload,
  450. timestamp: item.time,
  451. type: item.type,
  452. recalled: false,
  453. status: 'success',
  454. isHide: 0
  455. };
  456. msgData[ix] = message
  457. });
  458. // console.log(msgData)
  459. // 模拟只有少量数据
  460. // this.history.messages = [list[0],list[1],list[2]];
  461. this.history.messages = [...this.history.messages, ...msgData];
  462. this.history.allLoaded = false;
  463. // if (this.history.messages.length > 20) return;
  464. // msgData.forEach((item,index)=>{
  465. // this.formatMsg(item);
  466. // })
  467. } else {
  468. this.history.allLoaded = true;
  469. }
  470. })
  471. },
  472. getService(options){
  473. Api.shareout(options).then((res)=>{
  474. if (res.code && res.code == 0) {
  475. return app.$dialog.showSuccess(res.msg)
  476. }
  477. console.log(res.data)
  478. uni.setNavigationBarTitle({
  479. title:"与"+res.data.store.poi_name+"对话中"
  480. })
  481. this.storeData = res.data.store;
  482. this.sendId = res.data.sendId;
  483. this.serviceId = res.data.serviceId;
  484. this.myid = res.data.sendId;
  485. this.userAvatar = res.data.avatar;
  486. if (res.data.msg.rows.length > 0) {
  487. var msgData = res.data.msg.rows
  488. msgData.forEach((item,index)=>{
  489. this.formatMsg(item);
  490. })
  491. }
  492. if (res.data.code == 3) { // 无客服在线
  493. this.noService = true;
  494. this.emptyService()
  495. }
  496. this.initPush()
  497. })
  498. },
  499. emptyService(){
  500. const message = {
  501. groupId: this.storeData.poi_id,
  502. senderData: {
  503. avatar:"https://washmy.oss-cn-guangzhou.aliyuncs.com/storage/20260511/23627b2cb8f73a8a90b95c31d726e6ecad0cbb9a.png"
  504. },
  505. senderId: this.serviceId,
  506. messageId: Date.now(),
  507. payload: {
  508. text:"亲!当前无客服在线,请咨询商家电话客服哦!"
  509. },
  510. timestamp: Date.now(),
  511. type: "text",
  512. recalled: false,
  513. status: 'success',
  514. isHide: 0
  515. };
  516. this.pushList(message);
  517. },
  518. formatMsg(item){
  519. var payload = {};
  520. if (item.type == 'text') {
  521. payload.text = item.content
  522. }
  523. if (item.type == 'order') {
  524. var order = JSON.parse(item.content)
  525. payload.order = order
  526. }
  527. if (item.type == 'pay') {
  528. var order = JSON.parse(item.content)
  529. payload.pay = order
  530. }
  531. if (item.type == 'address') {
  532. var order = JSON.parse(item.content)
  533. payload.address = order
  534. }
  535. if (item.type == 'image') {
  536. payload = {
  537. contentType: 'image/png',
  538. name: 'uni-image.png',
  539. size: 82942,
  540. url: item.content,
  541. width: 2732,
  542. height: 2732,
  543. thumbnail: item.content
  544. };
  545. }
  546. const message = {
  547. groupId: item.poi_id,
  548. senderData: {
  549. avatar:item.avatar
  550. },
  551. senderId: (item.source==1?item.openid:item.service_id),
  552. messageId: item.msgId,
  553. payload: payload,
  554. timestamp: item.time,
  555. type: item.type,
  556. recalled: false,
  557. status: 'success',
  558. isHide: 0
  559. };
  560. this.pushList(message);
  561. },
  562. // 更多操作相关===============
  563. onMore(item) {
  564. // console.log(item)
  565. switch (item.type) {
  566. case 'img':
  567. this.sendImageMessage();
  568. break;
  569. case 'video':
  570. this.sendVideoMessage();
  571. break;
  572. case 'order':
  573. this.showOrder(1);
  574. break;
  575. }
  576. },
  577. sendOrder(items){
  578. var orderData = {};
  579. orderData.img = items.img;
  580. orderData.name = items.product.product_name;
  581. orderData.goods_id = items.life_goods_id;
  582. orderData.order = items.out_order_no;
  583. orderData.price = (parseInt(items.pay_money) / 100).toFixed(2);
  584. orderData.status = items.status;
  585. Api.send({type:"order",content: JSON.stringify(orderData),sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  586. if (res.code == 0) {
  587. return this.$dialog.showSuccess(res.msg)
  588. }
  589. this.showOrder(2);
  590. this.sendMessage({
  591. payload: {
  592. order: orderData
  593. },
  594. type: 'order'
  595. });
  596. })
  597. },
  598. // 创建发送照片内容
  599. sendImageMessage() {
  600. uni.chooseImage({
  601. count: 1,
  602. sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图,默认二者都有
  603. success: async (res) => {
  604. res.tempFiles.forEach((file) => {
  605. console.log(file);
  606. this.createImageMessage(file);
  607. });
  608. },
  609. fail(e) {
  610. console.log("选择失败",e)
  611. }
  612. });
  613. },
  614. // 创建发送照片内容
  615. createImageMessage(file) {
  616. Api.upload(file.path,{type:"image",sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  617. var respData = JSON.parse(res);
  618. if (respData.code == 0) {
  619. return this.$dialog.showSuccess(respData.msg)
  620. }
  621. this.sendMessage({
  622. payload: {
  623. contentType: 'image/png',
  624. name: 'uni-image.png',
  625. size: 82942,
  626. url: respData.data.path,
  627. width: 2732,
  628. height: 2732,
  629. thumbnail: respData.data.path
  630. },
  631. type: 'image'
  632. });
  633. })
  634. },
  635. // 创建发送视频内容
  636. sendVideoMessage() {
  637. uni.chooseVideo({
  638. success: async (res) => {
  639. console.log(res);
  640. this.createVideoMessage(res);
  641. }
  642. });
  643. },
  644. createVideoMessage(file) {
  645. this.sendMessage({
  646. payload: {
  647. video: {
  648. name: '3003009356267921_uni-video.mp4',
  649. url: file.tempFilePath,
  650. width: 640,
  651. height: 352,
  652. contentType: 'video/mp4',
  653. size: 501774,
  654. duration: 8.32
  655. },
  656. thumbnail: {
  657. name: 'uni-thumbnail.jpg',
  658. url: '封面路径',
  659. width: 364,
  660. height: 200,
  661. contentType: 'image/jpg'
  662. }
  663. },
  664. type: 'video'
  665. });
  666. },
  667. sendMessage({payload,type}){
  668. const message = {
  669. groupId: this.storeData.poi_id,
  670. senderData: {
  671. avatar:this.userAvatar
  672. },
  673. senderId: this.sendId,
  674. messageId: Date.now(),
  675. payload: payload,
  676. timestamp: Date.now(),
  677. type: type,
  678. recalled: false,
  679. status: 'success',
  680. isHide: 0
  681. };
  682. this.pushList(message);
  683. },
  684. // 组装item
  685. initMessageItem(message, index) {
  686. message['isHide'] = 0;
  687. if (index === 0 && (message.type === 'text' || message.type === 'text_quote')) {
  688. this.onSetText(message.payload.text);
  689. }
  690. },
  691. // 文本触发效果相关========
  692. onSetText(text) {
  693. // 触发礼花
  694. throttle(() => {
  695. if (text.includes('[彩带]')) {
  696. this.$refs.mScreenAnimationLihua.show();
  697. uni.vibrateLong();
  698. }
  699. }, 4000);
  700. },
  701. sendingEmojiPack(){
  702. },
  703. // 删除表情
  704. deleteFn() {
  705. const str = this.text.charAt(this.text.length - 1);
  706. if (str === ']') {
  707. let metaChars = /\[.*?(\u4e00*\u597d*)\]/g;
  708. let xstr = '';
  709. this.text.replace(metaChars, (match) => {
  710. xstr = match;
  711. });
  712. var text = this.text;
  713. function del(str) {
  714. return text.slice(0, text.length - str.length);
  715. }
  716. this.text = del(xstr);
  717. } else {
  718. this.text = this.text.substring(0, this.text.length - 1);
  719. }
  720. },
  721. onEmoji(key) {
  722. const text = `${this.text.slice(0, cursor)}${key}${this.text.slice(cursor)}`;
  723. this.text = text;
  724. },
  725. tapEmoji() {
  726. this.isEmoji = !this.isEmoji;
  727. if (this.isEmoji) {
  728. this.isKeyboard = true;
  729. }
  730. this.isMore = false;
  731. },
  732. tapMore() {
  733. this.isMore = !this.isMore;
  734. this.isEmoji = false;
  735. },
  736. touchmove(){
  737. this.isFocus = false;
  738. this.isFocisEmojius = false;
  739. this.isMore = false;
  740. this.isKeyboard = false;
  741. this.keyboardHeight = 0
  742. },
  743. onPage(){},
  744. // 监听输入
  745. input() {
  746. // if (inputValue.length > this.text.length) {} else {
  747. // const str = this.text.charAt(this.text.length - 1);
  748. // }
  749. // inputValue = this.text;
  750. },
  751. blured(){
  752. this.isFocus = false;
  753. this.keyboardHeight = 0
  754. // this.text = event.detail.value;
  755. },
  756. // 获取焦点
  757. focus(e) {
  758. this.testData = JSON.stringify(e.detail);
  759. this.isFocus = true;
  760. this.isEmoji = false;
  761. this.isMore = false;
  762. this.keyboardHeight = (e.detail.height==100)?0:e.detail.height
  763. },
  764. keyboardheightchange(e){
  765. // app.$dialog.showSuccess('asdasdasd')
  766. console.log(e)
  767. },
  768. sendingText() {
  769. if (this.text === '')
  770. return ;
  771. let body = this.text;
  772. if (this.text.length >= 50) {
  773. body = this.text.substring(0, 30) + '...';
  774. }
  775. Api.send({type:"text",content: this.text,sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  776. if (res.code == 0) {
  777. return this.$dialog.showSuccess(res.msg)
  778. }
  779. this.sendMessage({
  780. payload: {
  781. text: this.text
  782. },
  783. type: 'text'
  784. });
  785. this.text = '';
  786. })
  787. },
  788. async pushList(message) {
  789. this.initMessageItem(message);
  790. this.history.messages.unshift(message);
  791. // 是否触发文字动效果
  792. if (message.type === 'text' || message.type === 'text_quote') {
  793. this.onSetText(message.payload.text);
  794. }
  795. // 缓存照片地址,
  796. if (message.type === 'image' || message.type === 'image_transmit') {
  797. imageList.push(message.payload.url);
  798. }
  799. },
  800. }
  801. }
  802. </script>
  803. <style lang="scss">
  804. @import '@/static/index.scss';
  805. .order-popup .order-title{display: flex;align-items: center;justify-content: space-between;font-size: 28upx;padding: 20upx;}
  806. .order-popup .input-value-border{border: 0;}
  807. .order-popup .order-title.bb1{border-bottom: 2upx solid #efefef;}
  808. .order-popup .order-title image{width: 40upx;height: 40upx;}
  809. .order-popup .order-body{height: 40vh;overflow: auto;padding: 20upx;}
  810. .order-popup.address .order-body{height: 60vh;overflow: auto;padding: 20upx;}
  811. .view-more{text-align: center;font-size: 24upx;color: #666;padding: 20upx;}
  812. .order-popup .u-input {height: 60upx;}
  813. .order-popup .submit-btn{
  814. border-top: 2upx solid #efefef;
  815. border-radius: 0;
  816. }
  817. .submit-btn{
  818. background-color: #fff;
  819. border-radius: 20upx 0;
  820. padding: 20upx;
  821. }
  822. .submit-btn .btn{
  823. text-align: center;
  824. width: 100%;
  825. height: 80upx;
  826. line-height: 80upx;
  827. background-color: #956937;
  828. color: #fff;
  829. font-size: 30upx;
  830. border-radius: 40upx;
  831. }
  832. .submit-btn .btn::after{
  833. border: 0;
  834. }
  835. .form-feedbak{
  836. background-color: #fff;
  837. border-radius: 20upx;
  838. }
  839. .form-feedbak .title{
  840. line-height: 80upx;
  841. font-size: 28upx;
  842. }
  843. .form-feedbak .title text{
  844. color: #f00;
  845. margin-right: 10upx;
  846. }
  847. .form-feedbak .form-textarea{
  848. background-color: #f8f8f8;
  849. padding: 20upx;
  850. }
  851. .u-textarea{
  852. font-size: 24upx;
  853. }
  854. .u-input{
  855. font-size: 24upx;
  856. }
  857. .m-order-s{background-color: #f8f8f8;border-radius: 10upx;display: flex;font-size: 28upx;position: relative;margin-bottom: 20upx;}
  858. .m-order-s .order-img {display: flex;align-items: center;justify-content: center;}
  859. .m-order-s .order-img image{width: 150upx;height: 150upx;}
  860. .m-order-s .order-info {padding: 15upx;flex:1;overflow: hidden;}
  861. .m-order-s .order-info .title{font-size: 28upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
  862. .m-order-s .order-info .desc{font-size: 24upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #999;}
  863. .m-order-s .order-info .price{font-size: 28upx;color: #f00;}
  864. .m-order-s .status-btn-group{position: absolute;right: 0;bottom: 0;display: flex;align-items: center;gap: 15upx;}
  865. .m-order-s .status{border-radius: 10upx 0 10upx 0;background-color: #909399;font-size: 24upx;color: #fff;padding: 10upx;}
  866. .m-order-s .status.info{background-color: #909399;}
  867. .m-order-s .status.primary{background-color: #409eff;}
  868. .m-order-s .status.success{background-color: #67c23a;}
  869. .m-order-s .status.danger{background-color: #f56c6c;}
  870. .m-order-s .status.warn{background-color: #e6a23c;}
  871. .bottomOperationRef{background-color: #f6f6f6;}
  872. .bottom-btn-group{display: flex;gap: 20upx;padding: 10rpx 14rpx;}
  873. .bottom-btn-group .btn-item{display: flex;align-items: center;gap: 10upx;font-size: 24upx;background-color: #f6f6f6;padding: 10rpx 14rpx;border-radius: 10upx;}
  874. .bottom-btn-group .btn-item image{width: 30upx;height: 30upx;}
  875. .bottom-operation-box{display: flex;padding: 20rpx 20rpx 0 20rpx;gap: 20rpx;align-items: flex-end;}
  876. .bottom-operation-box .check-img{display: flex;align-items: center;justify-content: center;}
  877. .bottom-operation-box .check-img .check-icon{width: 84rpx;height: 84rpx;display: flex;align-items: center;justify-content: center;}
  878. .bottom-operation-box .check-img image{width: 75%;height: 75%;}
  879. .bottom-operation-box .input-text{flex: 1;width: 100%;
  880. box-sizing: border-box;
  881. padding: 10rpx 14rpx;
  882. min-height: 84rpx;
  883. max-height: 300rpx;
  884. overflow: auto;
  885. border-radius: 10rpx;
  886. background-color: #fff}
  887. .bottom-operation-box .input{margin: 10rpx 0;width: 100%;font-size: 24upx;height: 100%;background-color: transparent;min-height: 48rpx;
  888. max-height: 300rpx;}
  889. .safe-box{width: 100%;height: env(safe-area-inset-bottom);background-color: #f6f6f6;}
  890. .page {
  891. position: fixed;
  892. z-index: 1;
  893. top: 0;
  894. left: 0;
  895. bottom: 0;
  896. right: 0;
  897. background-color: #ededed;
  898. }
  899. .scroll-Y {
  900. width: 100%;
  901. height: 0;
  902. transition: all 0.2s;
  903. transform: rotate(180deg);
  904. background-color: #ededed;
  905. padding: 20upx 0;
  906. ::-webkit-scrollbar {
  907. display: none;
  908. }
  909. }
  910. .scroll-view-str {
  911. width: 100%;
  912. }
  913. .time {
  914. width: 100%;
  915. color: #a3a3a3;
  916. line-height: 100rpx;
  917. }
  918. .recalled {
  919. width: 100%;
  920. height: 50rpx;
  921. margin: 20rpx 0;
  922. color: #a3a3a3;
  923. .recalled-edit {
  924. color: #5a6693;
  925. margin-left: 14rpx;
  926. }
  927. }
  928. </style>