complaint.vue 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  1. <template>
  2. <view class="complaint-page">
  3. <template v-if="showComplaintList">
  4. <!-- 处理状态展示 -->
  5. <view class="status-block"
  6. v-if="complaintInfo.disposeLogList && complaintInfo.disposeLogList.length > 0 && complaintInfo.disposeLogList[0].userType == 1">
  7. <view class="status-title">书嗨处理</view>
  8. <view class="time">--</view>
  9. <view class="status-info">
  10. <view class="info-row">
  11. <text class="label">处理状态:</text>
  12. <text class="value status-text">{{ complaintStatusText }}</text>
  13. </view>
  14. <view class="info-row">
  15. <text class="label">平台回复:</text>
  16. <text class="value">{{ complaintInfo.description || "暂无" }}</text>
  17. </view>
  18. </view>
  19. </view>
  20. <!-- 处理记录时间轴 -->
  21. <view class="complaint-records">
  22. <!-- 我的投诉 -->
  23. <view class="complaint-item" v-for="(item, index) in complaintInfo.disposeLogList" :key="index">
  24. <view class="complaint-header">
  25. <view class="header-main">
  26. <text class="title">{{ item.userType == 1 ? "我的投诉" : "客服回复" }}</text>
  27. <text class="time">{{ item.createTime }}</text>
  28. </view>
  29. </view>
  30. <view class="complaint-content">
  31. <view class="info-row" v-if="item.reason">
  32. <text class="label">投诉原因:</text>
  33. <text class="value">{{ item.reason }}</text>
  34. </view>
  35. <view class="info-row" v-if="item.contactNumber">
  36. <text class="label">联系方式:</text>
  37. <text class="value">{{ item.contactNumber }}</text>
  38. </view>
  39. <view class="info-row">
  40. <text class="label">投诉说明:</text>
  41. <text class="value">{{ item.description }}</text>
  42. </view>
  43. <view class="info-row image-list" v-if="item.imgList && item.imgList.length">
  44. <text class="label">上传凭证:</text>
  45. <view class="images">
  46. <image v-for="(img, imgIndex) in item.imgList" :key="imgIndex" :src="img"
  47. mode="aspectFill" @click="previewImage(item.imgList, imgIndex)">
  48. </image>
  49. </view>
  50. </view>
  51. </view>
  52. </view>
  53. </view>
  54. <view class="bottom-fixed-con"
  55. v-if="complaintInfo.complaintsStatus == 2 && complaintInfo.disposeLogList && complaintInfo.disposeLogList.length > 0 && complaintInfo.disposeLogList[0].userType == 2">
  56. <u-button type="primary" @click="continueComplaint">继续投诉</u-button>
  57. </view>
  58. </template>
  59. <!-- 新投诉表单,仅在status为1时显示 -->
  60. <template v-else>
  61. <!-- 表单区域 -->
  62. <view class="form-block">
  63. <!-- 投诉原因 -->
  64. <view class="form-item flex-a">
  65. <view class="common-text-2 required">投诉原因</view>
  66. <view class="input-wrapper flex-1" @click="showReasonPicker">
  67. <text class="placeholder" v-if="!complaintReason">请选择投诉原因</text>
  68. <text v-else>{{ complaintReason }}</text>
  69. <u-icon name="arrow-right" color="#333" size="32" top="3rpx"></u-icon>
  70. </view>
  71. </view>
  72. </view>
  73. <!-- 相关订单 (新增部分,匹配原型) -->
  74. <view class="form-block order-block" v-if="orderInfo">
  75. <view class="common-text-2 mb-20">相关订单</view>
  76. <view class="order-item flex">
  77. <image class="goods-img" :src="orderInfo.goodsImg" mode="aspectFill"></image>
  78. <view class="goods-info flex-1">
  79. <view class="goods-name u-line-2">{{ orderInfo.goodsName }}</view>
  80. <view class="goods-price">¥{{ orderInfo.goodsPrice }}</view>
  81. </view>
  82. <!-- 简单的步进器展示或者数量 -->
  83. <!-- 原型右下角有步进器,这里只展示数量即可,因为是投诉整个订单或其中商品 -->
  84. <view class="goods-num">x{{ orderInfo.goodsNum }}</view>
  85. </view>
  86. </view>
  87. <view class="common-text-2 required mb-20">上传凭证(最多3张)</view>
  88. <u-upload class="upload-image" :fileList="fileList" @on-choose-complete="afterRead" @delete="deletePic"
  89. :maxCount="3" :auto-upload="false" :previewFullImage="true" uploadText="点击上传"
  90. @on-uploaded="onUploaded"></u-upload>
  91. <view class="common-text-2 required mb-20 mt-20">投诉说明</view>
  92. <view class="form-block" style="padding: 20rpx">
  93. <!-- 投诉说明 -->
  94. <u-input v-model="description" type="textarea" placeholder="描述具体情况,有助于客服更快处理" :height="200"
  95. :border="false" maxlength="300"></u-input>
  96. <view class="text-right" style="color: #999; font-size: 24rpx;">{{ description.length }}/300</view>
  97. </view>
  98. <view class="form-block mt-20">
  99. <!-- 联系方式 -->
  100. <view class="form-item flex-a" style="padding: 14rpx 0">
  101. <view class="common-text-2 required">联系电话</view>
  102. <u-input class="flex-1" input-align="right" placeholder-style="color:#999;font-size:28rpx;"
  103. v-model="phone" placeholder="请输入联系方式" :border="false" type="number" maxlength="11"></u-input>
  104. </view>
  105. </view>
  106. <!-- 底部按钮 -->
  107. <view class="bottom-fixed-con">
  108. <u-button type="primary" :custom-style="submitBtnStyle" @click="submitComplaint">提交</u-button>
  109. </view>
  110. <!-- 投诉原因选择器 -->
  111. <u-picker v-model="showPicker" mode="selector" :range="reasonList" @confirm="confirmReason"
  112. @cancel="showPicker = false"></u-picker>
  113. </template>
  114. </view>
  115. </template>
  116. <script>
  117. import ENV_CONFIG from "@/.env.js";
  118. // api前缀
  119. const env = ENV_CONFIG[process.env.ENV_TYPE || "dev"];
  120. export default {
  121. data() {
  122. return {
  123. showComplaintList: false,
  124. complaintReason: "",
  125. phone: "",
  126. description: "",
  127. fileList: [],
  128. showPicker: false,
  129. reasonList: [],
  130. orderId: "",
  131. complaintInfo: {
  132. status: 1,
  133. platformReply: "",
  134. disposeLogList: [],
  135. },
  136. orderInfo: null, // 用于展示相关订单信息
  137. uploadSuccessList: [],
  138. submitBtnStyle: {
  139. backgroundColor: '#38C148',
  140. color: '#fff',
  141. height: '88rpx',
  142. fontSize: '32rpx',
  143. borderRadius: '44rpx'
  144. }
  145. };
  146. },
  147. computed: {
  148. complaintStatusText() {
  149. const status = this.complaintInfo.complaintsStatus;
  150. const statusMap = {
  151. 0: "未投诉过",
  152. 1: "待处理",
  153. 2: "处理中",
  154. 3: "已完结",
  155. };
  156. return statusMap[status] || "未知状态";
  157. },
  158. },
  159. onLoad(ops) {
  160. if (ops.orderId) {
  161. this.orderId = ops.orderId;
  162. this.getComplaintInfo();
  163. }
  164. // 获取本地存储的订单信息用于展示
  165. const tempOrder = uni.getStorageSync('tempComplaintOrder');
  166. if (tempOrder && tempOrder.orderId == this.orderId) {
  167. // 提取第一个商品展示,或者根据业务逻辑展示
  168. // 假设展示第一个商品
  169. if (tempOrder.orderItemList && tempOrder.orderItemList.length > 0) {
  170. const item = tempOrder.orderItemList[0];
  171. this.orderInfo = {
  172. goodsImg: item.goodsCover || item.bookCover, // 适配不同字段
  173. goodsName: item.goodsName || item.bookName,
  174. goodsPrice: item.goodsPrice || item.price,
  175. goodsNum: item.goodsCount || item.count || 1
  176. }
  177. }
  178. // 预填联系方式
  179. if (tempOrder.address && tempOrder.address.phone) {
  180. this.phone = tempOrder.address.phone;
  181. }
  182. }
  183. this.getComplaintsOptions();
  184. },
  185. methods: {
  186. continueComplaint() {
  187. this.showComplaintList = false;
  188. },
  189. // 获取投诉信息
  190. getComplaintInfo() {
  191. // 修改为 shop/order 接口
  192. uni.$u.http.get(`/token/shop/order/getComplaintsInfo?orderId=${this.orderId}&type=1`).then((res) => {
  193. if (res.code === 200) {
  194. this.complaintInfo = res.data;
  195. this.showComplaintList = res.data.complaintsStatus != 0;
  196. }
  197. });
  198. },
  199. //根据code获取字典 /token/common/getDictOptions
  200. getDict(code) {
  201. return uni.$u.http.get("/token/common/getDictOptions?type=" + code);
  202. },
  203. //获取投诉选项 complaints_options
  204. getComplaintsOptions() {
  205. this.getDict("complaints_options").then((res) => {
  206. if (res.code === 200) {
  207. this.reasonList = res.data.map((item) => item.dictLabel);
  208. }
  209. });
  210. },
  211. showReasonPicker() {
  212. this.showPicker = true;
  213. },
  214. confirmReason(e) {
  215. this.complaintReason = this.reasonList[e[0]];
  216. this.showPicker = false;
  217. },
  218. onUploaded(lists, name) {
  219. console.log(lists, name, "xx111x");
  220. },
  221. afterRead(lists) {
  222. // 先检查token是否存在
  223. const token = uni.getStorageSync("token");
  224. const uploadTasks = lists.map((item) => {
  225. return new Promise((resolve, reject) => {
  226. // 修改为 shop/order 上传接口 (猜测路径,如果失败需确认)
  227. // 参考 getComplaintsInfo 是在 shop/order 下
  228. const uploadUrl = env.apiUrl + `/api/token/shop/order/complaintUpload/${this.orderId}`;
  229. console.log(item, uploadUrl, "xx111x");
  230. uni.uploadFile({
  231. url: uploadUrl,
  232. filePath: item.url,
  233. name: "file",
  234. header: {
  235. Authorization: "Bearer " + token,
  236. },
  237. success: (res) => {
  238. try {
  239. const result = JSON.parse(res.data);
  240. if (result.code === 200 && result.data) {
  241. resolve(result.data);
  242. } else {
  243. uni.$u.toast(result.msg || "上传失败");
  244. reject(new Error(result.msg || "上传失败"));
  245. }
  246. } catch (e) {
  247. reject(e);
  248. }
  249. },
  250. fail: (err) => {
  251. uni.$u.toast("上传失败");
  252. reject(err);
  253. },
  254. });
  255. });
  256. });
  257. Promise.all(uploadTasks)
  258. .then((results) => {
  259. this.uploadSuccessList = results.flat();
  260. this.fileList = lists;
  261. console.log(this.fileList, "xx111x", results);
  262. })
  263. .catch((err) => {
  264. console.error("Upload failed:", err);
  265. });
  266. },
  267. deletePic(event) {
  268. this.fileList.splice(event.index, 1);
  269. // 同时也需要从 uploadSuccessList 中移除
  270. if (this.uploadSuccessList && this.uploadSuccessList.length > event.index) {
  271. this.uploadSuccessList.splice(event.index, 1);
  272. }
  273. },
  274. submitComplaint() {
  275. if (!this.complaintReason) {
  276. return uni.$u.toast("请选择投诉原因");
  277. }
  278. // 移除图片必填校验,或者根据需求决定。原型上写着“上传凭证”,一般非必填,但这里保持逻辑一致
  279. // if (this.fileList.length === 0) { ... }
  280. if (!this.description) {
  281. return uni.$u.toast("请输入投诉说明");
  282. }
  283. if (!this.phone) {
  284. return uni.$u.toast("请输入联系方式");
  285. }
  286. // 准备投诉数据
  287. const complaintData = {
  288. orderId: this.orderId,
  289. reason: this.complaintReason,
  290. description: this.description,
  291. contactNumber: this.phone,
  292. fileUrls: this.uploadSuccessList || [],
  293. };
  294. // 提交投诉 - 修改为 shop/order 接口
  295. uni.$u.http.post("/token/shop/order/addComplaints", complaintData).then((res) => {
  296. if (res.code === 200) {
  297. uni.$u.toast("投诉上报已上报给管理员");
  298. // 返回订单页
  299. setTimeout(() => {
  300. uni.navigateBack({
  301. delta: 1,
  302. });
  303. }, 1500);
  304. } else {
  305. uni.$u.toast(res.msg || "提交失败");
  306. }
  307. });
  308. },
  309. // 图片预览
  310. previewImage(urls, current) {
  311. uni.previewImage({
  312. urls: urls,
  313. current: current,
  314. });
  315. },
  316. },
  317. };
  318. </script>
  319. <style lang="scss" scoped>
  320. .complaint-page {
  321. min-height: 100vh;
  322. background: #f8f8f8;
  323. padding: 20rpx;
  324. padding-bottom: 120rpx;
  325. .status-block {
  326. background: #ffffff;
  327. border-radius: 12rpx;
  328. padding: 30rpx;
  329. margin-bottom: 20rpx;
  330. .status-title {
  331. font-size: 32rpx;
  332. font-weight: 600;
  333. color: #222;
  334. }
  335. .status-info {
  336. .info-row {
  337. display: flex;
  338. font-size: 28rpx;
  339. line-height: 48rpx;
  340. .label {
  341. color: #333;
  342. min-width: 140rpx;
  343. }
  344. .value {
  345. color: #333;
  346. flex: 1;
  347. }
  348. .status-text {
  349. color: #ff5b5b;
  350. }
  351. }
  352. }
  353. }
  354. .complaint-records {
  355. .complaint-item {
  356. background: #ffffff;
  357. border-radius: 12rpx;
  358. padding: 30rpx;
  359. margin-bottom: 20rpx;
  360. .complaint-header {
  361. margin-bottom: 24rpx;
  362. .header-main {
  363. display: flex;
  364. flex-direction: column;
  365. gap: 8rpx;
  366. .title {
  367. font-size: 32rpx;
  368. font-weight: 600;
  369. color: #222222;
  370. }
  371. .time {
  372. font-size: 26rpx;
  373. color: #999;
  374. }
  375. }
  376. }
  377. .complaint-content {
  378. .info-row {
  379. display: flex;
  380. margin-bottom: 16rpx;
  381. font-size: 28rpx;
  382. line-height: 1.5;
  383. .label {
  384. color: #333;
  385. white-space: nowrap;
  386. }
  387. .value {
  388. color: #333;
  389. flex: 1;
  390. }
  391. }
  392. .image-list {
  393. .label {
  394. display: block;
  395. font-size: 28rpx;
  396. color: #333;
  397. margin-bottom: 16rpx;
  398. }
  399. .images {
  400. display: flex;
  401. flex-wrap: wrap;
  402. gap: 20rpx;
  403. image {
  404. width: 140rpx;
  405. height: 140rpx;
  406. border-radius: 8rpx;
  407. }
  408. }
  409. }
  410. }
  411. }
  412. }
  413. .form-block {
  414. background: #ffffff;
  415. border-radius: 12rpx;
  416. padding: 0 30rpx;
  417. margin-bottom: 20rpx;
  418. }
  419. .order-block {
  420. padding: 30rpx;
  421. .order-item {
  422. margin-top: 20rpx;
  423. .goods-img {
  424. width: 120rpx;
  425. height: 120rpx;
  426. border-radius: 8rpx;
  427. margin-right: 20rpx;
  428. background-color: #f5f5f5;
  429. }
  430. .goods-info {
  431. display: flex;
  432. flex-direction: column;
  433. justify-content: space-between;
  434. .goods-name {
  435. font-size: 28rpx;
  436. color: #333;
  437. }
  438. .goods-price {
  439. font-size: 28rpx;
  440. color: #333;
  441. font-weight: bold;
  442. }
  443. }
  444. .goods-num {
  445. font-size: 26rpx;
  446. color: #999;
  447. align-self: flex-end;
  448. }
  449. }
  450. }
  451. .required::before {
  452. content: "*";
  453. color: #ff5b5b;
  454. margin-right: 4rpx;
  455. }
  456. .form-item {
  457. padding: 30rpx 0;
  458. .input-wrapper {
  459. display: flex;
  460. justify-content: flex-end;
  461. align-items: center;
  462. font-size: 28rpx;
  463. color: #333;
  464. .placeholder {
  465. color: #999;
  466. }
  467. }
  468. }
  469. .common-text-2 {
  470. font-size: 28rpx;
  471. color: #333;
  472. font-weight: bold;
  473. }
  474. .mb-20 {
  475. margin-bottom: 20rpx;
  476. }
  477. .mt-20 {
  478. margin-top: 20rpx;
  479. }
  480. .text-right {
  481. text-align: right;
  482. }
  483. .bottom-fixed-con {
  484. position: fixed;
  485. bottom: 0;
  486. left: 0;
  487. width: 100%;
  488. background: #fff;
  489. padding: 20rpx 30rpx;
  490. padding-bottom: calc(20rpx + env(safe-area-inset-bottom));
  491. box-shadow: 0 -2rpx 10rpx rgba(0, 0, 0, 0.05);
  492. z-index: 100;
  493. }
  494. }
  495. .upload-image {
  496. ::v-deep .u-list-item {
  497. background: #ffffff !important;
  498. border: 2rpx dashed #ddd;
  499. }
  500. }
  501. </style>