outstoreVisit.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383
  1. <template>
  2. <div>
  3. <!-- 顶部条-->
  4. <van-nav-bar
  5. class="navBar"
  6. title="拜访"
  7. left-arrow
  8. @click-left="onClickLeft"
  9. >
  10. </van-nav-bar>
  11. <!-- 主体内容-->
  12. <div class="container">
  13. <div class="lineGrey"></div>
  14. <div class="card mt10">
  15. <div class="title f-blue">{{ storeName }}(<span style="color:#0057ba">{{ urlParameter.shopCode }}</span>)</div>
  16. <div class="info1">类型:{{ storeCategory }}</div>
  17. <div class="info1">地址:{{ addressLine }}</div>
  18. <div class="info1" v-if="hisTime==''||hisTime==undefined">上次拜访时间:{{ parseTime(hisTime) }}</div>
  19. <van-button type="info" style="background: rgb(0, 87, 186);color:#fff; margin: 10px 0; border-radius: 5px;"
  20. size="small" plain
  21. class="centerBtn"
  22. @click="visitFn(urlParameter.shopCode)">经营情况
  23. </van-button>
  24. </div>
  25. <div class="lineGrey"></div>
  26. <div class="card">
  27. <p style="text-align: center;">{{ msg }}</p>
  28. </div>
  29. </div>
  30. <br>
  31. <div id="allmap"></div>
  32. </div>
  33. </template>
  34. <script>
  35. import axios from 'axios';
  36. export default {
  37. name: "outstoreVisit",
  38. data() {
  39. return {
  40. visitModel: "1",
  41. storeId: "",
  42. rdId: "",
  43. lat: "",
  44. lon: "",
  45. cont: 0,
  46. list: [],
  47. storeGroupId: "",
  48. visitId: null,
  49. addressLine: "",
  50. storeCategory: "",
  51. storeName: "",
  52. contactName: "",
  53. shopCode: "",
  54. urlParameter: "",
  55. location: {
  56. lat: "34.6174",
  57. lon: "112.44039"
  58. },
  59. address: "",
  60. city: "",
  61. locationAccuracy: "",
  62. id: "89",
  63. closePag: true,
  64. msg: "",
  65. hisTime: ""
  66. }
  67. },
  68. created() {
  69. this.urlParameter = this.$route.query;
  70. this.storeId = this.$route.query.storeId + "";
  71. this.shopCode = this.$route.query.shopCode;
  72. this.addressLine = this.$route.query.addressLine + "";
  73. this.storeCategory = this.$route.query.storeCategory + "";
  74. this.storeName = this.$route.query.storeName + "";
  75. localStorage.setItem("visitModel", "1")
  76. setTimeout(() => {
  77. this.getLocation()
  78. })
  79. },
  80. methods: {
  81. // 定位
  82. getLocation() {
  83. this.visitId=this.$route.query.visitId
  84. let loading1 = this.$toast.loading({
  85. duration: 0,
  86. message: '加载中...',
  87. forbidClick: true,
  88. });
  89. let url = window.location.href;
  90. let that = this;
  91. let wx = this.wx
  92. let qiyeData
  93. const instance = axios.create();
  94. instance.defaults.headers.common['userId'] = localStorage.getItem("loginName");
  95. instance.get(process.env.VUE_APP_BASE_API + 'mobile/wx/ticket',
  96. {
  97. params: {
  98. url: url,
  99. storeCode: that.shopCode
  100. }
  101. }).then(response => {
  102. if (response.status == 200) {
  103. var dataList = response.data
  104. if (dataList.code == 200) {
  105. this.cont = 3;
  106. var flat = true;
  107. var times = setInterval(() => {
  108. this.cont--
  109. if (this.cont == "0") {
  110. if (flat) {
  111. loading1.clear()
  112. clearInterval(times)
  113. that.$dialog.alert({
  114. message: '定位失败,请开启企微定位权限',
  115. }).then(() => {
  116. this.$router.go(-1)
  117. });
  118. } else {
  119. clearInterval(times)
  120. }
  121. }
  122. }, 1000)
  123. qiyeData = JSON.parse(dataList.data.ticket);
  124. wx.config({
  125. beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  126. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  127. appId: qiyeData.appId, // 必填,企业微信的corpID
  128. timestamp: qiyeData.timestamp, // 必填,生成签名的时间戳
  129. nonceStr: qiyeData.nonceStr, // 必填,生成签名的随机串
  130. signature: qiyeData.signature, // 必填,签名,见 附录-JS-SDK使用权限签名算法
  131. jsApiList: ["ready", "getLocation"] // 必填,需要使用的JS接口列表,凡是要调用的接口都需要传进来
  132. });
  133. wx.ready(function () {
  134. wx.getLocation({
  135. type: 'gcj02',
  136. success: function (res) {
  137. flat = false;
  138. loading1.clear()
  139. var location = that.CJ02BD(res.latitude, res.longitude)
  140. that.location = location;
  141. that.lat = dataList.data.sfaStore.lat;
  142. that.lon = dataList.data.sfaStore.lon;
  143. that.storeId = dataList.data.sfaStore.storeId
  144. that.hisTime = dataList.data.sfaStore.hisTime,
  145. that.visitEntry = dataList.data.visitEntry
  146. var routeDetailsId = null
  147. if (dataList.data.rid != undefined) {
  148. routeDetailsId = dataList.data.rid
  149. }
  150. // if (dataList.data.visitId != undefined) {
  151. // that.visitId = dataList.data.visitId
  152. // }
  153. localStorage.setItem('chainNameR', dataList.data.sfaStore.chainName)
  154. if (that.lat == "" || that.lat == null) {
  155. that.lat = that.location.lat
  156. that.lon = that.location.lon
  157. }
  158. loading1.clear()
  159. let PointSum = that.twoPointSum(that.lat, that.lon, location.lat, location.lon).toFixed(2)
  160. if (PointSum > 500) {
  161. that.visitModel = "5"
  162. localStorage.setItem("visitModel", "5")
  163. that.$dialog.confirm({
  164. confirmButtonText: "确定",
  165. cancelButtonText: "重新定位",
  166. title: '系统提示',
  167. message: '距离本店距离差距太大',
  168. closeOnClickOverlay: true
  169. }).then(() => {
  170. that.$router.push({
  171. path: "/taskList", query: {
  172. storeId: that.storeId,
  173. rdId: routeDetailsId,
  174. lat: that.lat,
  175. lon: that.lon,
  176. visitId: that.visitId,
  177. addressLine: dataList.data.sfaStore.addressLine,
  178. storeCategory: that.storeCategory,
  179. storeName: dataList.data.sfaStore.storeName,
  180. hisTime: dataList.data.sfaStore.hisTime,
  181. contactName: dataList.data.sfaStore.contactName,
  182. storeCode: dataList.data.sfaStore.storeCode,
  183. visitEntry: dataList.data.visitEntry,
  184. visitModel: "5",
  185. latNew: location.lat,
  186. lonNew: location.lon,
  187. PointSum: PointSum,
  188. marklat:res.latitude,
  189. marklon:res.longitude
  190. }
  191. })
  192. localStorage.setItem('startTime', new Date());
  193. localStorage.setItem('chainNameR', dataList.data.sfaStore.chainName)
  194. })
  195. .catch(() => {
  196. that.getLocation()
  197. });
  198. } else {
  199. // that.addVisits(dataList.data.visitEntry,routeDetailsId,PointSum)
  200. that.$router.push({
  201. path: "/taskList", query: {
  202. storeId: that.storeId,
  203. rdId: routeDetailsId,
  204. lat: that.lat,
  205. lon: that.lon,
  206. hisTime: dataList.data.sfaStore.hisTime,
  207. visitId: that.visitId,
  208. addressLine: dataList.data.sfaStore.addressLine,
  209. storeCategory: that.storeCategory,
  210. storeName: dataList.data.sfaStore.storeName,
  211. // hisTime:dataList.data.sfaStore.hisTime,
  212. contactName: dataList.data.sfaStore.contactName,
  213. storeCode: dataList.data.sfaStore.storeCode,
  214. visitEntry: dataList.data.visitEntry,
  215. visitModel: "5",
  216. latNew: location.lat,
  217. lonNew: location.lon,
  218. PointSum: PointSum,
  219. marklat:res.latitude,
  220. marklon:res.longitude
  221. }
  222. })
  223. localStorage.setItem('startTime', new Date());
  224. localStorage.setItem('chainNameR', dataList.data.sfaStore.chainName)
  225. }
  226. },
  227. fail: function () {
  228. loading1.clear()
  229. that.$dialog.alert({
  230. message: 'GPS未开启',
  231. }).then(() => {
  232. that.getLocation()
  233. });
  234. }
  235. });
  236. })
  237. wx.error(function (res) {
  238. loading1.clear()
  239. that.$dialog.alert({
  240. message: '定位失败,请开启企微定位权限',
  241. }).then(() => {
  242. });
  243. });
  244. } else {
  245. this.msg = dataList.msg
  246. this.$toast.fail(dataList.msg);
  247. }
  248. }
  249. });
  250. },
  251. visitFn() {
  252. this.$router.go(-1);
  253. },
  254. onClickLeft() {
  255. this.$router.go(-1);
  256. },
  257. }
  258. }
  259. </script>
  260. <style lang="scss" scoped>
  261. .container {
  262. margin-bottom: 10px;
  263. background-color: white;
  264. }
  265. .card {
  266. background: #FFF;
  267. box-sizing: border-box;
  268. padding: 10px 16px;
  269. .title {
  270. line-height: 32px;
  271. font-size: 16px;
  272. font-weight: bold;
  273. color: #333;
  274. }
  275. .subtitle {
  276. line-height: 24px;
  277. font-size: 14px;
  278. color: #7B7B7B;
  279. .status {
  280. float: right;
  281. }
  282. }
  283. .info {
  284. font-size: 14px;
  285. color: #484848;
  286. padding: 14px;
  287. border-bottom: 1px solid #f1f1f1;
  288. .arrow {
  289. float: right;
  290. display: inline-block;
  291. height: 20px;
  292. width: 20px;
  293. line-height: 20px;
  294. text-align: center;
  295. border-radius: 50%;
  296. background: #0057ba;
  297. color: #FFF;
  298. font-weight: bold;
  299. font-size: 14px;
  300. }
  301. }
  302. .info1 {
  303. font-size: 14px;
  304. color: #666;
  305. line-height: 18px;
  306. padding: 4px 0;
  307. .arrow {
  308. float: right;
  309. display: inline-block;
  310. height: 20px;
  311. width: 20px;
  312. line-height: 20px;
  313. text-align: center;
  314. border-radius: 50%;
  315. background: #0057ba;
  316. color: #FFF;
  317. font-weight: bold;
  318. font-size: 14px;
  319. margin-top: 9px;
  320. }
  321. }
  322. }
  323. .must {
  324. font-size: 18px;
  325. color: #f56c6c;
  326. margin-right: 2px;
  327. }
  328. .zw {
  329. display: inline-block;
  330. width: 7px;
  331. height: 100%;
  332. }
  333. .lineGrey {
  334. height: 10px;
  335. width: 100%;
  336. background: #f1f1f1;
  337. }
  338. .submitBtn {
  339. margin: 16px 0;
  340. font-size: 18px;
  341. }
  342. .border {
  343. border: 1px solid #dedede;
  344. }
  345. .ht30 {
  346. height: 30px;
  347. }
  348. .bodrder-b {
  349. border-bottom: 1px solid #dedede;
  350. }
  351. .card .f-blue {
  352. color: #0057ba;
  353. }
  354. </style>
  355. <style>
  356. .ht30 .van-radio__label {
  357. color: #8B8B8B;
  358. }
  359. .van-dialog__confirm, .van-dialog__confirm:active {
  360. color: #0057ba;
  361. }
  362. </style>