<style>
  .LM_mainDiv {
    overflow-y: auto;
  }

  .LP_table {
    margin-top: 10px;
    background-color: #fff;
     border-top: 1px solid #d1d1d1;
    /*border-left: 1px solid #d1d1d1;*/
    /* border-right: 1px solid #d1d1d1;  */
    font-size: 14px;
    width:100%;
    min-width: 1200px;
    padding-bottom: 5px;
  }

  .LP_table tr {
    height: 40px;
  }


  .LP_table tr th {
    border-left: 1px solid #d1d1d1;
    border-bottom: 1px solid #d1d1d1;
    /* border-right: 1px solid #d1d1d1; */
    position: relative;
    background-color: #E6E6E6;
  }
  .LP_table tr th:last-child{

  border-right: 1px solid #d1d1d1;
}
  .LP_table td {
    border-left: 1px solid #d1d1d1;
    border-bottom: 1px solid #d1d1d1;
    /* border-right: 1px solid #d1d1d1; */
    text-align: center;
    padding: 5px 0;
  }
 .LP_table  td:last-child{

  border-right: 1px solid #d1d1d1;
}
  .LP_table .el-button--primary {
    padding: 5px;
  }

  .Lp_role {
    position: absolute;
    top: 15px;
    left: 30px;
  }

  .Lp_company {
    position: absolute;
    right: 30px;
    top: 5px;
  }
  .comLessDiv{
    width:100%;
    height:40px;
    margin-top:5px;
    padding-bottom:5px;
    border-bottom:1px solid #d1d1d1;
  }
  .comLessDiv:last-child{
    border:0;
    padding-bottom:0;
  }
  .comLessDiv input{
    padding: 0 5px;
  }
  .comLessDiv .el-input-group__append,.comLessDiv .el-input-group__append button{
    padding: 0 8px;
    cursor: pointer;
  }
  .addLessPrice{
    margin-left:10px;
    color:seagreen;
    cursor: pointer;
  }
  .lessBtn{
    margin-top:5px;
  }
</style>

<template>
  <div>
    <div class="LM_mainDiv">
      <!--保存-->
      <table border="0" cellspacing="0" cellpadding="0" class="LP_table" v-loading="this.loading">
        <tr>
          <th width="150">公司</th>
          <th width="255">线路/系列</th>
          <th>人数</th>
          <th>所有人</th>
          <th>部门主管</th>
          <th>分公司总经理</th>
          <th>当团op</th>
          <th width="150">操作</th>
        </tr>
        <tr v-for="(item,index) in dataList">
          <td>
            {{item.BName}} <i class="iconfont icon-bumenguanli-tianjia addLessPrice" @click="addLessPrice(item)"></i>
          </td>
          <td>
            <div v-for="subItem in item.LessPriceList" class="comLessDiv">
              <el-select class='w120' v-model="subItem.LineId" filterable :placeholder="$t('pub.pleaseSel')" @change="getLineTeamList(subItem),resetLineTeamId(subItem)">
                <el-option label="不限" :value='commonSelect'></el-option>
                <el-option v-for="item in LineList" :label='item.LineName' :value='item.LineID' :key='item.LineID'>
                </el-option>
              </el-select>
              <el-select class='w120' v-model="subItem.LineTeamId" @visible-change="getLineTeamListTwo($event,subItem)" filterable :placeholder="$t('pub.pleaseSel')">
                <el-option label="不限" :value='commonSelect'></el-option>
                <el-option v-for="sitem in subItem.LineTeamList" :label='sitem.LtName' :value='sitem.LtID' :key='sitem.LtID'>
                </el-option>
              </el-select>
            </div>
          </td>

          <td>
            <div v-for="subItem in item.LessPriceList" class="comLessDiv">
              <el-input class="w80"  placeholder="最大人数" v-model="subItem.MaxPeopleNum" @keyup.native="checkPrice(subItem,'MaxPeopleNum')"> <el-button slot="append">人</el-button></el-input>
            </div>
          </td>

          <td>
            <div v-for="subItem in item.LessPriceList" class="comLessDiv">
              <el-input class="w80"  placeholder="少价金額" v-model="subItem.LessMoney" @keyup.native="checkPrice(subItem,'LessMoney')"> <el-button slot="append">元</el-button></el-input>
              <el-input class="w80"  placeholder="减少提成" v-model="subItem.LessPercent" @keyup.native="checkPrice(subItem,'LessPercent')">
                <el-button slot="append">%</el-button>
              </el-input>
            </div>
          </td>
          <td>
            <div v-for="subItem in item.LessPriceList" class="comLessDiv">
              <el-input class="w80"  placeholder="少价金額"  v-model="subItem.DeptLessMoney" @keyup.native="checkPrice(subItem,'DeptLessMoney')"> <el-button slot="append">元</el-button></el-input>
               <el-input class="w80"  placeholder="减少提成"  v-model="subItem.DeptLessPercent" @keyup.native="checkPrice(subItem,'DeptLessPercent')">
                <el-button slot="append">%</el-button></el-input>
            </div>
          </td>
          <td>
            <div v-for="subItem in item.LessPriceList" class="comLessDiv">
              <el-input class="w80"  placeholder="少价金額"  v-model="subItem.FilialeLessMoney" @keyup.native="checkPrice(subItem,'FilialeLessMoney')"> <el-button slot="append">元</el-button></el-input>
              <el-input class="w80"  placeholder="减少提成"  v-model="subItem.FilialeLessPercent" @keyup.native="checkPrice(subItem,'FilialeLessPercent')">
                 <el-button slot="append">%</el-button>
              </el-input>
            </div>
          </td>
          <td>
            <div v-for="subItem in item.LessPriceList" class="comLessDiv">
              <el-input class="w80"  placeholder="少价金額"  v-model="subItem.OPLessMoney" @keyup.native="checkPrice(subItem,'OPLessMoney')"> <el-button slot="append">元</el-button></el-input>
               <el-input class="w80"  placeholder="减少提成"  v-model="subItem.OPLessPercent" @keyup.native="checkPrice(subItem,'OPLessPercent')">
                 <el-button slot="append">%</el-button>
              </el-input>
            </div>
          </td>
          <td>
            <div v-for="(subItem,subIndex) in item.LessPriceList" class="comLessDiv">
              <input type='button' class="normalBtn lessBtn" @click="SaveLessPrice(subItem,index)" value="保存"></input>
              <input type='button' class="normalBtn lessBtn" @click="RemoveItem(item,subItem,subIndex)" value="删除"></input>
            </div>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>
