<style scoped>
  .wrap {
    display: inline-block;
  }
  .wrap .input {
    width: calc(100% - 65px);
  }
</style>
<template>
  <div class="wrap">
    <el-input v-model="pickPath" :readonly="readonly" :disabled="disabled" class="input">
      <template slot="prepend" v-if="needLabel">路径</template>
    </el-input>
    <el-button @click="selectPath" :disabled="disabled" class="button" type="primary">
      <slot name="button">浏览...</slot>
    </el-button>
    <file-path-select-dialog :title="selectTitle" :show.sync="pathSelectModal" :extension="extension" :siteID="siteID" :platformID="platformID" :path="parentPath || pickPath" :select-type="selectType" @callback="confirmPath" :parentPath="!!parentPath"></file-path-select-dialog>
  </div>
</template>
<script>
import filePathSelectDialog from '../filePathSelectDialog.vue'
export default {
  data() {
    return {
      pathSelectModal: false
    }
  },
  computed: {
    pickPath: {
      get() {
        return this.path
      },
      set(val) {
        this.$emit('update:path', val)
      }
    }
  },
  methods: {
    selectPath() {
      this.pathSelectModal = true
    },
    confirmPath(val) {
      this.pickPath = val
    }
  },
  props: {
    path: {
      required: true
    }, // 绑定路径
    parentPath: {
      default: ''
    }, // 提供父路径
    readonly: {
      type: Boolean,
      default: false
    }, // 是否只读
    disabled: {
      type: Boolean,
      default: false
    }, // 是否禁用
    selectTitle: {
      default: '选择路径'
    }, // 路径选择标题
    selectType: {
      default: 'Path'
    }, // 路径选择类型
    extension: {
      default: ''
    }, // 路径文件扩展名
    siteID: {
      default: function() {
        return this.$root.siteID
      }
    }, // 站点ID
    platformID: {
      default: 'pc'
    }, // 发布平台ID
    needLabel: {
      type: Boolean,
      default: false
    }// 是否需要标签
  },
  components: {
    'file-path-select-dialog': filePathSelectDialog
  }
}
</script>
