deleteUploadImgTaskPhoto.vue 8.4 KB

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