wx.request({
url: 'http://www.week4.com/api/getshu',
method:'GET',
success:e=>{
var data = e.data.data
var res = e.data.res
let arr = e.data.arr
console.log(data)
this.setData({
data:data,
res:res,
arr:arr
})
}
})
页面加载接口查询数据,data定义数组赋值,
预算价格<Select prop-array='{{data}}' bind:myget="getDate2" ></Select>
<view><input hidden="true" type="text" name="price" value="{{id2}}" /></view>
<button type="default" form-type="submit">发布信息</button>
map(e){
var that = this
wx.chooseLocation({
success:res=>{
var location = res.address+res.name
that.setData({
location:location,
latitude:res.latitude,
longitude:res.longitude
})
}
})
},
getDate(e){
console.log(e);
var id = e.detail.ids;
console.log(id);
this.setData({
id:id,
})
},
获取下拉框id和地图方法
formAdd:function(e){
let add = e.detail.value
let _token =wx.getStorageSync('token');
console.log(add);
wx.request({
url: 'http://www.week4.com/api/zuAdd',
method:'POST',
data:{_token,add},
success:res=>{
console.log(res);
}
})
},
表单提交接口调用
public function getShu()
{
$data = Fangattr::where('pid',1)->get()->toArray();
$res = Fangattr::where('pid',2)->get()->toArray();
$arr = Fangattr::where('pid',3)->get()->toArray();
return ['code'=>200,'msg'=>'成功','data'=>$data,'res'=>$res,'arr'=>$arr];
}
public function zuAdd(Request $request)
{
$data = $request->except('_token');
$res = Validator::make($data['add'],[
'title'=>'required',
'position'=>'required',
'price'=>'required',
'house'=>'required',
'time'=>'required',
'sex'=>'required',
'number'=>'required',
'text'=>'required',
],[
'title.required'=>'标题不能为空',
'position.required'=>'位置不能为空',
'price.required'=>'价格不能为空',
'house.required'=>'户型不能为空',
'time.required'=>'入住时间不能为空',
'sex.required'=>'性别不能为空',
'number.required'=>'手机号不能为空',
'text.required'=>'描述不能为空',
]);
if ($res->fails()) {
return ['code'=>202,'data'=>'','msg'=>$res->errors()];
}
$res = Rent::create($data['add']);
if($res){
return ['code'=>200,'msg'=>'添加成功','data'=>$data];
}else{
return ['code'=>400,'msg'=>'添加失败','data'=>''];
}
}