<template>
  <el-row>
    <el-col :span="24">
      <el-form-item
        v-for="(item,index) in list"
        :key="index"
        :label="'第'+(index+1) +'阶梯'"
        >
        <el-row>
          <el-col :span="24">
            <el-row>
              <el-col :span="4">
                <el-input disabled v-model="item.pricestepUsagemin"/>
              </el-col>
              <el-col :span="2" style="display: flex;align-items:center">
                <div class="divider_center"></div>
              </el-col>
              <el-col :span="4" style="display:flex;align-items:center">
                <el-input
                  type="number"
                  v-model="item.pricestepUsagemax"
                  @change="(val) => changeMaxHandler(val,index)"
                />
              </el-col>
              <el-col :span="2">
                <span style="margin:0 10px;">吨</span>
              </el-col>
              <el-col :span="8" style="display:flex">
                <el-input type="number" v-model="item.pricestepUnitprice" style="width: 50%;margin-right:10px;"/>元/吨
              </el-col>
              <el-col :span="2" v-if="index + 1 == list.length && list.length > 2">
                <span style="margin: 0 10px;">
                  <i class="el-icon-delete-solid delete-icon" @click="() => handlerDeleteIcon(index)"></i>
                </span>
              </el-col>
            </el-row>
          </el-col>
        </el-row>
      </el-form-item>
      <div class="add" @click="handlerShowThree" v-if="this.list.length < 3">
        <i class="el-icon-circle-plus-outline add-icon"></i>
        添加
      </div>
    </el-col>
  </el-row>
</template>
<script>
export default {
  name: 'ladderLikeWaterPrice',
  props: ['list','type'],
  data() {
    return {
      shouldShowThree: this.list.length == 3,
    }
  },
  methods: {
    changeMaxHandler(row,index) { 
      this.$emit('changeList', this.list,this.type, row, index)
      // Vue.set(this.list)
    },
    handlerDeleteIcon(index){
      this.shouldShowThree = false
      this.list.splice(index,1)
    },
    // 关闭第三阶梯
    handlerHideThree() {
      this.shouldShowThree = false
    },
    // 打开第三阶梯
    handlerShowThree() {
      this.list.push({
        pricestepUsagemin: this.list[this.list.length - 1].pricestepUsagemax || '',
        pricestepUsagemax: '',
        pricestepUnitprice: '',
        pricestepNum: '0'
      })
      this.shouldShowThree = true
    },
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-form-item__label{
  text-align: left !important;
}
::v-deep .el-tooltip__popper.is-dark {
	background: #eeeeee;
}

::v-deep .el-popper.is-customized .el-popper__arrow::before {
	background: #eeeeee;
}
.add{
  width: 100%;
  height: 32px;
  line-height: 32px;
  text-align: center;
  border-radius: 4px;
  border: 1px solid #14A478;
  color:#14A478;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 14px;
  cursor: pointer;
  .add-icon{
    font-size: 16px;
    margin-right:2px;
  }
}
.delete-icon{
  font-size: 24px;
  color:#FF5951;
  margin-top:5px;
  cursor: pointer;
}
h3{
  color: #303133;
  font-family: Source Han Sans CN VF;
  font-size: 14px;
  font-style: normal;
  font-weight: 700;
  line-height: 24px;
}
.divider_center{
  width:100%;
  height: 1px;
  margin-top:16px;
  margin: 16px 15px 0 15px;
  background: #DCDFE6;
}
</style>