| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- <template>
- <div class="deleteUploadImgTaskPhoto">
- <van-row gutter="10">
- <van-col span="6" style="" v-if="insert == '1'">
- <div class="addImg">
- <uploadVNormalTaskPhoto
- :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 imgArr" :key="index">
- <div class="imgview">
- <van-icon
- v-if="insert == '1'"
- name="close"
- size="16"
- v-on:click="deleteImg(index, urls)" />
- <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: '0',
- },
- fileInfoList: {
- type: Array,
- default() {
- return [];
- },
- },
- },
- watch: {
- fileInfoList: {
- handler(val) {
- // <!-- 0=企业微信,1=H5相机 -->
- if (this.userInfo.photoMethod == '1') {
- this.imgArr = val || [];
- } else {
- debugger;
- this.imgArr = [];
- if (this.formData.mediaInfos) {
- getTicketFun(['downloadImage']).then(() => {
- this.toastLoading(0, '加载中,请稍候...', true);
- this.downloadImage(this.formData.mediaInfos);
- });
- }
- }
- },
- deep: true,
- immediate: true,
- },
- },
- activated() {
- // 授权
- // getTicketFun(['downloadImage']).then(() => {
- // this.imgArr = [];
- // // <!-- 0=企业微信,1=H5相机 -->
- // if (this.formData) {
- // if (this.userInfo.photoMethod == '1') {
- // this.imgArr = this.formData.collectionItemList[0].fileInfoList || [];
- // } else {
- // if (this.formData.mediaInfos) {
- // this.downloadImage(this.formData.mediaInfos);
- // }
- // }
- // }
- // });
- },
- data() {
- return {
- url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
- imgArr: [],
- mediaIds: [],
- locationRemark: '',
- isUploadImg: true,
- };
- },
- methods: {
- downloadImage(mediaInfos) {
- if (!mediaInfos.length) {
- this.toastLoading().clear();
- return;
- } else {
- let mediaitem = mediaInfos.pop();
- wx.downloadImage({
- serverId: mediaitem.mediaId,
- isShowProgressTips: 0, // 默认为1,显示进度提示
- success: (res) => {
- wx.getLocalImgData({
- localId: res.localId,
- success: (res2) => {
- this.imgArr.push({
- mediaId: mediaitem.mediaId,
- fileUrl: res2.localData,
- });
- this.downloadImage(mediaInfos);
- },
- fail: (err) => {
- console.error('获取本地图片数据失败:', err);
- this.$toast('获取图片数据失败');
- this.toastLoading().clear();
- this.downloadImage(mediaInfos);
- },
- });
- },
- fail: (err) => {
- console.error('下载图片失败:', err);
- this.$toast('下载图片失败,请重试');
- // 可以选择继续下载其他图片或停止
- this.downloadImage(mediaInfos);
- },
- });
- }
- },
- deleteImg(index, urls) {
- // <!-- 0=企业微信,1=H5相机 -->
- if (this.userInfo.photoMethod == '1') {
- removePhotoBatch({ fileIdList: urls.fileIdSplicing.split(',') }).then((res) => {
- if (res.code == 200) {
- this.$toast('删除成功!');
- this.$emit('upDataDetail');
- } else {
- this.$toast('删除失败!');
- }
- });
- } else {
- this.imgArr.splice(index, 1);
- }
- },
- previewsImg(index) {
- let urls = this.imgArr.map((item) => item.fileUrl);
- ImagePreview({
- images: urls,
- startPosition: index,
- });
- },
- newimgarr(data) {
- const { localIds, locationRemark, source } = data;
- this.locationRemark = locationRemark;
- console.log(source);
- // 0=企业微信,1=H5相机
- if (this.userInfo.photoMethod == '0') {
- this.isUploadImg = false;
- const startIndex = this.imgArr.length;
- this.imgArr = this.imgArr.concat(
- localIds.map((item) => {
- return {
- mediaId: '',
- fileUrl: item,
- };
- }),
- );
- this.$nextTick(() => {
- this.syncUpload(localIds, startIndex);
- });
- } else {
- this.$emit('upDataDetail');
- }
- // if (this.isIOS()) {
- // this.imgArr = this.imgArr.concat([...localIds]);
- // // 解决ios微信localId无法直接使用的问题,获取base64后再上传
- // // this.setIosImg(localIds);
- // } else {
- // this.imgArr = this.imgArr.concat([...localIds]);
- // }
- // this.$emit('upDataDetail');
- },
- syncUpload(localIds, baseIndex = 0, callback) {
- if (!localIds.length) {
- this.isUploadImg = true;
- callback && callback();
- return;
- } else {
- var localId = localIds.pop();
- wx.uploadImage({
- localId: localId,
- isShowProgressTips: 0, // 默认为1,显示进度提示
- success: (res) => {
- const index = baseIndex + localIds.length;
- if (this.imgArr[index]) {
- this.imgArr[index].mediaId = res.serverId;
- }
- this.syncUpload(localIds, baseIndex, callback);
- },
- });
- }
- },
- isIOS() {
- return /iPhone|iPad|iPod/i.test(navigator.userAgent);
- },
- setIosImg(localIds) {
- localIds.forEach((localId) => {
- this.wx.getLocalImgData({
- localId: localId, // 图片的localID
- success: (res) => {
- console.log(res.localData);
- // this.imgArr.push(res.localData);
- },
- });
- });
- },
- },
- };
- </script>
- <style lang="scss" scoped>
- .deleteUploadImgTaskPhoto {
- margin-left: 20px;
- }
- .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: -2px;
- top: -3px;
- color: white;
- background: red;
- overflow: hidden;
- border-radius: 50%;
- }
- img {
- width: 100%;
- height: 100%;
- }
- }
- </style>
|