<template>
  <drawer-page-container
    v-model="show"
    title="订单退款"
    height="55%"
    :show-close="true"
    :closeable="false"
    @close="onClose"
  >
    <view class="popup-wrap">
      <view class="order-no" v-if="orderNo">订单号：{{ orderNo }}</view>
      <view class="field">
        <text class="label">退款原因</text>
        <textarea
          class="textarea"
          v-model="refundReason"
          placeholder="请输入退款原因"
          placeholder-style="color:#BDBDBD"
        />
      </view>
      <view class="footer">
        <button class="btn-cancel" @click="onClose">取消</button>
        <button class="btn-submit" :loading="submitting" @click="submit">确认退款</button>
      </view>
    </view>
  </drawer-page-container>
</template>

<script>
import DrawerPageContainer from '@/subPackages/sub_business_shared/components/DrawerPageContainer.vue'

export default {
  name: 'RefundOrderPopup',
  components: { DrawerPageContainer },
  props: {
    bizApi: { type: Object, required: true },
  },
  data() {
    return {
      show: false,
      orderId: 0,
      orderNo: '',
      refundReason: '',
      submitting: false,
    }
  },
  methods: {
    open(order) {
      this.orderId = order.id
      this.orderNo = order.order_no || ''
      this.refundReason = ''
      this.show = true
    },
    onClose() {
      this.show = false
    },
    submit() {
      if (!this.refundReason.trim()) {
        uni.showToast({ title: '请输入退款原因', icon: 'none' })
        return
      }
      this.submitting = true
      this.bizApi.refundOrder({
        order_id: this.orderId,
        refund_reason: this.refundReason.trim(),
      }).then(w => {
        if (w.ok) {
          uni.showToast({ title: '已提交' })
          this.show = false
          this.$emit('success')
        }
      }).finally(() => { this.submitting = false })
    },
  },
}
</script>

<style lang="scss" scoped>
.popup-wrap {
  padding: 0 32rpx 32rpx;
  padding-bottom: calc(32rpx + env(safe-area-inset-bottom));
}
.order-no { font-size: 26rpx; color: #86909C; margin-bottom: 24rpx; }
.field { margin-bottom: 24rpx; }
.label { display: block; font-size: 28rpx; color: #4E5969; margin-bottom: 12rpx; }
.textarea {
  width: 100%;
  box-sizing: border-box;
  background: #F7F8FA;
  border-radius: 12rpx;
  min-height: 160rpx;
  padding: 24rpx;
  line-height: 1.5;
  font-size: 28rpx;
}
.footer { display: flex; gap: 24rpx; margin-top: 32rpx; }
.footer button {
  flex: 1;
  margin: 0;
  height: 88rpx;
  line-height: 88rpx;
  border-radius: 44rpx;
  font-size: 30rpx;
}
.footer button::after { display: none; }
.btn-cancel { background: #fff; color: #4E5969; border: 1rpx solid #E5E6EB; }
.btn-submit { background: #F53F3F; color: #fff; }
</style>
