addCoupon.vue 13 KB
Newer Older
xd's avatar
xd committed
1 2 3 4 5
<template>
  <div class="container">
    <div>
      <div class="title bTitle">优惠券配置</div>
      <van-cell-group class="all">
xd's avatar
xd committed
6 7
        <van-cell title="欧亚活动编码" style="font-size:14px;">
          <template slot="default">
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
            <div class="npbr">
              <van-field
                :value="addForm.cxcode"
                placeholder="请输入欧亚活动编码"
                class="right"
                readonly
                style="font-size:14px;"
                @touchstart.native.stop="codeShow = true"
              /> 
              <van-number-keyboard
                v-model="addForm.cxcode"
                :show="codeShow"
                @blur="codeShow = false"
              />
          </div>
        </template>          
xd's avatar
xd committed
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
        </van-cell>
        <van-cell title="商户类型" style="font-size:14px;"> 
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
                v-model="cxsh"
                placeholder="选择商户类型"
                readonly="readonly"               
                @click="cxshShow = true"
              />
              <van-popup v-model="cxshShow" position="bottom" :overlay="true">
                <van-picker
                  show-toolbar
                  title="商户类型"
                  :columns="storeList"
                  @cancel="cxshShow = false"
                  @confirm="onConfirms"
                  @change="handleStoreTypeChange"
                />
              </van-popup>
            </div>
          </template>
        </van-cell>
xd's avatar
xd committed
48 49 50 51 52 53 54 55 56 57
        <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>
xd's avatar
xd committed
58
        <van-cell title="优惠券类型" style="font-size:14px;"> 
xd's avatar
xd committed
59 60 61 62
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
xd's avatar
xd committed
63
                v-model="addForm.type"
xd's avatar
xd committed
64 65
                placeholder="选择优惠券类型"
                readonly="readonly"
xd's avatar
xd committed
66
                @click="typeShow = true"
xd's avatar
xd committed
67
              />
xd's avatar
xd committed
68 69 70 71 72 73 74
              <van-popup v-model="typeShow" position="bottom" :overlay="true">
                <van-picker
                  show-toolbar
                  title="标题"
                  :columns="typeList"
                  @cancel="typeShow = false"
                  @confirm="onConfirm"
xd's avatar
xd committed
75 76 77 78 79
                />
              </van-popup>
            </div>
          </template>
        </van-cell>
xd's avatar
xd committed
80
        <van-cell title="金额" style="font-size:14px;" class="js">
xd's avatar
xd committed
81
          <template slot="default">
xd's avatar
xd committed
82
            <van-stepper v-model="addForm.unit" step="1" :show-plus="false" :show-minus="false" />
xd's avatar
xd committed
83 84 85 86 87 88 89
          </template>
        </van-cell>
        <van-cell title="开始时间" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
xd's avatar
xd committed
90
                v-model="beginDate"
xd's avatar
xd committed
91 92 93 94 95 96 97 98
                placeholder="选择开始时间"
                readonly="readonly"
                @click="startShow = true"
              />
              <van-popup v-model="startShow" position="bottom" :overlay="true">
                <van-datetime-picker
                  v-model="startTime"
                  type="date"
99
                  :min-date="minStartDate"
xd's avatar
xd committed
100 101 102 103 104 105 106 107 108 109 110 111 112
                  @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"
xd's avatar
xd committed
113
                v-model="endDate"
xd's avatar
xd committed
114 115 116 117 118 119 120 121
                placeholder="选择结束时间"
                readonly="readonly"
                @click="endShow = true"
              />
              <van-popup v-model="endShow" position="bottom" :overlay="true">
                <van-datetime-picker
                  v-model="endTime"
                  type="date"
122
                  :min-date="minEndDate"
xd's avatar
xd committed
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140
                  @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>
141
        <van-cell title="优惠券ID" style="font-size:14px;">
xd's avatar
xd committed
142 143 144 145 146 147
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right noborder"
                readonly
                clickable
xd's avatar
xd committed
148
                :value="addForm.couponIds"
149 150
                placeholder="请输入优惠券ID"
                @touchstart.native.stop="unitShow = true"
xd's avatar
xd committed
151 152
              />
              <van-number-keyboard
xd's avatar
xd committed
153
                v-model="addForm.couponIds "
154 155
                :show="unitShow"
                @blur="unitShow = false"
xd's avatar
xd committed
156
              />
157
            </div>  
xd's avatar
xd committed
158 159
          </template>
        </van-cell>
