chat.vue 28 KB

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