customerService copy.vue 30 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148
  1. <template>
  2. <view class="customer-service-page">
  3. <!-- 顶部栏 -->
  4. <!-- 顶部导航栏 -->
  5. <view class="custom-navbar">
  6. <view class="navbar-left">
  7. <text class="fa fa-angle-left" @click="goBack"></text>
  8. <view class="navbar-title one-omit">
  9. 时间是一种解药时间是一种解药时间是一种解药时间是一种解药时间是一种解药
  10. </view>
  11. </view>
  12. <view class="navbar-right" @click="toggleDropdown">
  13. <image src="@/static/icon/more2.png" style="width: 64rpx; height: 64rpx; margin-top: 15rpx"
  14. mode="widthFix"></image>
  15. <view class="dropdown-menu" v-if="showDropdown">
  16. <view class="dropdown-item" @tap="handleOption('report')">举报内容</view>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 聊天内容区 -->
  21. <scroll-view class="cs-chat-list" :scroll-y="true" :scroll-with-animation="true"
  22. :scroll-into-view="scrollToView" :style="{
  23. paddingBottom: (keyboardHeight ? keyboardHeight + 100 : 100) + 'rpx',
  24. }">
  25. <view v-for="(msg, idx) in chatList" :key="msg.id">
  26. <view v-if="shouldShowTime(idx)" class="cs-time-bar">
  27. <view class="cs-time-inner">{{ formatTime(msg.time) }}</view>
  28. </view>
  29. <template v-if="msg.message_type == 5">
  30. <view class="cs-msg-order-card-box">
  31. <image class="order-card-avatar" :src="msg.avatar" />
  32. <view class="cs-msg-order-card">
  33. <image class="order-card-img" v-if="msg.order.main_image" :src="msg.order.main_image" mode="aspectFill" />
  34. <view class="order-card-info">
  35. <view class="order-card-title">{{ msg.order.title }}</view>
  36. <view class="order-card-row" v-if="msg.order.orderNo">
  37. <text class="order-card-label">订单编号</text>
  38. <text class="order-card-value">{{ msg.order.orderNo }}</text>
  39. </view>
  40. <view class="order-card-row" v-if="msg.order.orderTime">
  41. <text class="order-card-label">下单时间</text>
  42. <text class="order-card-value">{{
  43. msg.order.orderTime
  44. }}</text>
  45. </view>
  46. <view class="order-card-btn-box">
  47. <button class="order-card-btn" @click="goDetails( msg.order)">查看详情</button>
  48. </view>
  49. </view>
  50. </view>
  51. </view>
  52. </template>
  53. <template v-else>
  54. <view :id="'msg-' + msg.id" :class="[
  55. 'cs-msg-item',
  56. msg.type === 'user' ? 'cs-msg-self' : 'cs-msg-other',
  57. ]">
  58. <image class="cs-avatar" :src="msg.avatar" />
  59. <view class="cs-msg-bubble">
  60. <!-- 文本消息 -->
  61. <template v-if="msg.message_type === 1">
  62. {{ msg.content }}
  63. </template>
  64. <!-- 图片消息 -->
  65. <template v-else-if="msg.message_type === 2">
  66. <view style="position:relative;display:inline-block;">
  67. <image :src="msg.media_url" mode="widthFix"
  68. style="max-width: 180rpx; border-radius: 8rpx;"
  69. @tap="!msg.uploading && previewImage(msg.media_url)" />
  70. <view v-if="msg.uploading"
  71. style="position:absolute;left:0;top:0;width:100%;height:100%;background:rgba(255,255,255,0.7);display:flex;align-items:center;justify-content:center;">
  72. <text style="color:#a6e22e;font-size:24rpx;">{{ msg.progress || 0 }}%</text>
  73. </view>
  74. </view>
  75. </template>
  76. <!-- 语音消息 -->
  77. <template v-else-if="msg.message_type === 3">
  78. <view class="cs-msg-voice">[语音消息] <text style="color:#a6e22e">(暂不支持播放)</text></view>
  79. </template>
  80. <!-- 视频消息 -->
  81. <template v-else-if="msg.message_type === 4">
  82. <video :src="msg.media_url" controls
  83. style="max-width: 220rpx; max-height: 180rpx; border-radius: 8rpx;" />
  84. </template>
  85. <!-- 其它未知类型 -->
  86. <template v-else>
  87. <text style="color:#bbb">[未知消息类型]</text>
  88. </template>
  89. </view>
  90. </view>
  91. </template>
  92. </view>
  93. <view style="height: 200rpx; width: 100%"></view>
  94. <view :id="'bottom-anchor'"></view>
  95. <view v-if="adShow" :style="{ height: orderCardHeight + 'rpx' }"></view>
  96. </scroll-view>
  97. <!-- 底部输入栏 -->
  98. <view class="cs-input-bar" :style="{ bottom: keyboardHeight + 'rpx' }">
  99. <!-- 广告条 -->
  100. <view class="order-card" v-if="adShow">
  101. <view class="order-card-header">
  102. <image class="order-card-img" :src=" orderCardData.main_image " mode="aspectFill" />
  103. <view class="order-card-info">
  104. <view class="order-card-title one-omit">{{ orderCardData.title }}</view>
  105. <view class="order-card-btn-box">
  106. <button class="order-card-btn" @click="sendOrderCardMsg()">
  107. 发给客服
  108. </button>
  109. </view>
  110. </view>
  111. <image class="order-card-close" @click="closeOrderCard" src="@/static/icon/wd_icon_guanbi.png"
  112. mode="widthFix"></image>
  113. </view>
  114. <view class="order-card-row" v-if="orderCardData.orderNo">
  115. <text class="order-card-label">订单编号</text>
  116. <text class="order-card-value">{{ orderCardData.orderNo }}</text>
  117. </view>
  118. <view class="order-card-row" v-if="orderCardData.orderTime">
  119. <text class="order-card-label">下单时间</text>
  120. <text class="order-card-value">{{ orderCardData.orderTime }}</text>
  121. </view>
  122. </view>
  123. <!-- 假输入框 -->
  124. <view v-if="!showRealInput" class="fake-input-bar" @click="showInputAndFocus">
  125. <view class="fake-input-placeholder">在这里输入新消息</view>
  126. <view class="fake-input-icons">
  127. <image src="/static/icon/icon-picture.png" class="fake-input-icon" />
  128. <image src="/static/icon/icon-expression.png" class="fake-input-icon" />
  129. </view>
  130. </view>
  131. <!-- 真输入框 -->
  132. <view v-else class="cs-input-area">
  133. <textarea class="cs-textarea" v-model="inputValue" placeholder="在这里输入新消息" :focus="inputFocused"
  134. :adjust-position="false" @focus="onInputFocus" @blur="onInputBlur"
  135. @keyboardheightchange="onKeyboardHeightChange" maxlength="300" auto-height
  136. :style="{ 'max-height': '120rpx', 'overflow-y': 'auto' }"></textarea>
  137. <view class="bottom-bar">
  138. <view>
  139. <image @tap="upload" src="/static/icon/icon-picture.png" class="fake-input-icon" />
  140. <image @tap="toggleEmojiPanel" src="/static/icon/icon-expression.png" class="fake-input-icon" />
  141. </view>
  142. <view :class="['send_btn', inputValue.trim() ? '' : 'prohibit']" @tap="sendMsg(1)">发送</view>
  143. </view>
  144. </view>
  145. </view>
  146. <view class="emoji-panel" :class="{ show: showEmojiPanel }" v-if="showEmojiPanel">
  147. <view class="emoji-mask" @click="showEmojiPanel = false"></view>
  148. <view class="emoji-grid">
  149. <view class="emoji-item" v-for="(emoji, index) in emojiList" :key="index" @tap="selectEmoji(emoji)">
  150. {{ emoji }}
  151. </view>
  152. </view>
  153. </view>
  154. </view>
  155. </template>
  156. <script>
  157. import permission from '@/common/permission.js';
  158. export default {
  159. data() {
  160. return {
  161. chatList: [],
  162. inputValue: "",
  163. pollTimer: null,
  164. scrollToView: "bottom-anchor",
  165. adShow: true,
  166. keyboardHeight: 0,
  167. inputFocused: false,
  168. orderCardHeight: 260,
  169. showEmojiPanel: false,
  170. showDropdown: false,
  171. emojiList: ["😀", "😁", "😂", "🤣", "😃", "😄", "😅", "😆", "😉", "😊", "😋", "😎", "😍", "😘", "🥰", "😗", "😙", "😚", "🙂", "🤗", "🤩", "🤔", "🤨", "😐", "😑", "😶", "🙄", "😏", "😣", "😥", "😮", "🤐", "😯", "😪", "😫", "🥱", "😴", "😌", "😛", "😜", "😝", "🤤", "😒", "😓", "😔", "😕", "🙃", "🤑", "😲", "☹️", "🙁", "😖", "😞", "😟", "😤", "😢", "😭", "😦", "😧", "😨", "😩", "🤯", "😬", "😰", "😱", "🥵", "🥶", "😳", "🤪", "😵", "😡", "😠", "🤬", "😷", "🤒", "🤕", "🤢", "🤮", "🥴", "😇", "🥳", "🥺", "🤠", "😈", "👿", "👹", "👺", "💀", "👻", "👽", "🤖", "💩", "😺", "😸", "😹", "😻", "😼", "😽", "🙀", "😿", "😾", "🙈", "🙉", "🙊", "💋", "💌", "💘", "💝", "💖", "💗", "💓", "💞", "💕", "💟", "❣️", "💔", "❤️", "🧡", "💛", "💚", "💙", "💜", "🤎", "🖤", "🤍", "💯", "💢", "💥", "💫", "💦", "💨", "🕳️", "💣", "💬", "👋", "🤚", "🖐️", "✋", "🖖", "👌", "🤏", "✌️", "🤞", "🤟", "🤘", "🤙", "👈", "👉", "👆", "🖕", "👇", "☝️", "👍", "👎", "✊", "👊", "🤛", "🤜", "👏", "🙌", "👐", "🤲", "🙏", "✍️", "💅", "🤳", "💪", "🦾", "🦵", "🦶", "👂", "👃", "🧠", "🦷", "🦴", "��", "👁️", "👅", "👄"],
  172. conversationId: 0,
  173. creatorId: 0,
  174. zcId: 0,
  175. lastMsgId: 0,
  176. pageSize: 20,
  177. userInfo: {},
  178. showRealInput: false, // 控制显示真输入框还是假输入框
  179. orderCardData: {},
  180. };
  181. },
  182. onLoad(options) {
  183. this.creatorId = options.id || 0;
  184. this.zcId = options.zc_id || 0;
  185. this.fetchMessages();
  186. this.startPolling();
  187. this.getOrderCardData()
  188. },
  189. onHide() {
  190. this.clearPolling();
  191. },
  192. onUnload() {
  193. this.clearPolling();
  194. },
  195. methods: {
  196. goBack() {
  197. uni.navigateBack();
  198. },
  199. // 轮询获取消息
  200. startPolling() {
  201. this.clearPolling();
  202. this.pollTimer = setInterval(() => this.fetchMessages(false), 5000);
  203. this.fetchMessages(false);
  204. },
  205. clearPolling() {
  206. if (this.pollTimer) {
  207. clearInterval(this.pollTimer);
  208. this.pollTimer = null;
  209. }
  210. },
  211. // 获取消息
  212. fetchMessages(isAppend = false) {
  213. uni.request({
  214. url: this.$apiHost + '/App/kefuGetMessages',
  215. method: 'GET',
  216. data: {
  217. uuid: getApp().globalData.uuid,
  218. skey: getApp().globalData.skey,
  219. creator_id: this.creatorId,
  220. conversation_id: this.conversationId,
  221. last_id: isAppend ? this.lastMsgId : 0,
  222. page_size: this.pageSize,
  223. zc_id: this.zcId
  224. },
  225. success: (res) => {
  226. if (res.data && res.data.success === 'yes' && res.data.data) {
  227. const { messages, conversation, user_info } = res.data.data;
  228. this.userInfo = user_info || {};
  229. this.conversationId = conversation?.id || 0;
  230. // 格式化消息,保留 message_type、media_url 等字段
  231. const msgList = (messages || []).map(msg => {
  232. let returnValue= {
  233. id: msg.id,
  234. content: msg.content,
  235. type: msg.from_type === 1 ? 'user' : 'customerService',
  236. avatar: msg.from_type === 1 ? (user_info.avatar || '/static/makedetail/characterProfilePicture.png') : '/static/home/avator.png',
  237. time: msg.create_time,
  238. message_type: msg.message_type, // 消息类型
  239. media_url: msg.media_url, // 媒体文件URL
  240. progress: msg.progress,
  241. uploading: msg.uploading
  242. }
  243. if (msg.message_type == 5) {
  244. returnValue.order = JSON.parse(msg.content);
  245. }
  246. return returnValue;
  247. });
  248. console.log(msgList, "消息列表");
  249. // 合并未上传完成的临时消息
  250. const tempMsgs = this.chatList.filter(m => m.uploading);
  251. let newList;
  252. if (isAppend) {
  253. newList = [...msgList, ...this.chatList.filter(m => !m.uploading), ...tempMsgs];
  254. } else {
  255. newList = [...msgList, ...tempMsgs];
  256. }
  257. this.chatList = newList;
  258. // 记录最后一条消息ID
  259. if (messages && messages.length > 0) {
  260. this.lastMsgId = messages[0].id;
  261. }
  262. this.$nextTick(() => {
  263. this.scrollToView = "bottom-anchor";
  264. });
  265. } else {
  266. // 只保留临时消息
  267. this.chatList = this.chatList.filter(m => m.uploading);
  268. }
  269. },
  270. fail: () => {
  271. // 只保留临时消息
  272. this.chatList = this.chatList.filter(m => m.uploading);
  273. }
  274. });
  275. },
  276. // 发送消息
  277. sendMsg(message_type ) {
  278. if (!this.inputValue.trim() && message_type == 1) return;
  279. const content = this.inputValue;
  280. this.inputValue = "";
  281. console.log(content, "发送消息",message_type);
  282. uni.request({
  283. url: this.$apiHost + '/App/kefuSendMessage',
  284. method: 'POST',
  285. header: {
  286. "content-type": "application/x-www-form-urlencoded",
  287. uuid: getApp().globalData.uuid,
  288. skey: getApp().globalData.skey,
  289. },
  290. data: {
  291. uuid: getApp().globalData.uuid,
  292. skey: getApp().globalData.skey,
  293. creator_id: this.creatorId,
  294. conversation_id: this.conversationId,
  295. message_type: message_type, // 文本
  296. content: content,
  297. zc_id: this.zcId
  298. },
  299. success: (res) => {
  300. if (res.data && res.data.success === 'yes') {
  301. // 发送成功后刷新消息
  302. this.fetchMessages(false);
  303. } else {
  304. uni.showToast({ title: res.data.str || '发送失败', icon: 'none' });
  305. }
  306. },
  307. fail: () => {
  308. uni.showToast({ title: '网络错误', icon: 'none' });
  309. }
  310. });
  311. },
  312. closeOrderCard() {
  313. this.adShow = false;
  314. },
  315. shouldShowTime(idx) {
  316. if (idx === 0) return true;
  317. // 找到上一个显示时间条的消息
  318. let lastShowIdx = -1;
  319. for (let i = idx - 1; i >= 0; i--) {
  320. if (this.shouldShowTime(i)) {
  321. lastShowIdx = i;
  322. break;
  323. }
  324. }
  325. if (lastShowIdx === -1) return true;
  326. const curTime = new Date(
  327. this.chatList[idx].time.replace(/-/g, "/")
  328. ).getTime();
  329. const lastTime = new Date(
  330. this.chatList[lastShowIdx].time.replace(/-/g, "/")
  331. ).getTime();
  332. // 20分钟 = 20*60*1000 毫秒
  333. return curTime - lastTime > 20 * 60 * 1000;
  334. },
  335. formatTime(timeStr) {
  336. // 例:'2025-05-21 20:01' => '05月21日 20:01'
  337. if (!timeStr) return "";
  338. const d = new Date(timeStr.replace(/-/g, "/"));
  339. const MM = String(d.getMonth() + 1).padStart(2, "0");
  340. const DD = String(d.getDate()).padStart(2, "0");
  341. const hhmm = timeStr.slice(11, 16);
  342. return `${MM}月${DD}日 ${hhmm}`;
  343. },
  344. onInputFocus(e) {
  345. this.inputFocused = true;
  346. },
  347. onInputBlur(e) {
  348. this.inputFocused = false;
  349. this.keyboardHeight = 0;
  350. },
  351. px2rpx(px) {
  352. // 以750设计稿为例,1rpx = 屏幕宽度/750
  353. const screenWidth = uni.getSystemInfoSync().windowWidth;
  354. return (px * 750) / screenWidth;
  355. },
  356. onKeyboardHeightChange(e) {
  357. let pxHeight = e.detail ? e.detail.height : e.height || 0;
  358. // #ifdef H5 || APP-PLUS
  359. this.keyboardHeight = this.px2rpx(pxHeight);
  360. // #endif
  361. // #ifdef MP-WEIXIN
  362. this.keyboardHeight = pxHeight; // 小程序下直接用rpx
  363. // #endif
  364. },
  365. toggleEmojiPanel() {
  366. this.inputFocused = false;
  367. setTimeout(() => {
  368. this.showEmojiPanel = !this.showEmojiPanel;
  369. }, 100);
  370. },
  371. selectEmoji(emoji) {
  372. this.inputValue += emoji;
  373. this.showEmojiPanel = false;
  374. },
  375. sendOrderCardMsg() {
  376. this.chatList.push({
  377. id: Date.now(),
  378. message_type: 5,
  379. avatar: this.avatar, // 用户头像
  380. order: {
  381. img: "/static/crowdFunding/top-img.png",
  382. title: "【Woh】灯塔 塔罗牌 治愈风泛伟特系",
  383. orderNo: "12201544521215415415415",
  384. orderTime: "2025-05-27 09:35:30",
  385. },
  386. time: this.getNowTime(),
  387. });
  388. this.sendMsg(5);
  389. this.$nextTick(() => {
  390. this.closeOrderCard();
  391. setTimeout(() => {
  392. this.scrollToView = "bottom-anchor";
  393. }, 1000);
  394. });
  395. },
  396. getNowTime() {
  397. const d = new Date();
  398. const pad = (n) => (n < 10 ? "0" + n : n);
  399. return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(
  400. d.getDate()
  401. )} ${pad(d.getHours())}:${pad(d.getMinutes())}`;
  402. },
  403. // 切换下拉菜单显示状态
  404. toggleDropdown() {
  405. this.showDropdown = !this.showDropdown;
  406. },
  407. // 处理下拉菜单选项点击
  408. handleOption(type) {
  409. this.showDropdown = false;
  410. switch (type) {
  411. case 'report':
  412. uni.navigateTo({
  413. url: '/pages/my/feedback?isReportContent=true'
  414. });
  415. break;
  416. }
  417. },
  418. showInputAndFocus() {
  419. this.showRealInput = true;
  420. this.$nextTick(() => {
  421. this.inputFocused = true;
  422. });
  423. },
  424. // 上传图片并发送图片消息,增加进度展示
  425. async upload() {
  426. uni.showActionSheet({
  427. itemList: ['拍照', '从相册选择'],
  428. success: async (res) => {
  429. const sourceType = res.tapIndex === 0 ? 'camera' : 'album';
  430. let hasPermission = false;
  431. try {
  432. if (sourceType === 'camera') {
  433. hasPermission = await permission.request(permission.PermissionType.CAMERA, {
  434. title: '“萌创星球”想访问你的相机',
  435. describe: '萌创星球想访问您的摄像头,便于拍摄获取图片来与其他用户进行交流'
  436. });
  437. } else {
  438. hasPermission = await permission.request(permission.PermissionType.PHOTO_LIBRARY, {
  439. title: '“萌创星球”想访问你的照片图库',
  440. describe: '萌创星球想访问您本地照片图库,便于获取图片来与其他用户进行交流'
  441. });
  442. }
  443. if (!hasPermission) {
  444. uni.showToast({
  445. title: sourceType === 'camera' ? '未获得相机权限' : '未获得相册权限',
  446. icon: 'none'
  447. });
  448. return;
  449. }
  450. // 权限通过后,选择图片
  451. uni.chooseImage({
  452. count: 1,
  453. sizeType: ['compressed'],
  454. sourceType: [sourceType],
  455. success: (res) => {
  456. const filePath = res.tempFilePaths[0];
  457. // 1. 先插入临时消息
  458. const tempMsgId = 'temp_' + Date.now();
  459. this.chatList.push({
  460. id: tempMsgId,
  461. type: 'user',
  462. avatar: this.userInfo.avatar || '/static/makedetail/characterProfilePicture.png',
  463. time: this.getNowTime(),
  464. message_type: 2,
  465. media_url: filePath,
  466. progress: 0,
  467. uploading: true
  468. });
  469. this.$nextTick(() => {
  470. this.scrollToView = "bottom-anchor";
  471. });
  472. // 2. 上传图片
  473. uni.uploadFile({
  474. url: this.$apiHost + '/Xweb/upload_img?skey=' + getApp().globalData.skey,
  475. filePath: filePath,
  476. name: 'file',
  477. // 上传进度
  478. progress: (e) => {
  479. const idx = this.chatList.findIndex(m => m.id === tempMsgId);
  480. if (idx !== -1) this.$set(this.chatList, idx, { ...this.chatList[idx], progress: e.progress });
  481. },
  482. success: (uploadFileRes) => {
  483. let resdata = JSON.parse(uploadFileRes.data);
  484. const idx = this.chatList.findIndex(m => m.id === tempMsgId);
  485. if (resdata.success == 'no') {
  486. if (idx !== -1) this.chatList.splice(idx, 1);
  487. uni.showToast({ title: resdata.str, icon: 'none' });
  488. return;
  489. }
  490. if (resdata.code == 0) {
  491. // 替换为正式消息
  492. if (idx !== -1) this.$set(this.chatList, idx, {
  493. id: Date.now(),
  494. type: 'user',
  495. avatar: this.userInfo.avatar || '/static/makedetail/characterProfilePicture.png',
  496. time: this.getNowTime(),
  497. message_type: 2,
  498. media_url: resdata.data.path,
  499. progress: 100,
  500. uploading: false
  501. });
  502. // 发送图片消息到服务端
  503. this.sendImageMsg(resdata.data.path);
  504. }
  505. },
  506. fail: () => {
  507. const idx = this.chatList.findIndex(m => m.id === tempMsgId);
  508. if (idx !== -1) this.chatList.splice(idx, 1);
  509. uni.showToast({ title: '图片上传失败', icon: 'none' });
  510. }
  511. });
  512. }
  513. });
  514. } catch (error) {
  515. uni.showToast({
  516. title: '权限检查失败',
  517. icon: 'none'
  518. });
  519. }
  520. }
  521. });
  522. },
  523. sendImageMsg(imgUrl) {
  524. uni.request({
  525. url: this.$apiHost + '/App/kefuSendMessage',
  526. method: 'POST',
  527. header: {
  528. "content-type": "application/x-www-form-urlencoded",
  529. uuid: getApp().globalData.uuid,
  530. skey: getApp().globalData.skey,
  531. },
  532. data: {
  533. uuid: getApp().globalData.uuid,
  534. skey: getApp().globalData.skey,
  535. creator_id: this.creatorId,
  536. conversation_id: this.conversationId,
  537. message_type: 2, // 2为图片
  538. content: '', // 图片消息content可为空
  539. media_url: imgUrl, // 图片地址
  540. zc_id: this.zcId
  541. },
  542. success: (res) => {
  543. if (res.data && res.data.success === 'yes') {
  544. this.fetchMessages(false);
  545. } else {
  546. uni.showToast({ title: res.data.str || '发送失败', icon: 'none' });
  547. }
  548. },
  549. fail: () => {
  550. uni.showToast({ title: '网络错误', icon: 'none' });
  551. }
  552. });
  553. },
  554. goDetails(item) {
  555. console.log(item,'item');
  556. let url = '';
  557. if (item.orderNo) {
  558. url='/pages/crowdFunding/orderDetails?id=' + item.orderNo;
  559. }else{
  560. url='/pages/crowdFunding/crowdfundingDetails?id=' + item.id;
  561. }
  562. uni.navigateTo({
  563. url: url
  564. });
  565. },
  566. getOrderCardData() {
  567. if (this.zcId) {
  568. uni.request({
  569. url: this.$apiHost + '/crowdfund/detail',
  570. method: 'GET',
  571. data: {
  572. id: this.zcId,
  573. uuid: getApp().globalData.uuid,
  574. skey: getApp().globalData.skey
  575. },
  576. success: (res) => {
  577. if (res.data && res.data.success === 'yes' && res.data.data) {
  578. this.orderCardData = res.data.data;
  579. console.log(this.orderCardData,'this.orderCardData');
  580. // 可根据接口返回字段设置isFavorite等
  581. }
  582. }
  583. });
  584. }
  585. },
  586. // 图片预览
  587. previewImage(url) {
  588. // 收集当前消息列表中的所有图片URL
  589. const imageUrls = this.chatList
  590. .filter(msg => msg.message_type === 2 && msg.media_url)
  591. .map(msg => msg.media_url);
  592. const currentIndex = imageUrls.indexOf(url);
  593. uni.previewImage({
  594. current: currentIndex >= 0 ? currentIndex : 0,
  595. urls: imageUrls
  596. });
  597. },
  598. },
  599. };
  600. </script>
  601. <style lang="scss">
  602. .customer-service-page {
  603. min-height: 100vh;
  604. background: #f2f6f2;
  605. display: flex;
  606. flex-direction: column;
  607. position: relative;
  608. .custom-navbar {
  609. display: flex;
  610. flex-direction: row;
  611. align-items: center;
  612. justify-content: space-between;
  613. height: 90rpx;
  614. padding: 0 20rpx;
  615. padding-top: var(--status-bar-height);
  616. background-color: #ffffff;
  617. position: sticky;
  618. top: 0;
  619. height: calc(90rpx + var(--status-bar-height));
  620. z-index: 100;
  621. .navbar-left {
  622. height: 80rpx;
  623. display: flex;
  624. align-items: center;
  625. justify-content: center;
  626. .fa-angle-left {
  627. font-size: 48rpx;
  628. color: #333;
  629. }
  630. .navbar-title {
  631. max-width: 450rpx;
  632. font-family: "PingFang SC-Bold";
  633. font-weight: 400;
  634. font-size: 32rpx;
  635. color: #1f1f1f;
  636. padding-left: 20rpx;
  637. }
  638. }
  639. .navbar-right {
  640. width: 80rpx;
  641. height: 80rpx;
  642. display: flex;
  643. justify-content: center;
  644. align-items: center;
  645. .fa-ellipsis-h {
  646. font-size: 36rpx;
  647. color: #333;
  648. }
  649. }
  650. }
  651. .cs-chat-list {
  652. flex: 1;
  653. padding: 24rpx 0 0 0;
  654. overflow-y: auto;
  655. background: #f6f7f9;
  656. .cs-msg-item {
  657. display: flex;
  658. // align-items: flex-end;
  659. margin-bottom: 18rpx;
  660. padding: 0 24rpx;
  661. &.cs-msg-other {
  662. flex-direction: row;
  663. .cs-avatar {
  664. margin-right: 12rpx;
  665. }
  666. .cs-msg-bubble {
  667. background: #fff;
  668. color: #1f1f1f;
  669. border-top-left-radius: 0;
  670. border-top-right-radius: 12rpx;
  671. border-bottom-left-radius: 12rpx;
  672. border-bottom-right-radius: 12rpx;
  673. }
  674. }
  675. &.cs-msg-self {
  676. flex-direction: row-reverse;
  677. .cs-avatar {
  678. margin-left: 12rpx;
  679. }
  680. .cs-msg-bubble {
  681. background: #e6f6d9;
  682. color: #1f1f1f;
  683. border-top-right-radius: 0;
  684. border-top-left-radius: 12rpx;
  685. border-bottom-left-radius: 12rpx;
  686. border-bottom-right-radius: 12rpx;
  687. }
  688. }
  689. .cs-avatar {
  690. width: 64rpx;
  691. height: 64rpx;
  692. border-radius: 50%;
  693. }
  694. .cs-msg-bubble {
  695. max-width: 70vw;
  696. min-height: 40rpx;
  697. font-size: 28rpx;
  698. padding: 18rpx 24rpx;
  699. word-break: break-all;
  700. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  701. margin-bottom: 2rpx;
  702. display: flex;
  703. align-items: center;
  704. }
  705. }
  706. .cs-time-bar {
  707. display: flex;
  708. justify-content: center;
  709. align-items: center;
  710. margin: 18rpx 0 12rpx 0;
  711. .cs-time-inner {
  712. background: #fff;
  713. color: #b2b2b2;
  714. font-size: 24rpx;
  715. border-radius: 16rpx;
  716. padding: 8rpx 24rpx;
  717. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 2604);
  718. display: inline-block;
  719. }
  720. }
  721. }
  722. .order-card {
  723. background: #fff;
  724. border-radius: 20rpx;
  725. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  726. padding: 24rpx 24rpx 18rpx 24rpx;
  727. margin: 24rpx;
  728. position: absolute;
  729. top: -26rpx;
  730. transform: translateY(-100%);
  731. font-size: 28rpx;
  732. width: 670rpx;
  733. .order-card-header {
  734. display: flex;
  735. align-items: flex-start;
  736. position: relative;
  737. .order-card-img {
  738. width: 100rpx;
  739. height: 100rpx;
  740. border-radius: 12rpx;
  741. margin-right: 18rpx;
  742. flex-shrink: 0;
  743. }
  744. .order-card-info {
  745. flex: 1;
  746. display: flex;
  747. flex-direction: column;
  748. justify-content: flex-start;
  749. .order-card-title {
  750. font-size: 30rpx;
  751. color: #1f1f1f;
  752. font-weight: 500;
  753. margin-bottom: 18rpx;
  754. margin-top: 2rpx;
  755. line-height: 1.3;
  756. max-width: 450rpx;
  757. }
  758. .order-card-btn-box {
  759. display: flex;
  760. align-items: center;
  761. justify-content: flex-end;
  762. .order-card-btn {
  763. font-family: "PingFang SC-Bold";
  764. font-weight: 400;
  765. font-size: 24rpx;
  766. color: #acf934;
  767. background: #1f1f1f;
  768. border-radius: 128rpx;
  769. padding: 8rpx 14rpx;
  770. line-height: 1.2;
  771. margin: 0;
  772. }
  773. }
  774. }
  775. .order-card-close {
  776. position: absolute;
  777. right: -10rpx;
  778. top: -10rpx;
  779. font-size: 36rpx;
  780. color: #1f1f1f;
  781. background: #fff;
  782. border-radius: 50%;
  783. width: 34rpx;
  784. height: 34rpx;
  785. display: flex;
  786. align-items: center;
  787. justify-content: center;
  788. z-index: 2;
  789. }
  790. }
  791. .order-card-row {
  792. display: flex;
  793. align-items: center;
  794. margin-top: 12rpx;
  795. .order-card-label {
  796. color: #b2b2b2;
  797. font-size: 26rpx;
  798. width: 140rpx;
  799. flex-shrink: 0;
  800. }
  801. .order-card-value {
  802. color: #1f1f1f;
  803. font-size: 26rpx;
  804. margin-left: 12rpx;
  805. word-break: break-all;
  806. }
  807. }
  808. }
  809. .cs-input-bar {
  810. display: flex;
  811. align-items: center;
  812. background: #fff;
  813. padding: 12rpx 16rpx;
  814. border-top: 1rpx solid #ededed;
  815. position: fixed;
  816. left: 0;
  817. right: 0;
  818. bottom: 0;
  819. z-index: 10;
  820. padding-bottom: calc(12rpx + var(--window-bottom));
  821. .fake-input-bar {
  822. display: flex;
  823. align-items: center;
  824. background: #f6f7f9;
  825. border-radius: 24rpx;
  826. padding: 12rpx 20rpx;
  827. margin: 0 12rpx;
  828. flex: 1;
  829. min-height: 64rpx;
  830. border: 1rpx solid #ededed;
  831. .fake-input-placeholder {
  832. color: #bbb;
  833. font-size: 28rpx;
  834. flex: 1;
  835. }
  836. .fake-input-icons {
  837. display: flex;
  838. align-items: center;
  839. }
  840. }
  841. .fake-input-icon {
  842. width: 40rpx;
  843. height: 40rpx;
  844. margin-left: 16rpx;
  845. }
  846. .cs-input-area {
  847. display: flex;
  848. align-items: flex-end;
  849. flex-direction: column;
  850. background: #fff;
  851. border-radius: 32rpx;
  852. padding: 8rpx 12rpx;
  853. flex: 1;
  854. .cs-textarea {
  855. flex: 1;
  856. min-height: 64rpx;
  857. max-height: 120rpx;
  858. overflow-y: auto;
  859. border: none;
  860. font-size: 28rpx;
  861. background: #f6f7f9;
  862. border-radius: 24rpx;
  863. padding: 12rpx 20rpx;
  864. resize: none;
  865. width: 100%;
  866. }
  867. .bottom-bar {
  868. width: 100%;
  869. padding: 12rpx 0;
  870. display: flex;
  871. align-items: center;
  872. justify-content: space-between;
  873. }
  874. .send_btn {
  875. background: #a6e22e;
  876. color: #fff;
  877. border-radius: 32rpx;
  878. font-size: 28rpx;
  879. padding: 26rpx 32rpx;
  880. line-height: 0;
  881. border: 1rpx solid transparent;
  882. &.prohibit {
  883. background: #fff;
  884. border: 1rpx solid #999;
  885. color: #999;
  886. }
  887. }
  888. }
  889. }
  890. .emoji-panel {
  891. position: fixed;
  892. left: 0;
  893. right: 0;
  894. bottom: 0;
  895. z-index: 1000;
  896. width: 100vw;
  897. height: 100vh;
  898. &.show {
  899. transform: translateY(0);
  900. }
  901. .emoji-mask {
  902. position: fixed;
  903. left: 0;
  904. right: 0;
  905. top: 0;
  906. bottom: 0;
  907. background: rgba(0, 0, 0, 0.1);
  908. z-index: 1001;
  909. }
  910. .emoji-grid {
  911. position: relative;
  912. z-index: 1002;
  913. display: flex;
  914. flex-wrap: wrap;
  915. justify-content: center;
  916. padding-bottom: 24rpx;
  917. max-height: 50vh;
  918. width: 100vw;
  919. border-top: 1rpx solid #ededed;
  920. background: #fff;
  921. padding: 12rpx 0 0 0;
  922. box-shadow: 0 -4rpx 24rpx rgba(0, 0, 0, 0.08);
  923. overflow-y: auto;
  924. transform: translateY(100%);
  925. transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1);
  926. border-top: 20rpx solid #fff;
  927. .emoji-item {
  928. width: 60rpx;
  929. height: 60rpx;
  930. display: flex;
  931. align-items: center;
  932. justify-content: center;
  933. font-size: 36rpx;
  934. color: #333;
  935. margin: 8rpx;
  936. border-radius: 8rpx;
  937. padding: 8rpx;
  938. }
  939. }
  940. }
  941. .cs-msg-order-card-box {
  942. display: flex;
  943. flex-direction: row-reverse;
  944. .order-card-avatar {
  945. width: 64rpx;
  946. height: 64rpx;
  947. border-radius: 50%;
  948. margin-left: 12rpx;
  949. margin-right: 24rpx;
  950. }
  951. .cs-msg-order-card {
  952. position: relative;
  953. display: flex;
  954. flex-direction: row;
  955. align-items: flex-start;
  956. background: #fff;
  957. border-radius: 20rpx;
  958. box-shadow: 0 2rpx 8rpx rgba(0, 0, 0, 0.04);
  959. padding: 24rpx 24rpx 18rpx 24rpx;
  960. margin: 24rpx 0 0 0;
  961. width: 600rpx;
  962. min-height: 160rpx;
  963. .order-card-img {
  964. width: 100rpx;
  965. height: 100rpx;
  966. border-radius: 12rpx;
  967. margin-right: 18rpx;
  968. flex-shrink: 0;
  969. }
  970. .order-card-info {
  971. flex: 1;
  972. display: flex;
  973. flex-direction: column;
  974. justify-content: flex-start;
  975. .order-card-title {
  976. font-size: 30rpx;
  977. color: #1f1f1f;
  978. font-weight: 500;
  979. margin-bottom: 18rpx;
  980. margin-top: 2rpx;
  981. line-height: 1.3;
  982. max-width: 350rpx;
  983. word-break: break-all;
  984. }
  985. .order-card-btn-box {
  986. display: flex;
  987. align-items: center;
  988. justify-content: flex-end;
  989. margin-top: 12rpx;
  990. .order-card-btn {
  991. font-family: "PingFang SC-Bold";
  992. font-weight: 400;
  993. font-size: 24rpx;
  994. color: #1f1f1f;
  995. background: #acf934;
  996. border-radius: 128rpx;
  997. padding: 8rpx 24rpx;
  998. line-height: 1.2;
  999. margin: 0;
  1000. }
  1001. }
  1002. }
  1003. .order-card-row {
  1004. display: flex;
  1005. align-items: center;
  1006. margin-top: 8rpx;
  1007. .order-card-label {
  1008. color: #b2b2b2;
  1009. font-size: 26rpx;
  1010. width: 140rpx;
  1011. flex-shrink: 0;
  1012. }
  1013. .order-card-value {
  1014. color: #1f1f1f;
  1015. font-size: 26rpx;
  1016. margin-left: 12rpx;
  1017. word-break: break-all;
  1018. }
  1019. }
  1020. }
  1021. }
  1022. .dropdown-menu {
  1023. position: absolute;
  1024. top: calc(100% + 10rpx);
  1025. right: 20rpx;
  1026. background-color: #ffffff;
  1027. border-radius: 20rpx;
  1028. padding: 0;
  1029. width: 200rpx;
  1030. box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
  1031. z-index: 100;
  1032. transform-origin: top right;
  1033. animation: dropdownAnimation 0.2s ease-out;
  1034. overflow: hidden;
  1035. .dropdown-item {
  1036. padding: 24rpx 0;
  1037. color: #333333;
  1038. font-size: 28rpx;
  1039. position: relative;
  1040. text-align: center;
  1041. &:not(:last-child)::after {
  1042. content: '';
  1043. position: absolute;
  1044. left: 0;
  1045. right: 0;
  1046. bottom: 0;
  1047. height: 1rpx;
  1048. background-color: #EEEEEE;
  1049. }
  1050. &:active {
  1051. background-color: #f8f8f8;
  1052. }
  1053. }
  1054. }
  1055. @keyframes dropdownAnimation {
  1056. 0% {
  1057. opacity: 0;
  1058. transform: scale(0.95) translateY(-5rpx);
  1059. }
  1060. 100% {
  1061. opacity: 1;
  1062. transform: scale(1) translateY(0);
  1063. }
  1064. }
  1065. }
  1066. </style>