refundOrder.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  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.utils.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. console.log(e.detail.value)
  164. this.reasons = this.reasonsList[e.detail.value].dictLabel
  165. },
  166. submit(){
  167. if(this.reasons == "请选择"){
  168. uni.showToast({
  169. icon: 'none',
  170. title: '请选择原因'
  171. });
  172. return;
  173. }
  174. // 直接使用 this.items,因为已经在 onLoad 中解析过了
  175. if (!Array.isArray(this.items)) {
  176. uni.showToast({
  177. icon: 'none',
  178. title: '商品数据异常'
  179. });
  180. return;
  181. }
  182. var productIds = this.items.map(item => item.productId);
  183. var nums = this.items.map(item => item.num);
  184. var products = [];
  185. for(var i = 0; i < productIds.length; i++){
  186. var item = {productId: productIds[i], num: nums[i]};
  187. products.push(item);
  188. }
  189. var data = {
  190. refundAmount: this.refundAmount,
  191. orderCode: this.orderCode,
  192. serviceType: this.type,
  193. reasons: this.reasons,
  194. explains: this.explains,
  195. productList: products
  196. };
  197. applyAfterSales(data).then(res => {
  198. if(res.code == 200){
  199. uni.showToast({
  200. icon: 'success',
  201. title: '提交成功'
  202. });
  203. setTimeout(function() {
  204. uni.$emit('refreshOrder');
  205. uni.navigateBack({
  206. delta: 1
  207. })
  208. }, 500);
  209. } else {
  210. uni.showToast({
  211. icon: 'none',
  212. title: res.msg
  213. });
  214. }
  215. });
  216. },
  217. }
  218. }
  219. </script>
  220. <style lang="scss">
  221. .content{
  222. margin-bottom: 170upx;
  223. .inner{
  224. padding: 20upx;
  225. .drug-list{
  226. .item{
  227. background: #FFFFFF;
  228. border-radius: 16upx;
  229. margin-bottom: 20upx;
  230. padding: 0 30upx;
  231. .drug-info{
  232. display: flex;
  233. align-items: center;
  234. padding: 30upx 0;
  235. .img-box{
  236. width: 160upx;
  237. height: 160upx;
  238. margin-right: 30upx;
  239. image{
  240. width: 100%;
  241. height: 100%;
  242. }
  243. }
  244. .info{
  245. width: calc(100% - 160upx);
  246. height: 160upx;
  247. display: flex;
  248. flex-direction: column;
  249. justify-content: space-between;
  250. .top{
  251. .title{
  252. font-size: 28upx;
  253. font-family: PingFang SC;
  254. font-weight: 500;
  255. color: #111111;
  256. line-height: 1.4;
  257. .tag{
  258. display: inline-block;
  259. padding: 0 6upx;
  260. height: 30upx;
  261. background: linear-gradient(90deg, #66b2ef 0%, #2BC7B9 100%);
  262. border-radius: 4upx;
  263. margin-right: 10upx;
  264. font-size: 22upx;
  265. font-family: PingFang SC;
  266. font-weight: bold;
  267. color: #FFFFFF;
  268. line-height: 30upx;
  269. float: left;
  270. margin-top: 7upx;
  271. }
  272. }
  273. .spec{
  274. font-size: 24upx;
  275. font-family: PingFang SC;
  276. font-weight: 500;
  277. color: #999999;
  278. line-height: 1;
  279. margin-top: 14upx;
  280. }
  281. }
  282. .price-num{
  283. display: flex;
  284. align-items: center;
  285. justify-content: space-between;
  286. .price-box{
  287. display: flex;
  288. align-items: flex-end;
  289. .unit{
  290. font-size: 24upx;
  291. font-family: PingFang SC;
  292. font-weight: 500;
  293. color: #111111;
  294. line-height: 1.2;
  295. margin-right: 5upx;
  296. }
  297. .price{
  298. font-size: 32upx;
  299. font-family: PingFang SC;
  300. font-weight: 500;
  301. color: #111111;
  302. line-height: 1;
  303. }
  304. }
  305. .num{
  306. font-size: 24upx;
  307. font-family: PingFang SC;
  308. font-weight: bold;
  309. color: #666666;
  310. }
  311. }
  312. }
  313. }
  314. }
  315. }
  316. .reason-apply{
  317. margin-top: 20upx;
  318. background: #FFFFFF;
  319. border-radius: 16upx;
  320. padding: 0 30upx;
  321. .title-box{
  322. height: 86upx;
  323. display: flex;
  324. align-items: center;
  325. justify-content: space-between;
  326. border-bottom: 1px solid #F0F0F0;
  327. .label{
  328. font-size: 30upx;
  329. font-family: PingFang SC;
  330. font-weight: bold;
  331. color: #333333;
  332. }
  333. .money{
  334. font-size: 24upx;
  335. font-family: PingFang SC;
  336. font-weight: 500;
  337. color: #999999;
  338. }
  339. .chose-box{
  340. display: flex;
  341. align-items: center;
  342. .text{
  343. font-size: 24upx;
  344. font-family: PingFang SC;
  345. font-weight: 500;
  346. color: #999999;
  347. }
  348. image{
  349. width: 14upx;
  350. height: 24upx;
  351. margin-left: 10upx;
  352. }
  353. }
  354. }
  355. .textarea-box{
  356. padding: 30upx 0;
  357. textarea{
  358. width: 100%;
  359. box-sizing: border-box;
  360. background: #F5F5F5;
  361. border-radius: 16upx;
  362. padding: 30upx 20upx;
  363. font-size: 24upx;
  364. font-family: PingFang SC;
  365. font-weight: 500;
  366. color: #111111;
  367. }
  368. .textarea-place{
  369. font-size: 24upx;
  370. font-family: PingFang SC;
  371. font-weight: 500;
  372. color: #999999;
  373. }
  374. }
  375. }
  376. .return-method{
  377. background: #FFFFFF;
  378. border-radius: 16upx;
  379. margin-top: 20upx;
  380. padding: 0 30upx 40upx;
  381. .title-box{
  382. height: 86upx;
  383. display: flex;
  384. align-items: center;
  385. justify-content: space-between;
  386. border-bottom: 1px solid #F0F0F0;
  387. .text{
  388. font-size: 30upx;
  389. font-family: PingFang SC;
  390. font-weight: bold;
  391. color: #333333;
  392. }
  393. }
  394. .return-tips{
  395. margin-top: 30upx;
  396. margin-bottom: 30upx;
  397. height: 80upx;
  398. background: #FFF4E6;
  399. border-radius: 16upx;
  400. padding: 0 20upx;
  401. display: flex;
  402. align-items: center;
  403. .text{
  404. font-size: 24upx;
  405. font-family: PingFang SC;
  406. font-weight: 500;
  407. color: #EF8A07;
  408. }
  409. }
  410. .info-item{
  411. display: flex;
  412. align-items: center;
  413. justify-content: space-between;
  414. margin-bottom: 40upx;
  415. &:last-child{
  416. margin-bottom: 0;
  417. }
  418. .label{
  419. font-size: 26upx;
  420. font-family: PingFang SC;
  421. font-weight: 500;
  422. color: #666666;
  423. line-height: 1;
  424. }
  425. .text{
  426. font-size: 26upx;
  427. font-family: PingFang SC;
  428. font-weight: 500;
  429. color: #111111;
  430. line-height: 1;
  431. }
  432. .detail-box{
  433. display: flex;
  434. align-items: center;
  435. .price-box{
  436. display: flex;
  437. align-items: flex-end;
  438. margin-right: 18upx;
  439. .unit{
  440. font-size: 24upx;
  441. font-family: PingFang SC;
  442. font-weight: 500;
  443. color: #111111;
  444. line-height: 1.2;
  445. }
  446. .num{
  447. font-size: 32upx;
  448. font-family: PingFang SC;
  449. font-weight: bold;
  450. color: #111111;
  451. line-height: 1;
  452. }
  453. }
  454. .det-text{
  455. font-size: 26upx;
  456. font-family: PingFang SC;
  457. font-weight: 500;
  458. color: #111111;
  459. }
  460. image{
  461. width: 14upx;
  462. height: 24upx;
  463. margin-left: 10upx;
  464. }
  465. }
  466. }
  467. }
  468. }
  469. .reson-box{
  470. padding: 0 10upx 60upx;
  471. .reson-item{
  472. width: 100%;
  473. height: 110upx;
  474. display: flex;
  475. align-items: center;
  476. justify-content: space-between;
  477. .title{
  478. font-size: 30upx;
  479. font-family: PingFang SC;
  480. font-weight: 500;
  481. color: #111111;
  482. }
  483. }
  484. }
  485. }
  486. .btn-box{
  487. height: 120upx;
  488. padding: 0 30upx;
  489. display: flex;
  490. align-items: center;
  491. justify-content: center;
  492. .sub-btn{
  493. width: 100%;
  494. height: 88upx;
  495. line-height: 88upx;
  496. text-align: center;
  497. font-size: 30upx;
  498. font-family: PingFang SC;
  499. font-weight: bold;
  500. color: #FFFFFF;
  501. background: #2BC7B9;
  502. border-radius: 44upx;
  503. }
  504. }
  505. input{
  506. text-align: right;
  507. }
  508. .form-input{
  509. font-size: 30upx;
  510. font-family: PingFang SC;
  511. font-weight: 500;
  512. color: #999999;
  513. text-align: right;
  514. }
  515. </style>