cancel-order-popup.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <template>
  2. <common-dialog ref="popup" title="取消订单" confirm-text="确定" @confirm="handleConfirm" @cancel="close"
  3. :custom-style="{width: '600rpx'}">
  4. <view class="reason-list">
  5. <u-radio-group v-model="selectedReason" :wrap="true">
  6. <view class="reason-item" v-for="(item, index) in reasonList" :key="index"
  7. @click="selectedReason = item.value">
  8. <text class="reason-text">{{ item.label }}</text>
  9. <u-radio :name="item.value" active-color="#38C148"></u-radio>
  10. </view>
  11. </u-radio-group>
  12. </view>
  13. </common-dialog>
  14. </template>
  15. <script>
  16. import CommonDialog from '@/components/common-dialog.vue';
  17. export default {
  18. name: "cancel-order-popup",
  19. components: {
  20. CommonDialog
  21. },
  22. data() {
  23. return {
  24. reasonList: [],
  25. selectedReason: '',
  26. currentOrderId: null
  27. };
  28. },
  29. methods: {
  30. open(orderId) {
  31. this.currentOrderId = orderId;
  32. this.$refs.popup.openPopup();
  33. this.selectedReason = '';
  34. if (this.reasonList.length === 0) {
  35. this.getReasonList();
  36. }
  37. },
  38. close() {
  39. this.$refs.popup.closePopup();
  40. },
  41. getReasonList() {
  42. uni.$u.http.get('/token/common/getDictOptions?type=cancel_reason').then(res => {
  43. if (res.code === 200) {
  44. this.reasonList = res.data.map(item => ({
  45. label: item.dictLabel,
  46. value: item.dictValue
  47. }));
  48. }
  49. });
  50. },
  51. handleConfirm() {
  52. if (!this.selectedReason) {
  53. uni.showToast({
  54. title: '请选择取消原因',
  55. icon: 'none'
  56. });
  57. return;
  58. }
  59. if (!this.currentOrderId) return;
  60. this.$u.api.cancelOrderAjax({
  61. orderId: this.currentOrderId,
  62. reason: this.selectedReason
  63. }).then(res => {
  64. if (res.code === 200) {
  65. uni.showToast({
  66. title: '订单取消成功',
  67. icon: 'success'
  68. });
  69. this.close();
  70. this.$emit('success');
  71. }
  72. });
  73. }
  74. }
  75. };
  76. </script>
  77. <style lang="scss" scoped>
  78. .reason-list {
  79. padding: 20rpx 0;
  80. text-align: left;
  81. max-height: 500rpx;
  82. overflow-y: auto;
  83. .reason-item {
  84. display: flex;
  85. justify-content: space-between;
  86. align-items: center;
  87. padding: 20rpx 0;
  88. border-bottom: 1px solid #f5f5f5;
  89. &:last-child {
  90. border-bottom: none;
  91. }
  92. .reason-text {
  93. font-size: 28rpx;
  94. color: #333;
  95. flex: 1;
  96. }
  97. }
  98. }
  99. </style>