审查视图

pages/shopdetail/shopdetail.js 17.0 KB
lihongjuan authored
1
// pages/shopdetail/shopdetail.js
1  
lihongjuan authored
2
const app = getApp();
lihongjuan authored
3 4 5 6 7 8
Page({

  /**
   * 页面的初始数据
   */
  data: {
1  
lihongjuan authored
9
    imgUrls: [],
lihongjuan authored
10 11 12 13 14 15
    indicatorDots: false,
    autoplay: true,
    interval: 2000,
    duration: 1000,
    currentSwiper: 0,
    hidewrapno: false,
1  
lihongjuan authored
16 17 18 19
    hidewraptrue: false,
    shopid: '',
    shopdetail: '',
    images:[],
1  
lihongjuan authored
20 21 22
    pic:[],
    shoplist:[],
    posterurl:'',
1  
lihongjuan authored
23 24
    postershow:false,
    remarklen:''
lihongjuan authored
25 26 27 28 29 30
  },

  swiperChange: function(e) {
    this.setData({
      currentSwiper: e.detail.current
    })
1  
lihongjuan authored
31 32 33 34 35 36 37 38 39 40 41
    wx.previewImage({
      current: that.data.explain_pic[index],
      urls: that.data.explain_pic,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
      })
    // wx.previewImage({
    //   urls: [],
    // })
  },
1  
lihongjuan authored
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
  // 获取推荐店铺
  getrecomondshop(){
    let that = this;
    var url = 'shop/infoShopRecommend';
    var params = {
     id: that.data.shopid,
      limit:6,

    }
    app.post(url, params).then((res) => {
      console.log(res);
    that.setData({
      shoplist:res
    })
    }).catch((err) => {

    })
  },
  goodtail(e) {
    let id = e.currentTarget.dataset.id;
      wx.navigateTo({
        url: '/pages/shopdetail/shopdetail?id=' + id,
      })

  },

share(){
  this.setData({
    postershow:true
  })
 
  this.getcode()
},
  // 获取海报
  getcode(){
    let that = this;
    var url = 'common/getCode';
    var params = {
      shop_id: that.data.shopid,
      url:'pages/shopdetail/shopdetail',

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        posterurl:res
      })

      that.savefilecode()
     

   
    }).catch((err) => {

    })
  },
1  
lihongjuan authored
98 99 100 101 102 103 104 105 106 107 108 109 110
  // 评论图片预览
  previewimgk(e){
    console.log(e)
    let pindex=e.currentTarget.dataset.pindex;
    let index=e.currentTarget.dataset.index;
    wx.previewImage({
      current: this.data.shopdetail.remarks[pindex].images[index],
      urls:this.data.shopdetail.remarks[pindex].images,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
      })
lihongjuan authored
111 112 113
  },
  morecomment() {
    wx.navigateTo({
1  
lihongjuan authored
114
      url: '/pages/morecomment/morecomment?shopid='+this.data.shopid,
lihongjuan authored
115 116 117
    })
  },
  xiangce() {
1  
lihongjuan authored
118
    console.log(33443)
1  
lihongjuan authored
119 120 121 122 123 124 125 126 127 128 129 130 131
    wx.navigateTo({
      url: '/pages/morepic/morepic',
    })
    // if(this.data.pic.length!=0){
    //   wx.navigateTo({
    //     url: '/pages/morepic/morepic',
    //   })
    // }else{
    //     wx.showToast({
    //       title: '没有更多图片了~',
    //       icon:'none'
    //     })
    // }
1  
lihongjuan authored
132
   
lihongjuan authored
133 134 135 136 137 138 139
  },
  // 隐藏遮罩层
  sure() {
    this.setData({
      hidewraptrue: false
    })
  },
1  
lihongjuan authored
140 141 142
  // 点评详情
  comentdetail(e) {
    let commentid = e.currentTarget.dataset.id
lihongjuan authored
143
    wx.navigateTo({
1  
lihongjuan authored
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
      url: '/pages/commentdetail/commentdetail?commentid=' + commentid + '&shopid=' + this.data.shopid,
    })
  },

  // 推荐
  recomond() {
    let that = this;
    var url = 'shop/shopRecommend';
    var params = {
      shop_id: that.data.shopid,

    }
    app.post(url, params).then((res) => {
      console.log(res);
      if (that.data.shopdetail.is_recommend == 0) {
        wx.showToast({
          title: '推荐成功',
          icon: 'none'
        })
        that.data.shopdetail.is_recommend = 1;
        that.setData({
          shopdetail: that.data.shopdetail
        })
      } else {
        wx.showToast({
          title: '取消推荐成功',
          icon: 'none'
        })
        that.data.shopdetail.is_recommend = 0;
        that.setData({
          shopdetail: that.data.shopdetail
        })
      }

    }).catch((err) => {

    })
  },
