addCoupon.vue 14.3 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 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 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
<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.cxcode"
              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="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>
        <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="addForm.type"
                placeholder="选择优惠券类型"
                readonly="readonly"
                @click="typeShow = true"
              />
              <van-popup v-model="typeShow" position="bottom" :overlay="true">
                <van-picker
                  show-toolbar
                  title="标题"
                  :columns="typeList"
                  @cancel="typeShow = false"
                  @confirm="onConfirm"
                />
              </van-popup>
            </div>
          </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.unit"
                placeholder="请输入金额"
                @touchstart.native.stop="unitShow = true"
              />
              <van-number-keyboard
                v-model="addForm.unit "
                :show="unitShow"
                @blur="unitShow = false"
              />
            </div>
          </template>
        </van-cell>
        <van-cell title="开始时间" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                class="right"
                v-model="beginDate"
                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="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="allLimitShow = true"
              />
              <van-number-keyboard
                v-model="addForm.limitOfUse"
                :show="allLimitShow"
                :maxlength="6"
                @blur=" allLimitShow = 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">
            <div class="npbr">
              <van-field
                class="right noborder"
                readonly
                clickable
                :value="addForm.salesAmount"
                placeholder="请输入销售金额"
                @touchstart.native.stop="salesAmountShow = true"
              />
              <van-number-keyboard
                v-model="addForm.salesAmount "
                :show="salesAmountShow"
                @blur="salesAmountShow = false"
              />
            </div>
          </template>
        </van-cell>
        <van-cell title="用券金额" style="font-size:14px;">
          <template slot="default">
            <div class="npbr">
              <van-field
                :value="addForm.usageAmount"
                placeholder="请输入用券金额"
                class="right"
                style="font-size:14px;"
                readonly
                @touchstart.native.stop="usageAmountShow = true"
              />
              <van-number-keyboard
                  v-model="addForm.usageAmount"
                  :show="usageAmountShow"
                  :maxlength="6"
                  @blur="usageAmountShow = false"
                />
            </div>
          </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>
import { addCoupon } from "@/api/sidebar/voucher"
export default { 
  data() {
    return {
      allLimitShow: false,
      show: false,
      show2: false,
      startTime: new Date(),
      startTime1: "",
      endTime: new Date(),
      endTime1: "",
      startShow: false,
      endShow: false,
      typeShow: false,
      salesAmountShow: false,
      usageAmountShow:false,
      unitShow: false,
      beginDate: '',     
      endDate: '',
      cxsh: '',
      cxshShow: false,
      //
      addForm: {
        cxcode: '',
        cxsh: '',
        name: "",
        begin_date: '',
        end_date: '',     
        type: '',
        unit: '',
        instruction: '',
        limitOfUse: '',
        couponId: '',
        remind: '',
        usageMax: '',
        salesAmount: '',
        usageAmount: '',
        usageMax: '',
        deptId: '',
        cxcode: ''  
      },
      typeList: ['现金券'],
      storeList: [       
	      {"keyId":'CS',"text":"超市"},
	      {"keyId":'BG',"text":"百购"},
	      {"keyId":'BH',"text":"百货"}      
      ]
    };
  },
  mounted() {
    this.addForm.deptId = Number(sessionStorage.getItem("oyStallCode"))
  },
  methods: {
    timeFormat(time) {
      let year = 1900 + time.getYear();
      let month = "0" + (time.getMonth() + 1);
      let date = "0" + time.getDate();
      let hour = time.getHours()
      let minute =  time.getMinutes()
      return (
        year + "-" + month.substring(month.length - 2, month.length) + "-" + date.substring(date.length - 2, date.length)
      );
    },
    startTimeChange(e) {
      let startTimeArr = e.getValues();      
      console.log(startTimeArr,'startTimeArr') 
      this.beginDate = `${startTimeArr[0]}-${startTimeArr[1]}-${startTimeArr[2]}`; 
      this.addForm.begin_date =  this.beginDate     
    },
    handleStartTime(value) {
      this.addForm.begin_date = this.beginDate = this.timeFormat(value)
      this.startShow = false;
    },
    handleEndTime(value) {
      this.addForm.end_date = this.endDate = this.timeFormat(value);
      this.endShow = false;
    },
    endTimeChange(e) {     
      let endTimeArr = e.getValues();
      this.addForm.end_date = this.endDate = `${endTimeArr[0]}-${endTimeArr[1]}-${endTimeArr[2]}`
    },
    onConfirm(val,index) {      
      this.typeShow = false
      this.addForm.type = val      
    },
    // 商户类型确定
    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
    },
    handleCancel() {
      this.$router.push('coupon')
    },
    handleSave() {
       if(!this.addForm.cxcode ){
          this.$toast("请输入欧亚活动编码")
          return false
        }
      if(!this.addForm.cxsh){
        this.$toast("请选择商户类型")
        return false
      } 
      if(!this.addForm.name ){
          this.$toast("请输入优惠券名称")
          return false
        }
      if(!this.addForm.type){
        this.$toast("请选择优惠券类型")
        return false
      } 
      if(!this.addForm.unit){
        this.$toast("请输入优惠券金额")
        return false
      } 
      if(!this.beginDate){
        this.$toast("请输入开始时间")
        return false
      }
       if(!this.endDate){
        this.$toast("请输入结束时间")
        return false
      }
      if(!this.addForm.couponId){
          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')
        if(res.errorCode == "fail") {
          this.$toast("活动编码不能重复!")
          }else {
            this.$router.push('coupon')
          }
      })
    }
  }
  
};
</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: 100%;
  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>