xd's avatar
xd committed
160 161
        <van-cell title="总限制次数" style="font-size:14px;" class="js">
          <van-stepper v-model="addForm.limitOfUse" step="1"  :show-plus="false" :show-minus="false" />
162
        </van-cell>
xd's avatar
xd committed
163 164 165 166
        <van-cell title="总限制提示" style="font-size:14px;">
          <template slot="default">
            <van-field
              v-model="addForm.remind"
xd's avatar
xd committed
167
              placeholder="请输入总限制提示"
xd's avatar
xd committed
168 169 170 171 172
              class="right"
              style="font-size:14px;"
            />
          </template>
        </van-cell>
xd's avatar
xd committed
173 174
        <van-cell title="编码券使用上限(次)" style="font-size:14px;" class="js" >
          <van-stepper v-model="addForm.usageMax" step="1" :show-plus="false" :show-minus="false" />
xd's avatar
xd committed
175 176 177 178
        </van-cell>
      </van-cell-group>
      <div class="title">编码券使用规则明细</div>
      <van-cell-group class="all">
xd's avatar
xd committed
179 180
        <van-cell title="销售金额" style="font-size:14px;" class="js">
          <van-stepper v-model="addForm.salesAmount" step="1" :min="addForm.usageAmount"  :show-plus="false" :show-minus="false" />
xd's avatar
xd committed
181
        </van-cell>
xd's avatar
xd committed
182 183
        <van-cell title="用券金额" style="font-size:14px;" class="js">
          <van-stepper v-model="addForm.usageAmount" step="1"  :show-plus="false" :show-minus="false" />
xd's avatar
xd committed
184 185 186 187 188 189 190 191 192 193 194 195
        </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>
