outbackpeopledetail.js 6.3 KB
// pages/backdetail/backdetail.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    showcode: false,
    back_list: '',
    basic: '',
    first: '',
    codeurl: ''
  },
  closecode() {
    this.setData({
      showcode: false
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getdetail()
    this.getuser()
  },
  dian() {
    this.setData({
      showcode: true
    })
  },

  getdetail() {
    let that = this;
    var url = '/api/user/back_nation_detail';
    var params = {


    }
    app.post(url, params, "post").then((res) => {
      console.log(res);
      that.setData({
        back_list: res.back_list,
        basic: res.basic,
        first: res.back
      })
      app.globalData.workname = res.first.company_name;
      app.globalData.workid = res.first.company_id;
      app.globalData.shortworkname = res.first.unit_id



    }).catch((err) => {

    })

  },
  edit() {
    wx.navigateTo({
      url: '/pages/outbackpeopledoor/outbackpeopledoor?type=' + 1,
    })
  },

  getuser() {
    let that = this;
    var url = '/api/user/index';
    var params = {


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

      })
      that.savefilecode()




    }).catch((err) => {

    })

  },

  // 保存图片
  //点击保存到相册
  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.codeurl,
                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.codeurl,
            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) {

                }
              })
            }
          })
        }
      }
    })

  },

  savefilecode() {
    let that = this;
    console.log(that.data.codeurl)
    wx.downloadFile({
      url: that.data.codeurl,
      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({
              codeurl: 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) { },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

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

  },

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

  },

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

  },

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

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})