index.js 1.82 KB
import util from '../../../../utils/util';
import App from '../../../../utils/api';
Page({
	data:{
		alllabel:[
			
		],
	},
	onLoad:function(){
        this.getlabellist();
	},
	onShow:function(){
		
	},
	inputremark:function(e){
		this.setData({
			defineremark:util.trim(e.detail.value)
		})
	},
	//选择常用备注
	taplabel:function(e){
		var _target=e.currentTarget.dataset;
		var oftenlabel=0,alllabel=this.data.alllabel;
		alllabel.forEach(function(v,i){
			if(v.often_use!=''){
				oftenlabel++;
			}
		})
		if(_target.type=='often'){
			this.setlabel(_target.id,_target.type);
		}else{
			if(oftenlabel<10){
				this.setlabel(_target.id,_target.type);
			}else{
				wx.showToast({
					title:'最多可添加10个',
					icon:'none',
					duration:2000
				})
			}
		}
	},
	getlabellist:function(){
		App.User.GetCustomRemark({
			uid:util.cache('enter_params')['manager_id']
		}).then(res=>{
			console.log(res)
			this.setData({
				alllabel:res.data,
			})
			this.setData({
				focus:true,
			})
		})
	},
	setlabel:function(id,flag){
		App.User.GetCustomRemark({
			uid:util.cache('enter_params')['manager_id'],
			kid:id,
			flag:flag,
		}).then(res=>{
			console.log(res)
			this.setData({
				alllabel:res.data
			})
		})
	},
	addinputlabel:function(e){
		this.setData({
			focus:false
		})
		if(util.trim(e.detail.value)!=''){
			this.addlabel(util.trim(e.detail.value))
		}
		
	},
	//添加自定义标签
	addlabel:function(custom){
		App.User.AddCustomRemark({
			uid:util.cache('enter_params')['manager_id'],
			custom:custom,
		}).then(res=>{
			console.log(res)
			if(res.ret==200){
				this.setData({
					defineremark:null,
				})
				this.getlabellist();
			}else{
				this.setData({
					defineremark:null,
				})
				wx.showToast({
					title:'最多可添加20个备注',
					icon:'none',
					duration:2000
				})
			}
		})
	},
})