apply-refound.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. refoundValue: "", // 退款内容
  22. refoundPhone: ''
  23. },
  24. /**
  25. * 组件的方法列表
  26. */
  27. methods: {
  28. textareaInput(e: { detail: any }) {
  29. this.setData({
  30. refoundValue: e.detail.value
  31. })
  32. },
  33. phoneInput(e: { detail: any }) {
  34. this.setData({
  35. refoundPhone: e.detail.value
  36. })
  37. },
  38. onRefoundClose() {
  39. this.triggerEvent("changeRefoundStatus", false)
  40. },
  41. checkPhone(phone: string) {
  42. const phoneRule =
  43. /^((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}$/;
  44. return phoneRule.test(phone);
  45. },
  46. async onRefound() {
  47. const refoundValue = this.data.refoundValue
  48. const refoundPhone = this.data.refoundPhone
  49. if (!refoundValue) {
  50. wx.showToast({ title: '请输入退款原因', icon: 'none' })
  51. return
  52. }
  53. if (!this.checkPhone(refoundPhone)) {
  54. wx.showToast({ title: '请输入正确的手机号码', icon: 'none' })
  55. return
  56. }
  57. try {
  58. const { goods, orderNo } = this.data.goodsInfo
  59. const details: any = []
  60. goods.forEach((item: any) => {
  61. details.push({
  62. num: item.goodsNum,
  63. onlyRefund: false,
  64. userPaymentOrderDetailId: item.id,
  65. refundAmount: item.currentPrice
  66. })
  67. })
  68. const params = {
  69. merOrderNo: orderNo,
  70. serviceCharge: false,
  71. refundReason: refoundValue,
  72. phone: refoundPhone, // 手机号
  73. serviceChargeFee: 0,
  74. userRefundOrderDetails: details
  75. }
  76. const { data } = await api_userPaymentOrderRefundPayment(params)
  77. if (data.code == 200) {
  78. wx.showToast({ title: '申请成功', icon: 'none' })
  79. this.triggerEvent('onConfirm')
  80. } else {
  81. wx.showToast({ title: data.message, icon: 'none' })
  82. }
  83. } catch { }
  84. },
  85. }
  86. })