deleteUploadImgTaskPhoto.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div class="deleteUploadImgTaskPhoto">
  3. <van-row gutter="10">
  4. <van-col
  5. span="6"
  6. style=""
  7. v-if="formData.processStatus != 1 || formData.displayRewardTaskEditable">
  8. <div class="addImg">
  9. <uploadVNormalTaskPhoto
  10. :formData="formData"
  11. :shouws="true"
  12. :storeGroupId="storeGroupId"
  13. :taskList="taskIds.split(',')"
  14. :collectionItemId="collectionItemId"
  15. :visitModel="1 + ''"
  16. :visitsId="visitsId"
  17. :putInCode="putInCode"
  18. :photoIdentifyType="photoIdentifyType"
  19. :pictureSource="pictureSource"
  20. :continuousShoot="continuousShoot"
  21. :objectType="objectType"
  22. @newimgarr="newimgarr"
  23. ref="uploadVNormal" />
  24. </div>
  25. </van-col>
  26. <van-col span="6" v-for="(urls, index) in imgArr" :key="index">
  27. <div class="imgview">
  28. <van-icon
  29. v-if="formData.processStatus != 1 || formData.displayRewardTaskEditable"
  30. name="close"
  31. size="20"
  32. v-on:click="deleteImg(index, urls)" />
  33. <img
  34. :src="urls.fileUrl || urls.mediaFileUrl"
  35. width="100px"
  36. height="100px"
  37. @click="previewsImg(index)" />
  38. <!-- <img
  39. v-else
  40. :src="urls.fileUrl"
  41. width="100px"
  42. height="100px"
  43. @click="previewsImg(index)" /> -->
  44. </div>
  45. </van-col>
  46. </van-row>
  47. </div>
  48. </template>
  49. <script>
  50. import { ImagePreview } from 'vant';
  51. import { removePhotoBatch } from '@/api/index';
  52. import uploadVNormalTaskPhoto from '@/components/uploadVNormalTaskPhoto';
  53. import { mapState } from 'vuex';
  54. import { getTicketFun } from '@/utils/TXApiFun';
  55. export default {
  56. name: 'deleteUploadImgTaskPhoto',
  57. components: { uploadVNormalTaskPhoto },
  58. computed: {
  59. ...mapState({
  60. userInfo: (state) => state.user.userInfo,
  61. }),
  62. },
  63. props: {
  64. formData: {
  65. type: Object,
  66. default() {
  67. return {};
  68. },
  69. },
  70. photoIdentifyType: {
  71. // 图匠识别目的(1:店招内容识别,2:门店代码识别,3:调色机识别,4:更换店招,6:sku陈列照)
  72. type: String,
  73. default: '',
  74. },
  75. storeGroupId: {
  76. type: String,
  77. },
  78. taskIds: {
  79. type: [Array, String],
  80. default() {
  81. return [];
  82. },
  83. },
  84. collectionItemId: {
  85. type: [String, Number],
  86. },
  87. visitsId: {
  88. type: String,
  89. default: '',
  90. },
  91. putInCode: {
  92. type: String,
  93. default: '',
  94. },
  95. pictureSource: {
  96. // 是否允许从相册选择图片 1:允许;0:不允许
  97. type: String,
  98. default: '0',
  99. },
  100. continuousShoot: {
  101. // 是否允许连拍/相册多选 1:允许;0:不允许
  102. type: String,
  103. default: '0',
  104. },
  105. objectType: {
  106. type: String,
  107. default: '',
  108. },
  109. insert: {
  110. type: String,
  111. default: 'false',
  112. },
  113. fileInfoList: {
  114. type: Array,
  115. default() {
  116. return [];
  117. },
  118. },
  119. },
  120. watch: {
  121. formData: {
  122. handler(val) {
  123. // <!-- 0=企业微信,1=H5相机 -->
  124. if (this.userInfo.photoMethod == '1') {
  125. this.imgArr = this.fileInfoList || [];
  126. } else {
  127. this.imgArr = val.mediaInfos || [];
  128. // if (this.formData.mediaInfos) {
  129. // getTicketFun(['downloadImage']).then(() => {
  130. // this.toastLoading(0, '加载中,请稍候...', true);
  131. // let mediaInfosCopy = JSON.parse(JSON.stringify(this.formData.mediaInfos));
  132. // this.downloadImage(mediaInfosCopy);
  133. // });
  134. // }
  135. }
  136. },
  137. deep: true,
  138. immediate: true,
  139. },
  140. },
  141. data() {
  142. return {
  143. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  144. imgArr: [],
  145. mediaIds: [],
  146. locationRemark: '',
  147. isUploadImg: true,
  148. };
  149. },
  150. methods: {
  151. downloadImage(mediaInfos) {
  152. if (!mediaInfos.length) {
  153. this.toastLoading().clear();
  154. return;
  155. } else {
  156. let mediaitem = mediaInfos.pop();
  157. if (mediaitem.fileUrl) {
  158. this.imgArr.push(mediaitem);
  159. this.downloadImage(mediaInfos);
  160. } else {
  161. wx.downloadImage({
  162. serverId: mediaitem.mediaId,
  163. isShowProgressTips: 0, // 默认为1,显示进度提示
  164. success: (res) => {
  165. wx.getLocalImgData({
  166. localId: res.localId,
  167. success: (res2) => {
  168. this.imgArr.push({
  169. mediaId: mediaitem.mediaId,
  170. mediaFileUrl: res2.localData,
  171. });
  172. this.downloadImage(mediaInfos);
  173. },
  174. fail: (err) => {
  175. console.error('获取本地图片数据失败:', err);
  176. this.$toast('获取图片数据失败');
  177. this.toastLoading().clear();
  178. this.downloadImage(mediaInfos);
  179. },
  180. });
  181. },
  182. fail: (err) => {
  183. console.error('下载图片失败:', err);
  184. this.$toast('下载图片失败,请重试');
  185. // 可以选择继续下载其他图片或停止
  186. this.downloadImage(mediaInfos);
  187. },
  188. });
  189. }
  190. }
  191. },
  192. deleteImg(index, urls) {
  193. // <!-- 0=企业微信,1=H5相机 -->
  194. if (this.userInfo.photoMethod == '1') {
  195. removePhotoBatch({ fileIdList: urls.fileIdSplicing.split(',') }).then((res) => {
  196. if (res.code == 200) {
  197. this.$toast('删除成功!');
  198. this.$emit('upDataDetail');
  199. } else {
  200. this.$toast('删除失败!');
  201. }
  202. });
  203. } else {
  204. this.imgArr.splice(index, 1);
  205. }
  206. },
  207. previewsImg(index) {
  208. let urls = this.imgArr.map((item) => item.fileUrl || item.mediaFileUrl);
  209. ImagePreview({
  210. images: urls,
  211. startPosition: index,
  212. });
  213. },
  214. newimgarr(data) {
  215. const { localIds, locationRemark, source } = data;
  216. this.locationRemark = locationRemark;
  217. console.log(source);
  218. // 0=企业微信,1=H5相机
  219. if (this.userInfo.photoMethod == '0') {
  220. this.isUploadImg = false;
  221. const startIndex = this.imgArr.length;
  222. this.imgArr = this.imgArr.concat(
  223. localIds.map((item) => {
  224. return {
  225. mediaId: '',
  226. mediaFileUrl: item,
  227. };
  228. }),
  229. );
  230. // this.$nextTick(() => {
  231. // this.syncUpload(localIds, startIndex);
  232. // });
  233. } else {
  234. this.$emit('upDataDetail');
  235. }
  236. },
  237. // syncUpload(localIds, baseIndex = 0, callback) {
  238. // if (!localIds.length) {
  239. // this.isUploadImg = true;
  240. // callback && callback();
  241. // return;
  242. // } else {
  243. // var localId = localIds.pop();
  244. // wx.uploadImage({
  245. // localId: localId,
  246. // isShowProgressTips: 0, // 默认为1,显示进度提示
  247. // success: (res) => {
  248. // const index = baseIndex + localIds.length;
  249. // if (this.imgArr[index]) {
  250. // this.imgArr[index].mediaId = res.serverId;
  251. // }
  252. // this.syncUpload(localIds, baseIndex, callback);
  253. // },
  254. // });
  255. // }
  256. // },
  257. },
  258. };
  259. </script>
  260. <style lang="scss" scoped>
  261. .deleteUploadImgTaskPhoto {
  262. max-height: 180px;
  263. overflow-y: auto;
  264. margin-left: 20px;
  265. padding: 5px;
  266. }
  267. .addImg {
  268. height: 88px;
  269. display: flex;
  270. align-items: center;
  271. justify-content: center;
  272. background: #f5f5f5;
  273. }
  274. .imgview {
  275. width: 100%;
  276. height: 88px;
  277. position: relative;
  278. display: inline-block;
  279. i {
  280. position: absolute;
  281. right: -7px;
  282. top: -7px;
  283. color: white;
  284. background: red;
  285. overflow: hidden;
  286. border-radius: 50%;
  287. }
  288. img {
  289. width: 100%;
  290. height: 100%;
  291. }
  292. }
  293. </style>