<!-- 车场选择器 -->
<!-- change方法输出对象 { parkId, parkName } -->
<!--
<ParkSelect v-model="searchParams.parkId" search-mode />
<ParkSelect v-model="formData.parkId" @change="Object.assign(formData, $event)" />
-->
<template>
  <el-select v-bind="$attrs" :value="value" filterable clearable placeholder="请选择车场" @change="selectPark">
    <el-option v-if="searchMode" value="" label="全部" />
    <el-option v-for="(park) in parkOptions" :key="park.parkId" :label="park.parkName" :value="park.parkId" />
  </el-select>
</template>
<script>
import { getParkOptions } from '@/apiV2/park'
export default {
  name: 'ParkSelect',
  props: {
    value: {
      type: String,
      default: ''
    },
    searchMode: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      parkOptions: []
    }
  },
  watch: {
    globalProjectNo: {
      handler(val) {
        this.selectPark('')
        this.getParkOptions()
      }
    }
  },
  async created() {
    this.getParkOptions()
  },
  methods: {
    async getParkOptions(pNo) {
      const { success, data } = await getParkOptions(pNo || this.globalProjectNo)
      if (success) {
        this.parkOptions = data
      }
    },
    selectPark(e) {
      this.$emit('input', e)
      this.$emit('change', { parkId: e.parkId, parkName: e.parkName })
    }
  }
}
</script>
<style lang="scss"></style>
