deleteUploadImgTaskPhoto.vue 6.5 KB

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