deleteUploadImgTaskPhoto.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  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. this.imgArr = [];
  116. // <!-- 0=企业微信,1=H5相机 -->
  117. // if (val) {
  118. if (this.userInfo.photoMethod == '1') {
  119. this.imgArr = val || [];
  120. } else {
  121. }
  122. // }
  123. },
  124. deep: true,
  125. immediate: true,
  126. },
  127. },
  128. created() {
  129. // 授权
  130. getTicketFun(['downloadImage']).then(() => {
  131. this.imgArr = [];
  132. // <!-- 0=企业微信,1=H5相机 -->
  133. if (this.formData) {
  134. if (this.userInfo.photoMethod == '1') {
  135. this.imgArr = this.formData.collectionItemList[0].fileInfoList || [];
  136. } else {
  137. if (this.formData.mediaInfos) {
  138. this.downloadImage(this.formData.mediaInfos);
  139. }
  140. }
  141. }
  142. });
  143. },
  144. data() {
  145. return {
  146. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  147. imgArr: [],
  148. mediaIds: [],
  149. locationRemark: '',
  150. };
  151. },
  152. methods: {
  153. downloadImage(mediaInfos) {
  154. if (!mediaInfos.length) {
  155. return;
  156. } else {
  157. let mediaitem = mediaInfos.pop();
  158. wx.downloadImage({
  159. serverId: mediaitem.mediaId,
  160. isShowProgressTips: 0, // 默认为1,显示进度提示
  161. success: (res) => {
  162. wx.getLocalImgData({
  163. localId: res.localId,
  164. success: (res2) => {
  165. this.imgArr.push({
  166. mediaId: mediaitem.mediaId,
  167. fileUrl: res2.localData,
  168. });
  169. this.downloadImage(mediaInfos);
  170. },
  171. fail: (err) => {
  172. console.error('获取本地图片数据失败:', err);
  173. this.$toast('获取图片数据失败');
  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. 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.imgArr = this.imgArr.concat(
  216. localIds.map((item) => {
  217. return {
  218. mediaId: '',
  219. fileUrl: item,
  220. };
  221. }),
  222. );
  223. this.$nextTick(() => {
  224. this.syncUpload(localIds);
  225. });
  226. } else {
  227. this.$emit('upDataDetail');
  228. }
  229. // if (this.isIOS()) {
  230. // this.imgArr = this.imgArr.concat([...localIds]);
  231. // // 解决ios微信localId无法直接使用的问题,获取base64后再上传
  232. // // this.setIosImg(localIds);
  233. // } else {
  234. // this.imgArr = this.imgArr.concat([...localIds]);
  235. // }
  236. // this.$emit('upDataDetail');
  237. },
  238. syncUpload(localIds, callback) {
  239. if (!localIds.length) {
  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. console.log(localIds.length);
  249. this.imgArr[localIds.length].mediaId = res.serverId;
  250. this.syncUpload(localIds, callback);
  251. },
  252. });
  253. }
  254. },
  255. isIOS() {
  256. return /iPhone|iPad|iPod/i.test(navigator.userAgent);
  257. },
  258. setIosImg(localIds) {
  259. localIds.forEach((localId) => {
  260. this.wx.getLocalImgData({
  261. localId: localId, // 图片的localID
  262. success: (res) => {
  263. console.log(res.localData);
  264. // this.imgArr.push(res.localData);
  265. },
  266. });
  267. });
  268. },
  269. },
  270. };
  271. </script>
  272. <style lang="scss" scoped>
  273. .deleteUploadImgTaskPhoto {
  274. margin-left: 20px;
  275. }
  276. .addImg {
  277. height: 88px;
  278. display: flex;
  279. align-items: center;
  280. justify-content: center;
  281. background: #f5f5f5;
  282. }
  283. .imgview {
  284. width: 100%;
  285. height: 88px;
  286. position: relative;
  287. display: inline-block;
  288. i {
  289. position: absolute;
  290. right: -2px;
  291. top: -3px;
  292. color: white;
  293. background: red;
  294. overflow: hidden;
  295. border-radius: 50%;
  296. }
  297. img {
  298. width: 100%;
  299. height: 100%;
  300. }
  301. }
  302. </style>