customerService.vue 33 KB

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