<template>
  <div>
    <el-dialog class="special-opt-dlg" :title="dialogTitle" @open="init" :visible.sync="isShow" width="690px">
      <image-picker-tab ref="imagePickerTab" @imagePicked="imagePicked"></image-picker-tab>
      <span slot="footer" class="dialog-footer">
        <el-button @click="isShow = false">取 消</el-button>
        <el-button type="primary" :loading="confirmLoading" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
import ImagePickerTab from './components/ImagePickerTab.vue'
export default {
  components: {
    ImagePickerTab
  },
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      dialogTitle: '更换图片',
      confirmLoading: false
    }
  },
  computed: {
    isShow: {
      get() {
        return this.show
      },
      set(val) {
        this.$emit('update:show', val)
      }
    },
    oprateName() {
      return this.pageType === 'Template' ? '模板' : '专题'
    }
  },
  methods: {
    init() {
      this.confirmLoading = false
      window.eventHub.$off('confirmInvalid')
      window.eventHub.$on('confirmInvalid', this.confirmInvalid)
    },
    confirm() {
      this.confirmLoading = true
      this.$refs.imagePickerTab.doConfirm()
    },
    confirmInvalid() {
      this.confirmLoading = false
    },
    imagePicked(imageData) {
      window.dialogSavedCallback(imageData)
      this.confirmLoading = false
      this.isShow = false
    }
  }
}

</script>
<style>
  .special-opt-dlg .el-dialog__body {
    padding: 0 10px;
  }

</style>
