c_store.js 4.34 KB
// pages/currency/c_store.js
var util = require('../../utils/util.js')
var uri = require('../../utils/uri.js')
import App from '../../utils/api.js'
Page({
  data: {
      storehidden:false,
      historyhidden:true,
      searchhidden:true,
      isloading:false
  },

  onLoad: function (options) {
      util.setBarTitle('选择店铺');
      this.setData({
        openid:util.cache('openid'),
      })
      this.alert=this.selectComponent('#confirmalert');
  },
  onShow: function () {
      this.getsellerlist();
  },
	getsellerlist(){
		App.Seller.GetSystemByOpenid({openid:this.data.openid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				if(json.data.auth==0){
					// wx.navigateTo({
					// 	url:'../login/l_login'
					// })
				}else{
					this.setData({
					    sellerlist:json.data,
						isloading:true
					})
				}
				
			}
		})
	},
  chooseStore:function (e) {
    util.cache('role_name',e.currentTarget.dataset.rolename);
    if(util.cache('e.currentTarget.dataset.nickname')!=''){
        util.cache('nick_name',e.currentTarget.dataset.nickname);
    }else{
        wx.removeStorage({key:'nick_name'})
    }
    wx.reLaunch({
        url:"../me/s_index?sellerid="+e.currentTarget.dataset.id
    })
    util.cache('identity',e.currentTarget.dataset.identity)
  },
  historyStore:function(e){
      wx.removeStorage({key:'identity'})
      util.cache('sellerid',e.currentTarget.dataset.id)
      wx.reLaunch({
          url:"../me/s_index?sellerid="+e.currentTarget.dataset.id
      })
  },
  //通过openid识别当前用户身份、打开的商户信息
  getInfo:function(){
     util.post(uri.CGI__USER_GETSYSTEMBYOPENID,{openid:this.data.openid},uri.CGI__USER_GETSYSTEMBYOPENID__CODE)
  },
  showstorelist:function () {
      this.setData({
          storehidden:!this.data.storehidden
      })
  },
  showhistorylist:function () {
      this.setData({
          historyhidden:!this.data.historyhidden
      })
  },
  searchseller:function(e){
    var inputval=e.detail.value;
    if(util.removespace(inputval)!=''){
        this.setData({
            storehidden:true,
            searchhidden:false
        })
        var parmsdata={
            x:1,
            y:5,
            sign:util.removespace(inputval)
        }
        if(this.data.manage==2){
            parmsdata.openid=this.data.openid;
        }
        util.post(uri.CGI_USER_GETSELLERLISTBYISADMIN,parmsdata,uri.CGI_USER_GETSELLERLISTBYISADMIN__CODE)
    }else{
        this.setData({
            storehidden:false,
            searchhidden:true
        })
    }
  },
  selectseller:function(e){
      var id=e.currentTarget.dataset.id;
      util.post(uri.CGI_USER_VISITLOG,{sellerid:id},uri.CGI_USER_VISITLOG__CODE);
      wx.removeStorage({key:'identity'})
      util.cache('sellerid',id)
      this.setData({
          thisid:id
      })
  },
  //重新调起授权后,想接口获取信息
  login_start:function(iv,encryptedData){
        console.log(iv,encryptedData)
        var that=this;
        wx.login({
            //获取code
            success: function(login_res) {
                console.log('cc',login_res.code)
                var data = {
                    code: login_res.code,
                    appid: 'wx28fa5be22ae0ad55',
                    //secret: 'cf7059061bb79d764a9bba55d7197b12',
                    iv:iv,
                    encryptedData:encryptedData
                }
                //获取openid
                wx.request({
                    url: "https://xt.colorcun.com/WechatApi/Api/dcLogin",
                    data: data,
                    header: {
                        'content-type': 'application/json'
                    },
                    success: function(res) {
                        that.loginseller();
                    }
                })

            }
        })

    },
    getuserinfo:function(e){
        console.log(e)
        if(e.detail && e.detail.errMsg=='getUserInfo:ok'){
            wx.setStorageSync('nickname',e.detail.userInfo.nickName)
            var iv=e.detail.iv;
            var encryptedData=e.detail.encryptedData;
            this.login_start(iv,encryptedData)
        }else{
            this.alert.show('需要授权才能继续访问');
        }
    },
  loginseller:function(){
      wx.navigateTo({             //无商家
          url:'../login/l_info'
      })
  },
  netchange:function(){
      this.onShow();
  }
})