cardFound.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. <template>
  2. <view>
  3. <view class="map-box">
  4. <map class="map" id="map1" ref="map1" @regionchange="regionChange" :latitude="latitude" :longitude="longitude" :markers="covers" @markertap="clickMap" :scale="mapScale" :circles="circles"></map>
  5. <!-- <view class="store" @click="showStore"><image src="../../static/images/sj_map_ico.png"></image></view>
  6. <view class="ibn" @click="showCab"><image src="../../static/images/jg_map_ico.png"></image><view class="count ddflex">12</view></view> -->
  7. <view class="nearby-box ddflex">
  8. <view class="nearby-yuan"></view>
  9. <image src="../../static/images/fj_loca.png" class="loca"></image>
  10. <view class="nearby">
  11. <view class="nearby-text ddflex" @click="jumpUrl('/card/cardList/cardList')">附近<image src="/static/pages/images/more.png"></image></view>
  12. <view class="gan"></view>
  13. </view>
  14. </view>
  15. <view class="side">
  16. <view class="li ddflex" @click="getLoca"><image src="../../static/images/side_ico3.png"></image></view>
  17. </view>
  18. </view>
  19. <view class="cabinet" :style="'bottom:' + cabBottom">
  20. <view class="register-box">
  21. <view class="register-title ddflex fflex" @click.stop="jumpUrl('/card/cardDetail/cardDetail?id='+cabInfo.id)">
  22. <image class="register-title-icon" :src="cabInfo.avatar?cabInfo.avatar:'/static/images/userimg.png'"></image>
  23. <view class="flex" style="min-width: 0;">
  24. <view class="ddflex">
  25. <view class="card-name fflex tover">{{cabInfo.realName?cabInfo.realName:''}}</view>
  26. <uni-rate class="ddflex" color="#999999" active-color="#FF4600" :readonly="true" size="16" allow-half :value="cabInfo.evaluateScore?cabInfo.evaluateScore/2:5" />
  27. </view>
  28. <view class="ddflex" style="margin-top: 4rpx;">
  29. <view class="card-tag">{{cabInfo.jobName}}</view>
  30. <view class="card-tag">入司{{cabInfo.inDate?monthDayDiff(cabInfo.inDate):'1年'}}</view>
  31. </view>
  32. <view class="card-area ddflex">
  33. <image src="/static/pages/images/dzico.png"></image>
  34. <view class="flex tover">{{cabInfo.address}}</view>
  35. <view style="color: #A1A1A1;margin-left: 10rpx;">距离{{cabInfo.distance>1000?((cabInfo.distance/1000).toFixed(2)+'km'):(cabInfo.distance+'m')}}</view>
  36. </view>
  37. </view>
  38. </view>
  39. </view>
  40. <!-- @click="jumpUrl('/card/cardList/cardList')" -->
  41. <view class="found-more ddflex" @click="jumpUrl('/card/cardList/cardList')">
  42. <image src="../../static/images/found_more.png"></image>
  43. 寻找更多保险顾问
  44. </view>
  45. </view>
  46. <canvas v-if="canvasShow" class="canvas" style="width:80px;height:92px;" canvas-id="logoIcon"></canvas>
  47. <!-- <update-userinfo :update-info="isUpdateInfo" :update-mobile="isUpdateMobile" v-if="isShowUpdate" @closeUpdate="closeUpdate" @updateInfo="updateInfo" @updateMobile="updateMobile"></update-userinfo> -->
  48. </view>
  49. </template>
  50. <script>
  51. const app = getApp();
  52. const req = require('../../utils/request.js');
  53. const api = require('../../utils/api.js');
  54. const util = require('../../utils/util.js');
  55. const QQMapWX = require("../../utils/qqmap.js");
  56. export default {
  57. data() {
  58. return {
  59. picUrlss: req.public.picUrls,
  60. userInfo: {},
  61. map: '',
  62. latitude: '23.027923',
  63. longitude: '113.753815',
  64. mapScale: 16,
  65. circles: [],
  66. covers: [],
  67. cabList: [],//机柜列表
  68. cabInfo: {},//机柜详情
  69. cabBottom: '-100%',
  70. storeList: [],//门店列表
  71. storeInfo: {},//门店详情
  72. storeBottom: '-100%',
  73. isAuth: false,//是否实名认证
  74. markerId: '',
  75. orderCount: '',//订单数
  76. isShowUpdate: false,//是否显示更新信息弹窗
  77. // isUpdateInfo: false,//更新用户信息
  78. isUpdateMobile: false,//绑定手机号
  79. realInfo: {},//实名认证信息
  80. config: {},//配置信息
  81. popadv: '',//弹窗广告
  82. topadv: '',//顶部广告
  83. isShowPopAdv: false,
  84. isShowTopAdv: false,
  85. canvasShow:false
  86. }
  87. },
  88. async onLoad(options) {
  89. if(options.userId){
  90. req.setStorage('pidCode',options.userId);
  91. }
  92. // req.silenceLogin(options.userId, '');
  93. this.map = uni.createMapContext("map1", this);
  94. let locations = req.getStorage('loctionAddressMap');
  95. QQMapWX.initMap();
  96. req.getLocation(res => {
  97. const to = {
  98. latitude: res.latitude,
  99. longitude: res.longitude
  100. };
  101. req.setStorage('loctionAddressMap',to)
  102. this.latitude = res.latitude;
  103. this.longitude = res.longitude;
  104. this.map.moveToLocation(to,res=>{})
  105. QQMapWX.reverseGeocoder(to,async resp => {
  106. await this.getCabList();
  107. });
  108. });
  109. },
  110. onShow() {
  111. this.getConfig();
  112. // this.userInfo.authState = 1;
  113. },
  114. onHide() {
  115. this.hideStore();
  116. this.hideCab();
  117. },
  118. methods: {
  119. hidePopAdv(){
  120. this.isShowPopAdv = false;
  121. },
  122. hideTopAdv(){
  123. this.isShowTopAdv = false;
  124. },
  125. banJump(item){
  126. app.globalData.clickBanner(item)
  127. },
  128. getConfig(){
  129. req.getRequest('/api/other/config',{},data=>{
  130. req.setStorage('configRes',JSON.stringify(data));
  131. this.config = data;
  132. })
  133. },
  134. addNearby(){
  135. let cover = [];
  136. let obj = {
  137. column: 0,
  138. type: 2,
  139. latitude: req.getStorage('loctionAddressMap').location.lat,
  140. longitude: req.getStorage('loctionAddressMap').location.lng,
  141. width: 75,
  142. height: 99,
  143. iconPath: '/static/images/nearby.png',
  144. // joinCluster: true
  145. }
  146. cover.unshift(obj);
  147. return cover;
  148. },
  149. async getLoca(){
  150. this.map.moveToLocation({latitude:this.latitude,longitude:this.longitude},res=>{})
  151. // this.covers = [];
  152. // this.latitude = req.getStorage('loctionAddressMap').location.lat;
  153. // this.longitude = req.getStorage('loctionAddressMap').location.lng;
  154. // await this.getCabList();
  155. },
  156. async regionChange(e){
  157. // console.log('视野发生变化时触发',e)
  158. // if(e.type == 'end' && e.causedBy == 'drag'){
  159. // this.covers = [];
  160. // this.latitude = e.detail.centerLocation.latitude;
  161. // this.longitude = e.detail.centerLocation.longitude;
  162. // await this.getCabList();
  163. // }
  164. },
  165. async clickMap(e){
  166. console.log('e==',e.detail)
  167. let markerId = e.detail.markerId
  168. let oldIndex = this.covers.findIndex(item=>item.did==this.cabInfo.id)
  169. let index = this.covers.findIndex(item=>item.id==markerId)
  170. // if(this.markerId == this.covers[markerId-1].column && this.markerId != 0) return false;
  171. this.cabBottom = '-100%';
  172. this.storeBottom = '-100%';
  173. this.getCabInfo(index);
  174. let covers = [];
  175. // this.covers = []
  176. if(this.covers&&this.covers.length>0){
  177. for(let i=0;i<this.covers.length;i++){
  178. let it = this.covers[i]
  179. if(i == index || i == oldIndex){
  180. console.log('i 当前转换的下标',i,index,oldIndex,it.id==markerId)
  181. let markerLogo = await this.getMarkerLogo(it.logo,it.id==markerId?2:null)
  182. let obj = {
  183. latitude: it.latitude,
  184. longitude: it.longitude,
  185. width: 80,
  186. height: 92,
  187. logo:it.logo,
  188. id:it.id,
  189. did:it.did,
  190. // iconPath: '/static/images/jg_map_ico.png',
  191. // 'https://img.zhiqiyun.com/test/2023/07/27/ec50eeee1ab3358d9ba397c86ae8fcc6.jpeg'
  192. iconPath: markerLogo//显示的图标
  193. // radius: it.column_4[0].radius,//检索的半径,单位为米
  194. // joinCluster: true
  195. }
  196. covers.push(obj)
  197. }else{
  198. covers.push(it)
  199. }
  200. }
  201. }
  202. this.covers = JSON.parse(JSON.stringify(covers))
  203. this.$forceUpdate()
  204. // console.log('covers==',this.covers[markerId-1])
  205. // console.log('this.circles=',this.circles[0])
  206. },
  207. timeRange(beginTime, endTime) {
  208. let strb = beginTime.split(":");
  209. if (strb.length != 2) {
  210. return false;
  211. }
  212. let stre = endTime.split(":");
  213. if (stre.length != 2) {
  214. return false;
  215. }
  216. let b = new Date();
  217. let e = new Date();
  218. let n = new Date();
  219. b.setHours(strb[0]);
  220. b.setMinutes(strb[1]);
  221. e.setHours(stre[0]);
  222. e.setMinutes(stre[1]);
  223. if (n.getTime() - b.getTime() >= 0 && n.getTime() - e.getTime() < 0) {
  224. return true;
  225. } else {
  226. return false;
  227. }
  228. },
  229. captureTime(time,isTime){
  230. return util.captureTime(time,isTime)
  231. },
  232. getCabList(){
  233. let that = this;
  234. let form = {
  235. latitude: this.latitude,
  236. longitude: this.longitude,
  237. page:1,
  238. limit:10
  239. // distance: 2000
  240. }
  241. return new Promise(async(resolve,reject)=>{
  242. req.getRequest('/api/visiting/card/cardInfoList',form,async res=>{
  243. this.cabList = res.list;
  244. this.getCabInfo(0)
  245. let data = {list:[]}
  246. data.list = res.list.map(item=>{
  247. let obj = {
  248. userId:item.id,
  249. latitude:item.latitude,
  250. longitude:item.longitude,
  251. logo:item.avatar
  252. }
  253. return obj
  254. })
  255. let covers = this.covers; //this.addNearby();
  256. if(data.list&&data.list.length>0){
  257. for(let i=0;i<data.list.length;i++){
  258. let it = data.list[i]
  259. let markerLogo = await this.getMarkerLogo(it.logo)
  260. let obj = {
  261. id:i+1,
  262. did:it.userId,
  263. latitude: it.latitude,
  264. longitude: it.longitude,
  265. width: 80,
  266. height: 92,
  267. logo:it.logo,
  268. // iconPath: '/static/images/jg_map_ico.png',
  269. // 'https://img.zhiqiyun.com/test/2023/07/27/ec50eeee1ab3358d9ba397c86ae8fcc6.jpeg'
  270. iconPath: markerLogo//显示的图标
  271. // radius: it.column_4[0].radius,//检索的半径,单位为米
  272. // joinCluster: true
  273. }
  274. covers.push(obj);
  275. }
  276. }
  277. // if(covers.length > 0){
  278. // covers.map((it,index)=>{
  279. // it.id = Number(index+1);
  280. // return it;
  281. // })
  282. // }
  283. that.covers = covers
  284. resolve();
  285. })
  286. })
  287. },
  288. getCabInfo(index){
  289. this.cabInfo = this.cabList[index];
  290. this.cabBottom = 0;
  291. },
  292. routePlan(type){
  293. let that = this;
  294. let plugin = requirePlugin('routePlan');
  295. let key = req.public.mapLBSKEY; //使用在腾讯位置服务申请的key
  296. let referer = '线上会客厅系统'; //调用插件的app的名称
  297. let endPoint = '';
  298. if(type == 1){
  299. endPoint = JSON.stringify({ //终点
  300. 'name': that.cabInfo.devName,
  301. 'latitude': that.cabInfo.latitude,
  302. 'longitude': that.cabInfo.longitude
  303. });
  304. }else{
  305. endPoint = JSON.stringify({ //终点
  306. 'name': that.storeInfo.name,
  307. 'latitude': that.storeInfo.latitude,
  308. 'longitude': that.storeInfo.longitude
  309. });
  310. }
  311. console.log('endPoint==',endPoint)
  312. wx.navigateTo({
  313. url: 'plugin://routePlan/index?key=' + key + '&referer=' + referer + '&endPoint=' + endPoint
  314. });
  315. },
  316. callPhone(number){
  317. uni.makePhoneCall({
  318. phoneNumber: number
  319. })
  320. },
  321. hideCab(){
  322. this.cabBottom = '-100%';
  323. this.markerId = '';
  324. },
  325. showCab(){
  326. this.isShowCab = true;
  327. },
  328. jumpUrl(url){
  329. if (!req.isLogins(true)) return false;
  330. uni.navigateTo({
  331. url: url
  332. })
  333. },
  334. monthDayDiff(date) {
  335. return util.monthDayDiff(date)
  336. },
  337. // 获取markerLogo
  338. getMarkerLogo(url,type){
  339. // 多次绘图时重置canvas
  340. this.canvasShow = true
  341. let that = this
  342. return new Promise(async(re,rj)=>{
  343. let mapBgUrl = 'https://img.zhiqiyun.com/test/2023/07/27/2d30f06817365b83a5f78c455fce8974.png'
  344. if(type&&type==2) mapBgUrl = 'https://img.zhiqiyun.com/test/2023/07/27/ad0bfade8dcffa6b20c045a53945dea3.png'
  345. // console.log('mapBgUrl',mapBgUrl)
  346. const avatarp = this.getImageInfo(url); // 获取小程序码图
  347. const mapBg = this.getImageInfo(mapBgUrl); // 获取小程序码图
  348. Promise.all([avatarp,mapBg]).then(([avatar,mapIcon]) => {
  349. const ctx = uni.createCanvasContext('logoIcon', this); // 绘制背景,填充满整个canvas画布
  350. let width = 80,
  351. height = 92; //默认背景
  352. // ctx.setFillStyle('transparent');
  353. // ctx.fillRect(0, 0, width, height); // 画布背景
  354. ctx.drawImage(mapIcon.path, 0, 0, width, height); //绘制图片
  355. // ctx.save();
  356. // ctx.restore();
  357. // ctx.beginPath();
  358. const avatarW = width-28;
  359. that.roundRect(ctx, 14, 12, avatarW, avatarW, avatarW/2);
  360. ctx.clip(); //裁剪
  361. ctx.drawImage(avatar.path, 14, 12, avatarW, avatarW);
  362. ctx.restore();
  363. ctx.draw(false, function() {
  364. uni.canvasToTempFilePath({
  365. canvasId: 'logoIcon',
  366. success: function(res) {
  367. // console.log('ctx.draw',res.tempFilePath)
  368. that.canvasShow = false
  369. re(res.tempFilePath)
  370. },
  371. fail: function(res) {
  372. console.log(res)
  373. rj()
  374. }
  375. }, that);
  376. });
  377. })
  378. })
  379. },
  380. getImageInfo(url) {
  381. // console.log('getImageInfo',url)
  382. return new Promise((resolve, reject) => {
  383. if (!url) {
  384. resolve();
  385. return false;
  386. }
  387. uni.getImageInfo({
  388. src: url,
  389. success: resolve,
  390. fail: reject
  391. });
  392. });
  393. },
  394. /**
  395. *
  396. * @param {CanvasContext} ctx canvas上下文
  397. * @param {number} x 圆角矩形选区的左上角 x坐标
  398. * @param {number} y 圆角矩形选区的左上角 y坐标
  399. * @param {number} w 圆角矩形选区的宽度
  400. * @param {number} h 圆角矩形选区的高度
  401. * @param {number} r 圆角的半径
  402. */
  403. roundRect: function(ctx, x, y, w, h, r) {
  404. // 开始绘制
  405. ctx.beginPath(); // 因为边缘描边存在锯齿,最好指定使用 transparent 填充
  406. // 这里是使用 fill 还是 stroke都可以,二选一即可
  407. ctx.setFillStyle('white'); // ctx.setStrokeStyle('transparent')
  408. // 左上角
  409. ctx.arc(x + r, y + r, r, Math.PI, Math.PI * 1.5); // border-top
  410. ctx.moveTo(x + r, y);
  411. ctx.lineTo(x + w - r, y);
  412. ctx.lineTo(x + w, y + r); // 右上角
  413. ctx.arc(x + w - r, y + r, r, Math.PI * 1.5, Math.PI * 2); // border-right
  414. ctx.lineTo(x + w, y + h - r);
  415. ctx.lineTo(x + w - r, y + h); // 右下角
  416. ctx.arc(x + w - r, y + h - r, r, 0, Math.PI * 0.5); // border-bottom
  417. ctx.lineTo(x + r, y + h);
  418. ctx.lineTo(x, y + h - r); // 左下角
  419. ctx.arc(x + r, y + h - r, r, Math.PI * 0.5, Math.PI); // border-left
  420. ctx.lineTo(x, y + r);
  421. ctx.lineTo(x + r, y); // 这里是使用 fill 还是 stroke都可以,二选一即可,但是需要与上面对应
  422. ctx.fill(); // ctx.stroke()
  423. ctx.closePath(); // 剪切
  424. ctx.clip();
  425. }
  426. },
  427. }
  428. </script>
  429. <style>
  430. @import "./cardFound.css";
  431. </style>