// pages/newQuanzi/newQuanzi.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    value:'',
    checked: false,
    fuwuplace:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var location = wx.getStorageSync('location');
    var place = location.province + location.city + location.district
    this.setData({
      fuwuplace:place
    })
  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },

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

  },
  onChange(event) {
    this.setData({
      value:event.detail
    })
  },
  onChange1({ detail }) {
    // 需要手动对 checked 状态进行更新
    this.setData({ checked: detail });
  },
  newQuanzijianli(){
    this.circleNew1()
  },
  circleNew1(){
    var that = this;
    var config = wx.getStorageSync('config');
    var jingweidu = wx.getStorageSync('jingweidu');
    wx: wx.request({
      url: app.url + 'ajax_circle_new1.php',
      data: {
        unionId: config.unionId,
        latitude: jingweidu.latitude,
        longitude: jingweidu.longitude,
        title: that.data.value,
        needCheck: 1
      },
      header: { 'content-type': 'application/json' },
      method: 'GET',
      dataType: 'json',
      success: function (res) {
        console.log(res)
        if (res.statusCode == 200) {
          wx.navigateTo({
            url: '../newCircle2/newCircle2',
          })
          wx.setNavigationBarTitle({
            title: '我的圈子'
          })
        }
      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  dingwei(){
    var config = wx.getStorageSync('config');
    var that = this;
    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        // console.log(res);
        var latitude = res.latitude;
        var longitude = res.longitude;
        let jingweidu = {
          latitude: res.latitude,
          longitude: res.longitude
        };
        wx.setStorage({
          key: 'jingweidu',
          data: jingweidu,
        })
        wx: wx.request({
          url: app.url + 'ajax_get_user_role.php',
          data: {
            unionId: config.unionId,
            latitude: latitude,
            longitude: longitude
          },
          header: { 'content-type': 'application/json' },
          method: 'GET',
          dataType: 'json',
          success: function (res) {
            var place = res.data.result.province + res.data.result.city + res.data.result.district;
            that.setData({
              fuwuplace:place
            })
            let location = {
              province: res.data.result.province,
              city: res.data.result.city,
              district: res.data.result.district
            }
            wx.setStorage({
              key: 'location',
              data: location,
            })
          },
          fail: function (res) { },
          complete: function (res) { },
        })
      }
    })
  }
})