1  
lihongjuan authored
182 183 184 185 186 187 188 189 190 191 192 193 194
  // 预览图片
  previewimg(e){
    let that=this;
    let index=e.currentTarget.dataset.index
    wx.previewImage({
      current: that.data.images[index],
      urls: that.data.images,
      success: function (res) { },
      fail: function (res) { },
      complete: function (res) { },
    })
    
  },
1  
lihongjuan authored
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

  // 收藏
  collect() {
    let that = this;
    var url = 'shop/shopCollect';
    var params = {
      shop_id: that.data.shopid,

    }
    app.post(url, params).then((res) => {
      console.log(res);
      if (that.data.shopdetail.is_collect == 0) {
        wx.showToast({
          title: '收藏成功',
          icon: 'none'
        })
        that.data.shopdetail.is_collect = 1;
        that.setData({
          shopdetail: that.data.shopdetail
        })
      } else {
        wx.showToast({
          title: '取消收藏成功',
          icon: 'none'
        })
        that.data.shopdetail.is_collect = 0;
        that.setData({
          shopdetail: that.data.shopdetail
        })
      }

    }).catch((err) => {

    })
  },

  // 打卡
  daka() {
    let that = this;
    var url = 'shop/addSign';
    var params = {
      shop_id: that.data.shopid

    }
    app.post(url, params).then((res) => {
      console.log(res);
      that.setData({
        hidewraptrue: true
      })


    }).catch((err) => {
      console.log(err)
      wx.showToast({
        title: err.data.msg,
        icon:'none'
      })
lihongjuan authored
253 254 255 256 257 258 259
    })
  },
  write(e) {
    let id = e.currentTarget.dataset.id;
    console.log(id)
    if (id == 1) {
      console.log(38843)
1  
lihongjuan authored
260
      this.daka()
lihongjuan authored
261 262 263
    } else if (id == 2) {
      console.log(334)
      wx.navigateTo({
1  
lihongjuan authored
264
        url: '/pages/passPhotos/passPhotos?type=' + 1 + '&shopid=' + this.data.shopid
lihongjuan authored
265 266 267 268 269 270 271 272 273
      })

    } else if (id == 3) {
      wx.navigateTo({
        url: '/pages/passPhotos/passPhotos?type=' + 2,
      })

    } else if (id == 4) {
      wx.navigateTo({
1  
lihongjuan authored
274
        url: '/pages/comment/comment?name='+this.data.shopdetail.name+'&shopid='+this.data.shopid,
lihongjuan authored
275 276 277
      })
    }
  },
1  
lihongjuan authored
278 279 280 281 282 283 284 285 286

  // 进入个人主页
  personpage(e){
    console.log(e)
    let userid=e.currentTarget.dataset.userid;
    wx.navigateTo({
      url: '/pages/personpage/personpage?userid='+userid,
    })
  },
lihongjuan authored
287 288 289 290
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
1  
lihongjuan authored
291 292 293 294 295 296 297 298
    this.setData({
      shopid: options.id
    })
    if (app.globalData.shopid != undefined) {
      this.setData({
        shopid: app.globalData.shopid
      })
    }
1  
lihongjuan authored
299 300 301
// 获取推荐店铺
  this.getrecomondshop();
  this.getcode()
