<template>
  <view class="min-page bg-f7 default-box-padding u-font-28 color-333">
    <view class="default-box-padding bg-fff default-box-radius">
      <view>
        <view class="font-bold u-m-b-16">兑换码名称</view>
        <up-input
          placeholder="请输入兑换码名称"
          border="none"
          v-model="form.name"
          placeholder-class="color-999 u-font-28"
        ></up-input>
        <view class="u-m-t-24">
          <up-line></up-line>
        </view>
      </view>

      <view class="u-m-t-24">
        <view class="font-bold u-m-b-16">活动日期</view>
        <DateTimePicker
          v-model:startTime="form.startTime"
          v-model:endTime="form.endTime"
        >
        </DateTimePicker>
      </view>
    </view>
    <view class="default-box-padding bg-fff default-box-radius u-m-t-32">
      <view class="font-bold u-m-b-16">发放数量（个）</view>
      <view class="u-flex u-m-t-16">
        <input
          class="number-box"
          placeholder="填写数量"
          placeholder-class="color-999 u-font-28"
          type="number"
          v-model="form.total"
        />
        <view class="unit">个</view>
      </view>
      <view class="u-m-t-24">
        <up-line></up-line>
      </view>
      <view class="font-bold u-m-t-24">金额（元）</view>

      <view class="u-flex u-m-t-16">
        <input
          class="number-box"
          placeholder="请输入金额"
          placeholder-class="color-999 u-font-28"
          type="number"
          v-model="form.amount"
        />
        <view class="unit">元</view>
      </view>
    </view>

    <my-bottom-btn-group
      @cancel="cancel"
      @save="save"
      direction="column"
    ></my-bottom-btn-group>
  </view>
</template>

<script setup>
import { reactive, onMounted } from "vue";
import DateTimePicker from "@/pageMarket/components/date-time-picker.vue";
import CouponList from "@/pageMarket/components/coupon-list.vue";
import * as rechargeRedemptionApi from "@/http/api/market/rechargeRedemption.js";
import {
  onLoad,
  onReady,
  onShow,
  onPageScroll,
  onReachBottom,
  onBackPress,
} from "@dcloudio/uni-app";

function cancel() {
  uni.navigateBack({
    delta: 1,
  });
}

const form = reactive({
  name: "",
  startTime: "",
  endTime: "",
  stock: "",
  total: '',
  amount:'',
});

function save() {
  if (!form.name) {
    uni.showToast({
      title: "请输入兑换码名称",
      icon: "none",
    });
    return;
  }
  if (!form.startTime || !form.endTime) {
    uni.showToast({
      title: "请选择活动日期",
      icon: "none",
    });
    return;
  }

  if (!form.total) {
    uni.showToast({
      title: "请输入发行数量",
      icon: "none",
    });
    return;
  }
  if (!form.amount) {
    uni.showToast({
      title: "请输入金额",
      icon: "none",
    });
    return;
  }

  
  rechargeRedemptionApi.add(form).then((res) => {
    uni.showToast({
      title: "添加成功",
      icon: "none",
    });
    setTimeout(() => {
      uni.navigateBack({
        delta: 1,
      });
    }, 1500);
  });
}
function addCoupon() {
  form.couponInfoList.push({
    id: "",
    num: "",
    title: "",
  });
}
const options = reactive({});
onLoad((opt) => {});
</script>

<style lang="scss" scoped>
:deep(.my-hour-area .container) {
  padding: 32rpx 28rpx;
  background-color: #f7f7f7;
  border-radius: 8rpx;
  margin-top: 16rpx;
}
:deep(.my-hour-area .box) {
  margin-top: 0 !important;
}
:deep(.fixed-bottom) {
  left: 110rpx;
  right: 110rpx;
}
</style>
