deleteUploadImgTaskPhoto.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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="16"
  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 = [];
  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. // if (this.isIOS()) {
  237. // this.imgArr = this.imgArr.concat([...localIds]);
  238. // // 解决ios微信localId无法直接使用的问题,获取base64后再上传
  239. // // this.setIosImg(localIds);
  240. // } else {
  241. // this.imgArr = this.imgArr.concat([...localIds]);
  242. // }
  243. // this.$emit('upDataDetail');
  244. },
  245. syncUpload(localIds, baseIndex = 0, callback) {
  246. if (!localIds.length) {
  247. this.isUploadImg = true;
  248. callback && callback();
  249. return;
  250. } else {
  251. var localId = localIds.pop();
  252. wx.uploadImage({
  253. localId: localId,
  254. isShowProgressTips: 0, // 默认为1,显示进度提示
  255. success: (res) => {
  256. const index = baseIndex + localIds.length;
  257. if (this.imgArr[index]) {
  258. this.imgArr[index].mediaId = res.serverId;
  259. }
  260. this.syncUpload(localIds, baseIndex, callback);
  261. },
  262. });
  263. }
  264. },
  265. isIOS() {
  266. return /iPhone|iPad|iPod/i.test(navigator.userAgent);
  267. },
  268. setIosImg(localIds) {
  269. localIds.forEach((localId) => {
  270. this.wx.getLocalImgData({
  271. localId: localId, // 图片的localID
  272. success: (res) => {
  273. console.log(res.localData);
  274. // this.imgArr.push(res.localData);
  275. },
  276. });
  277. });
  278. },
  279. },
  280. };
  281. </script>
  282. <style lang="scss" scoped>
  283. .deleteUploadImgTaskPhoto {
  284. margin-left: 20px;
  285. }
  286. .addImg {
  287. height: 88px;
  288. display: flex;
  289. align-items: center;
  290. justify-content: center;
  291. background: #f5f5f5;
  292. }
  293. .imgview {
  294. width: 100%;
  295. height: 88px;
  296. position: relative;
  297. display: inline-block;
  298. i {
  299. position: absolute;
  300. right: -2px;
  301. top: -3px;
  302. color: white;
  303. background: red;
  304. overflow: hidden;
  305. border-radius: 50%;
  306. }
  307. img {
  308. width: 100%;
  309. height: 100%;
  310. }
  311. }
  312. </style>