Vnewhome.js 16.1 KB
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
import {
  request
} from "../../request/index.js"
const a = getApp()
Page({
  data: {
    imagesUrl: a.globalData.baseUrl,
    a: '未添加爱车',
    homeListTop: '', //首页上部 
    homeListTopInfo: [],
    homeListCenter: '', // 首页中部
    swiperList: [], // 轮播图数组
    storeList: [], // 
    hornloop: [], // 公共轮播
    click_switch: '',
    page: 1,
    size: '',
    noAddCar: 1, // 0 未添加爱车  1 添加了 
    S4S: 1, // 0 获积分 
    bind4S: 0,
    pin_id: '',
    cnt: [], //底部活动
    car_login: 'https://xiaoxiangauto.com/assets/static/img/che_img@2x.png',
    msg: '',
    DWcity: '',
    shortnameCity: '',
    indicatorDots: true,
    interval: 2000,
    city_id: '',
    autoplay: true,
    showDialog: false,
    url: '',
    kefu: [],
    phones: '',
    msg: '',


  },

  onShow: function () {
    wx.showToast({
      title: '加载中',
      icon: "loading",
      duration: 2000,
      mask: false
    })
    this.getHomeListTop()
    this.getHomeListCenter()
    this.getSwiperList()
    this.getStoreList()
    this.getmoretiao()
    this.getDWcity()

  },
  async getHomeListTop() { //首页上部
    let that = this;
    const {
      data: {
        data
      }
    } = await request({
      url: 'api/index/index1',
    })
    // //  console.log(data);
    that.setData({
      homeListTop: data.che,
      homeListTopInfo: data.info,
    })
  },
  async getHomeListCenter() { //首页中部
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/index2',
      })
      //  console.log(data);
      if (data.s4 != null) {
        that.setData({
          homeListCenter: data.s4,
        })
        if (data.s4.kefu != null) {
          that.setData({
            kefu: data.s4.kefu || []
          })
        }
      }
      // //  console.log(data, "首页中部", that.data.homeListCenter);
    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  async getSwiperList() { //  轮播列表
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/index3'
      })
      that.setData({
        swiperList: data

      })
      // //  console.log(that.data.swiperList, "轮播列表");
    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }


  },
  async getDWcity() { //定位城市
    let that = this;
    try {
      const {
        data: {
          data
        }
      } = await
      request({
        url: 'api/citys/dingWei',
      })
      that.setData({
        DWcity: data,
        shortnameCity: data.shortname
      })
      // //  console.log(that.data.shortnameCity, "定位城市", that.data.DWcity);
    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  getStoreList() { //获取商城
    let that = this;
    request({
        url: 'api/index/index5',
        data: {
          page: that.data.page,
        }
      })
      .then(res => {
        that.setData({
          storeList: res.data.data.data,
          total: res.data.data.total
        })
        // //  console.log(that.data.storeList, "底部", that.data.total);
      }).catch(err => {
        //  console.log(err);
        that.setData({
          msg: err.msg
        })
        that.popMaskTest()
      })
  },
  addLoveCar() { // 添加爱车
    let that = this
    let token = wx.getStorageSync("token")

    if (token) {
      if (that.data.homeListCenter) {
        wx.navigateTo({
          url: '/pages/addcars/addcars'
        })
      } else {
        wx.navigateTo({
          url: '/pages/addcar/addcar'
        })
      }
    } else {
      that.popConfirm()
    }

  },
  addLoveCareden() {
    let that = this
    let token = wx.getStorageSync("token")
    if (token) {
      wx.navigateTo({
        url: '/pages/MyGarage/MyGarage'
      })
    } else {
      that.popConfirm()
    }
  },
  gocityList() { // 去定位城市
    let that = this
    let token = wx.getStorageSync("token")
    if (token) {
      wx.navigateTo({
        // url: '/pages/cityList/cityList'
        url: '/pages/homeNoLogin2/homeNoLogin2'
      })
    } else {
      that.popConfirm()
    }
  },
  addLoveCared() { // 去添加车辆
    let that = this
    let token = wx.getStorageSync("token")
    if (token) {
      if (that.data.homeListCenter) {
        wx.navigateTo({
          url: '/pages/addcars/addcars'
        })
      } else {
        wx.navigateTo({
          url: '/pages/addcar/addcar'
        })
      }
    } else {
      that.popConfirm()
    }



  },
  popConfirm: function () {
    wx.showModal({
      title: '提示',
      content: '您尚未登录,请登录后操作',
      success: function (res) {
        if (res.confirm) {
          wx.navigateTo({
            url: '/pages/authorization/authorization'
          })
        } else {
          //  console.log('点击取消回调')
        }
      }
    })

  },
  goBinding4S() { // 绑定4s店
    let pin_id = this.data.pin_id
    wx.navigateTo({
      url: '/pages/my4S/my4S?pin_id=' + pin_id,
    })
  },
  storeDetail(e) {
    let id = e.currentTarget.dataset.jump_id
    let type = e.currentTarget.dataset.type
    let num = e.currentTarget.dataset.num
    if (type == 1) {
      if (num == 1) {
        wx.navigateTo({
          url: '/pages/productdetailsImg/productdetailsImg?id=' + id
        })
      } else {
        // 无图详情
        wx.navigateTo({
          url: '/pages/productdetails/productdetails?id=' + id
        })
      }

    } else if (type == 2) {
      wx.navigateTo({
        url: '/pages/detail/detail?id=' + id
      })
    } else if (type == 3) {
      if (num == 1) {
        wx.navigateTo({
          url: '/pages/goAccessoriesDetailIMG/goAccessoriesDetailIMG?id=' + id
        })
      } else {
        // 无图详情
        wx.navigateTo({
          url: '/pages/goAccessoriesDetail/goAccessoriesDetail?id=' + id
        })
      }
    } else if (type == 4) {
      if (num == 1) {
        wx.navigateTo({
          url: '/pages/productdetailsImg/productdetailsImg?id=' + id
        })
      } else {
        // 无图详情
        wx.navigateTo({
          url: '/pages/productdetails/productdetails?id=' + id
        })
      }
    } else if (type == 5) {
      if (num == 1) {
        wx.navigateTo({
          url: '/pages/VehicleListDetail/VehicleListDetail?id=' + id
        })
      }
    }
  },
  hotDetails(e) {
    let that = this
    let id = e.currentTarget.dataset.id
    let type = e.currentTarget.dataset.type
    let token = wx.getStorageSync("token")
    if (token) {
      wx.navigateTo({
        url: '/pages/activityDetails/activityDetails?id=' + id + '&type=' + type
      })
    } else {
      that.popConfirm()
    }

  },
  lookMoreActivity() { //  双向箭头   更多活动
    let that = this
    let token = wx.getStorageSync("token")
    if (token) {
      wx.navigateTo({
        url: '/pages/moreActivity/moreActivity'
      })
    } else {
      that.popConfirm()
    }


  },
  lookMoreTap() { //查看更多
    wx.switchTab({
      url: '/pages/stores/index'
    })
  },
  goUpkeepImg() { // 保养
    let that = this
    let token = wx.getStorageSync("token")
    if (token) {
      if (that.data.homeListTop) {
        wx.navigateTo({
          url: '/pages/upkeepImg/upkeepImg'
        })
      } else {
        wx.showModal({
          title: '提示',
          content: '您尚未绑定车辆,请先绑定车',
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/addcar/addcar'
              })
            } else {
              //  console.log('点击取消回调')
            }
          }
        })
      }

    } else {
      that.popConfirm()
    }

  },
  async getmoretiao() { //底部活动
    let that = this
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/index4'
      })

      that.setData({
        cnt: data
      })
      //  console.log(data, "底部活动");
    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }

  },
  freeTell(e) { // 打电话
    //  console.log(e);
    let that = this
    let kefu = that.data.kefu
    let id = e.currentTarget.dataset.id
    kefu.forEach(item => {
      if (item.id == id) {
        that.setData({
          phones: item.phone
        })
      }
    });
    wx.makePhoneCall({
      phoneNumber: that.data.phones,
    })
  },
  popMaskTest() {
    wx.showToast({
      title: this.data.msg,
      duration: 2000,
      icon: 'none',
      mask: true //是否有透明蒙层,默认为false 
      //如果有透明蒙层,弹窗的期间不能点击文档内容 
    })
  },
  onShareAppMessage(options) {
    var that = this;
    //  console.log(that.data.user_id)
    // 设置菜单中的转发按钮触发转发事件时的转发内容
    var shareObj = {
      title: "同放分享", // 默认是小程序的名称(可以写slogan等)
      path: '/pages/home/home', // 默认是当前页面,必须是以‘/’开头的完整路径
      imageUrl: '', //自定义图片路径,可以是本地文件路径、代码包文件路径或者网络图片路径,支持PNG及JPG,不传入 imageUrl 则使用默认截图。显示图片长宽比是 5:4
      success: function (res) {
        // 转发成功之后的回调
        //  console.log(res);
        that.setData({
          msg: '易分享'
        })
        that.popMaskTest()
      },
      fail: function () {
        // 转发失败之后的回调
        if (res.errMsg == 'shareAppMessage:fail cancel') {
          // 用户取消转发
        } else if (res.errMsg == 'shareAppMessage:fail') {}
      },
    };
    // 返回shareObj
    return shareObj;

  },
  async onClickpopUp() { // 弹窗海报
    this.setData({
      showDialog: !this.data.showDialog
    })
    try {
      const {
        data: {
          data
        }
      } = await request({
        url: 'api/index/haiBao'
      })
      // //  console.log(data.img);
      this.setData({
        url: data.img
      })

    } catch (err) {
      //  console.log(err);
      that.setData({
        msg: err.msg
      })
      that.popMaskTest()
    }
  },
  keepPoster() {
    var that = this;
    wx.showLoading({
      title: '加载中',
      icon: 'none'
    })
    wx.downloadFile({
      url: that.data.url,
      success: function (res) {
        wx.hideLoading()
        //  console.log('下载图片下载图片下载图片', res)
        var tempFilePath = res.tempFilePath
        ////  console.log('临时文件地址是:' + tempFilePath)
        wx.saveFile({
          tempFilePath: tempFilePath,
          success: function (res) {
            //  console.log(res)
            var saveFilePath = res.savedFilePath;
            that.setData({
              water_url: res.savedFilePath,
              savepic: 1
            })

            wx.getSetting({
              success(res) {
                if (!res.authSetting['scope.writePhotosAlbum']) {
                  wx.authorize({
                    scope: 'scope.writePhotosAlbum',
                    success() { //这里是用户同意授权后的回调
                      //  console.log('111', that.data.water_url)
                      wx.saveImageToPhotosAlbum({
                        filePath: that.data.water_url,
                        success(res) {
                          wx.showModal({
                            content: '图片已保存到相册',
                            showCancel: false,
                            confirmText: '好的',
                            confirmColor: '#333',
                            success: function (res) {
                              if (res.confirm) {
                                //  console.log('用户点击确定');
                                /* 该隐藏的隐藏 */
                                that.setData({
                                  maskHidden: false
                                })
                              }
                            },
                            fail: function (res) {

                            }
                          })
                        }
                      })



                    },
                    fail() { //这里是用户拒绝授权后的回调
                      // wx.openSetting({
                      //   success: function (data) {
                      //     //  console.log(data)
                      //     if (data.authSetting["scope.writePhotosAlbum"] === true) {
                      //      //  console.log("是否授权成功")
                      //     } else {
                      //       applyApi.toast("授权失败");
                      //     }
                      //   }
                      // })
                      wx.showModal({
                        title: '提示',
                        content: '您取消授权,无法保存图片,点击确定打开权限',
                        success(res) {
                          if (res.confirm) {
                            //  console.log('用户点击确定')
                            wx.openSetting({
                              success(res) {
                                //  console.log(res.authSetting)
                                // res.authSetting = {
                                //   "scope.userInfo": true,
                                //   "scope.userLocation": true
                                // }
                              }
                            })
                          } else if (res.cancel) {
                            //  console.log('用户点击取消')
                          }
                        }
                      })

                    }
                  })
                } else { //用户已经授权过了

                  //  console.log('333', that.data.water_url)

                  // //  console.log(that.data.imagePath)
                  wx.saveImageToPhotosAlbum({
                    filePath: that.data.water_url,
                    success(res) {
                      //  console.log(res)
                      wx.showModal({
                        content: '图片已保存到相册',
                        showCancel: false,
                        confirmText: '好的',
                        confirmColor: '#333',
                        success: function (res) {
                          if (res.confirm) {
                            //  console.log('用户点击确定');
                            /* 该隐藏的隐藏 */
                            that.setData({
                              maskHidden: false,
                              showDialog: !that.data.showDialog
                            })
                          }
                        },
                        fail: function (res) {

                        }
                      })
                    }
                  })
                }
              }
            })
            //  console.log('123456855555555', that.data.water_url)
          }, //可以将saveFilePath写入到页面数据中
          fail: function (res) {
            //  console.log('失败', res)
          },
          complete: function (res) {
            //  console.log('complete后的res数据:')
          },
        }) //,
      },
      // fail: function (res) {
      //   wx.showModal({
      //     title: '下载失败',
      //     content: '请联系管理员',
      //   })
      // },
      complete: function (res) {},
    })
  },
  getCanvas() { // 获取结果
    let that = this;
    wx.showLoading({
      title: '加载中'
    })
    request({
        url: 'api/shop/haiBao',
        data: {
          id: that.data.id,
        }
      })
      .then(res => {

        that.setData({
          url: res.data.data,
        })
        wx.hideLoading()

      }).catch(err => {
        that.setData({
          msg: err.msg
        })
        that.popMaskTest()
      })
  },

})