apply-refound.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. import { api_userPaymentOrderRefundPayment } from "../../api/login";
  2. // components/apply-refound/apply-refound.ts
  3. Component({
  4. /**
  5. * 组件的属性列表
  6. */
  7. properties: {
  8. refoundStatus: {
  9. type: Boolean,
  10. default: false,
  11. },
  12. goodsInfo: {
  13. type: Object,
  14. default: {}
  15. }
  16. },
  17. /**
  18. * 组件的初始数据
  19. */
  20. data: {
  21. submitStatus: false,
  22. refoundValue: "", // 退款内容
  23. refoundPhone: ''
  24. },
  25. /**
  26. * 组件的方法列表
  27. */
  28. methods: {
  29. textareaInput(e: { detail: any }) {
  30. this.setData({
  31. refoundValue: e.detail.value
  32. })
  33. },
  34. phoneInput(e: { detail: any }) {
  35. this.setData({
  36. refoundPhone: e.detail.value
  37. })
  38. },
  39. onRefoundClose() {
  40. this.triggerEvent("changeRefoundStatus", false)
  41. },
  42. checkPhone(phone: string) {
  43. const phoneRule =
  44. /^((13[0-9])|(14(0|[5-7]|9))|(15([0-3]|[5-9]))|(16(2|[5-9]))|(17[0-8])|(18[0-9])|(19([0-3]|[5-9])))\d{8}$/;
  45. return phoneRule.test(phone);
  46. },
  47. async onRefound() {
  48. const refoundValue = this.data.refoundValue
  49. const refoundPhone = this.data.refoundPhone
  50. if (!refoundValue) {
  51. wx.showToast({ title: '请输入退款原因', icon: 'none' })
  52. return
  53. }
  54. if (!this.checkPhone(refoundPhone)) {
  55. wx.showToast({ title: '请输入正确的手机号码', icon: 'none' })
  56. return
  57. }
  58. try {
  59. this.setData({
  60. submitStatus: true
  61. })
  62. const { goods, orderNo } = this.data.goodsInfo
  63. const details: any = []
  64. goods.forEach((item: any) => {
  65. details.push({
  66. num: item.goodsNum,
  67. onlyRefund: false,
  68. userPaymentOrderDetailId: item.id,
  69. refundAmount: item.currentPrice
  70. })
  71. })
  72. const params = {
  73. merOrderNo: orderNo,
  74. serviceCharge: false,
  75. refundReason: refoundValue,
  76. phone: refoundPhone, // 手机号
  77. serviceChargeFee: 0,
  78. userRefundOrderDetails: details
  79. }
  80. const { data } = await api_userPaymentOrderRefundPayment(params)
  81. this.setData({
  82. submitStatus: false
  83. })
  84. if (data.code == 200) {
  85. wx.showToast({ title: '申请成功', icon: 'none' })
  86. this.triggerEvent('onConfirm')
  87. } else {
  88. wx.showToast({ title: data.message, icon: 'none' })
  89. }
  90. } catch { }
  91. },
  92. }
  93. })