1  
lihongjuan authored
302 303 304 305 306 307 308 309 310 311 312 313 314

  },

  // 获取店铺详情
  getshopdetail() {
    let that = this;
    var url = 'shop/getShopInfo';
    var params = {
      id: that.data.shopid

    }
    app.post(url, params).then((res) => {
      console.log(res);
1  
lihongjuan authored
315 316 317 318
    
      that.setData({
        remarklen:res.remarks.length
      })
1  
lihongjuan authored
319 320 321 322 323
      let image=[]


      console.log(res.images.length)
      // res.synthetical_score.tofixed("1");
1  
lihongjuan authored
324 325 326 327 328 329 330 331 332 333
      var pic=[]
      for(var j=0;j<res.images.length;j++){
        pic.push(res.images[j])
      }
     
      that.setData({
        pic:pic
      })
      app.globalData.images=pic;
      console.log( app.globalData.images)
1  
lihongjuan authored
334
      if (res.images.length>6){
1  
lihongjuan authored
335
      
1  
lihongjuan authored
336 337 338 339
        for(var i=0;i<=6;i++){
          image.push(res.images[i])
        }
        that.setData({
1  
lihongjuan authored
340 341 342
          images: image
        }) 
       
1  
lihongjuan authored
343 344 345 346 347 348
      }else{
       
        that.setData({
          images: res.images
        }) 
      }
1  
lihongjuan authored
349 350 351 352 353 354 355 356 357 358
      // 只保留两条评论
      let newremarks=[];
      console.log('784889439',res.remarks)
      for(var i=0;i<res.remarks.length;i++){
        if(i<2){
          newremarks.push(res.remarks[i])
        }
      }
      console.log(newremarks)
      res.remarks=newremarks;
1  
lihongjuan authored
359 360 361 362

      that.setData({
        shopdetail: res
      })
1  
lihongjuan authored
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382

      // 评论里的图片保留9张
      that.data.shopdetail.remarks.forEach(function(value,index,array){
        console.log('484389843',value)

        var imagesk=[];
        if(value.images.length>9){
          for(var i=0;i<value.images.length;i++){
            if(i<=9){
              imagesk.push(value.images[i])
            }
          }
          value.images=imagesk
        }
       
      })

      that.setData({
        shopdetail:that.data.shopdetail
      })
1  
lihongjuan authored
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399
      let token=wx.getStorageSync("token");
    if(token==''){
      wx.showToast({
        title: '请先登录',
        icon:"none"
      })
      setTimeout(function(){
        wx.redirectTo({
          url: '/pages/index/index?id='+that.data.shopid+'&type='+1,
        })
      },1500)
    }
      console.log(that.data.shopdetail)
    }).catch((err) => {

    })
lihongjuan authored
400 401
  },
1  
lihongjuan authored
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
    //点击保存到相册
    baocun: function () {
      console.log(999)
      var that = this
      wx.getSetting({
        success(res) {
          if (!res.authSetting['scope.writePhotosAlbum']) {
            wx.authorize({
              scope: 'scope.writePhotosAlbum',
              success() { //这里是用户同意授权后的回调
  
  
                wx.saveImageToPhotosAlbum({
                  filePath: that.data.posterurl,
                  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(that.data.codeurl)
            wx.saveImageToPhotosAlbum({
              filePath: that.data.posterurl,
              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) {
  
                  }
                })
              }
            })
          }
        }
      })
  
    },
1  
lihongjuan authored
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

    // 分享到朋友圈
    shareimg(){
      var that = this
      wx.getSetting({
        success(res) {
          if (!res.authSetting['scope.writePhotosAlbum']) {
            wx.authorize({
              scope: 'scope.writePhotosAlbum',
              success() { //这里是用户同意授权后的回调
  
  
                wx.saveImageToPhotosAlbum({
                  filePath: that.data.posterurl,
                  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(that.data.codeurl)
            wx.saveImageToPhotosAlbum({
              filePath: that.data.posterurl,
              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) {
  
                  }
                })
              }
            })
          }
        }
      })
    },
1  
lihongjuan authored
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
    hideposter(){
      this.setData({
        postershow:false
      })
    },
  
    savefilecode() {
      let that = this;
      console.log(that.data.codeurl)
      wx.downloadFile({
        url: that.data.posterurl,
        header: {},
        success: function (res) {
          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({
                posterurl: res.savedFilePath
              })
  
              console.log('123456855555555', that.data.qrcode)
  
            }, //可以将saveFilePath写入到页面数据中
            fail: function (res) { },
            complete: function (res) {
              console.log('complete后的res数据:')
            },
          }) //,
        },
        // fail: function (res) {
        //   wx.showModal({
        //     title: '下载失败',
        //     content: '请联系管理员',
        //   })
        // },
        complete: function (res) { },
      })
    },
lihongjuan authored
657 658 659 660 661 662 663 664 665 666 667
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
1  
lihongjuan authored
668
    this.getshopdetail()
lihongjuan authored
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
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
1  
lihongjuan authored
703 704 705 706 707
    return {
      title: this.data.shopdetail.name,
      path: '/pages/shopdetail/shopdetail?id=' + this.data.shopid,
      success: function (res) { }
    }
lihongjuan authored
708 709 710

  }
})