vue+elemntui 加减表单框功能样式

       <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="配置时间" prop="currentAllocationDate">
            <div v-for="(item,key) in timeList">
              <el-date-picker
                v-model="item.time"
                type="datetimerange"
                value-format="timestamp"
                range-separator=""
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>

                <el-button class="add" @click="passStreamAdd">+</el-button>
                <el-button class="reduce" @click="passStreamReduce(key)">-</el-button>
            </div>
        </el-form-item>
</el-form>

  data() {
    return {
          // 增加 or 减少时间 配置时间项
      timeList: [{}],
      form: {
          currentAllocationDate: ''
      }
    }
 }),
   watch: {
    timeList: {
      handler: function(val, oldVal) {
        this.form.currentAllocationDate = JSON.stringify(val)
      },
      immediate: true
    }
  },
   methods: {
    //增加
    passStreamAdd(){
      this.timeList.push({})
    },
    //减少
    passStreamReduce(index){
      let newArr = [];
      //为一层时禁止减
      if(this.timeList.length == 1){ return; }
      if(index == 0){
        //为首
        newArr = this.timeList.slice( 1,this.timeList.length)
      }else if(index == this.timeList.length-1){
        //为尾
        newArr = this.timeList.slice( 0,this.timeList.length-1)
      }else{
        //为中
        let arr1 = this.timeList.slice( 0,index)
        let arr2 = this.timeList.slice( index+1, this.timeList.length)
        newArr = arr1.concat(arr2)
      }
      this.timeList = [].concat(newArr);
    },
   }
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.timeList = [{}] // 注意这
      this.title = "添加平衡清零";
    },
        /** 修改按钮操作 */
    handleUpdate(row) {
      this.loading = true;
      this.reset();
      const id = row.id || this.ids
      getBalancedZeroing(id).then(response => {
        this.loading = false;
        this.form = response.data;
        this.timeList = this.form.currentAllocationDate ?                JSON.parse(this.form.currentAllocationDate) : [{}]
        this.open = true;
        this.title = "修改平衡清零";
      });
    },

在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值