complaintImg.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <div class="cameraDiv1">
  3. <p class="coverImg" @click="uploadImg">
  4. <van-icon class="photo ico" name="photograph" size="24px" color="#969696"></van-icon>
  5. </p>
  6. </div>
  7. </template>
  8. <script>
  9. import { ImagePreview } from 'vant';
  10. import axios from 'axios';
  11. import { addPhotoK } from '@/api/clew';
  12. import { getPosition, getTicketFun } from '@/utils/TXApiFun';
  13. export default {
  14. name: 'uploadImg',
  15. props: {
  16. itemData: {
  17. type: Object,
  18. default: {},
  19. },
  20. isRequired: {
  21. // 是否开启拍照前校验
  22. type: Boolean,
  23. default: true,
  24. },
  25. customerClueId: {
  26. type: String | Number,
  27. default: '',
  28. },
  29. customerClueItemId: {
  30. type: String | Number,
  31. default: '',
  32. },
  33. },
  34. data() {
  35. return {};
  36. },
  37. created() {
  38. // 授权
  39. getTicketFun(['chooseImage', 'uploadImage']).then(() => {});
  40. },
  41. methods: {
  42. uploadImg() {
  43. // 拍照前校验
  44. if (this.required) {
  45. }
  46. this.wx.ready(() => {
  47. this.wx.chooseImage({
  48. count: 1,
  49. sizeType: ['original'], // 可以指定是原图还是压缩图,默认二者都有 compressed:压缩后的图片;original:原图
  50. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  51. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  52. isSaveToAlbum: 0,
  53. success: (res) => {
  54. let localIds = '';
  55. if (res.localIds != undefined) {
  56. localIds = res.localIds[0];
  57. } else {
  58. localIds = res.localId;
  59. }
  60. // andriod中localId可以作为img标签的src属性显示图片;
  61. // iOS应当使用 getLocalImgData 获取图片base64数据,从而用于img标签的显示(在img标签内使用 wx.chooseImage 的 localid 显示可能会不成功)
  62. wx.uploadImage({
  63. localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
  64. isShowProgressTips: 1, // 默认为1,显示进度提示
  65. success: (res) => {
  66. this.addPhotoK(res.serverId);
  67. },
  68. });
  69. },
  70. });
  71. });
  72. },
  73. addPhotoK(meidaId) {
  74. var form = {
  75. mediaId: meidaId,
  76. customerClueId: this.customerClueId,
  77. customerClueItemId: this.customerClueItemId,
  78. };
  79. this.toastLoading(0, '加载中...', true);
  80. addPhotoK(form).then((res) => {
  81. this.toastLoading().clear();
  82. if (res.code == 200) {
  83. this.$toast('上传成功!');
  84. this.$emit('newimgarr', {
  85. fileUrl: res.data.url,
  86. id: res.data.fileId,
  87. itemData: this.itemData,
  88. });
  89. } else {
  90. this.$toast('上传失败!');
  91. }
  92. });
  93. },
  94. },
  95. };
  96. </script>
  97. <style scoped>
  98. .cameraDiv1 {
  99. height: 100%;
  100. width: 100%;
  101. }
  102. .cameraDiv1 img {
  103. /* position: absolute;
  104. width: 100%;
  105. display: block;
  106. height: 20px;
  107. top: 0; */
  108. }
  109. .imgPre {
  110. height: 20px;
  111. width: 100%;
  112. background-color: white;
  113. border-radius: 6px;
  114. overflow: hidden;
  115. }
  116. .photos1 {
  117. margin: 0px auto;
  118. left: 20%;
  119. margin-left: -14px;
  120. }
  121. .photobrowsing {
  122. position: absolute;
  123. padding: 4px;
  124. right: 0;
  125. top: 0;
  126. z-index: 99;
  127. background-color: rgba(255, 255, 255, 0.8);
  128. border-bottom-left-radius: 3px;
  129. border-top-left-radius: 3px;
  130. }
  131. .coverImg {
  132. height: 100%;
  133. width: 100%;
  134. display: flex;
  135. align-items: center;
  136. justify-content: center;
  137. margin: 0;
  138. }
  139. .coverImg .ico {
  140. top: 0%;
  141. }
  142. </style>