taskList.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <div>
  3. <!-- 顶部条-->
  4. <van-nav-bar class="navBar" title="拜访" left-arrow @click-left="onClickLeft" />
  5. <!-- 主体内容-->
  6. <div class="container">
  7. <div class="lineGrey"></div>
  8. <div class="card mt10">
  9. <div class="title f-blue">
  10. {{ storeName }}(<span style="color: #0057ba">{{ storeCode }}</span
  11. >)
  12. </div>
  13. <div class="info1">类型:{{ storeCategory }}</div>
  14. <div class="info1">地址:{{ addressLine }}</div>
  15. <div class="info1" v-if="notes != null">上次拜访备注:{{ notes }}</div>
  16. <div class="info1" v-if="hisTime == '' || hisTime == undefined">
  17. 上次拜访时间:{{ parseTime(hisTime) }}
  18. </div>
  19. <van-button
  20. type="info"
  21. style="background: rgb(0, 87, 186); color: #fff; margin: 10px 0; border-radius: 5px"
  22. size="small"
  23. plain
  24. class="centerBtn"
  25. @click="visitFn(shopCode)"
  26. >经营情况</van-button
  27. >
  28. </div>
  29. <div style="color: #999; font-size: 12px; padding: 10px; background-color: #f5f5f5">
  30. <van-icon name="info-o" />&nbsp;今天拜访拍照内容,将同步传给部主管查阅。
  31. </div>
  32. <div class="card">
  33. <div
  34. class="info"
  35. v-for="(item, index) in list"
  36. :key="index"
  37. @click="addStoreVisit(item, index)">
  38. <span class="must" v-show="item.isMust == '0'">*</span>
  39. <p style="width: 94%; margin: 0; line-height: 24px; display: inline-block">
  40. {{ item.taskName }}
  41. </p>
  42. <span v-show="!item.success" class="arrow" style="background-color: #fff; color: #444"
  43. ><van-icon name="arrow"
  44. /></span>
  45. <span v-show="item.success" class="arrow" style="background-color: #0057ba"
  46. ><van-icon name="success"
  47. /></span>
  48. </div>
  49. </div>
  50. </div>
  51. <div class="tc" style="padding: 0 16px">
  52. <van-button class="submitBtn" block type="info" color="#0057ba" @click="endVisitsFn"
  53. >提交拜访</van-button
  54. >
  55. </div>
  56. <br />
  57. <div id="allmap"></div>
  58. </div>
  59. </template>
  60. <script>
  61. import { getStoreGroupTask, endVisits, editDwellTime, suishenbangStoreSale } from '@/api/index';
  62. import axios from 'axios';
  63. export default {
  64. name: 'outstoreVisit',
  65. data() {
  66. return {
  67. notes: '',
  68. visitModel: '1',
  69. storeId: '',
  70. rdId: '',
  71. lat: '',
  72. lon: '',
  73. timer: null,
  74. flag: true,
  75. list: [],
  76. storeGroupId: '',
  77. visitId: null,
  78. addressLine: '',
  79. storeCategory: '',
  80. storeName: '',
  81. contactName: '',
  82. shopCode: '',
  83. storeCode: '',
  84. urlParameter: '',
  85. location: {
  86. lat: '34.6174',
  87. lon: '112.44039',
  88. },
  89. address: '',
  90. city: '',
  91. locationAccuracy: '',
  92. id: '89',
  93. visitEntry: '',
  94. hisTime: '',
  95. latNew: '',
  96. lonNew: '',
  97. PointSum: '',
  98. };
  99. },
  100. created() {
  101. this.urlParameter = this.$route.query;
  102. this.storeId = this.$route.query.storeId + '';
  103. this.rdId = this.$route.query.rdId + '';
  104. this.lat = this.$route.query.lat + '';
  105. this.lon = this.$route.query.lon + '';
  106. this.visitId = this.$route.query.visitId;
  107. this.addressLine = this.$route.query.addressLine + '';
  108. this.storeCategory = this.$route.query.storeCategory + '';
  109. this.storeName = this.$route.query.storeName + '';
  110. this.contactName = this.$route.query.contactName;
  111. this.visitEntry = this.$route.query.visitEntry + '';
  112. this.visitModel = this.$route.query.visitModel + '';
  113. this.latNew = this.$route.query.latNew + '';
  114. this.lonNew = this.$route.query.lonNew + '';
  115. this.hisTime = this.$route.query.hisTime + '';
  116. this.PointSum = this.$route.query.PointSum + '';
  117. this.storeCode = this.$route.query.storeCode + '';
  118. },
  119. beforeRouteLeave(to, from, next) {
  120. if (to.path == '/outstoreVisit' && from.path == '/taskList') {
  121. this.editDwellTimes();
  122. localStorage.removeItem('visitModel');
  123. this.$router.go(-1);
  124. }
  125. next();
  126. },
  127. activated() {
  128. this.urlParameter = this.$route.query;
  129. this.storeId = this.$route.query.storeId + '';
  130. this.rdId = this.$route.query.rdId + '';
  131. this.lat = this.$route.query.lat + '';
  132. this.lon = this.$route.query.lon + '';
  133. this.visitId = this.$route.query.visitId;
  134. this.addressLine = this.$route.query.addressLine + '';
  135. this.storeCategory = this.$route.query.storeCategory + '';
  136. this.storeName = this.$route.query.storeName + '';
  137. this.contactName = this.$route.query.contactName;
  138. this.visitEntry = this.$route.query.visitEntry + '';
  139. this.visitModel = this.$route.query.visitModel + '';
  140. this.latNew = this.$route.query.latNew + '';
  141. this.lonNew = this.$route.query.lonNew + '';
  142. this.hisTime = this.$route.query.hisTime + '';
  143. this.PointSum = this.$route.query.PointSum + '';
  144. this.storeCode = this.$route.query.storeCode + '';
  145. this.list = [];
  146. if (localStorage.getItem('visitId') != null) {
  147. this.visitId = localStorage.getItem('visitId');
  148. setTimeout(() => {
  149. this.addVisits();
  150. });
  151. } else {
  152. setTimeout(() => {
  153. this.addVisits();
  154. });
  155. }
  156. },
  157. methods: {
  158. visitFn(val) {
  159. this.$router.go(-2);
  160. },
  161. // 停留时间
  162. editDwellTimes() {
  163. let dwellTime = this.weekend(localStorage.getItem('startTime'), new Date()) + '';
  164. editDwellTime({ dwellTime: dwellTime, visitsId: this.visitId }).then((res) => {
  165. if (res.code == 200) {
  166. localStorage.removeItem('visitId');
  167. }
  168. });
  169. },
  170. // 获取任务组
  171. getLocation() {
  172. this.list = [];
  173. let url = window.location.href;
  174. let that = this;
  175. let wx = this.wx;
  176. let qiyeData;
  177. const instance = axios.create();
  178. instance.defaults.headers.common['userId'] = localStorage.getItem('loginName');
  179. instance
  180. .get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket', {
  181. params: {
  182. url: url,
  183. storeCode: that.shopCode,
  184. },
  185. })
  186. .then((response) => {
  187. if (response.status == 200) {
  188. var dataList = response.data;
  189. if (dataList.code == 200) {
  190. qiyeData = JSON.parse(dataList.data.ticket);
  191. wx.config({
  192. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  193. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  194. appId: qiyeData.appId, // 必填,企业微信的corpID
  195. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  196. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  197. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  198. jsApiList: ['ready', 'getLocation'], // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  199. });
  200. wx.ready(function () {
  201. wx.getLocation({
  202. type: 'gcj02',
  203. success: function (res) {
  204. var location = that.CJ02BD(res.latitude, res.longitude);
  205. that.location = location;
  206. that.lat = dataList.data.sfaStore.lat;
  207. that.lon = dataList.data.sfaStore.lon;
  208. that.storeId = dataList.data.sfaStore.storeId;
  209. that.visitEntry = dataList.data.visitEntry;
  210. var routeDetailsId = null;
  211. if (dataList.data.rid != undefined) {
  212. routeDetailsId = dataList.data.rid;
  213. }
  214. if (dataList.data.visitId != undefined) {
  215. that.visitId = dataList.data.visitId;
  216. }
  217. localStorage.setItem('chainNameR', dataList.data.sfaStore.chainName);
  218. if (that.lat == '' || that.lat == null) {
  219. that.lat = that.location.lat;
  220. that.lon = that.location.lon;
  221. }
  222. let PointSum = that
  223. .twoPointSum(that.lat, that.lon, location.lat, location.lon)
  224. .toFixed(2);
  225. if (PointSum > 500) {
  226. that.visitModel = '5';
  227. localStorage.setItem('visitModel', '5');
  228. that.$dialog
  229. .confirm({
  230. confirmButtonText: '确定',
  231. cancelButtonText: '重新定位',
  232. title: '系统提示',
  233. message: '距离本店距离差距太大',
  234. })
  235. .then(() => {
  236. that.addVisits(dataList.data.visitEntry, routeDetailsId, PointSum);
  237. })
  238. .catch(() => {
  239. that.getLocation();
  240. });
  241. } else {
  242. that.addVisits(dataList.data.visitEntry, routeDetailsId, PointSum);
  243. }
  244. },
  245. fail: function () {
  246. that.$dialog
  247. .alert({
  248. message: 'GPS未开启',
  249. })
  250. .then(() => {
  251. that.getLocation();
  252. });
  253. },
  254. });
  255. });
  256. } else {
  257. this.$toast.fail(dataList.msg);
  258. }
  259. }
  260. });
  261. },
  262. addVisits() {
  263. let loading1 = this.$toast.loading({
  264. duration: 0,
  265. message: '加载中...',
  266. forbidClick: true,
  267. });
  268. var that = this;
  269. var map = new TMap.Map('allmap', {
  270. zoom: 14,
  271. center: new TMap.LatLng(39.986785, 116.301012),
  272. });
  273. var geocoder = new TMap.service.Geocoder(); // 新建一个正逆地址解析类
  274. var markers = new TMap.MultiMarker({
  275. map: map,
  276. geometries: [],
  277. });
  278. markers.setGeometries([]);
  279. var input = [that.urlParameter.marklat, that.urlParameter.marklon];
  280. var location = new TMap.LatLng(Number(input[0]), Number(input[1]));
  281. map.setCenter(location);
  282. markers.updateGeometries([
  283. {
  284. id: 'main', // 点标注数据数组
  285. position: location,
  286. },
  287. ]);
  288. geocoder.getAddress({ location: location }).then(
  289. function (result) {
  290. var addresses = result.result.formatted_addresses;
  291. let address_component = result.result.address_component;
  292. let province = address_component.province;
  293. let city = address_component.city;
  294. let district = address_component.district;
  295. console.log('province=' + province);
  296. console.log('city=' + city);
  297. console.log('district=' + district);
  298. var params = {
  299. storeId: that.storeId,
  300. storeCode: that.storeCode,
  301. visitEntry: that.visitEntry,
  302. lat: that.lat,
  303. lon: that.lon,
  304. visitSource: '1',
  305. visitModel: that.visitModel,
  306. routeDetailsId: that.rdId,
  307. locationCity: '',
  308. locationRemark: addresses.recommend,
  309. locationAccuracy: that.PointSum,
  310. province: address_component.province,
  311. city: address_component.city,
  312. district: address_component.district,
  313. };
  314. that.locationAccuracy = that.PointSum;
  315. that.city = '';
  316. that.address = '';
  317. localStorage.setItem('address', '');
  318. if (that.visitId != null) {
  319. params.id = that.visitId;
  320. }
  321. that.list = [];
  322. getStoreGroupTask(params).then((res) => {
  323. if (res.code == 200) {
  324. loading1.clear();
  325. localStorage.setItem('visitId', res.data.visitId);
  326. that.notes = res.data.notes;
  327. that.visitId = res.data.visitId;
  328. that.list = res.data.sfaTaskList;
  329. that.storeGroupId = res.data.storeGroupId;
  330. } else {
  331. that.$toast(res.msg);
  332. }
  333. });
  334. },
  335. function (err) {
  336. var params = {
  337. storeId: that.storeId,
  338. storeCode: that.storeCode,
  339. visitEntry: that.visitEntry,
  340. lat: that.lat,
  341. lon: that.lon,
  342. visitSource: '1',
  343. visitModel: that.visitModel,
  344. routeDetailsId: that.rdId,
  345. locationCity: '',
  346. locationRemark: '',
  347. locationAccuracy: that.PointSum,
  348. };
  349. that.locationAccuracy = that.PointSum;
  350. that.city = '';
  351. that.address = '';
  352. localStorage.setItem('address', '');
  353. if (that.visitId != null) {
  354. params.id = that.visitId;
  355. }
  356. that.list = [];
  357. getStoreGroupTask(params).then((res) => {
  358. if (res.code == 200) {
  359. loading1.clear();
  360. localStorage.setItem('visitId', res.data.visitId);
  361. that.notes = res.data.notes;
  362. that.visitId = res.data.visitId;
  363. that.list = res.data.sfaTaskList;
  364. that.storeGroupId = res.data.storeGroupId;
  365. } else {
  366. that.$toast(res.msg);
  367. }
  368. });
  369. }
  370. );
  371. },
  372. // 任务填写
  373. addStoreVisit(val, index) {
  374. if (this.flag) {
  375. this.flag = false;
  376. this.timer = null;
  377. this.timer = setTimeout(() => {
  378. this.flag = true;
  379. }, 2000);
  380. this.$router.push({
  381. path: '/addStoreVisit',
  382. query: {
  383. visitSource: '1',
  384. storeId: this.storeId,
  385. storeCode: this.storeCode,
  386. visitId: this.visitId,
  387. visitEntry: this.visitEntry,
  388. ids: index,
  389. taskId: val.taskId,
  390. storeGroupId: this.storeGroupId,
  391. taskType: val.taskType,
  392. photoType: val.photoType,
  393. lat: this.lat,
  394. lon: this.lon,
  395. visitModel: this.visitModel,
  396. locationCity: this.city,
  397. locationRemark: this.address,
  398. locationAccuracy: this.locationAccuracy,
  399. },
  400. });
  401. }
  402. },
  403. onClickLeft() {
  404. this.$router.go(-1);
  405. },
  406. weekend(time1) {
  407. var arrtime1 = new Date(time1).getTime();
  408. var arrtime2 = new Date().getTime();
  409. return Math.round((arrtime2 - arrtime1) / 1000);
  410. },
  411. // 任务提交
  412. endVisitsFn() {
  413. if (this.list.length == 0) {
  414. this.$toast('暂无任务提交');
  415. return;
  416. }
  417. for (var vl = 0; vl < this.list.length; vl++) {
  418. if (this.list[vl].isMust == '0') {
  419. if (!this.list[vl].success) {
  420. this.$toast(this.list[vl].taskName + '任务未完成');
  421. return;
  422. }
  423. }
  424. }
  425. let loading1 = this.$toast.loading({
  426. duration: 0,
  427. message: '加载中...',
  428. forbidClick: true,
  429. });
  430. let dwellTime = this.weekend(localStorage.getItem('startTime'), new Date());
  431. // dwellTime:dwellTime,
  432. if (this.flag) {
  433. this.flag = false;
  434. this.timer = null;
  435. this.timer = setTimeout(() => {
  436. this.flag = true;
  437. }, 5000);
  438. endVisits({
  439. storeGroupId: this.storeGroupId,
  440. dwellTime: dwellTime,
  441. id: this.visitId,
  442. storeCode: this.$route.query.storeCode,
  443. visitModel: this.$route.query.visitModel,
  444. visitSource: '1',
  445. }).then((res) => {
  446. loading1.clear();
  447. this.flag = true;
  448. if (res.code == 200) {
  449. this.$router.go(-2);
  450. } else {
  451. this.$toast(res.msg);
  452. }
  453. });
  454. }
  455. },
  456. },
  457. };
  458. </script>
  459. <style lang="scss" scoped>
  460. .container {
  461. margin-bottom: 10px;
  462. background-color: white;
  463. }
  464. .card {
  465. background: #fff;
  466. box-sizing: border-box;
  467. padding: 10px 16px;
  468. .title {
  469. line-height: 32px;
  470. font-size: 16px;
  471. font-weight: bold;
  472. color: #333;
  473. }
  474. .subtitle {
  475. line-height: 24px;
  476. font-size: 14px;
  477. color: #7b7b7b;
  478. .status {
  479. float: right;
  480. }
  481. }
  482. .info {
  483. font-size: 14px;
  484. color: #484848;
  485. padding: 14px;
  486. border-bottom: 1px solid #f1f1f1;
  487. position: relative;
  488. .arrow {
  489. float: right;
  490. display: inline-block;
  491. height: 20px;
  492. width: 20px;
  493. line-height: 20px;
  494. text-align: center;
  495. border-radius: 50%;
  496. background: #0057ba;
  497. color: #fff;
  498. font-weight: bold;
  499. font-size: 14px;
  500. position: absolute;
  501. margin-top: -10px;
  502. right: 0;
  503. top: 50%;
  504. }
  505. }
  506. .info1 {
  507. font-size: 14px;
  508. color: #666;
  509. line-height: 18px;
  510. padding: 4px 0;
  511. position: relative;
  512. .arrow {
  513. float: right;
  514. display: inline-block;
  515. height: 20px;
  516. width: 20px;
  517. line-height: 20px;
  518. text-align: center;
  519. border-radius: 50%;
  520. background: #0057ba;
  521. color: #fff;
  522. font-weight: bold;
  523. font-size: 14px;
  524. margin-top: 9px;
  525. position: absolute;
  526. margin-top: -10px;
  527. right: 0;
  528. top: 50%;
  529. }
  530. }
  531. }
  532. .must {
  533. font-size: 18px;
  534. color: #f56c6c;
  535. margin-right: 2px;
  536. }
  537. .zw {
  538. display: inline-block;
  539. width: 7px;
  540. height: 100%;
  541. }
  542. .lineGrey {
  543. height: 10px;
  544. width: 100%;
  545. background: #f1f1f1;
  546. }
  547. .submitBtn {
  548. margin: 16px 0;
  549. font-size: 18px;
  550. }
  551. .border {
  552. border: 1px solid #dedede;
  553. }
  554. .bodrder-b {
  555. border-bottom: 1px solid #dedede;
  556. }
  557. .card .f-blue {
  558. color: #0057ba;
  559. }
  560. </style>
  561. <style>
  562. #allmap {
  563. width: 20px;
  564. height: 20px;
  565. left: -1000px;
  566. position: relative;
  567. }
  568. .van-dialog__confirm,
  569. .van-dialog__confirm:active {
  570. color: #0057ba;
  571. }
  572. </style>