uploadVNormal.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445
  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 class="mask" v-if="progressFlag">
  8. <el-progress
  9. type="circle"
  10. :percentage="percentage"
  11. :show-text="true"
  12. :width="110"
  13. :format="format"></el-progress>
  14. <!-- <div class="progressClose" @progressClose="progressClose">取消</div> -->
  15. </div>
  16. <imageAIVerifyErr
  17. v-if="imageAIVerifyFlag"
  18. :imageAIVerifyFlag="imageAIVerifyFlag"
  19. :imageAIVerifyData="imageAIVerifyData"
  20. @confirmUpload="confirmUpload"
  21. @uploadImgFun="uploadImg"
  22. :source="'visit'"
  23. @normalFlow="normalFlow"
  24. @close="close"></imageAIVerifyErr>
  25. </div>
  26. </template>
  27. <script>
  28. import { addstorePhoto, addVisitsPosition, addPhotoToDB } from '@/api/index';
  29. import imageAIVerifyErr from './imageAIVerifyErr';
  30. import axios from 'axios';
  31. export default {
  32. name: 'uploadImg',
  33. components: { imageAIVerifyErr },
  34. props: {
  35. uploadid: {
  36. type: String,
  37. default: '',
  38. },
  39. storeGroupId: {
  40. type: String,
  41. default: '',
  42. },
  43. parentCollectionId: {
  44. type: String,
  45. default: '',
  46. },
  47. secondCollectionId: {
  48. type: String,
  49. default: '',
  50. },
  51. firstCollectionId: {
  52. type: String,
  53. default: '',
  54. },
  55. fourthCollectionId: {
  56. type: String,
  57. default: '',
  58. },
  59. thirdCollectionId: {
  60. type: String,
  61. default: '',
  62. },
  63. visitsId: {
  64. type: String,
  65. default: '',
  66. },
  67. taskId: {
  68. type: String,
  69. default: '',
  70. },
  71. collectionId: {
  72. type: String,
  73. default: '',
  74. },
  75. objectType: {
  76. type: String,
  77. default: '',
  78. },
  79. type: {
  80. type: Number,
  81. default: 1,
  82. },
  83. imgArr: {
  84. type: Array,
  85. default() {
  86. return [];
  87. },
  88. },
  89. visitModel: {
  90. type: String,
  91. default: '1',
  92. },
  93. deviceCode: {
  94. type: String,
  95. default: '',
  96. },
  97. putInCode: {
  98. type: String,
  99. default: '',
  100. },
  101. photoIdentifyType: {
  102. // 图匠识别目的(1:店招内容识别,2:门店代码识别,3:调色机识别,4:更换店招)
  103. type: String,
  104. default: '',
  105. },
  106. },
  107. data() {
  108. return {
  109. shows: false,
  110. url: '',
  111. progressFlag: false,
  112. percentage: 0,
  113. timeFlag: null,
  114. imageAIVerifyFlag: false,
  115. imageAIVerifyData: null, //图匠校验返回的数据
  116. meidaId: '', //当前上传图片id
  117. addressesRemark: '', //当前位置信息
  118. };
  119. },
  120. methods: {
  121. uploadImg() {
  122. var map = new TMap.Map('allmap', {
  123. zoom: 14,
  124. center: new TMap.LatLng(39.986785, 116.301012),
  125. });
  126. var geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
  127. var markers = new TMap.MultiMarker({
  128. map: map,
  129. geometries: [],
  130. });
  131. markers.setGeometries([]);
  132. if (this.objectType == '' || this.objectType == null) {
  133. this.$toast('请选择类型!');
  134. return;
  135. }
  136. let url = window.location.href;
  137. let that = this;
  138. let wx = this.wx;
  139. let qiyeData;
  140. let addressesRemark = '';
  141. const instance = axios.create();
  142. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  143. instance
  144. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  145. params: {
  146. url: url,
  147. },
  148. })
  149. .then((response) => {
  150. if (response.status == 200) {
  151. qiyeData = response.data.data;
  152. wx.config({
  153. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  154. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  155. appId: qiyeData.appId, // 必填,企业微信的corpID
  156. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  157. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  158. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  159. jsApiList: ['ready', 'chooseImage', 'uploadImage', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  160. });
  161. wx.ready(function () {
  162. wx.getLocation({
  163. type: 'gcj02',
  164. success: function (res) {
  165. var location = new TMap.LatLng(res.latitude, res.longitude);
  166. map.setCenter(location);
  167. markers.updateGeometries([
  168. {
  169. id: 'main', // 点标注数据数组
  170. position: location,
  171. },
  172. ]);
  173. geocoder.getAddress({ location: location }).then(
  174. function (result) {
  175. var addresses = result.result.formatted_addresses;
  176. addressesRemark = addresses.recommend;
  177. },
  178. function (err) {
  179. addressesRemark = '';
  180. }
  181. );
  182. },
  183. fail: function () {
  184. that.$dialog.alert({
  185. message: 'GPS未开启',
  186. });
  187. },
  188. });
  189. wx.chooseImage({
  190. count: 1,
  191. sizeType: ['compressed'], // 可以指定是原图还是压缩图,默认二者都有
  192. sourceType: ['camera'], // 可以指定来源是相册还是相机,默认二者都有
  193. defaultCameraMode: 'normal', //表示进入拍照界面的默认模式,目前有normal与batch两种选择,normal表示普通单拍模式,batch表示连拍模式,不传该参数则为normal模式。从3.0.26版本开始支持front和batch_front两种值,其中front表示默认为前置摄像头单拍模式,batch_front表示默认为前置摄像头连拍模式。(注:用户进入拍照界面仍然可自由切换两种模式)
  194. isSaveToAlbum: 0,
  195. success: function (res) {
  196. var localIds = '';
  197. if (res.localIds != undefined) {
  198. localIds = res.localIds[0];
  199. } else {
  200. localIds = res.localId;
  201. }
  202. wx.uploadImage({
  203. localId: localIds, // 需要上传的图片的本地ID,由chooseImage接口获得
  204. isShowProgressTips: 1, // 默认为1,显示进度提示
  205. success: function (res) {
  206. that.uploadImagev(res.serverId, addressesRemark);
  207. },
  208. });
  209. },
  210. });
  211. });
  212. }
  213. });
  214. },
  215. uploadImagev(meidaId, addressesRemark) {
  216. // 初始化重置 图匠校验
  217. this.resetProgress();
  218. this.close();
  219. var that = this;
  220. var parentCollectionId = null;
  221. if (that.parentCollectionId != null && that.parentCollectionId != 'null') {
  222. parentCollectionId = that.parentCollectionId;
  223. }
  224. var secondCollectionId = null;
  225. if (that.secondCollectionId != null && that.secondCollectionId != 'null') {
  226. secondCollectionId = that.secondCollectionId;
  227. }
  228. var firstCollectionId = null;
  229. if (that.firstCollectionId != null && that.firstCollectionId != 'null') {
  230. firstCollectionId = that.firstCollectionId;
  231. }
  232. var fourthCollectionId = null;
  233. if (that.fourthCollectionId != null && that.fourthCollectionId != 'null') {
  234. fourthCollectionId = that.fourthCollectionId;
  235. }
  236. var thirdCollectionId = null;
  237. if (that.thirdCollectionId != null && that.thirdCollectionId != 'null') {
  238. thirdCollectionId = that.thirdCollectionId;
  239. }
  240. this.meidaId = meidaId;
  241. this.addressesRemark = addressesRemark;
  242. var form = {
  243. mediaId: meidaId,
  244. collectionItemId: that.collectionId,
  245. objectType: that.objectType,
  246. storeGroupId: that.storeGroupId,
  247. taskId: that.taskId,
  248. visitsId: localStorage.getItem('visitId'),
  249. visitModel: that.visitModel,
  250. visitSource: '1',
  251. locationRemark: addressesRemark,
  252. parentCollectionId: parentCollectionId,
  253. secondCollectionId: secondCollectionId,
  254. firstCollectionId: firstCollectionId,
  255. fourthCollectionId: fourthCollectionId,
  256. thirdCollectionId: thirdCollectionId,
  257. deviceCode: that.deviceCode, //设备编号
  258. putInCode: that.putInCode, //投放编号
  259. };
  260. // 需要图匠校验的添加参数和loading
  261. if (this.photoIdentifyType) {
  262. form.photoIdentifyType = this.photoIdentifyType;
  263. this.progress();
  264. } else {
  265. this.toastLoading(0, '上传中...', true);
  266. }
  267. addstorePhoto(form)
  268. .then((res) => {
  269. this.toastLoading().clear();
  270. if (res.code == -1) {
  271. // 图匠图片校验接口超时
  272. this.requestTimeOut(res);
  273. } else if (res.code == 200) {
  274. // 图匠校验结果返回
  275. if (this.photoIdentifyType) {
  276. // 重置loaidng状态
  277. this.resetProgress();
  278. this.imageAIVerifyFlag = true;
  279. this.imageAIVerifyData = res.data;
  280. } else {
  281. // 正常流程
  282. this.normalFlow(res);
  283. }
  284. } else {
  285. this.resetProgress();
  286. that.$toast('上传失败!');
  287. }
  288. })
  289. .catch(() => {
  290. this.resetProgress();
  291. });
  292. },
  293. // 正常流程
  294. normalFlow(res) {
  295. this.$toast('上传成功!');
  296. this.$emit('newimgarr', {
  297. fileUrl: res.data.url,
  298. id: res.data.fileId,
  299. type: 2,
  300. photoIdentifyType: this.photoIdentifyType,
  301. });
  302. },
  303. progress() {
  304. // 后端接口20000ms后失效,每1000m progress加10,到90停止;
  305. this.progressFlag = true;
  306. this.percentage = 10;
  307. this.timeFlag = setInterval(() => {
  308. this.percentage = this.percentage + 10;
  309. if (this.percentage == 90) clearInterval(this.timeFlag);
  310. }, 1000);
  311. },
  312. format(percentage) {
  313. return `${percentage} %\n图像识别中`;
  314. },
  315. // 重置loaidng状态
  316. resetProgress() {
  317. this.percentage = 100;
  318. clearInterval(this.timeFlag);
  319. this.progressFlag = false;
  320. this.percentage = 0;
  321. },
  322. // 照片是否入库,1.照片识别三次不通过仍要上传,2.照片识别通过
  323. // isUpdate:是否更新店招照片,只有门店店招需要更新
  324. confirmUpload(res) {
  325. if (this.photoIdentifyType) {
  326. var form = {
  327. mediaId: this.meidaId, // string 图片素材id
  328. visitSource: '1', // Long 拜访模式
  329. storeGroupId: this.storeGroupId, // string 门店任务组,多个用逗号隔开
  330. visitsId: localStorage.getItem('visitId'), // string 拜访id
  331. taskId: this.taskId, // string 任务id
  332. objectType: this.objectType, // string 照片类型,取任务上的照片类型,如果没有则取手动选择的照片类型
  333. locationRemark: this.addressesRemark, // String 当前地址信息
  334. firstCollectionId: this.firstCollectionId, // Long 第一级采集项id,取当前采集项的字段就行
  335. secondCollectionId: this.secondCollectionId, // Long 第二级采集项id,取当前采集项的字段就行
  336. putInCode: this.putInCode, // String 当前任务对应的投放编号
  337. deviceCode: this.deviceCode, // String 当前任务对应的设备编号
  338. collectionItemId: this.collectionId,
  339. url: res.data.url, // String 当前拍摄图片的url
  340. businessId: res.data.businessId, // 当前拍摄图片id
  341. };
  342. if (res.isUpdate) form.isUpdate = 'true';
  343. addPhotoToDB(form).then((resData) => {
  344. if (resData.code == 200) {
  345. console.log(resData);
  346. res.data.fileId = resData.data.fileId;
  347. this.normalFlow(res);
  348. }
  349. });
  350. }
  351. },
  352. close() {
  353. this.imageAIVerifyFlag = false;
  354. },
  355. requestTimeOut(res) {
  356. this.resetProgress();
  357. this.close();
  358. this.$dialog
  359. .confirm({
  360. title: '系统提示',
  361. message: res.msg,
  362. showCancelButton: false,
  363. })
  364. .then(() => {
  365. this.confirmUpload(res);
  366. });
  367. },
  368. // 取消图片上传
  369. progressClose() {},
  370. },
  371. };
  372. </script>
  373. <style lang="scss" scoped>
  374. .questionNamep {
  375. font-size: 16px;
  376. color: #484848;
  377. line-height: 40px;
  378. padding: 0 15px;
  379. box-sizing: border-box;
  380. position: relative;
  381. .cameraDivp {
  382. flex: 1;
  383. display: flex;
  384. align-items: center;
  385. justify-content: center;
  386. .photo {
  387. /*margin-top: 9px;*/
  388. float: right;
  389. }
  390. .camera {
  391. width: 60px;
  392. height: 100%;
  393. position: absolute;
  394. right: 0;
  395. top: 0;
  396. opacity: 0;
  397. z-index: 89;
  398. }
  399. }
  400. .mask {
  401. position: fixed;
  402. top: 0;
  403. left: 0;
  404. right: 0;
  405. bottom: 0;
  406. width: 100%;
  407. height: 100%;
  408. background: rgba(255, 255, 255, 1);
  409. display: flex;
  410. justify-content: center;
  411. align-items: center;
  412. z-index: 99999999;
  413. .progressClose {
  414. width: 60px;
  415. text-align: center;
  416. background: #67c23a;
  417. color: #fff;
  418. height: 30px;
  419. line-height: 30px;
  420. border-radius: 5px;
  421. margin-top: 5px;
  422. font-size: 12px;
  423. }
  424. }
  425. }
  426. #allmap {
  427. width: 10px;
  428. height: 10px;
  429. left: -1000px;
  430. position: relative;
  431. }
  432. </style>
  433. <style lang="scss">
  434. .mask {
  435. .el-progress__text {
  436. white-space: pre-wrap;
  437. }
  438. }
  439. </style>