1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731
import {
  request
} from "../../request/index.js";
var QQMapWX = require('../../qqmap/qqmap-wx-jssdk.min.js');
var qqmapsdk;
const a = getApp()
Page({
  data: {
    baseUrl: a.globalData.baseUrl,
    statusTop: a.globalData.statusHeight,
    imagesUrl: a.globalData.imagesUrl,
    four: 4,
    six: 6,
    msg: '',
    autoplay: true,
    interval: 3000,
    indicatorDots: true,
    indicator: '#F9F9F9',
    indicatorActive: '#E8370F',
    bind_car: 1,
    time: 30 * 60 * 60 * 1000,
    timeData: {},
    pin_id: '1',
    rest: false,
    groom: [], //  推荐
    homeInfo: [],
    homeChe: {},
    homeGouDay: {},
    homeLoop: [],
    S4Info: '',
    id: '',
    nobindCar: false,
    goodDetal: {},
    index4S: [],
    city_id: '',
  },
  onLoad: function (options) {
    let that = this
    console.log(options);
    qqmapsdk = new QQMapWX({
      key: 'B4MBZ-3VICV-THBPQ-UCLHB-SLCEK-B7FIK'
    });
  },
  onShow: function () {
    let that = this
    that.gethomeIndex()
    that.gethomeLoop()
    that.getStarModel()
    that.getS4Info()
    that.getindexUser()
    that.getCitied()
  },
  getCitied() { // 获取城市信息
    let that = this
    wx.getLocation({
      type: 'wgs84', //默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 
      success: function (res) {
        qqmapsdk.reverseGeocoder({
          //位置坐标,默认获取当前位置,非必须参数
          //Object格式
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function (res) { //成功后的回调
            console.log(res);
            var res = res.result;
            let city = res.ad_info.city
            that.saveCity(city)
          },
          fail: function (error) {
            console.error(error);
          },
          complete: function (res) {
            // console.log(res);
          }
        })
      },
      fail: res => {}
    })
    return
  },
  async saveCity(city) {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/citys/getCity',
        data: {
          city: city
        }
      })
      console.log(data, "首页全局城市定位");
      that.setData({
        city_id: data.city_id
      })
      that.getSuccessPage()
    } catch (err) {
      console.log(err);
      that.popTest(err.msg)
    }
  },
  gohome() {
    wx.switchTab({
      url: '/pages/home/home'
    })
  },
  onChange(e) {
    this.setData({
      timeData: e.detail,
    });
  },
  more4SList() {
    wx.navigateTo({
      url: '/pages/Vmore4SList/Vmore4SList'
    })
  },
  goSearch() {
    wx.navigateTo({
      url: '/pages/Vmore4SList/Vmore4SList?home=1'
    })
  },
  addLoveCared() { // 去添加车辆
    let that = this
    let token = wx.getStorageSync("token")
    if (token) {
      if (that.data.nobindCar) {
        wx.navigateTo({
          url: '/pages/addcars/addcars'
        })
      } else {
        wx.navigateTo({
          url: '/pages/addcar/addcar'
        })
      }
    } else {
      that.goLogin()
    }
  },
  async getSuccessPage() { // 获取推荐
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index2/tuiList2',
        data: {
          city_id: that.data.city_id
        }
      })
      console.log(data);
      that.setData({
        groom: data
      })

    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }

  },
  async gethomeIndex() { // 获取首页
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index2/index',
      })
      console.log(data);
      that.setData({
        homeChe: data.che,
        homeInfo: data.info,
        homeGouDay: data.gou_day
      })

    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }

  },
  async gethomeLoop() { // 获取轮播
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index2/img',
      })
      console.log(data);
      that.setData({
        homeLoop: data,
      })

    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }

  },
  async getStarModel() { // 获取明星车型 
    let that = this
    let bind_car = that.data.bind_car
    if (bind_car == 1) {
      try {
        const {
          data
        } = await request({
          url: 'api/index2/mingXing',
        })
        console.log(data);
        if (data.code == 1) {
          that.setData({
            starModel: data.data,
            bind_car: 1,
          })
        } else {
          //code为0的话,说明没绑定4s店
          that.setData({
            msg: data.msg,
            bind_car: 0
          })
          that.popTest()
        }


      } catch (err) {
        console.log(err);
        that.setData({
          msg: err.msg
        })
        that.popTest()
      }
    }
  },
  async getS4Info() { // 获取 4s店数据 
    let that = this
    try {
      const {
        data
      } = await request({
        url: 'api/index2/s4Info',
      })
      console.log(data);
      if (data.code == 1) {
        that.setData({
          S4Info: data.data.name,
          id: data.data.id,
          bind_car: 1
        })
      } else {
        //code为0的话,说明没绑定4s店
        that.setData({
          msg: data.msg,
          bind_car: 0,

        })
        that.popTest()
      }


    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      // that.popTest()
      if (err.code == 0) {
        that.setData({
          bind_car: 0,
        })
      }
    }

  },
  async getindexUser() { // 获取 4s关注数据
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index2/indexUnder',
      })
      console.log(data, "4SD店列表");
      if (data.length == 0) { // 如果是空数组,你调用的是【推荐4s店】这个接口
        that.getCitied()
      }
      that.setData({
        index4S: data
      })
    } catch (err) {
      console.log(err);
      if (err.code == 0) {
        that.setData({
          bind_car: 0,
        })
      }
    }

  },
  async clickAttention(e) { // 点击关注
    let that = this
    let id = e.currentTarget.dataset.id
    let token = wx.getStorageSync('token')
    if (token) {
      try {
        const {
          data
        } = await request({
          url: 'api/index2/guan',
          data: {
            id: id
          }
        })
        console.log(data);
        if (data.code == 1) {
          that.setData({
            msg: data.msg
          })
          that.popSuccessTest()
        } else {
          that.setData({
            msg: data.msg
          })
          that.popTest()
        }
        setTimeout(() => {
          that.getSuccessPage()
        }, 500);


      } catch (err) {
        console.log(err);
        that.setData({
          msg: err.msg
        })
        that.popTest()
      }
    } else {
      that.goLogin()
    }
  },
  goToAccess(e) {
    let id = e.currentTarget.dataset.id
    console.log(e);
    wx.navigateTo({
      url: '/pages/goAccessoriesDetailIMG/goAccessoriesDetailIMG?id=' + id
    })
  },
  gobind4S() { // 立即绑定4S店
    let that = this
    let pin_id = that.data.pin_id
    wx.navigateTo({
      url: '/pages/my4S/my4S?pin_id=' + pin_id,
    })

  },
  goViolationQuery() { //
    let that = this
    let token = wx.getStorageSync('token')
    if (token) {
      wx.navigateTo({
        url: '/pages/ViolationQuery/ViolationQuery'
      })
    } else {
      that.goLogin()
    }
  },
  goAccessoriesDetailIMG(e) { //进入配件详情
    let that = this
    let token = wx.getStorageSync('token')
    let goodDetal = that.data.goodDetal
    let tir = e.currentTarget.dataset.tir
    if (token) {
      if (tir == 1) {
        wx.navigateTo({
          url: '/pages/productdetailsImg/productdetailsImg?id=' + goodDetal.good1_id
        })
      } else if (tir == 2) {
        wx.navigateTo({
          url: '/pages/productdetailsImg/productdetailsImg?id=' + goodDetal.good2_id
        })
      } else {
        wx.navigateTo({
          url: '/pages/productdetailsImg/productdetailsImg?id=' + goodDetal.good3_id
        })
      }

    } else {
      that.goLogin()
    }
  },
  goV4Sstores(e) { // 进入我的4s店
    let that = this
    console.log(e);
    let s4_id = e.currentTarget.dataset.id
    let token = wx.getStorageSync('token')
    // a.globalData.stores_id = s4_id
    console.log(s4_id);
    if (token) {
      wx.navigateTo({
        // url: '/pages/4Sstore/4Sstore'
        url: '/pages/Vnew4Sstore/Vnew4Sstore?s4_id=' + s4_id

      })
    } else {
      that.goLogin()
    }
  },
  ToV4Sstores(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    let token = wx.getStorageSync('token')
    if (token) {
      wx.navigateTo({
        url: '/pages/Vnew4Sstore/Vnew4Sstore?s4_id=' + id
      })
    } else {
      that.goLogin()
    }
  },
  goUpkeepimg() { // 保养预约
    let that = this
    let token = wx.getStorageSync('token')
    let id = that.data.id
    let homeChe = that.data.homeChe
    if (token) {
      if (id == '') {
        that.setData({
          msg: '您尚未绑定4S店'
        })
        that.popTest()
      }
      if (homeChe.length == 0) {
        that.setData({
          msg: '请先绑定爱车'
        })
        that.popTest()
      }
      if (homeChe.length != 0 && id != '') {
        wx.navigateTo({
          url: '/pages/upkeepImg/upkeepImg?id=' + id
        })
      }
    } else {
      that.goLogin()
    }
  },
  toMyGarage() { // 我的车库
    let token = wx.getStorageSync("token")
    if (token) {
      wx.navigateTo({
        url: '/pages/MyGarage/MyGarage?tdTap=1'
      })
    } else {
      this.goLogin()
    }

  },
  goVopenPolicy() {
    let that = this
    let token = wx.getStorageSync('token')
    let id = that.data.id
    let homeChe = that.data.homeChe
    console.log(homeChe);
    if (token) {
      if (id == '') {
        that.setData({
          msg: '您尚未绑定4S店'
        })
        that.popTest()

      }
      if (homeChe == null) {
        that.setData({
          msg: '请先绑定爱车'
        })
        that.popTest()

      }
      if (homeChe != null && id != '') {
        wx.navigateTo({
          url: '/pages/VopenPolicy/VopenPolicy?che_id=' + homeChe.id
        })
      }

    } else {
      that.goLogin()
    }
  },
  goVopenPolicyB() {
    let that = this
    let token = wx.getStorageSync('token')
    let id = that.data.id
    let homeChe = that.data.homeChe
    if (token) {
      if (id == '') {
        that.setData({
          msg: '您尚未绑定4S店'
        })
        that.popTest()

      }
      if (homeChe == null) {
        that.setData({
          msg: '请先绑定爱车'
        })
        that.popTest()

      }
      if (homeChe != null && id != '') {
        wx.navigateTo({
          url: '/pages/VopenPolicyB/VopenPolicyB?che_id=' + homeChe.id
        })
      }

    } else {
      that.goLogin()
    }
  },
  goVopenPolicyC() {
    let that = this
    let token = wx.getStorageSync('token')
    let id = that.data.id
    let homeChe = that.data.homeChe
    if (token) {
      if (id == '') {
        that.setData({
          msg: '您尚未绑定4S店'
        })
        that.popTest()
      }
      if (homeChe == null) {
        that.setData({
          msg: '请先绑定爱车'
        })
        that.popTest()
      }
      if (homeChe != null && id != '') {
        wx.navigateTo({
          url: '/pages/VopenPolicyC/VopenPolicyC?che_id=' + homeChe.id
        })
      }
    } else {
      that.goLogin()
    }
  },
  gobindChe() {
    let that = this
    wx.showModal({
      title: '提示',
      content: that.data.msg,
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/MyGarage/MyGarage?tdTap=1'
          })

        } else {

        }
      }
    })
  },
  onShareAppMessage(options) {
    var that = this;
    var shareObj = {
      title: "汽车互联网4S店",
      path: '/pages/home/home',
      imageUrl: '',
    };
    return shareObj;

  },
  toGoDetailA(e) {
    let that = this
    let idata = e.currentTarget.dataset.idata
    let jump = idata.jump_type
    let good_type = Number(idata.good_type1)
    let good_id = idata.good1_id
    that.publicDetails(jump, good_type, good_id)
  },
  toGoDetailB(e) {
    let that = this
    let idata = e.currentTarget.dataset.idata
    let jump = idata.jump_type
    let good_type = Number(idata.good_type2)
    let good_id = idata.good2_id
    that.publicDetails(jump, good_type, good_id)
  },
  toGoDetailC(e) {
    let that = this
    let idata = e.currentTarget.dataset.idata
    let jump = idata.jump_type
    let good_type = Number(idata.good_type3)
    let good_id = idata.good3_id
    that.publicDetails(jump, good_type, good_id)
  },
  publicDetails(jump, good_type, good_id) {
    if (jump == 1) { //可以跳转
      switch (good_type) {
        case 1: // 人气好物
          wx.navigateTo({
            url: '/pages/detail/detail?id=' + good_id
          })
          break;
        case 2: // 精选推荐
          wx.navigateTo({
            url: '/pages/productdetailsImg/productdetailsImg?id=' + good_id
          })
          break;
        case 3: // 团购热卖
          wx.navigateTo({
            url: '/pages/VtuanDetail/VtuanDetail?id' + good_id
          })
          break;
        case 4: //限时抢购
          wx.navigateTo({
            url: '/pages/VSpikeMallDetail/VSpikeMallDetail?id=' + good_id
          })
          break;
        case 5: //车型商品
          wx.navigateTo({
            url: '/pages/carDetails/carDetails?id=' + good_id
          })
          break;
        default:
          break;
      }
    } else {
      a.popTest('该4s店暂未运营')
    }
  },


















  async public() {
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: '',
        data: {
          goods_id: that.data.goods_id
        }
      })
      console.log(data);
      that.setData({
        public: data
      })
    } catch (err) {
      console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popTest()
    }
  },
  popTest() {
    wx.showToast({
      title: this.data.msg,
      icon: 'none', //如果要纯文本,不要icon,将值设为'none'
      duration: 1300
    })
  },
  goLogin() {
    wx.showModal({
      title: '提示',
      content: '您尚未登录,前往登录',
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/authorization/authorization?num=1'
          })

        } else {
          // wx.switchTab({
          //   url: '/pages/home/home'
          // })
        }
      }
    })
  },
  popSuccessTest() {
    wx.showToast({
      title: this.data.msg,
      icon: '', //默认值是success,就算没有icon这个值,就算有其他值最终也显示success
      duration: 1300, //停留时间
    })
  },

})