<script>
  export default {
    data() {
      return {
        //分公司列表
        dataList: [],
        //角色列表
        RoleList: [],
        loading:false,
        LineList: [],
        commonSelect:0,
      };
    },
    methods: {
      //保存少价管理
      SaveLessPrice(subItem) {
        subItem.LineTeamList=[];
        this.apipost(
          "lessprice_post_Set", subItem,
          res => {
            if (res.data.resultCode == 1) {
              this.Success(res.data.message);
              this.getList();
            }else{
              this.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      //获取列表
      getList() {
        this.loading = true;
        var that=this;
        that.apipost(
          "lessprice_get_GetPageList", {},
          res => {
            that.loading = false;
            if (res.data.resultCode == 1) {
              var data = res.data.data;
              data.forEach(x=>{
                x.LessPriceList.forEach(y=>{
                  if(y.LineTeamId>0){
                    y.LineTeamList=[
                      {
                        LtName:y.lineTeamName,
                        LtID:y.LineTeamId
                      }
                    ]
                  }
                })
              })
              that.dataList=data;
            }else{
              that.Error(res.data.message);
            }
          },
          err => {}
        );
      },
      //获取列表
      RemoveItem(item,subItem, index) {
        if(subItem.Id==0){
            item.LessPriceList.splice(index,1);
            return;
        }
        var that = this;
        this.Confirm("是否删除此少价信息?", function () {
          if (subItem.Id > 0) {
            that.apipost(
              "lessprice_post_Remove", {
                ID: subItem.Id
              },
              res => {
                if (res.data.resultCode == 1) {
                  that.Success("操作成功!");
                  that.getList();
                } else {
                  that.Error(res.data.message);
                }
              },
              err => {}
            );
          }
        });
      },
      //获取线路列表
      getLineList() {
        this.apipost("line_post_GetAllList", {}, res => {
          if (res.data.resultCode == 1) {
            this.LineList = res.data.data;
          }
        });
      },

      //获取系列列表
      getLineTeamList(subItem) {
        if(subItem.LineId>0){
          this.apipost("team_post_GetList", {
            lineID: subItem.LineId,
            isTOOP: 1
          }, res => {
            if (res.data.resultCode == 1) {
              subItem.LineTeamList = res.data.data;
            }
          });
        }else{
          subItem.LineTeamList=[];
        }
      },
      getLineTeamListTwo(event,subItem){
        if(event&&subItem.LineId>0){
          this.apipost("team_post_GetList", {
            lineID: subItem.LineId,
            isTOOP: 1
          }, res => {
            if (res.data.resultCode == 1) {
              subItem.LineTeamList = res.data.data;
            }
          });
        }
      },
      //系列重置默认不限
      resetLineTeamId(subItem){
        subItem.LineTeamId = 0;
      },
      //点击添加
      addLessPrice(item){
        var obj = {
          DeptLessMoney:"",
          DeptLessPercent:"",
          DetailExtList:'',
          FilialeLessMoney:"",
          FilialeLessPercent:"",
          Id:0,
          LessMoney:"",
          LessPercent:"",
          LineId:0,
          LineTeamId:0,
          OPLessMoney:"",
          OPLessPercent:"",
          RB_Branch_Id:item.Id,
          RB_Group_Id:0,
          LineTeamList:[],
          MaxPeopleNum:"",
        }
        item.LessPriceList.push(obj);
      }
    },
    mounted() {
      this.getLineList();
      this.getList();
    },
  };

</script>
