uploadVvisit.vue 6.6 KB

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