uploadVvisit.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="questionNamep">
  3. <div class="cameraDivp" @click="uploadImg">
  4. <van-icon class="photo" name="photograph" size="22px" color="#969696" />
  5. </div>
  6. <div id="allmap"></div>
  7. </div>
  8. </template>
  9. <script>
  10. import { addstorePhoto } from '@/api/index';
  11. import axios from 'axios';
  12. export default {
  13. name: 'uploadImg',
  14. props: {
  15. shouws: {
  16. type: Boolean,
  17. default: false,
  18. },
  19. uploadid: {
  20. type: String,
  21. default: '',
  22. },
  23. storeGroupId: {
  24. type: String,
  25. default: '',
  26. },
  27. visitsId: {
  28. type: String,
  29. default: '',
  30. },
  31. taskId: {
  32. type: String,
  33. default: '',
  34. },
  35. collectionId: {
  36. type: String,
  37. default: '',
  38. },
  39. objectType: {
  40. type: String,
  41. default: 'rw-ycbf',
  42. },
  43. visitModel: {
  44. type: String,
  45. default: '3',
  46. },
  47. },
  48. methods: {
  49. uploadImg() {
  50. let url = window.location.href;
  51. let that = this;
  52. let wx = this.wx;
  53. let qiyeData;
  54. let addressesRemark = '';
  55. var map = new TMap.Map('allmap', {
  56. zoom: 14,
  57. center: new TMap.LatLng(39.986785, 116.301012),
  58. });
  59. var geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
  60. var markers = new TMap.MultiMarker({
  61. map: map,
  62. geometries: [],
  63. });
  64. markers.setGeometries([]);
  65. const instance = axios.create();
  66. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  67. instance
  68. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  69. params: {
  70. url: url,
  71. },
  72. })
  73. .then((response) => {
  74. if (response.status == 200) {
  75. qiyeData = response.data.data;
  76. wx.config({
  77. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  78. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  79. appId: qiyeData.appId, // 必填,企业微信的corpID
  80. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  81. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  82. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  83. jsApiList: ['ready', 'chooseImage', 'uploadImage', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  84. });
  85. wx.ready(function () {
  86. wx.getLocation({
  87. type: 'gcj02',
  88. success: function (res) {
  89. var location = new TMap.LatLng(res.latitude, res.longitude);
  90. map.setCenter(location);
  91. markers.updateGeometries([
  92. {
  93. id: 'main', // 点标注数据数组
  94. position: location,
  95. },
  96. ]);
  97. geocoder.getAddress({ location: location }).then(
  98. function (result) {
  99. var addresses = result.result.formatted_addresses;
  100. addressesRemark = addresses.recommend;
  101. },
  102. function (err) {
  103. addressesRemark = '';
  104. }
  105. );
  106. },
  107. fail: function () {
  108. that.$dialog.alert({
  109. message: 'GPS未开启',
  110. });
  111. },
  112. });
  113. wx.chooseImage({
  114. count: 1,
  115. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  116. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  117. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  118. isSaveToAlbum: 0,
  119. success: function (res) {
  120. var localIds = '';
  121. if (res.localIds != undefined) {
  122. localIds = res.localIds[0];
  123. } else {
  124. localIds = res.localId;
  125. }
  126. // andriod中localId可以作为img标签的src属性显示图片;
  127. // iOS应当使用 getLocalImgData 获取图片base64数据,从而用于img标签的显示(在img标签内使用 wx.chooseImage 的 localid 显示可能会不成功)
  128. wx.uploadImage({
  129. localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
  130. isShowProgressTips: 1, // 默认为1,显示进度提示
  131. success: function (res) {
  132. that.uploadImagev(res.serverId, addressesRemark);
  133. },
  134. });
  135. },
  136. });
  137. });
  138. }
  139. });
  140. },
  141. uploadImagev(meidaId, addressesRemark) {
  142. var that = this;
  143. var form = {
  144. mediaIds: [meidaId],
  145. collectionItemId: that.collectionId,
  146. objectType: that.objectType,
  147. storeGroupId: that.storeGroupId,
  148. taskId: '',
  149. visitsId: localStorage.getItem('visitId'),
  150. visitModel: that.visitModel,
  151. visitSource: '2',
  152. locationRemark: addressesRemark,
  153. };
  154. var loind1 = that.$toast.loading({
  155. duration: 0,
  156. message: '上传中...',
  157. forbidClick: true,
  158. });
  159. addstorePhoto(form).then((res) => {
  160. if (res.code == 200) {
  161. loind1.clear();
  162. that.$toast('上传成功!');
  163. that.$emit('newimgarr', { fileUrl: res.data[0].url, id: res.data[0].fileId, type: 2 });
  164. } else {
  165. that.$toast('上传失败!');
  166. }
  167. });
  168. },
  169. },
  170. };
  171. </script>
  172. <style lang="scss" scoped>
  173. .questionNamep {
  174. font-size: 16px;
  175. color: #484848;
  176. line-height: 40px;
  177. padding: 0 15px;
  178. box-sizing: border-box;
  179. position: relative;
  180. .cameraDivp {
  181. flex: 1;
  182. display: flex;
  183. align-items: center;
  184. justify-content: center;
  185. .photo {
  186. /*margin-top: 9px;*/
  187. float: right;
  188. }
  189. .camera {
  190. width: 60px;
  191. height: 100%;
  192. position: absolute;
  193. right: 0;
  194. top: 0;
  195. opacity: 0;
  196. z-index: 89;
  197. }
  198. }
  199. }
  200. #allmap {
  201. width: 10px;
  202. height: 10px;
  203. left: -1000px;
  204. position: relative;
  205. }
  206. </style>