chat.vue 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934
  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. userAvatar:null
  225. }
  226. },
  227. computed: mapState({
  228. //显示时间
  229. renderMessageDate() {
  230. return (message, index) => {
  231. if (message.timestamp - this.history.messages[index + 1]?.timestamp > 3 * 60 * 1000) {
  232. return formatDate(message.timestamp, 'timestamp');
  233. }
  234. return '';
  235. };
  236. },
  237. // 是否本人isMy
  238. isSelf() {
  239. return (senderId) => {
  240. const {
  241. member_id = this.myid
  242. } = {"member_id":this.myid};
  243. return senderId === `${member_id}`;
  244. };
  245. },
  246. }),
  247. onLoad(options) {
  248. var app = this;
  249. app.optionsData = options;
  250. uni.setNavigationBarTitle({
  251. title:"加载中..."
  252. });
  253. app.getService(options)
  254. },
  255. beforeDestroy() {
  256. cursor = 0;
  257. this.pushObj.disconnect()
  258. },
  259. onPageScroll(e) {
  260. // this.$refs.bottomOperationRef.closeAll();
  261. },
  262. onReady() {
  263. // this.videoPlayer.context = uni.createVideoContext('videoPlayer', this);
  264. },
  265. methods: {
  266. initPush(){
  267. var _this = this;
  268. this.pushObj = new Push({
  269. "url":this.wsUrl,
  270. "app_key":"265c33b73d5c04f918978577df2c48d2",
  271. "auth":this.wsAuth
  272. });
  273. var user_channel = this.pushObj.subscribe('user-' + this.myid);
  274. user_channel.on('message', function (data) {
  275. // console.log(data);
  276. _this.formatMsg(data);
  277. })
  278. },
  279. addressChange(data){
  280. if (data.detail) {
  281. this.addressForm.city = JSON.stringify(data.detail.value);
  282. }
  283. },
  284. submitForm(){
  285. var formData = this.addressForm;
  286. var validation = form.validation(formData,[
  287. {name:"nickname",rule:["required"],msg:["请输入"]},
  288. {name:"mobile",rule:["required","isMobile"],msg:["请填写手机号码","手机号码格式错误"]},
  289. {name:"city",rule:["required"],msg:["请选择地区"]},
  290. {name:"address",rule:["required"],msg:["请输入"]},
  291. ]);
  292. if(validation){
  293. this.$dialog.showSuccess(validation);
  294. return false;
  295. }
  296. formData.order = JSON.stringify(this.addressData);
  297. this.submitState = true;
  298. Api.address(formData).then((res)=>{
  299. if (res.code == 0) {
  300. return this.$dialog.showSuccess(res.msg);
  301. }
  302. this.$dialog.showSuccess(res.msg);
  303. this.showAddress(2)
  304. return
  305. })
  306. },
  307. imgLoad(data){},
  308. onItem(data,index){
  309. switch(data.type) {
  310. case "address":
  311. var order = data.payload.address;
  312. order.msgId = data.messageId;
  313. this.addressData = order;
  314. Api.city().then((res)=>{
  315. this.cityData = res.data;
  316. this.showAddress(1)
  317. })
  318. break;
  319. case "order":
  320. var order = data.payload.order;
  321. break;
  322. case "image":
  323. uni.previewImage({
  324. urls:[data.payload.url]
  325. })
  326. break;
  327. case "pay":
  328. var payInfo = data.payload.pay;
  329. if (payInfo.status == 1) {
  330. return this.$dialog.showSuccess("已完成支付")
  331. }
  332. uni.showLoading({
  333. title:"发起中..."
  334. })
  335. Api.pricePay({order:payInfo.order}).then((res)=>{
  336. uni.hideLoading()
  337. if (res.code == 0) {
  338. return app.$dialog.showSuccess(res.msg)
  339. }
  340. uni.requestPayment({
  341. orderInfo:res.data.pay,
  342. service:5,
  343. success(resp){
  344. if (resp.code == 0) { // res.code=0时,才表示支付成功
  345. app.$dialog.showSuccess("支付成功","none",function(){
  346. app.getService(app.optionsData)
  347. });
  348. }
  349. },
  350. fail(resp) {
  351. app.$dialog.showSuccess("支付失败,可再次重试","none");
  352. }
  353. })
  354. })
  355. break;
  356. default:
  357. break;
  358. }
  359. },
  360. onLongpress(data){
  361. },
  362. // 滚动中
  363. scroll(e) {
  364. scroll_top = e.detail.scrollTop;
  365. // this.$refs.operateRef.close();
  366. if (isBottomOperationScrollToBottom) return;
  367. // this.$refs.bottomOperationRef.closeAll();
  368. },
  369. // 滚动到底部
  370. scrolltolower() {
  371. if (this.history.allLoaded) return;
  372. console.log('触底')
  373. this.getMoreMsg()
  374. // this.loadHistoryMessage();
  375. },
  376. // 滚动到顶部
  377. scrolltoupper() {
  378. console.log('滚动到顶部')
  379. },
  380. showAddress(type){
  381. if (type == 2) {
  382. this.$refs.addresspopup.close()
  383. return ;
  384. }
  385. this.$refs.addresspopup.open()
  386. },
  387. showOrder(type){
  388. if (type == 2) {
  389. this.$refs.orderpopup.close()
  390. return ;
  391. }
  392. Api.order({"size":this.size,"page":this.orderPage}).then((res)=>{
  393. if (res.code == 0) {
  394. return this.$dialog.showSuccess(res.msg)
  395. }
  396. this.orderData = this.orderData.concat(res.data.rows);
  397. this.$refs.orderpopup.open()
  398. this.orderPage = res.data.page + 1;
  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. },
  755. // 获取焦点
  756. focus(e) {
  757. this.testData = JSON.stringify(e.detail);
  758. this.isFocus = true;
  759. this.isEmoji = false;
  760. this.isMore = false;
  761. this.keyboardHeight = (e.detail.height==100)?0:e.detail.height
  762. },
  763. keyboardheightchange(e){
  764. // app.$dialog.showSuccess('asdasdasd')
  765. console.log(e)
  766. },
  767. sendingText() {
  768. if (this.text === '')
  769. return ;
  770. let body = this.text;
  771. if (this.text.length >= 50) {
  772. body = this.text.substring(0, 30) + '...';
  773. }
  774. Api.send({type:"text",content: this.text,sendId: this.serviceId,groupId: this.storeData.poi_id}).then((res)=>{
  775. if (res.code == 0) {
  776. return this.$dialog.showSuccess(res.msg)
  777. }
  778. this.sendMessage({
  779. payload: {
  780. text: this.text
  781. },
  782. type: 'text'
  783. });
  784. this.text = '';
  785. })
  786. },
  787. async pushList(message) {
  788. this.initMessageItem(message);
  789. this.history.messages.unshift(message);
  790. // 是否触发文字动效果
  791. if (message.type === 'text' || message.type === 'text_quote') {
  792. this.onSetText(message.payload.text);
  793. }
  794. // 缓存照片地址,
  795. if (message.type === 'image' || message.type === 'image_transmit') {
  796. imageList.push(message.payload.url);
  797. }
  798. },
  799. }
  800. }
  801. </script>
  802. <style lang="scss">
  803. @import '@/static/index.scss';
  804. .order-popup .order-title{display: flex;align-items: center;justify-content: space-between;font-size: 28upx;padding: 20upx;}
  805. .order-popup .order-title image{width: 40upx;height: 40upx;}
  806. .order-popup .order-body{height: 40vh;overflow: auto;padding: 20upx;}
  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. .form-feedbak{
  823. background-color: #fff;
  824. border-radius: 20upx;
  825. }
  826. .form-feedbak .title{
  827. line-height: 80upx;
  828. font-size: 28upx;
  829. }
  830. .form-feedbak .title text{
  831. color: #f00;
  832. margin-right: 10upx;
  833. }
  834. .form-feedbak .form-textarea{
  835. background-color: #f8f8f8;
  836. padding: 20upx;
  837. }
  838. .u-textarea{
  839. font-size: 24upx;
  840. }
  841. .u-input{
  842. font-size: 24upx;
  843. }
  844. .m-order-s{background-color: #f8f8f8;border-radius: 10upx;display: flex;font-size: 28upx;position: relative;margin-bottom: 20upx;}
  845. .m-order-s .order-img {display: flex;align-items: center;justify-content: center;}
  846. .m-order-s .order-img image{width: 150upx;height: 150upx;}
  847. .m-order-s .order-info {padding: 15upx;flex:1;overflow: hidden;}
  848. .m-order-s .order-info .title{font-size: 28upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;}
  849. .m-order-s .order-info .desc{font-size: 24upx;overflow: hidden;text-overflow: ellipsis;white-space: nowrap;color: #999;}
  850. .m-order-s .order-info .price{font-size: 28upx;color: #f00;}
  851. .m-order-s .status-btn-group{position: absolute;right: 0;bottom: 0;display: flex;align-items: center;gap: 15upx;}
  852. .m-order-s .status{border-radius: 10upx 0 10upx 0;background-color: #909399;font-size: 24upx;color: #fff;padding: 10upx;}
  853. .m-order-s .status.info{background-color: #909399;}
  854. .m-order-s .status.primary{background-color: #409eff;}
  855. .m-order-s .status.success{background-color: #67c23a;}
  856. .m-order-s .status.danger{background-color: #f56c6c;}
  857. .m-order-s .status.warn{background-color: #e6a23c;}
  858. .bottomOperationRef{background-color: #f6f6f6;}
  859. .bottom-btn-group{display: flex;gap: 20upx;padding: 10rpx 14rpx;}
  860. .bottom-btn-group .btn-item{display: flex;align-items: center;gap: 10upx;font-size: 24upx;background-color: #f6f6f6;padding: 10rpx 14rpx;border-radius: 10upx;}
  861. .bottom-btn-group .btn-item image{width: 30upx;height: 30upx;}
  862. .bottom-operation-box{display: flex;padding: 20rpx 20rpx 0 20rpx;gap: 20rpx;align-items: flex-end;}
  863. .bottom-operation-box .check-img{display: flex;align-items: center;justify-content: center;}
  864. .bottom-operation-box .check-img .check-icon{width: 84rpx;height: 84rpx;display: flex;align-items: center;justify-content: center;}
  865. .bottom-operation-box .check-img image{width: 75%;height: 75%;}
  866. .bottom-operation-box .input-text{flex: 1;width: 100%;
  867. box-sizing: border-box;
  868. padding: 10rpx 14rpx;
  869. min-height: 84rpx;
  870. max-height: 300rpx;
  871. overflow: auto;
  872. border-radius: 10rpx;
  873. background-color: #fff}
  874. .bottom-operation-box .input{margin: 10rpx 0;width: 100%;font-size: 24upx;height: 100%;background-color: transparent;min-height: 48rpx;
  875. max-height: 300rpx;}
  876. .safe-box{width: 100%;height: env(safe-area-inset-bottom);background-color: #f6f6f6;}
  877. .page {
  878. position: fixed;
  879. z-index: 1;
  880. top: 0;
  881. left: 0;
  882. bottom: 0;
  883. right: 0;
  884. background-color: #ededed;
  885. }
  886. .scroll-Y {
  887. width: 100%;
  888. height: 0;
  889. transition: all 0.2s;
  890. transform: rotate(180deg);
  891. background-color: #ededed;
  892. padding: 20upx 0;
  893. ::-webkit-scrollbar {
  894. display: none;
  895. }
  896. }
  897. .scroll-view-str {
  898. width: 100%;
  899. }
  900. .time {
  901. width: 100%;
  902. color: #a3a3a3;
  903. line-height: 100rpx;
  904. }
  905. .recalled {
  906. width: 100%;
  907. height: 50rpx;
  908. margin: 20rpx 0;
  909. color: #a3a3a3;
  910. .recalled-edit {
  911. color: #5a6693;
  912. margin-left: 14rpx;
  913. }
  914. }
  915. </style>