deleteUploadImgTaskPhoto.vue 6.6 KB

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