refundOrder.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. <template>
  2. <view class="content">
  3. <view class="inner">
  4. <!-- 产品列表 -->
  5. <view class="drug-list">
  6. <view class="item">
  7. <!-- 产品信息 -->
  8. <!-- <view v-if="order!=null&&order.isPackage!=1" class="drug-info" v-for="(item,index) in items" :key="index"> -->
  9. <view class="drug-info" v-for="(item,index) in items" :key="index">
  10. <view class="img-box">
  11. <image :src="JSON.parse(item.jsonInfo).image" mode="aspectFit"></image>
  12. </view>
  13. <view class="info">
  14. <view class="top">
  15. <view class="title ellipsis2">{{ JSON.parse(item.jsonInfo).productName}}</view>
  16. <view class="spec">{{JSON.parse(item.jsonInfo).sku}}</view>
  17. </view>
  18. <view class="price-num">
  19. <view class="price-box">
  20. <text class="unit">¥</text>
  21. <text class="price">{{JSON.parse(item.jsonInfo).price.toFixed(2)}}</text>
  22. </view>
  23. <view class="num">x{{item.num}}</view>
  24. </view>
  25. </view>
  26. </view>
  27. <view v-if="order!=null&&order.isPackage==1&&order.packageJson!=null" class="drug-info">
  28. <view class="img-box">
  29. <image :src="JSON.parse(order.packageJson).imgUrl" mode="aspectFit"></image>
  30. </view>
  31. <view class="info">
  32. <view class="top">
  33. <view class="title ellipsis2">
  34. <view class="tag">套餐</view>{{JSON.parse(order.packageJson).title}}
  35. </view>
  36. <view class="spec">{{JSON.parse(order.packageJson).descs}}</view>
  37. </view>
  38. </view>
  39. </view>
  40. </view>
  41. </view>
  42. <!-- 申请原因 -->
  43. <view class="reason-apply">
  44. <view class="title-box">
  45. <text class="label">退款金额</text>
  46. <input class="money" type="text" disabled v-model="refundAmount" placeholder="退款金额" placeholder-class="form-input" />
  47. </view>
  48. <view class="title-box">
  49. <text class="label">申请原因</text>
  50. <picker @change="reasonsChange" :value="reasons" range-key="dictLabel" :range="reasonsList">
  51. <view class="chose-box" >
  52. <text class="text">{{reasons}}</text>
  53. <image src="https://jnlzjk-1323137866.cos.ap-chongqing.myqcloud.com/shop/images/arrow_gray.png" mode=""></image>
  54. </view>
  55. </picker>
  56. </view>
  57. <view class="textarea-box">
  58. <textarea v-model="explains" placeholder="请描述申请售后服务的具体原因" placeholder-class="textarea-place" />
  59. </view>
  60. </view>
  61. <!-- 退回方式 -->
  62. <!-- <view class="return-method">
  63. <view class="title-box">
  64. <text class="text">退货方式</text>
  65. <text class="text">用户发货</text>
  66. </view>
  67. <view class="return-tips">
  68. <text class="text">请您在审核通过后7天内,将商品发货到指定点</text>
  69. </view>
  70. <view class="info-item">
  71. <text class="label">联系人</text>
  72. <text class="text">张三 1572325612</text>
  73. </view>
  74. <view class="info-item">
  75. <text class="label">发货地址</text>
  76. <text class="text">重庆市江北区建玛特商场5楼</text>
  77. </view>
  78. </view> -->
  79. <!-- 底部按钮 -->
  80. <view class="btn-box">
  81. <view class="sub-btn" @click="submit()">申请售后</view>
  82. </view>
  83. </view>
  84. </view>
  85. </template>
  86. <script>
  87. import {applyAfterSales,getMyStoreOrderItemByOrderId} from '@/api/storeAfterSales'
  88. export default {
  89. data() {
  90. return {
  91. orderId:null,
  92. order:null,
  93. orderCode:null,
  94. items:[],
  95. type:null,
  96. reasonsList:[],
  97. reasons:"请选择",
  98. explains:"",
  99. // refundAmount:0.00,
  100. }
  101. },
  102. onLoad(option) {
  103. //console.log(option);
  104. this.type = option.type;
  105. this.orderCode = option.orderCode;
  106. // 统一在 onLoad 中解析数据
  107. try {
  108. // 如果 option.items 是字符串,解析为数组
  109. if (typeof option.items === 'string') {
  110. this.items = JSON.parse(option.items);
  111. } else {
  112. this.items = option.items || [];
  113. }
  114. //console.log("解析后的 items:", this.items);
  115. } catch (e) {
  116. console.error('解析 items 失败:', e);
  117. this.items = [];
  118. }
  119. this.reasonsList = this.$getDict("storeAfterSalesReasons");
  120. this.orderId = option.orderId;
  121. },
  122. computed: {
  123. refundAmount(){
  124. if(!this.items || !Array.isArray(this.items)) return 0;
  125. const total = this.items.reduce((sum, item) => {
  126. try {
  127. // 确保 jsonInfo 是对象,如果是字符串则解析
  128. const jsonInfo = typeof item.jsonInfo === 'string'
  129. ? JSON.parse(item.jsonInfo)
  130. : item.jsonInfo;
  131. return sum + (jsonInfo.price || 0) * (item.num || 0);
  132. } catch (e) {
  133. console.error('解析 jsonInfo 失败:', e);
  134. return sum;
  135. }
  136. }, 0);
  137. console.log('退款金额:', total);
  138. return total;
  139. }
  140. },
  141. methods: {
  142. getMyStoreOrderItemByOrderId(){
  143. var data={orderId:this.orderId};
  144. getMyStoreOrderItemByOrderId(data).then(res => {
  145. if(res.code==200){
  146. this.order=res.order;
  147. this.items=res.items;
  148. if(this.order.isPayRemain==0){
  149. this.refundAmount=this.order.payMoney.toFixed(2)
  150. }
  151. else{
  152. this.refundAmount=this.order.payPrice.toFixed(2)
  153. }
  154. }else{
  155. uni.showToast({
  156. icon:'none',
  157. title: "请求失败",
  158. });
  159. }
  160. });
  161. },
  162. reasonsChange(e) {
  163. const index = e.detail.value;
  164. // 🔥 安全判断:必须有值、必须在数组范围内
  165. if (index === undefined || !this.reasonsList || !this.reasonsList[index]) {
  166. this.reasons = "请选择";
  167. return;
  168. }
  169. this.reasons = this.reasonsList[e.detail.value].dictLabel
  170. },
  171. submit(){
  172. if(this.reasons == "请选择"){
  173. uni.showToast({
  174. icon: 'none',
  175. title: '请选择原因'
  176. });
  177. return;
  178. }
  179. // 直接使用 this.items,因为已经在 onLoad 中解析过了
  180. if (!Array.isArray(this.items)) {
  181. uni.showToast({
  182. icon: 'none',
  183. title: '商品数据异常'
  184. });
  185. return;
  186. }
  187. var productIds = this.items.map(item => item.productId);
  188. var nums = this.items.map(item => item.num);
  189. var products = [];
  190. for(var i = 0; i < productIds.length; i++){
  191. var item = {productId: productIds[i], num: nums[i]};
  192. products.push(item);
  193. }
  194. var data = {
  195. refundAmount: this.refundAmount,
  196. orderCode: this.orderCode,
  197. serviceType: this.type,
  198. reasons: this.reasons,
  199. explains: this.explains,
  200. productList: products
  201. };
  202. applyAfterSales(data).then(res => {
  203. if(res.code == 200){
  204. uni.showToast({
  205. icon: 'success',
  206. title: '提交成功'
  207. });
  208. setTimeout(function() {
  209. uni.$emit('refreshOrder');
  210. uni.navigateBack({
  211. delta: 1
  212. })
  213. }, 500);
  214. } else {
  215. uni.showToast({
  216. icon: 'none',
  217. title: res.msg
  218. });
  219. }
  220. });
  221. },
  222. }
  223. }
  224. </script>
  225. <style lang="scss">
  226. .content{
  227. margin-bottom: 170upx;
  228. .inner{
  229. padding: 20upx;
  230. .drug-list{
  231. .item{
  232. background: #FFFFFF;
  233. border-radius: 16upx;
  234. margin-bottom: 20upx;
  235. padding: 0 30upx;
  236. .drug-info{
  237. display: flex;
  238. align-items: center;
  239. padding: 30upx 0;
  240. .img-box{
  241. width: 160upx;
  242. height: 160upx;
  243. margin-right: 30upx;
  244. image{
  245. width: 100%;
  246. height: 100%;
  247. }
  248. }
  249. .info{
  250. width: calc(100% - 160upx);
  251. height: 160upx;
  252. display: flex;
  253. flex-direction: column;
  254. justify-content: space-between;
  255. .top{
  256. .title{
  257. font-size: 28upx;
  258. font-family: PingFang SC;
  259. font-weight: 500;
  260. color: #111111;
  261. line-height: 1.4;
  262. .tag{
  263. display: inline-block;
  264. padding: 0 6upx;
  265. height: 30upx;
  266. background: linear-gradient(90deg, #66b2ef 0%, #FF233C 100%);
  267. border-radius: 4upx;
  268. margin-right: 10upx;
  269. font-size: 22upx;
  270. font-family: PingFang SC;
  271. font-weight: bold;
  272. color: #FFFFFF;
  273. line-height: 30upx;
  274. float: left;
  275. margin-top: 7upx;
  276. }
  277. }
  278. .spec{
  279. font-size: 24upx;
  280. font-family: PingFang SC;
  281. font-weight: 500;
  282. color: #999999;
  283. line-height: 1;
  284. margin-top: 14upx;
  285. }
  286. }
  287. .price-num{
  288. display: flex;
  289. align-items: center;
  290. justify-content: space-between;
  291. .price-box{
  292. display: flex;
  293. align-items: flex-end;
  294. .unit{
  295. font-size: 24upx;
  296. font-family: PingFang SC;
  297. font-weight: 500;
  298. color: #111111;
  299. line-height: 1.2;
  300. margin-right: 5upx;
  301. }
  302. .price{
  303. font-size: 32upx;
  304. font-family: PingFang SC;
  305. font-weight: 500;
  306. color: #111111;
  307. line-height: 1;
  308. }
  309. }
  310. .num{
  311. font-size: 24upx;
  312. font-family: PingFang SC;
  313. font-weight: bold;
  314. color: #666666;
  315. }
  316. }
  317. }
  318. }
  319. }
  320. }
  321. .reason-apply{
  322. margin-top: 20upx;
  323. background: #FFFFFF;
  324. border-radius: 16upx;
  325. padding: 0 30upx;
  326. .title-box{
  327. height: 86upx;
  328. display: flex;
  329. align-items: center;
  330. justify-content: space-between;
  331. border-bottom: 1px solid #F0F0F0;
  332. .label{
  333. font-size: 30upx;
  334. font-family: PingFang SC;
  335. font-weight: bold;
  336. color: #333333;
  337. }
  338. .money{
  339. font-size: 24upx;
  340. font-family: PingFang SC;
  341. font-weight: 500;
  342. color: #999999;
  343. }
  344. .chose-box{
  345. display: flex;
  346. align-items: center;
  347. .text{
  348. font-size: 24upx;
  349. font-family: PingFang SC;
  350. font-weight: 500;
  351. color: #999999;
  352. }
  353. image{
  354. width: 14upx;
  355. height: 24upx;
  356. margin-left: 10upx;
  357. }
  358. }
  359. }
  360. .textarea-box{
  361. padding: 30upx 0;
  362. textarea{
  363. width: 100%;
  364. box-sizing: border-box;
  365. background: #F5F5F5;
  366. border-radius: 16upx;
  367. padding: 30upx 20upx;
  368. font-size: 24upx;
  369. font-family: PingFang SC;
  370. font-weight: 500;
  371. color: #111111;
  372. }
  373. .textarea-place{
  374. font-size: 24upx;
  375. font-family: PingFang SC;
  376. font-weight: 500;
  377. color: #999999;
  378. }
  379. }
  380. }
  381. .return-method{
  382. background: #FFFFFF;
  383. border-radius: 16upx;
  384. margin-top: 20upx;
  385. padding: 0 30upx 40upx;
  386. .title-box{
  387. height: 86upx;
  388. display: flex;
  389. align-items: center;
  390. justify-content: space-between;
  391. border-bottom: 1px solid #F0F0F0;
  392. .text{
  393. font-size: 30upx;
  394. font-family: PingFang SC;
  395. font-weight: bold;
  396. color: #333333;
  397. }
  398. }
  399. .return-tips{
  400. margin-top: 30upx;
  401. margin-bottom: 30upx;
  402. height: 80upx;
  403. background: #FFF4E6;
  404. border-radius: 16upx;
  405. padding: 0 20upx;
  406. display: flex;
  407. align-items: center;
  408. .text{
  409. font-size: 24upx;
  410. font-family: PingFang SC;
  411. font-weight: 500;
  412. color: #EF8A07;
  413. }
  414. }
  415. .info-item{
  416. display: flex;
  417. align-items: center;
  418. justify-content: space-between;
  419. margin-bottom: 40upx;
  420. &:last-child{
  421. margin-bottom: 0;
  422. }
  423. .label{
  424. font-size: 26upx;
  425. font-family: PingFang SC;
  426. font-weight: 500;
  427. color: #666666;
  428. line-height: 1;
  429. }
  430. .text{
  431. font-size: 26upx;
  432. font-family: PingFang SC;
  433. font-weight: 500;
  434. color: #111111;
  435. line-height: 1;
  436. }
  437. .detail-box{
  438. display: flex;
  439. align-items: center;
  440. .price-box{
  441. display: flex;
  442. align-items: flex-end;
  443. margin-right: 18upx;
  444. .unit{
  445. font-size: 24upx;
  446. font-family: PingFang SC;
  447. font-weight: 500;
  448. color: #111111;
  449. line-height: 1.2;
  450. }
  451. .num{
  452. font-size: 32upx;
  453. font-family: PingFang SC;
  454. font-weight: bold;
  455. color: #111111;
  456. line-height: 1;
  457. }
  458. }
  459. .det-text{
  460. font-size: 26upx;
  461. font-family: PingFang SC;
  462. font-weight: 500;
  463. color: #111111;
  464. }
  465. image{
  466. width: 14upx;
  467. height: 24upx;
  468. margin-left: 10upx;
  469. }
  470. }
  471. }
  472. }
  473. }
  474. .reson-box{
  475. padding: 0 10upx 60upx;
  476. .reson-item{
  477. width: 100%;
  478. height: 110upx;
  479. display: flex;
  480. align-items: center;
  481. justify-content: space-between;
  482. .title{
  483. font-size: 30upx;
  484. font-family: PingFang SC;
  485. font-weight: 500;
  486. color: #111111;
  487. }
  488. }
  489. }
  490. }
  491. .btn-box{
  492. height: 120upx;
  493. padding: 0 30upx;
  494. display: flex;
  495. align-items: center;
  496. justify-content: center;
  497. .sub-btn{
  498. width: 100%;
  499. height: 88upx;
  500. line-height: 88upx;
  501. text-align: center;
  502. font-size: 30upx;
  503. font-family: PingFang SC;
  504. font-weight: bold;
  505. color: #FFFFFF;
  506. background: #FF233C;
  507. border-radius: 44upx;
  508. }
  509. }
  510. input{
  511. text-align: right;
  512. }
  513. .form-input{
  514. font-size: 30upx;
  515. font-family: PingFang SC;
  516. font-weight: 500;
  517. color: #999999;
  518. text-align: right;
  519. }
  520. </style>