<template>
  <ali-oss-uploader v-model="currentValue" :max-count="maxCount" :max-size="maxSize" accept="image/*" :userId="userId"
    :type="ossType" width="100%" @input="onInput" @change="onChange" />
</template>

<script>
import AliOssUploader from '../ali-oss-uploader/ali-oss-uploader.vue'

export default {
  name: 'FormItemImage',
  components: { AliOssUploader },
  props: {
    value: { type: Array, default: function () { return []; } },
    maxCount: { type: Number, default: 9 },
    maxSize: { type: Number, default: 5 }
  },
  data: function () {
    return {
      currentValue: []
    };
  },
  computed: {
    userId: function () {
      return this.$store && this.$store.state && this.$store.state.sjInfo
        ? this.$store.state.sjInfo.id : null;
    },
    ossType: function () {
      var artisanType = getApp().globalData ? getApp().globalData.artisanType : 0;
      return (artisanType || 0) + 1;
    }
  },
  watch: {
    value: {
      handler: function (val) {
        this.currentValue = Array.isArray(val) ? val.slice() : [];
      },
      immediate: true
    }
  },
  methods: {
    onInput: function (list) {
      this.$emit('input', list);
    },
    onChange: function (list) {
      this.$emit('change', list);
    }
  }
};
</script>
