前端页面
JS
methods: {
formSubmit:function(e){
let tmp = JSON.stringify(e.detail.value)
console.log('form发生了submit事件,携带数据为:' + JSON.stringify(e.detail.value))
var formdata = e.detail.value
// 数据校验
// console.log(formdata.birth);
//正则表达式
let reg_name = /^[\u4e00-\u9fa5]{0,}$/
let reg_birth = /^(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31)|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)-02-29)$/;
let reg_tel = /(\d{11})|^((\d{7,8})|(\d{4}|\d{3})-(\d{7,8})|(\d{4}|\d{3})-(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1})|(\d{7,8})-(\d{4}|\d{3}|\d{2}|\d{1}))$/
//结果标记
let sign_name = RegExp(reg_name).test(formdata.name);
let sign_birth = RegExp(reg_birth).test(formdata.birth);
let sign_tel = RegExp(reg_tel).test(formdata.tel);
// console.log(sign+",数据类型:"+typeof(sign));
if(!sign_name||formdata.name==''){
this.showModal('请检查姓名');
}else if(formdata.gender==''){
this.showModal('请选择性别')
}else if(!sign_birth||formdata.name==''){
this.showModal("请检查出生日期");
}else if(!sign_tel||formdata.name==''){
this.showModal("请检查电话号码");
}else if(formdata.diagnose==''){
this.showModal('请填写初步诊断')
}else if(formdata.item==''){
this.showModal("请填写检查部位");
}else{
uni.request({
url: this.$baseUrl.baseUrl+"Wxtest/ApplyCheck",
data: tmp,
method: "post",
success:(res)=> {
this.showModal(res.data.msg);
if (res.confirm||res.cancel) {
console.log('用户点击确定');
}
},
fail:(res)=>{
console.log("错误")
}
})
}
},
formReset: function(e) {
console.log('清空数据')
},
showModal:function(content){
uni.showModal({
title:'提示',
content:content,
})
},
}
C#后端处理方法
public string ApplyCheck()
{
string name = GetRequestString("name", Request);
string gender = GetRequestString("gender", Request);
string birth = GetRequestString("birth", Request);
string tel = GetRequestString("tel", Request);
string diagnose = GetRequestString("diagnose", Request);
string item = GetRequestString("item", Request);
//创建随机数
Random ran = new Random();
string id = DateTime.Now.ToString("yyyyMMddHHmmss") + ran.Next(100,999);
//sql
string inser_t_check = @"insert into t_check (p_id,p_name,p_gender,p_birth,p_tel,p_diagnose,p_item) values ('{0}','{1}','{2}','{3}','{4}','{5}','{6}')";
inser_t_check = string.Format(inser_t_check,id, name, gender, birth, tel, diagnose, item);
//执行
OracleHelper.ExecuteNonQuerySQL(inser_t_check);
//
Dictionary dic = new Dictionary();
dic.Add("msg", "预约成功");
string response = JsonConvert.SerializeObject(dic);
return response;
}