s_staffadd.js 5.25 KB
var util = require('../../utils/util.js')
var uri=require('../../utils/uri.js')
import App from '../../utils/api.js'
Page({
    data:{
        atn_ishidden:true,
        actionSheetHidden:true,
        auto_focus:false,
        reminder_ishidden:true,
        phonehide:true,
        phone:''
    },
    onLoad:function(opt){
        console.log('opt:',opt)
        var sellerid = opt.storeid
        var title = ''
        if(opt.type){
            title = '店员详情'
        }else{
            title = '添加店员'
        }
        util.setBarTitle(title);
        this.setData({
            opt:opt,
            sellerid: util.cache("sellerid"),
            identity:util.cache('identity') ? util.cache('identity') : null,
            openid:util.cache('openid'),
        })
		this.opt=opt;
		if(opt.id){
			this.getuserinfo();
		}else{
			
		}
		this.getsellerinfo();
    },
    onShow:function(){
    },
    editname:function(e){
        this.setData({
            atn_ishidden:false,
            username:e.currentTarget.dataset.name,
            auto_focus:true
        })
    },
    modalInput:function(e){
        if(e.detail.value!=''){
            this.setData({
                reminder:null,
                username:e.detail.value
            })
        }else{
            this.setData({
                reminder:true,
                username:e.detail.value
            })
        }
    },
    confirmModel:function(){
        if(this.data.username!=''){
			App.Seller.EditAuthUser({id:this.opt.id,user_name:this.data.username}).then((json)=>{
				this.setData({
				    atn_ishidden:true,
				    username:'',
				    auto_focus:false
				})
				if(json.ret==200){
				    this.getuserinfo();
				}
				
			})
        }else{
            this.setData({
                reminder:true
            })
        }
    },
    cancelModel:function(){
        this.setData({
            atn_ishidden:true,
            class_name:'',
            auto_focus:false
        })
    },
    actionSheetTap:function(){
        this.setData({
            actionSheetHidden:false
        })
    },
    removeStaff:function(){
        var id=this.data.id;
        var data={seller_user_id:id};
        if(this.data.service_info && this.data.service_info.code){
            var code=this.data.service_info.code;
            data.code=code;
        }
		App.Seller.DeleteAuthUser({id:this.data.opt.id}).then((json)=>{
			if(json.ret==200){
				wx.showToast({
					title:'已移除',
					icon:'none',
					mask:true,
					duration:1500,
					success:()=>{
						setTimeout(()=>{
							wx.navigateBack();
						},1500)
					}
				})
			}
		})
        util.post(uri.CGI__USER_DELETEAUTHUSER,data,uri.CGI__USER_DELETEAUTHUSER__CODE)
    },
    cancelsheet:function(){
        this.setData({
            actionSheetHidden:true
        })
    },
    saveImage:function(){
        wx.downloadFile({
            url: this.data.service_info.receipt_code,
            success:function(res){
                console.log('ggg',res)
                wx.saveImageToPhotosAlbum({
                    filePath: res.tempFilePath,
                    success: function (res) {
                        console.log(res)
                    },
                    fail: function (res) {
                        console.log(res)
                        console.log('fail')
                    }
                })
            },
            fail:function(){
                console.log('fail')
            }
        })
    },
    //绑定微信
    bindwx:function(){
        this.data.opt.type=null;
        this.setData({
            opt:this.data.opt
        })
    },
    //查看密码
    lookpass:function(){
       wx.navigateTo({
           url:'s_password?account='+this.data.service_info.account+'&id='+this.data.service_info.id
       })
    },
    inputphone:function (e) {
       var phone=e.detail.value;
       this.setData({
           phone:phone,
           reminderphone:phone!='' ? null : this.data.reminderphone
       })

    },
    bindphonenumber:function () {
        this.setData({
            phonehide:false
        })
    },
    cancelphone:function () {
        this.setData({
            phonehide:true
        })
    },
    confirmphone:function () {
        var phone=this.data.phone;
        var myreg = /^[1][3,4,5,6,7,8,9][0-9]{9}$/;
        if(phone!=''){
            if(!myreg.test(phone)){
                this.setData({
                    reminderphone:'手机格式不正确'
                })
            }else{
                this.setData({
                    reminderphone:null,
                })
				App.Seller.EditAuthUser({id:this.opt.id,phone:this.data.phone}).then((json)=>{
					this.cancelphone();
					if(json.ret==200){
					    this.getuserinfo();
					}
					
				})
            }
        }else{
            this.setData({
                reminderphone:'请输入手机号',
            })
        }

    },
    netchange:function () {
        this.onShow()
    },
	getuserinfo(){
		App.Seller.GetAuthUser({id:this.opt.id}).then((json)=>{
			if(json.ret==200){
				this.setData({
					user:json.data
				})
			}
		})
	},
	getsellerinfo(){
		App.Seller.GetSellerById({sellerid:this.data.sellerid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				this.setData({
					seller:json.data.seller,
				})
			}
			
		})
	},
	
})