index.vue 5.14 KB
<template>
  <div v-if="show" class="select-seach-con">
    <!-- <div class="find_line"> -->
    <div class="cell_wrapper flex_sc">
      <!-- <div v-if="accountLevel == 2" class="cell_label h13_title">4S店</div>
      <div v-if="accountLevel == 1 && !isAdmin" class="cell_label h13_title">市级经销商</div>
      <div v-if="accountLevel == 1 && isAdmin" class="cell_label h13_title">省级经销商</div> -->
      <el-select class="find_width" v-if="accountLevel == 2" clearable size="mini" v-model="storeId" placeholder="请选择" @change="selectStoreId">
        <el-option v-for="item in storeList" :key="item.id" :label="item.label" :value="item.id"></el-option>
      </el-select>
      <el-select class="find_width" v-if="accountLevel == 1" clearable size="mini" v-model="nextAccountId" placeholder="请选择" @change="selectCurAccount">
        <el-option v-for="item in storeList" :key="item.id" :label="item.label" :value="item.id"></el-option>
      </el-select>
    </div>
    <div v-if="nextAccountId" class="cell_wrapper flex_sc">
      <!-- <div v-if="accountLevel == 1 && !isAdmin" class="cell_label h13_title">4S店</div>
      <div v-if="accountLevel == 1 && isAdmin" class="cell_label h13_title">市级经销商</div> -->
      <el-select class="find_width" v-if="!isAdmin" clearable size="mini" v-model="storeId" placeholder="请选择" @change="selectStoreId">
        <el-option v-for="item in newStroeList" :key="item.id" :label="item.label" :value="item.id"></el-option>
      </el-select>
      <el-select class="find_width" v-if="isAdmin" clearable size="mini" v-model="nextAccountId1" placeholder="请选择" @change="selectLastAccount">
        <el-option v-for="item in newStroeList" :key="item.id" :label="item.label" :value="item.id"></el-option>
      </el-select>
    </div>
    <div v-if="nextAccountId1" class="cell_wrapper flex_sc">
      <!-- <div class="cell_label h13_title">4S店</div> -->
      <el-select class="find_width" clearable size="mini" v-model="storeId" placeholder="请选择" @change="selectStoreId">
        <el-option v-for="item in lastStoreList" :key="item.id" :label="item.label" :value="item.id"></el-option>
      </el-select>
    </div>
    <!-- </div> -->
  </div>
</template>

<script>
import { getMerchantList } from '../../api/modules/rules'
export default {
  name: '',
  props: {
    show: Boolean
  },
  data() {
    return {
      accountLevel: 1,
      isAdmin: false,
      storeId: '',
      nextAccountId: '',
      nextAccountId1: '',
      newStroeList: [],
      lastStoreList: [],
      merchantList: [],
      storeList: []
    }
  },
  created() {
    const { session } = this.$globalState
    this.accountLevel = session.accountLevel
    this.isAdmin = session.admin
    if (session.accountLevel < 3) {
      this.getMerchantListData()
    }
  },
  methods: {
    getMerchantListData() {
      getMerchantList({}).then(res => {
        this.merchantList = res || []
      })
    },
    selectCurMechant(e) {
      this.$emit('getId', e)
      this.nextAccountId = ''
      this.storeId = ''
      this.nextAccountId1 = ''
      if (!e) {
        this.showThreeLine = false
        return
      }
      let arr = this.merchantList
      let newArr = []
      arr.forEach(item => {
        if (item.id == Number(e)) {
          newArr = item.children || []
        }
      })
      this.storeList = newArr
      // 测试时使用
      if (this.isAdmin) {
        this.storeList = arr
      }
      this.showThreeLine = true
    },
    selectCurAccount(e) {
      this.storeId = ''
      this.nextAccountId1 = ''
      this.$emit('getId', e)
      if (!e) {
        return
      }
      let newArr = []
      this.storeList.forEach(item => {
        if (item.id == e) {
          newArr = item.children || []
        }
      })
      this.newStroeList = newArr
    },
    selectLastAccount(e) {
      this.$emit('getId', e)
      this.storeId = ''
      if (!e) {
        return
      }
      let newArr = []
      this.newStroeList.forEach(item => {
        if (item.id == e) {
          newArr = item.children || []
        }
      })
      this.lastStoreList = newArr
    },
    selectStoreId(e) {
      this.$emit('getId', e)
    }
  }
}
</script>
<style lang="scss" scoped>
.select-seach-con {
  display: flex;
  align-items: center;
  .cell_wrapper {
    // width: 25%;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    margin-bottom: 18px;
    margin-right: 5px;
    // padding-right: 30px;
    .cell_label {
      text-align: right;
      padding-right: 15px;
      white-space: nowrap;
      width: 80px;
    }
    .cell_btn {
      width: 78px;
    }
    .cell_btn_max {
      width: 156px;
    }
  }
  // .find_line {
  //   padding: 9px 15px;
  //   display: flex;
  //   align-items: center;
  //   .cell_wrapper {
  //     width: 25%;
  //     box-sizing: border-box;
  //     padding-right: 30px;
  //     .cell_label {
  //       text-align: right;
  //       padding-right: 15px;
  //       white-space: nowrap;
  //       width: 80px;
  //     }
  //     .cell_btn {
  //       width: 78px;
  //     }
  //     .cell_btn_max {
  //       width: 156px;
  //     }
  //   }
  // }
  .find_width {
    width: 215px;
  }
}
</style>