config.js 3.11 KB
import App from '../../utils/api.js'
var util = require('../../utils/util.js')
Page({
	data:{
		config:{
			is_receiving:1,
			is_place_order:1,
			is_full_amount:'',
			lunch_time:'',
			dinner_time:'',
			is_many_people:'',
			is_full_range:'',
			prints:''
			
		}
	},
	onLoad(opt){
		this.setData({
			sellerid:opt.sellerid
		})
		this.getsellerconfig();
	},
	getsellerconfig(){
		App.Seller.GetSellerConfig({sellerid:this.data.sellerid}).then((json)=>{
			console.log(json)
			if(json.ret==200){
				this.setData({
					config:json.data[0]
				})
			}
		})
	},
	setsellerconfig(){
		let parmdata={
			sellerid:this.data.sellerid,
			...this.data.config,
		};
		if(parmdata.is_full_range>20){
			return wx.showToast({
				title:'配送范围不能超过20',
				icon:'none',
				mask:true,
				duration:1000
			})
		}
		let reg=/[0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]/
		if(parmdata.lunch_time!=''){
			if(!reg.test(parmdata.lunch_time)){
				return this.setData({
					reminderlunch:true
				})
			}else{
				this.setData({
					reminderlunch:false
				})
			}
		}
		if(parmdata.dinner_time!=''){
			if(!reg.test(parmdata.dinner_time)){
				return this.setData({
					reminderdinner:true
				})
			}
		}
		App.Seller.SetSellerConfig(parmdata).then((json)=>{
			console.log(json)
			if(json.ret==200){
				wx.showToast({
					title:'已保存',
					mask:true,
					duration:2000,
				})
				this.getsellerconfig();
			}
		})
	},
	setconfig(){
		
	},
	switchorder(e){
		this.setData({
			'config.is_place_order':this.data.config.is_place_order==1 ? 0 : 1
		})
	},
	test(){
		let reg=/[0-2][0-9]:[0-5][0-9]-[0-2][0-9]:[0-5][0-9]/
		if(this.data.config.lunch_time!=''){
			if(!reg.test(this.data.config.lunch_time)){
				return this.setData({
					reminderlunch:true
				})
			}else{
				this.setData({
					reminderlunch:false
				})
			}
		}else{
			this.setData({
				reminderlunch:false
			})
		}
		if(this.data.config.dinner_time!=''){
			if(!reg.test(this.data.config.dinner_time)){
				return this.setData({
					reminderdinner:true
				})
			}else{
				this.setData({
					reminderdinner:false
				})
			}
		}
	},
	inputval(e){
		let key=e.currentTarget.dataset.key,setkey='config.'+key,val=e.detail.value;
		if(val!=''){
			val=util.trim(val);
		}
		if(key=='lunch_time' || key=='dinner_time'){
			val=e.detail.value.replace(/:/, ":");
			if(val==''){
				let timekey='reminder'+key
				this.setData({
					[timekey]:false
				})
			}
		}
		if(val!=''){
			if(key=='is_full_range'){
				if(val>20){
					wx.showToast({
						title:'配送范围不能超过20',
						icon:'none',
						mask:true,
						duration:1000
					})
				}
				if(val==0){
					wx.showToast({
						title:'配送范围必须大于0',
						icon:'none',
						mask:true,
						duration:1000
					})
				}
				
			}
			if(key=='prints'){
				if(val==0){
					wx.showToast({
						title:'打印份数不能是0',
						icon:'none',
						mask:true,
						duration:1000
					})
				}
				if(val>5){
					wx.showToast({
						title:'打印份数不能超过5',
						icon:'none',
						mask:true,
						duration:1000
					})
				}
			}
		}
		this.setData({
			[setkey]:e.detail.value
		})
	}
})