xd's avatar
xd committed
196 197
import { addCoupon } from "@/api/sidebar/voucher"
export default { 
xd's avatar
xd committed
198 199
  data() {
    return {
200 201
      minStartDate: null,
      minEndDate: null,
xd's avatar
xd committed
202
      allLimitShow: false,
xd's avatar
xd committed
203 204 205 206 207 208 209 210
      show: false,
      show2: false,
      startTime: new Date(),
      startTime1: "",
      endTime: new Date(),
      endTime1: "",
      startShow: false,
      endShow: false,
xd's avatar
xd committed
211 212 213 214 215 216
      typeShow: false,
      salesAmountShow: false,
      usageAmountShow:false,
      unitShow: false,
      beginDate: '',     
      endDate: '',
xd's avatar
xd committed
217 218
      cxsh: '',
      cxshShow: false,
219
      codeShow: false,
xd's avatar
xd committed
220 221
      //
      addForm: {
xd's avatar
xd committed
222 223
        cxcode: '',
        cxsh: '',
xd's avatar
xd committed
224
        name: "",
xd's avatar
xd committed
225 226
        begin_date: '',
        end_date: '',     
xd's avatar
xd committed
227 228 229 230
        type: '',
        unit: '',
        instruction: '',
        limitOfUse: '',
xd's avatar
xd committed
231
        couponIds: '',
xd's avatar
xd committed
232 233 234
        remind: '',
        usageMax: '',
        salesAmount: '',
xd's avatar
xd committed
235
        usageAmount: '',
xd's avatar
xd committed
236
        deptId: '',
xd's avatar
xd committed
237 238
        cxcode: '',
        couponId: 126
xd's avatar
xd committed
239
      },
xd's avatar
xd committed
240 241 242 243 244 245
      typeList: ['现金券'],
      storeList: [       
	      {"keyId":'CS',"text":"超市"},
	      {"keyId":'BG',"text":"百购"},
	      {"keyId":'BH',"text":"百货"}      
      ]
xd's avatar
xd committed
246 247
    };
  },
xd's avatar
xd committed
248
  mounted() {
249 250 251
    this.addForm.deptId = sessionStorage.getItem("oyStallCode")
    this.minStartDate = new Date((new Date()/1000+3600)*1000)
    this.minEndDate = new Date((new Date()/1000+86400)*1000)
xd's avatar
xd committed
252
  },
xd's avatar
xd committed
253 254 255 256 257
  methods: {
    timeFormat(time) {
      let year = 1900 + time.getYear();
      let month = "0" + (time.getMonth() + 1);
      let date = "0" + time.getDate();
xd's avatar
xd committed
258 259
      let hour = time.getHours()
      let minute =  time.getMinutes()
xd's avatar
xd committed
260
      return (
xd's avatar
xd committed
261
        year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length)
xd's avatar
xd committed
262 263 264
      );
    },
    startTimeChange(e) {
xd's avatar
xd committed
265 266
      let startTimeArr = e.getValues();      
      console.log(startTimeArr,'startTimeArr') 
xd's avatar
xd committed
267 268
      this.beginDate = `${startTimeArr[0]}-${startTimeArr[1]}-${startTimeArr[2]}`; 
      this.addForm.begin_date =  this.beginDate     
xd's avatar
xd committed
269 270
    },
    handleStartTime(value) {
xd's avatar
xd committed
271
      this.addForm.begin_date = this.beginDate = this.timeFormat(value)
xd's avatar
xd committed
272 273 274
      this.startShow = false;
    },
    handleEndTime(value) {
xd's avatar
xd committed
275
      this.addForm.end_date = this.endDate = this.timeFormat(value);
xd's avatar
xd committed
276 277
      this.endShow = false;
    },
xd's avatar
xd committed
278
    endTimeChange(e) {     
xd's avatar
xd committed
279
      let endTimeArr = e.getValues();
xd's avatar
xd committed
280 281 282 283 284
      this.addForm.end_date = this.endDate = `${endTimeArr[0]}-${endTimeArr[1]}-${endTimeArr[2]}`
    },
    onConfirm(val,index) {      
      this.typeShow = false
      this.addForm.type = val      
xd's avatar
xd committed
285
    },
xd's avatar
xd committed
286 287 288 289 290 291 292 293 294 295 296 297
    // 商户类型确定
    onConfirms(val,index) {           
      this.cxshShow = false
      this.cxsh = val.text
      this.addForm.cxsh = val.keyId      
    },
    // 商户类型修改
    handleStoreTypeChange(picker, value, index) {
      this.cxshShow = false
      this.cxsh = value.text
      this.addForm.cxsh = value.keyId
    },
xd's avatar
xd committed
298 299 300 301
    handleCancel() {
      this.$router.push('coupon')
    },
    handleSave() {
xd's avatar
xd committed
302 303 304 305 306 307 308 309
       if(!this.addForm.cxcode ){
          this.$toast("请输入欧亚活动编码")
          return false
        }
      if(!this.addForm.cxsh){
        this.$toast("请选择商户类型")
        return false
      } 
xd's avatar
xd committed
310 311 312 313 314
      if(!this.addForm.name ){
          this.$toast("请输入优惠券名称")
          return false
        }
      if(!this.addForm.type){
xd's avatar
xd committed
315
        this.$toast("请选择优惠券类型")
xd's avatar
xd committed
316 317 318 319 320 321 322 323 324 325 326 327 328 329
        return false
      } 
      if(!this.addForm.unit){
        this.$toast("请输入优惠券金额")
        return false
      } 
      if(!this.beginDate){
        this.$toast("请输入开始时间")
        return false
      }
       if(!this.endDate){
        this.$toast("请输入结束时间")
        return false
      }
xd's avatar
xd committed
330
      if(!this.addForm.couponIds){
xd's avatar
xd committed
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356
          this.$toast("请输入优惠券ID")
          return false
        }
      
      if(!this.addForm.limitOfUse){
        this.$toast("请输入总限制次数")
        return false
      }             
      if(!this.addForm.remind ){
        this.$toast("请输入限制提示")
        return false
      } 
      if(!this.addForm.usageMax){
        this.$toast("请输入编码券使用上限")
        return false
      } 
      if(!this.addForm.salesAmount){
        this.$toast("请输入销售金额")
        return false
      }      
      if(!this.addForm.usageAmount){
        this.$toast("请输入用券金额")
        return false
      } 
      addCoupon(this.addForm).then(res => {
        console.log(res,'res')
xd's avatar
xd committed
357
        if(res.errorCode == "fail") {
358
          this.$toast("活动创建失败!")
xd's avatar
xd committed
359 360 361
          }else {
            this.$router.push('coupon')
          }
xd's avatar
xd committed
362
      })
xd's avatar
xd committed
363
    }
xd's avatar
xd committed
364 365
  }
  
xd's avatar
xd committed
366 367 368 369 370
};
</script>
<style></style>

<style scoped>
xd's avatar
xd committed
371 372 373 374 375 376 377
.js >>> .van-stepper {
  text-align: right;
}
.js >>> .van-stepper__input {
  text-align: center;
  width: 60%;
}
xd's avatar
xd committed
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395
.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 {
xd's avatar
xd committed
396
  width: 100%;
xd's avatar
xd committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
  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>