uploadVNormal.vue 8.8 KB

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