uploadVNormal.vue 8.5 KB

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