<template>
  <div class="deleteUploadImgTaskPhoto">
    <van-row gutter="10">
      <van-col
        span="6"
        style=""
        v-if="formData.processStatus != 1 || formData.displayRewardTaskEditable">
        <div class="addImg">
          <uploadVNormalTaskPhoto
            :imgArr="imgs"
            :formData="formData"
            :shouws="true"
            :storeGroupId="storeGroupId"
            :taskList="taskIds.split(',')"
            :collectionItemId="collectionItemId"
            :visitModel="1 + ''"
            :visitsId="visitsId"
            :putInCode="putInCode"
            :photoIdentifyType="photoIdentifyType"
            :pictureSource="pictureSource"
            :continuousShoot="continuousShoot"
            :objectType="objectType"
            @newimgarr="newimgarr"
            ref="uploadVNormal" />
        </div>
      </van-col>
      <van-col span="6" v-for="(urls, index) in imgs" :key="index">
        <div class="imgview">
          <van-icon
            v-if="formData.processStatus != 1 || formData.displayRewardTaskEditable"
            name="close"
            size="20"
            v-on:click="deleteImg(index, urls.fileIdSplicing)" />
          <img :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)" />
          <!-- <img
            v-else
            :src="urls.fileUrl"
            width="100px"
            height="100px"
            @click="previewsImg(index)" /> -->
        </div>
      </van-col>
    </van-row>
  </div>
</template>

<script>
import { ImagePreview } from 'vant';
import { removePhotoBatch } from '@/api/index';
import uploadVNormalTaskPhoto from '@/components/uploadVNormalTaskPhoto';
import { mapState } from 'vuex';
import { getTicketFun } from '@/utils/TXApiFun';
export default {
  name: 'deleteUploadImgTaskPhoto',
  components: { uploadVNormalTaskPhoto },
  computed: {
    ...mapState({
      userInfo: (state) => state.user.userInfo,
    }),
  },
  props: {
    formData: {
      type: Object,
      default() {
        return {};
      },
    },
    photoIdentifyType: {
      // 图匠识别目的(1:店招内容识别,2:门店代码识别,3:调色机识别,4:更换店招,6:sku陈列照)
      type: String,
      default: '',
    },
    storeGroupId: {
      type: String,
    },
    taskIds: {
      type: [Array, String],
      default() {
        return [];
      },
    },
    collectionItemId: {
      type: [String, Number],
    },
    visitsId: {
      type: String,
      default: '',
    },
    putInCode: {
      type: String,
      default: '',
    },
    pictureSource: {
      // 是否允许从相册选择图片 1:允许；0:不允许
      type: String,
      default: '0',
    },
    continuousShoot: {
      // 是否允许连拍/相册多选 1:允许；0:不允许
      type: String,
      default: '0',
    },
    objectType: {
      type: String,
      default: '',
    },
    insert: {
      type: String,
      default: 'false',
    },
    fileInfoList: {
      type: Array,
      default() {
        return [];
      },
    },
    imgs: {
      type: Array,
      default() {
        return [];
      },
    },
  },
  watch: {
    imgs: {
      handler(val) {},
      deep: true,
      immediate: true,
    },
  },
  data() {
    return {
      url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
    };
  },
  methods: {
    deleteImg(index, fileIdList) {
      this.toastLoading(0, '请稍候...', true);
      removePhotoBatch({ fileIdList: fileIdList.split(',') }).then((res) => {
        if (res.code == 200) {
          this.$emit('upDataDetail');
        } else {
          this.$toast('删除失败！');
        }
      });
    },
    previewsImg(index) {
      var arrimg = [];
      for (var imgi = 0; imgi < this.imgs.length; imgi++) {
        arrimg.push(this.imgs[imgi].fileUrl);
      }
      ImagePreview({
        images: arrimg,
        startPosition: index,
        onClose() {
          // do something
        },
      });
    },
    newimgarr() {
      this.$emit('upDataDetail');
    },
  },
};
</script>

<style lang="scss" scoped>
.deleteUploadImgTaskPhoto {
  max-height: 180px;
  overflow-y: auto;
  margin-left: 20px;
  padding: 5px;
}
.addImg {
  height: 88px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f5f5f5;
}
.imgview {
  width: 100%;
  height: 88px;
  position: relative;
  display: inline-block;
  i {
    position: absolute;
    right: -7px;
    top: -7px;
    color: white;
    background: red;
    overflow: hidden;
    border-radius: 50%;
  }
  img {
    width: 100%;
    height: 100%;
  }
}
</style>
