deleteUploadImgTaskPhoto.vue 8.3 KB

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