<template>
  <div class="container">
    <div>
      <div class="title bTitle">优惠券配置</div>
      <van-cell-group class="all">
        <van-cell title="优惠券名称" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.name"
              placeholder="请输入优惠券名称"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
        <van-cell title="优惠券类型" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
                v-model="startTime1"
                placeholder="选择优惠券类型"
                readonly="readonly"
                @click="startShow = true"
              />
              <van-popup v-model="startShow" position="bottom" :overlay="true">
                <van-datetime-picker
                  v-model="startTime"
                  type="date"
                  @cancel="startShow = false"
                  @confirm="handleStartTime"
                  @change="startTimeChange"
                />
              </van-popup>
            </div>
          </template>
        </van-cell>
        <van-cell title="金额" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.unit"
              placeholder="请输入金额"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
        <van-cell title="开始时间" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
                v-model="addForm.startTime"
                placeholder="选择开始时间"
                readonly="readonly"
                @click="startShow = true"
              />
              <van-popup v-model="startShow" position="bottom" :overlay="true">
                <van-datetime-picker
                  v-model="startTime"
                  type="date"
                  @cancel="startShow = false"
                  @confirm="handleStartTime"
                  @change="startTimeChange"
                />
              </van-popup>
            </div>
          </template>
        </van-cell>
        <van-cell title="结束时间" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
                v-model="addForm.endDate"
                placeholder="选择结束时间"
                readonly="readonly"
                @click="endShow = true"
              />
              <van-popup v-model="endShow" position="bottom" :overlay="true">
                <van-datetime-picker
                  v-model="endTime"
                  type="date"
                  @cancel="endShow = false"
                  @confirm="handleEndTime"
                  @change="endTimeChange"
                />
              </van-popup>
            </div>
          </template>
        </van-cell>
        <van-cell title="使用说明" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.instruction"
              placeholder="请输入使用说明"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
        <van-cell title="优惠券Id" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.couponId"
              placeholder="请输入优惠券Id"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
        <van-cell title="总限制次数" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right noborder"
                readonly
                clickable
                :value="addForm.limitOfUse"
                placeholder="请输入总限制次数"
                @touchstart.native.stop="show = true"
              />
              <van-number-keyboard
                v-model="addForm.limitOfUse"
                :show="show"
                :maxlength="6"
                @blur="show = false"
              />
            </div>
          </template>
        </van-cell>
        <van-cell title="总限制提示" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.remind"
              placeholder="请输入使用说明"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
        <van-cell title="编码券使用上限(次)" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right noborder"
                readonly
                clickable
                :value="addForm.usageMax"
                placeholder="请输入编码券使用上限"
                @touchstart.native.stop="show = true"
              />
              <van-number-keyboard
                v-model="addForm.usageMax "
                :show="show"
                :maxlength="6"
                @blur="show = false"
              />
            </div>
          </template>
        </van-cell>
      </van-cell-group>
      <div class="title">编码券使用规则明细</div>
      <van-cell-group class="all">
        <van-cell title="销售金额" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.salesAmount"
              placeholder="请输入销售金额"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
        <van-cell title="用券金额" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.usageMax"
              placeholder="请输入用券金额"
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
      </van-cell-group>
    </div>

    <div class="creat">
      <div class="btn-l" @click="handleCancel">取消</div>
      <div class="btn-y" @click="handleSave">保存</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      show2: false,
      startTime: new Date(),
      startTime1: "",
      endTime: new Date(),
      endTime1: "",
      startShow: false,
      endShow: false,
      //
      addForm: {
        name: "",
        endDate: '',
        startDate: '',
        type: '',
        unit: '',
        instruction: '',
        limitOfUse: '',
        couponId: '',
        remind: '',
        usageMax: '',
        salesAmount: '',
        usageMax: ''       
      }
    };
  },
  methods: {
    timeFormat(time) {
      let year = 1900 + time.getYear();
      let month = "0" + (time.getMonth() + 1);
      let date = "0" + time.getDate();
      return (
        year +
        "-" +
        month.substring(month.length - 2, month.length) +
        "-" +
        date.substring(date.length - 2, date.length) +
        " "
      );
    },
    startTimeChange(e) {
      let startTimeArr = e.getValues();
      this.addForm.startTime = `${startTimeArr[0]}-${startTimeArr[1]}-${startTimeArr[2]}`;
    },
    handleStartTime(value) {
      this.addForm.startTime = this.timeFormat(value);
      this.startShow = false;
    },
    handleEndTime(value) {
      this.addForm.endDate = this.timeFormat(value);
      this.endShow = false;
    },
    endTimeChange(e) {
      let endTimeArr = e.getValues();
      this.addForm.endDate = `${endTimeArr[0]}-${endTimeArr[1]}-${endTimeArr[2]}`;
    },
    handleCancel() {
      this.$router.push('coupon')
    },
    handleSave() {

    }
  },
  mounted() {}
};
</script>
<style></style>

<style scoped>
.condition {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}
.phone {
  margin-right: 10px;
}
.all >>> input {
  text-align: right;
}
.noborder >>> .van-cell:not(:last-child)::after {
  display: none !important;
}
.npbr .van-cell:not(:last-child)::after {
  display: none !important;
}
.creat {
  width: 96%;
  display: flex;
  height: 40px;
  background: rgba(117, 178, 253, 1);
  align-items: center;
  font-size: 16px;
  font-weight: bold;
  color: #fff;
}
.btn-l,.btn-y {
  display: flex;
  align-items: center;
  height: 100%;
  width: 50%;
  justify-content: center;
}
.btn-l {
  background-color: #fff;
  color: #000;
}
.container {
  height: auto;
  display: flex;
  justify-content: space-between;
  flex-direction: column;
  background: rgba(248, 248, 248, 1);
  min-height: 100%;
}
.area >>> .van-field__control {
  background: #f8f8f8;
  padding: 12px;
}
.des {
  padding: 5px 18px 0px;
  font-size: 14px;
  color: #2d476a;
}

.title {
  background-color: #f8f8f8;
  height: 36px;
  line-height: 36px;
  font-size: 12px;
  padding-left: 16px;
  color: #2d476a;
}
[data-v-08d4afe1] .van-cell {
  height: 100%;
  font-size: 14px;
}
.right {
  padding: 0;
}
.van-cell__title {
  color: #2d476a !important;
}
.bTitle {
  height: 60px;
  font-size: 18px;
  line-height: 60px;
}
</style>