deleteUploadImgTaskPhoto.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  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. data() {
  121. return {
  122. url: process.env.VUE_APP_Target1 + process.env.VUE_APP_BASE_API,
  123. imgArr: [],
  124. mediaIds: [],
  125. locationRemark: '',
  126. };
  127. },
  128. methods: {
  129. getLocalImgData(mediaInfos) {
  130. if (!mediaInfos.length) {
  131. console.log(this.imgArr);
  132. return;
  133. } else {
  134. let mediaitem = mediaInfos.pop();
  135. this.wx.getLocalImgData({
  136. localId: mediaitem.mediaId, // 图片的localID
  137. success: (res) => {
  138. console.log(res.localData);
  139. this.imgArr.push({
  140. mediaId: mediaitem.mediaId,
  141. fileUrl: res.localData,
  142. });
  143. this.getLocalImgData(mediaInfos);
  144. },
  145. });
  146. }
  147. },
  148. deleteImg(index) {
  149. this.imgArr.splice(index, 1);
  150. },
  151. previewsImg(index) {
  152. let urls = this.imgArr.map((item) => item.fileUrl);
  153. ImagePreview({
  154. images: urls,
  155. startPosition: index,
  156. });
  157. },
  158. newimgarr(data) {
  159. const { localIds, locationRemark, source } = data;
  160. this.locationRemark = locationRemark;
  161. console.log(source);
  162. // 0=企业微信,1=H5相机
  163. if (this.userInfo.photoMethod == '0') {
  164. this.syncUpload(localIds);
  165. } else {
  166. this.$emit('upDataDetail');
  167. }
  168. // if (this.isIOS()) {
  169. // this.imgArr = this.imgArr.concat([...localIds]);
  170. // // 解决ios微信localId无法直接使用的问题,获取base64后再上传
  171. // // this.setIosImg(localIds);
  172. // } else {
  173. // this.imgArr = this.imgArr.concat([...localIds]);
  174. // }
  175. // this.$emit('upDataDetail');
  176. },
  177. syncUpload(localIds, callback) {
  178. if (!localIds.length) {
  179. callback && callback();
  180. return;
  181. } else {
  182. var localId = localIds.pop();
  183. wx.uploadImage({
  184. localId: localId,
  185. isShowProgressTips: 0, // 默认为1,显示进度提示
  186. success: (res) => {
  187. this.imgArr.push({
  188. mediaId: res.serverId,
  189. fileUrl: localId,
  190. });
  191. this.syncUpload(localIds, callback);
  192. },
  193. });
  194. }
  195. },
  196. isIOS() {
  197. return /iPhone|iPad|iPod/i.test(navigator.userAgent);
  198. },
  199. setIosImg(localIds) {
  200. localIds.forEach((localId) => {
  201. this.wx.getLocalImgData({
  202. localId: localId, // 图片的localID
  203. success: (res) => {
  204. console.log(res.localData);
  205. // this.imgArr.push(res.localData);
  206. },
  207. });
  208. });
  209. },
  210. },
  211. };
  212. </script>
  213. <style lang="scss" scoped>
  214. .deleteUploadImgTaskPhoto {
  215. margin-left: 20px;
  216. }
  217. .addImg {
  218. height: 88px;
  219. display: flex;
  220. align-items: center;
  221. justify-content: center;
  222. background: #f5f5f5;
  223. }
  224. .imgview {
  225. width: 100%;
  226. height: 88px;
  227. position: relative;
  228. display: inline-block;
  229. i {
  230. position: absolute;
  231. right: -2px;
  232. top: -3px;
  233. color: white;
  234. background: red;
  235. overflow: hidden;
  236. border-radius: 50%;
  237. }
  238. img {
  239. width: 100%;
  240. height: 100%;
  241. }
  242. }
  243. </style>