customerService.vue 33 KB

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