deleteUploadImgTaskPhoto.vue 8.3 KB

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