chat.vue 27 KB

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