<!-- 上传凭证 -->
<template>
  <el-dialog title="上传凭证" :visible.sync="isShow" :close-on-click-modal="false" class="drawer-box" width="700px" @close="handleCancel" append-to-body>
    <el-upload action="#" list-type="picture-card" :auto-upload="false">
      <i slot="default" class="el-icon-plus"></i>
      <div slot="file" slot-scope="{file}">
        <img class="el-upload-list__item-thumbnail" :src="file.url" alt="">
        <span class="el-upload-list__item-actions">
          <span class="el-upload-list__item-preview" @click="handlePictureCardPreview(file)">
            <i class="el-icon-zoom-in"></i>
          </span>
          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleDownload(file)">
            <i class="el-icon-download"></i>
          </span>
          <span v-if="!disabled" class="el-upload-list__item-delete" @click="handleRemove(file)">
            <i class="el-icon-delete"></i>
          </span>
        </span>
      </div>
    </el-upload>
    <el-dialog :visible.sync="dialogVisible">
      <img width="100%" :src="dialogImageUrl" alt="">
    </el-dialog>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel" size="small">取消</el-button>
      <el-button type="primary" size="small" @click="handleSave">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
export default {
  name: '',
  props: {
    isOpen: Boolean,
    propSelectArr: Array,
  },
  watch: {
    isOpen: {
      handler(val) {
        this.isShow = val
        if (val) {
          this.handleInit()
        }
      },
      deep: true,
      immediate: true
    }
  },
  data() {
    return {
      dialogImageUrl: '',
      dialogVisible: false,
      disabled: false,
      isShow: false,
      selectArr: [],
      tableData: [{
        id: 1,
        date: '2016-05-03',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        id: 2,
        date: '2016-05-02',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }, {
        id: 3,
        date: '2016-05-04',
        name: '王小虎',
        address: '上海市普陀区金沙江路 1518 弄'
      }
      ],
      multipleSelection: []
    }
  },


  methods: {
    handleRemove(file) {
      console.log(file);
    },
    handlePictureCardPreview(file) {
      this.dialogImageUrl = file.url;
      this.dialogVisible = true;
    },
    handleDownload(file) {
      console.log(file);
    },
    handleInit() {
      this.$nextTick(() => {
        if (this.propSelectArr.length) {
          this.$refs.table.toggleRowSelection(this.propSelectArr, true)
        } else {
          this.$refs.table.clearSelection()
        }
      })
    },
    handleSave() {
      this.$emit('onConfirm', this.selectArr)
    },
    handleCancel() {
      this.$emit('onCancel')
    },
    handleSelectionChange(val) {
      console.log('selectArr', val);
      this.selectArr = val;
    }
  }
}

</script>
<style lang='scss' scoped>
</style>