deleteUploadImgTaskPhoto.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  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. this.downloadImage(this.formData.mediaInfos);
  128. });
  129. }
  130. }
  131. },
  132. deep: true,
  133. immediate: true,
  134. },
  135. },
  136. data() {
  137. return {
  138. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  139. imgArr: [],
  140. mediaIds: [],
  141. locationRemark: '',
  142. isUploadImg: true,
  143. };
  144. },
  145. methods: {
  146. downloadImage(mediaInfos) {
  147. if (!mediaInfos.length) {
  148. this.toastLoading().clear();
  149. return;
  150. } else {
  151. let mediaitem = mediaInfos.pop();
  152. if (mediaitem.fileUrl) {
  153. this.imgArr.push(mediaitem);
  154. return;
  155. } else {
  156. wx.downloadImage({
  157. serverId: mediaitem.mediaId,
  158. isShowProgressTips: 0, // 默认为1,显示进度提示
  159. success: (res) => {
  160. wx.getLocalImgData({
  161. localId: res.localId,
  162. success: (res2) => {
  163. this.imgArr.push({
  164. mediaId: mediaitem.mediaId,
  165. mediaFileUrl: res2.localData,
  166. });
  167. this.downloadImage(mediaInfos);
  168. },
  169. fail: (err) => {
  170. console.error('获取本地图片数据失败:', err);
  171. this.$toast('获取图片数据失败');
  172. this.toastLoading().clear();
  173. this.downloadImage(mediaInfos);
  174. },
  175. });
  176. },
  177. fail: (err) => {
  178. console.error('下载图片失败:', err);
  179. this.$toast('下载图片失败,请重试');
  180. // 可以选择继续下载其他图片或停止
  181. this.downloadImage(mediaInfos);
  182. },
  183. });
  184. }
  185. }
  186. },
  187. deleteImg(index, urls) {
  188. // <!-- 0=企业微信,1=H5相机 -->
  189. if (this.userInfo.photoMethod == '1') {
  190. removePhotoBatch({ fileIdList: urls.fileIdSplicing.split(',') }).then((res) => {
  191. if (res.code == 200) {
  192. this.$toast('删除成功!');
  193. this.$emit('upDataDetail');
  194. } else {
  195. this.$toast('删除失败!');
  196. }
  197. });
  198. } else {
  199. this.imgArr.splice(index, 1);
  200. }
  201. },
  202. previewsImg(index) {
  203. let urls = this.imgArr.map((item) => item.fileUrl);
  204. ImagePreview({
  205. images: urls,
  206. startPosition: index,
  207. });
  208. },
  209. newimgarr(data) {
  210. const { localIds, locationRemark, source } = data;
  211. this.locationRemark = locationRemark;
  212. console.log(source);
  213. // 0=企业微信,1=H5相机
  214. if (this.userInfo.photoMethod == '0') {
  215. this.isUploadImg = false;
  216. const startIndex = this.imgArr.length;
  217. this.imgArr = this.imgArr.concat(
  218. localIds.map((item) => {
  219. return {
  220. mediaId: '',
  221. fileUrl: item,
  222. };
  223. }),
  224. );
  225. this.$nextTick(() => {
  226. this.syncUpload(localIds, startIndex);
  227. });
  228. } else {
  229. this.$emit('upDataDetail');
  230. }
  231. // if (this.isIOS()) {
  232. // this.imgArr = this.imgArr.concat([...localIds]);
  233. // // 解决ios微信localId无法直接使用的问题,获取base64后再上传
  234. // // this.setIosImg(localIds);
  235. // } else {
  236. // this.imgArr = this.imgArr.concat([...localIds]);
  237. // }
  238. // this.$emit('upDataDetail');
  239. },
  240. syncUpload(localIds, baseIndex = 0, callback) {
  241. if (!localIds.length) {
  242. this.isUploadImg = true;
  243. callback && callback();
  244. return;
  245. } else {
  246. var localId = localIds.pop();
  247. wx.uploadImage({
  248. localId: localId,
  249. isShowProgressTips: 0, // 默认为1,显示进度提示
  250. success: (res) => {
  251. const index = baseIndex + localIds.length;
  252. if (this.imgArr[index]) {
  253. this.imgArr[index].mediaId = res.serverId;
  254. }
  255. this.syncUpload(localIds, baseIndex, callback);
  256. },
  257. });
  258. }
  259. },
  260. isIOS() {
  261. return /iPhone|iPad|iPod/i.test(navigator.userAgent);
  262. },
  263. setIosImg(localIds) {
  264. localIds.forEach((localId) => {
  265. this.wx.getLocalImgData({
  266. localId: localId, // 图片的localID
  267. success: (res) => {
  268. console.log(res.localData);
  269. // this.imgArr.push(res.localData);
  270. },
  271. });
  272. });
  273. },
  274. },
  275. };
  276. </script>
  277. <style lang="scss" scoped>
  278. .deleteUploadImgTaskPhoto {
  279. margin-left: 20px;
  280. }
  281. .addImg {
  282. height: 88px;
  283. display: flex;
  284. align-items: center;
  285. justify-content: center;
  286. background: #f5f5f5;
  287. }
  288. .imgview {
  289. width: 100%;
  290. height: 88px;
  291. position: relative;
  292. display: inline-block;
  293. i {
  294. position: absolute;
  295. right: -2px;
  296. top: -3px;
  297. color: white;
  298. background: red;
  299. overflow: hidden;
  300. border-radius: 50%;
  301. }
  302. img {
  303. width: 100%;
  304. height: 100%;
  305. }
  306. }
  307. </style>