deleteUploadImgTaskPhoto.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 v-if="insert == '1'" name="close" size="16" v-on:click="deleteImg(index)" />
  25. <img :src="urls.fileUrl" width="100px" height="100px" @click="previewsImg(index)" />
  26. <!-- <img
  27. v-else
  28. :src="urls.fileUrl"
  29. width="100px"
  30. height="100px"
  31. @click="previewsImg(index)" /> -->
  32. </div>
  33. </van-col>
  34. </van-row>
  35. </div>
  36. </template>
  37. <script>
  38. import { ImagePreview } from 'vant';
  39. import { removePhotoBatch } from '@/api/index';
  40. import uploadVNormalTaskPhoto from '@/components/uploadVNormalTaskPhoto';
  41. export default {
  42. name: 'deleteUploadImgTaskPhoto',
  43. components: { uploadVNormalTaskPhoto },
  44. props: {
  45. formData: {
  46. type: Object,
  47. default() {
  48. return {};
  49. },
  50. },
  51. photoIdentifyType: {
  52. // 图匠识别目的(1:店招内容识别,2:门店代码识别,3:调色机识别,4:更换店招,6:sku陈列照)
  53. type: String,
  54. default: '',
  55. },
  56. storeGroupId: {
  57. type: String,
  58. },
  59. taskIds: {
  60. type: [Array, String],
  61. default() {
  62. return [];
  63. },
  64. },
  65. collectionItemId: {
  66. type: [String, Number],
  67. },
  68. visitsId: {
  69. type: String,
  70. default: '',
  71. },
  72. putInCode: {
  73. type: String,
  74. default: '',
  75. },
  76. pictureSource: {
  77. // 是否允许从相册选择图片 1:允许;0:不允许
  78. type: String,
  79. default: '0',
  80. },
  81. continuousShoot: {
  82. // 是否允许连拍/相册多选 1:允许;0:不允许
  83. type: String,
  84. default: '0',
  85. },
  86. objectType: {
  87. type: String,
  88. default: '',
  89. },
  90. insert: {
  91. type: String,
  92. default: '0',
  93. },
  94. },
  95. watch: {
  96. formData: {
  97. handler(val) {
  98. this.imgArr = [];
  99. if (val) {
  100. if (val.collectionItemList[0].fileInfoList) {
  101. this.imgArr = val.collectionItemList[0].fileInfoList || [];
  102. } else {
  103. this.getLocalImgData(val.mediaInfos);
  104. }
  105. }
  106. },
  107. deep: true,
  108. immediate: true,
  109. },
  110. },
  111. data() {
  112. return {
  113. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  114. imgArr: [],
  115. mediaIds: [],
  116. locationRemark: '',
  117. };
  118. },
  119. methods: {
  120. getLocalImgData(mediaInfos) {
  121. mediaInfos.forEach((item) => {
  122. this.wx.getLocalImgData({
  123. localId: item.mediaId, // 图片的localID
  124. success: (res) => {
  125. this.imgArr.push({
  126. mediaId: item.mediaId,
  127. fileUrl: res.localData,
  128. });
  129. },
  130. });
  131. });
  132. },
  133. deleteImg(index) {
  134. this.imgArr.splice(index, 1);
  135. },
  136. previewsImg(index) {
  137. let urls = this.imgArr.map((item) => item.fileUrl);
  138. ImagePreview({
  139. images: urls,
  140. startPosition: index,
  141. });
  142. },
  143. newimgarr(data) {
  144. const { localIds, locationRemark, source } = data;
  145. this.locationRemark = locationRemark;
  146. console.log(source);
  147. if (source == 'weixin') {
  148. this.syncUpload(localIds);
  149. } else {
  150. this.$emit('upDataDetail');
  151. }
  152. // if (this.isIOS()) {
  153. // this.imgArr = this.imgArr.concat([...localIds]);
  154. // // 解决ios微信localId无法直接使用的问题,获取base64后再上传
  155. // // this.setIosImg(localIds);
  156. // } else {
  157. // this.imgArr = this.imgArr.concat([...localIds]);
  158. // }
  159. // this.$emit('upDataDetail');
  160. },
  161. syncUpload(localIds, callback) {
  162. if (!localIds.length) {
  163. callback && callback();
  164. return;
  165. } else {
  166. var localId = localIds.pop();
  167. wx.uploadImage({
  168. localId: localId,
  169. isShowProgressTips: 0, // 默认为1,显示进度提示
  170. success: (res) => {
  171. this.imgArr.push({
  172. mediaId: res.serverId,
  173. fileUrl: localId,
  174. });
  175. this.syncUpload(localIds, callback);
  176. },
  177. });
  178. }
  179. },
  180. isIOS() {
  181. return /iPhone|iPad|iPod/i.test(navigator.userAgent);
  182. },
  183. setIosImg(localIds) {
  184. localIds.forEach((localId) => {
  185. this.wx.getLocalImgData({
  186. localId: localId, // 图片的localID
  187. success: (res) => {
  188. console.log(res.localData);
  189. // this.imgArr.push(res.localData);
  190. },
  191. });
  192. });
  193. },
  194. },
  195. };
  196. </script>
  197. <style lang="scss" scoped>
  198. .deleteUploadImgTaskPhoto {
  199. margin-left: 20px;
  200. }
  201. .addImg {
  202. height: 88px;
  203. display: flex;
  204. align-items: center;
  205. justify-content: center;
  206. background: #f5f5f5;
  207. }
  208. .imgview {
  209. width: 100%;
  210. height: 88px;
  211. position: relative;
  212. display: inline-block;
  213. i {
  214. position: absolute;
  215. right: -2px;
  216. top: -3px;
  217. color: white;
  218. background: red;
  219. overflow: hidden;
  220. border-radius: 50%;
  221. }
  222. img {
  223. width: 100%;
  224. height: 100%;
  225. }
  226. }
  227. </style>