deleteUploadImgTaskPhoto.vue 6.7 KB

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