refund.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. <template>
  2. <view class="refund-page">
  3. <!-- 商品选择卡片 -->
  4. <view class="card-section">
  5. <view class="section-title">
  6. <text class="title-text">退货商品</text>
  7. </view>
  8. <view class="product-list-compact">
  9. <template v-if="!$util.isEmpty(goodsInfoList)">
  10. <view class="product-row" v-for="(res,i) in goodsInfoList" :key="i">
  11. <view class="product-basic-info">
  12. <text class="product-name-compact">{{res.name}}</text>
  13. <view class="product-meta">
  14. <text class="stock-info">{{parseFloat(res.num)}}份 X ¥{{parseFloat(res.unitPrice)}}</text>
  15. <text class="available-info">可退 {{Number(res.num)-Number(res.refundNum)}}份</text>
  16. </view>
  17. </view>
  18. <view class="refund-control">
  19. <view class="refund-input-group">
  20. <view class="input-item">
  21. <text class="input-label">数量</text>
  22. <input
  23. class="refund-input-compact"
  24. type="number"
  25. placeholder="0"
  26. v-model="res.refundCount"
  27. placeholder-style="color:#ccc"
  28. @focus="clearRefundCount(res)" />
  29. <text class="unit-label">份</text>
  30. </view>
  31. <view class="input-item">
  32. <text class="input-label">单价</text>
  33. <input
  34. class="refund-input-compact"
  35. type="digit"
  36. placeholder="0.00"
  37. v-model="res.perPrice"
  38. placeholder-style="color:#ccc"
  39. @focus="clearPerPrice(res)" />
  40. <text class="unit-label">元</text>
  41. </view>
  42. </view>
  43. </view>
  44. </view>
  45. </template>
  46. <template v-if="!$util.isEmpty(itemInfoList)">
  47. <view class="product-row" v-for="(res,i) in itemInfoList" :key="i">
  48. <view class="product-basic-info">
  49. <text class="product-name-compact">{{res.name}}</text>
  50. <view class="product-meta">
  51. <text class="stock-info">{{parseFloat(res.num)}}{{res.unitName}} X ¥{{parseFloat(res.unitPrice)}}</text>
  52. <text class="available-info">可退 {{Number(res.num)-Number(res.refundNum)}}{{res.unitName}}</text>
  53. </view>
  54. </view>
  55. <view class="refund-control">
  56. <view class="refund-input-group">
  57. <view class="input-item">
  58. <text class="input-label">数量</text>
  59. <input
  60. class="refund-input-compact"
  61. type="number"
  62. placeholder="0"
  63. v-model="res.refundCount"
  64. placeholder-style="color:#ccc"
  65. @focus="clearRefundCount(res)" />
  66. <text class="unit-label">{{res.unitName}}</text>
  67. </view>
  68. <view class="input-item">
  69. <text class="input-label">单价</text>
  70. <input
  71. class="refund-input-compact"
  72. type="digit"
  73. placeholder="0.00"
  74. v-model="res.perPrice"
  75. placeholder-style="color:#ccc"
  76. @focus="clearPerPrice(res)" />
  77. <text class="unit-label">元</text>
  78. </view>
  79. </view>
  80. </view>
  81. </view>
  82. </template>
  83. </view>
  84. </view>
  85. <!-- 金额信息卡片 -->
  86. <view class="card-section">
  87. <view class="section-title">
  88. <text class="title-text">金额信息</text>
  89. </view>
  90. <view class="amount-info">
  91. <view class="amount-row">
  92. <text class="amount-label">订单金额</text>
  93. <view class="amount-value">
  94. <text class="price-text">¥{{parseFloat(orderInfo.orderPrice)||0}}</text>
  95. </view>
  96. </view>
  97. <view class="amount-row" v-if="Number(orderInfo.tkPrice)>0">
  98. <text class="amount-label">已退金额</text>
  99. <view class="amount-value">
  100. <text class="refunded-text">¥{{orderInfo.tkPrice ? parseFloat(orderInfo.tkPrice) : 0}}</text>
  101. </view>
  102. </view>
  103. <view class="amount-row">
  104. <text class="amount-label">可退金额</text>
  105. <text class="amount-value available-amount">¥{{coundRefundPrice}}</text>
  106. </view>
  107. <view class="amount-row input-row">
  108. <text class="amount-label required">退款金额</text>
  109. <view class="amount-input-wrapper">
  110. <text class="currency-symbol">¥</text>
  111. <input
  112. class="amount-input"
  113. type="digit"
  114. v-model="refundMoney"
  115. placeholder="请输入"
  116. placeholder-style="color:#999"
  117. @focus="clearRefundMoney">
  118. </view>
  119. </view>
  120. </view>
  121. </view>
  122. <!-- 退款方式选择卡片 -->
  123. <view class="card-section">
  124. <view class="section-title">
  125. <text class="title-text">库存变化</text>
  126. </view>
  127. <view class="refund-type-buttons">
  128. <button
  129. class="admin-button-com big"
  130. :class="refundType==1?'blue':'default'"
  131. @tap="refundType=1">
  132. 库存退回来
  133. </button>
  134. <button
  135. class="admin-button-com big"
  136. :class="refundType==2?'blue':'default'"
  137. @tap="refundType=2">
  138. 库存不退回
  139. </button>
  140. </view>
  141. </view>
  142. <!-- 备注卡片 -->
  143. <view class="card-section">
  144. <view class="section-title">
  145. <text class="title-text">备注</text>
  146. </view>
  147. <view class="remark-container">
  148. <textarea
  149. class="remark-textarea"
  150. v-model="remark"
  151. placeholder="选填"
  152. placeholder-style="color:#999"
  153. @focus="clearRemark" />
  154. </view>
  155. </view>
  156. <!-- 底部操作按钮 -->
  157. <view class="bottom-actions">
  158. <button class="action-btn cancel-btn" @tap="cancelRefund">取消</button>
  159. <button class="action-btn confirm-btn" @tap="confirmRefund">确认退款</button>
  160. </view>
  161. </view>
  162. </template>
  163. <script>
  164. import { getDetail,refund } from "@/api/order/index";
  165. export default {
  166. name: "orderDetail",
  167. components: {},
  168. data() {
  169. return {
  170. goodsInfoList:[],
  171. itemInfoList:[],
  172. refundMoney:0,
  173. refundType:0,
  174. remark:'',
  175. orderInfo:{},
  176. coundRefundPrice:0
  177. };
  178. },
  179. computed:{
  180. refundPrice(){
  181. let price = 0
  182. if(!this.$util.isEmpty(this.goodsInfoList)){
  183. for (const item of this.goodsInfoList) {
  184. if(Number(item.refundCount)>0){
  185. let currentPrice = Number(item.refundCount)*Number(item.perPrice || item.unitPrice)
  186. currentPrice.toFixed(2)
  187. price = Number(price) + Number(currentPrice)
  188. price.toFixed(2)
  189. }
  190. }
  191. }
  192. if(!this.$util.isEmpty(this.itemInfoList)){
  193. for (const item of this.itemInfoList) {
  194. if(Number(item.refundCount)>0){
  195. let currentPrice = Number(item.refundCount)*Number(item.perPrice || item.unitPrice)
  196. currentPrice.toFixed(2)
  197. price = Number(price) + Number(currentPrice)
  198. price.toFixed(2)
  199. }
  200. }
  201. }
  202. this.refundMoney = parseFloat(price.toFixed(2))
  203. return price
  204. }
  205. },
  206. methods: {
  207. clearRefundCount(item) {
  208. this.$set(item, 'refundCount', '');
  209. },
  210. clearPerPrice(item) {
  211. this.$set(item, 'perPrice', '');
  212. },
  213. clearRefundMoney() {
  214. this.refundMoney = '';
  215. },
  216. clearRemark() {
  217. this.remark = '';
  218. },
  219. cancelRefund(){
  220. uni.navigateBack({delta: 1});
  221. },
  222. confirmRefund(){
  223. let hasError = false
  224. let selectProduct = []
  225. let that = this
  226. if(!this.$util.isEmpty(this.goodsInfoList)){
  227. this.goodsInfoList.forEach(ele=>{
  228. let currentRefundCont = ele.refundCount ? Number(ele.refundCount) :0
  229. let currentNum = ele.num ? Number(ele.num) : 0
  230. let hasRefundNum = ele.refundNum ? Number(ele.refundNum) : 0
  231. let couldRefundNum = Number(currentNum) - Number(hasRefundNum)
  232. if(Number(currentRefundCont) > Number(couldRefundNum)){
  233. uni.showToast({title:ele.name+'超过可退数量',icon:'none'})
  234. hasError = true;
  235. return false
  236. }
  237. if(Number(ele.refundCount)>0){
  238. if(Number(ele.perPrice)>Number(ele.unitPrice)){
  239. uni.showToast({title:ele.name+' 退款单价不能大于原价',icon:'none'})
  240. hasError = true;
  241. return false
  242. }
  243. selectProduct.push({"productId":ele.goodsId,"num":ele.refundCount,"unitType":ele.unitType,unitName:ele.unitName,unitPrice:ele.perPrice || ele.unitPrice,property:0})
  244. }
  245. })
  246. }
  247. if(!this.$util.isEmpty(this.itemInfoList)){
  248. this.itemInfoList.forEach(ele=>{
  249. let currentRefundCont = ele.refundCount ? Number(ele.refundCount) :0
  250. let currentNum = ele.num ? Number(ele.num) : 0
  251. let hasRefundNum = ele.refundNum ? Number(ele.refundNum) : 0
  252. let couldRefundNum = Number(currentNum) - Number(hasRefundNum)
  253. if(Number(currentRefundCont) > Number(couldRefundNum)){
  254. uni.showToast({title:ele.name+'超过可退数量',icon:'none'})
  255. hasError = true;
  256. return false
  257. }
  258. if(Number(ele.refundCount)>0){
  259. if(Number(ele.perPrice)>Number(ele.unitPrice)){
  260. uni.showToast({title:ele.name+' 退款单价不能大于原价',icon:'none'})
  261. hasError = true;
  262. return false
  263. }
  264. selectProduct.push({"productId":ele.itemId,"num":ele.refundCount,"unitType":ele.unitType,unitName:ele.unitName,unitPrice:ele.perPrice || ele.unitPrice,property:1})
  265. }
  266. })
  267. }
  268. if(hasError){
  269. return
  270. }
  271. if(this.$util.isEmpty(selectProduct)){
  272. uni.showToast({title:'请选择商品',icon:'none'})
  273. return;
  274. }
  275. if(this.refundType==0){
  276. uni.showToast({title:'请选择 库存退否退回',icon:'none'})
  277. return false
  278. }
  279. let refundParams = {product:JSON.stringify(selectProduct),id: this.option.id,price:this.refundMoney,remark:this.remark,refundType:this.refundType,getOriginalItem:1,version:2}
  280. that.$util.confirmModal({content:'确认退款?'},() => {
  281. uni.showLoading({mask:true})
  282. refund(refundParams).then(res => {
  283. uni.hideLoading()
  284. if(res.code == 1){
  285. this.$util.pageTo({url:'/common/success',query:{titleType:1},type:2})
  286. }
  287. })
  288. })
  289. },
  290. async init() {
  291. const res = await getDetail({ id: this.option.id})
  292. this.orderInfo = res.data
  293. this.coundRefundPrice = Number(res.data.orderPrice) - Number(res.data.tkPrice)
  294. this.coundRefundPrice = this.coundRefundPrice.toFixed(2)
  295. this.coundRefundPrice = parseFloat(this.coundRefundPrice)
  296. this.goodsInfoList = res.data.goodsInfoList.map(ele=>{
  297. return {...ele,refundCount:null,perPrice:''}
  298. })
  299. this.itemInfoList = res.data.itemInfoList.map(ele=>{
  300. return {...ele,refundCount:null,perPrice:''}
  301. })
  302. }
  303. }
  304. };
  305. </script>
  306. <style lang="scss" scoped>
  307. .refund-page {
  308. min-height: 100vh;
  309. background: #f5f6f8;
  310. padding: 20upx 0 200upx;
  311. }
  312. // 卡片样式
  313. .card-section {
  314. background: #fff;
  315. margin: 0 20upx 20upx;
  316. border-radius: 16upx;
  317. box-shadow: 0 2upx 12upx rgba(0, 0, 0, 0.08);
  318. overflow: hidden;
  319. }
  320. // 节标题
  321. .section-title {
  322. padding: 30upx 30upx 20upx;
  323. border-bottom: 1upx solid #f0f0f0;
  324. display: flex;
  325. align-items: center;
  326. .title-text {
  327. font-size: 32upx;
  328. font-weight: 600;
  329. color: #333;
  330. }
  331. .required-mark {
  332. color: #ff4757;
  333. font-size: 32upx;
  334. margin-left: 8upx;
  335. }
  336. }
  337. // 退款方式按钮
  338. .refund-type-buttons {
  339. padding: 30upx 30upx 20upx;
  340. display: flex;
  341. gap: 30upx;
  342. .admin-button-com {
  343. flex: 1;
  344. border-radius: 12upx;
  345. font-weight: 500;
  346. transition: all 0.3s ease;
  347. }
  348. }
  349. // 紧凑商品列表
  350. .product-list-compact {
  351. margin-top:15upx;
  352. padding: 0 20upx 20upx;
  353. }
  354. .product-row {
  355. display: flex;
  356. align-items: center;
  357. justify-content: space-between;
  358. padding: 20upx;
  359. margin-bottom: 8upx;
  360. background: #fafbfc;
  361. border-radius: 8upx;
  362. border: 1upx solid #eef0f2;
  363. &:last-child {
  364. margin-bottom: 0;
  365. }
  366. &:active {
  367. background: #f0f8ff;
  368. }
  369. }
  370. .product-basic-info {
  371. flex: 1;
  372. margin-right: 20upx;
  373. .product-name-compact {
  374. font-size: 30upx;
  375. font-weight: 600;
  376. color: #333;
  377. line-height: 1.3;
  378. display: block;
  379. margin-bottom: 8upx;
  380. overflow: hidden;
  381. text-overflow: ellipsis;
  382. white-space: nowrap;
  383. width: 360upx;
  384. }
  385. .product-meta {
  386. display: flex;
  387. gap: 12upx;
  388. flex-wrap: wrap;
  389. .stock-info {
  390. font-size: 28upx;
  391. color: #666;
  392. background: #f5f5f5;
  393. padding: 4upx 8upx;
  394. border-radius: 4upx;
  395. }
  396. .available-info {
  397. font-size: 28upx;
  398. color: #ff6b35;
  399. background: rgba(255, 107, 53, 0.1);
  400. padding: 4upx 8upx;
  401. border-radius: 4upx;
  402. }
  403. }
  404. }
  405. .refund-control {
  406. display: flex;
  407. align-items: center;
  408. gap: 8upx;
  409. .refund-input-group {
  410. display: flex;
  411. flex-direction: column;
  412. gap: 12upx;
  413. .input-item {
  414. display: flex;
  415. align-items: center;
  416. gap: 8upx;
  417. .input-label {
  418. font-size: 22upx;
  419. color: #666;
  420. min-width: 60upx;
  421. }
  422. }
  423. }
  424. .refund-input-compact {
  425. width: 100upx;
  426. height: 60upx;
  427. background: #fff;
  428. border: 1upx solid #ddd;
  429. border-radius: 6upx;
  430. text-align: center;
  431. font-size: 26upx;
  432. color: #333;
  433. font-weight: 500;
  434. &:focus {
  435. border-color: #09c567;
  436. box-shadow: 0 0 0 2upx rgba(9, 197, 103, 0.2);
  437. }
  438. }
  439. .unit-label {
  440. font-size: 24upx;
  441. color: #666;
  442. min-width: 40upx;
  443. }
  444. }
  445. // 金额信息
  446. .amount-info {
  447. padding: 30upx;
  448. }
  449. .amount-row {
  450. display: flex;
  451. justify-content: space-between;
  452. align-items: center;
  453. padding: 20upx 0;
  454. border-bottom: 1upx solid #f0f0f0;
  455. &:last-child {
  456. border-bottom: none;
  457. }
  458. &.input-row {
  459. align-items: flex-start;
  460. padding-top: 30upx;
  461. }
  462. .amount-label {
  463. font-size: 28upx;
  464. color: #666;
  465. &.required::after {
  466. content: "*";
  467. color: #ff4757;
  468. margin-left: 5upx;
  469. }
  470. }
  471. .amount-value {
  472. display: flex;
  473. align-items: center;
  474. .price-text {
  475. font-size: 32upx;
  476. font-weight: 600;
  477. color: #333;
  478. }
  479. .refunded-text {
  480. margin-left: 20upx;
  481. font-size: 24upx;
  482. color: #09c567;
  483. background: rgba(9, 197, 103, 0.1);
  484. padding: 6upx 12upx;
  485. border-radius: 16upx;
  486. }
  487. &.available-amount {
  488. font-size: 32upx;
  489. font-weight: 600;
  490. color: #09c567;
  491. }
  492. }
  493. }
  494. .amount-input-wrapper {
  495. display: flex;
  496. align-items: center;
  497. background: #fafbfc;
  498. border: 1upx solid #ddd;
  499. border-radius: 8upx;
  500. padding: 0 20upx;
  501. width: 210upx;
  502. &:focus-within {
  503. border-color: #09c567;
  504. }
  505. .currency-symbol {
  506. font-size: 28upx;
  507. color: #666;
  508. margin-right: 10upx;
  509. }
  510. .amount-input {
  511. flex: 1;
  512. height: 80upx;
  513. font-size: 28upx;
  514. color: #333;
  515. font-weight: 500;
  516. border: none;
  517. background: transparent;
  518. width: 135upx;
  519. }
  520. }
  521. // 备注输入框
  522. .remark-container {
  523. padding: 20upx 30upx 30upx;
  524. }
  525. .remark-textarea {
  526. width: 100%;
  527. height: 120upx;
  528. background: #fafbfc;
  529. border: 1upx solid #ddd;
  530. border-radius: 8upx;
  531. padding: 15upx;
  532. font-size: 28upx;
  533. color: #333;
  534. line-height: 1.2;
  535. box-sizing: border-box;
  536. resize: none;
  537. &:focus {
  538. border-color: #09c567;
  539. }
  540. }
  541. // 警告提示
  542. .warning-notice {
  543. background: linear-gradient(135deg, #fff3cd 0%, #ffeaa7 100%);
  544. margin: 0 20upx 20upx;
  545. border-radius: 16upx;
  546. border-left: 6upx solid #f39c12;
  547. padding: 30upx;
  548. display: flex;
  549. align-items: flex-start;
  550. .warning-icon {
  551. font-size: 40upx;
  552. margin-right: 20upx;
  553. margin-top: 5upx;
  554. }
  555. .warning-text {
  556. flex: 1;
  557. .warning-title {
  558. font-size: 28upx;
  559. font-weight: 600;
  560. color: #d68910;
  561. margin-bottom: 12upx;
  562. }
  563. .warning-content {
  564. font-size: 26upx;
  565. color: #85751a;
  566. line-height: 1.5;
  567. }
  568. }
  569. }
  570. // 底部操作按钮
  571. .bottom-actions {
  572. z-index:9999;
  573. position: fixed;
  574. bottom: 0;
  575. left: 0;
  576. right: 0;
  577. background: #fff;
  578. padding: 30upx;
  579. border-top: 1upx solid #eee;
  580. display: flex;
  581. gap: 30upx;
  582. box-shadow: 0 -4upx 12upx rgba(0, 0, 0, 0.1);
  583. }
  584. .action-btn {
  585. flex: 1;
  586. height: 88upx;
  587. border-radius: 12upx;
  588. font-size: 32upx;
  589. font-weight: 600;
  590. border: none;
  591. transition: all 0.3s ease;
  592. &.cancel-btn {
  593. background: #f8f9fa;
  594. color: #666;
  595. border: 1upx solid #ddd;
  596. &:active {
  597. background: #e9ecef;
  598. }
  599. }
  600. &.confirm-btn {
  601. background: linear-gradient(135deg, #09c567 0%, #00b894 100%);
  602. color: #fff;
  603. box-shadow: 0 4upx 12upx rgba(9, 197, 103, 0.3);
  604. &:active {
  605. transform: translateY(2upx);
  606. box-shadow: 0 2upx 8upx rgba(9, 197, 103, 0.3);
  607. }
  608. }
  609. }
  610. </style>