<form bindsubmit="addSubmit">
<view class="consignee">
<text class="consignee-tit">收货人信息</text>
<view class="consignee-main">
<view class="flex flex-align-center flex-pack-justify">
<text>姓名</text>
<input class="flex-1" name="name" type="number" maxlength="11" placeholder="请输入收货人姓名" />
</view>
<view class="flex flex-align-center flex-pack-justify">
<text>电话</text>
<input class="flex-1" name="mobile" type="number" maxlength="11" placeholder="请输入手机号" />
</view>
<view class="flex flex-align-center flex-pack-justify">
<text>地址</text>
<input class="flex-1" name="address" type="text" maxlength="11" placeholder="请输入地址" />
</view>
</view>
</view>
<view class="delivery-time flex flex-align-center flex-pack-justify">
<text>送货时间</text>
<picker mode="date"></picker>
</view>
<view class="receipt-address">
<view class="receipt-address-tit">收货地址信息</view>
<view wx:for="{{addressInfo}}" wx:key="unique">
<view class="receipt-address-list clearfix">
<image src="../../images/address-icon.png"></image>
<view class="address-list-main">
<view class="clearfix"><text>收货地址{{item.address}}</text><text>1km</text></view>
<view class="address-info">收货人{{item.name}}</view>
<view class="address-time">收货人电话{{item.mobile}}</view>
<view data-deleteid="{{item.id}}" bindtap="deleteClick">删除</view>
<view data-editid="{{item.id}}" bindtap="editClick">编辑</view>
</view>
</view>
</view>
</view>
<view class="receipt-true">
<button class="btn_login" formType="submit">保存</button>
</view>
</form>
var app = getApp()
Page({
data:{},
onLoad: function() {
var that = this;
//收货地址首页
wx.request({
//缺少用户唯一标识,现在的在服务器的控制器里有一个假id = 2
url: 'https://shop.yunapply.com/home/shipping/index',
method: 'GET',
data: {},
header: {
'Accept': 'application/json'
},
success: function(res) {
that.setData({
"addressInfo": res.data.info,
})
console.log(res.data.info);
},
fail:function(){
wx.showToast({
title: '服务器网络错误!',
icon: 'loading',
duration: 1500
})
}
})
}
})
var that = this;
success: function(res) {
that.setData({
"addressInfo": res.data.info,
})
},
fail:function(){
wx.showToast({
title: '服务器网络错误!',
icon: 'loading',
duration: 1500
})
}
public function index()
{
//$id 为用户名id 等以后可以通过token获取或者session(id)什么的
$use_id = 2;
$res = D('Shipping')->getAddress($use_id);
if ($res == false){
$this->error('暂无收货地址','',true);
}else{
$this->success($res,'',true);
}
}
/**
* 获取收货地址信息
* @param $id 当前用户id
* @return 属于用户的所有地址
*/
public function getAddress($id)
{
$address_list = $this->where(array('user_id'=>$id))->select();
if ($address_list == false){
return false;
}
return $address_list;
}
{"info":[{"id":"4","user_id":"2","name":"addTest","mobile":"15162550544","province":"",
"city":"","district":"","address":"44563","createtime":"2017-01-10 18:45:27"
,"modifytime":"2017-01-10 18:45:27","default":"0"}],"status":1,"url":""}
<view wx:for="{{addressInfo}}" wx:key="unique">
<view class="receipt-address-list clearfix">
<image src="../../images/address-icon.png"></image>
<view class="address-list-main">
<view class="clearfix"><text>收货地址{{item.address}}</text><text>1km</text></view>
<view class="address-info">收货人{{item.name}}</view>
<view class="address-time">收货人电话{{item.mobile}}</view>
<view data-deleteid="{{item.id}}" bindtap="deleteClick">删除</view>
<view data-editid="{{item.id}}" bindtap="editClick">编辑</view>
</view>
</view>
</view>
event.currentTarget.dataset.deleteid;表示事件对象的目标的data-*的值
//删除地址
deleteClick:function(event){
var id = event.currentTarget.dataset.deleteid;
wx.request({
url: 'https://shop.yunapply.com/home/shipping/delAddress?id='+id,
data: {},
method: 'GET',
success: function(res){
if(res.data.status == 0){
wx.showToast({
title: res.data.info,
icon: 'loading',
duration: 1500
})
}else{
wx.showToast({
title: res.data.info,
icon: 'success',
duration: 1000
})
//删除之后应该有一个刷新页面的效果,等和其他页面刷新跳转一起做
}
},
fail:function(){
wx.showToast({
title: '服务器网络错误!',
icon: 'loading',
duration: 1500
})
}
})
}
public function delAddress($id)
{
$res = D('Shipping')->where(array('id'=>$id))->delete();
if ($res){
$this->success('删除成功','',true);
}else{
$this->error('删除失败','',true);
}
}
<form bindsubmit="addSubmit">
<view class="consignee">
<text class="consignee-tit">收货人信息</text>
<view class="consignee-main">
<input name="id" type="hidden" value="{{addressEdit.id}}" />
<view class="flex flex-align-center flex-pack-justify">
<text>姓名</text>
<input class="flex-1" name="name" type="number" value="{{addressEdit.name}}" maxlength="11" placeholder="请输入收货人姓名" />
</view>
<view class="flex flex-align-center flex-pack-justify">
<text>电话</text>
<input class="flex-1" name="mobile" type="number" value="{{addressEdit.mobile}}" maxlength="11" placeholder="请输入手机号" />
</view>
<view class="flex flex-align-center flex-pack-justify">
<text>地址</text>
<input class="flex-1" name="address" type="text" value="{{addressEdit.address}}" maxlength="-1" placeholder="请输入地址" />
</view>
</view>
</view>
<view wx:for="{{addressInfo}}" wx:key="unique">
<view class="receipt-address-list clearfix">
<image src="../../images/address-icon.png"></image>
<view class="address-list-main">
<view class="clearfix"><text>收货地址{{item.address}}</text><text>1km</text></view>
<view class="address-info">收货人{{item.name}}</view>
<view class="address-time">收货人电话{{item.mobile}}</view>
<view data-deleteid="{{item.id}}" bindtap="deleteClick">删除</view>
<view data-editid="{{item.id}}" bindtap="editClick">编辑</view> <view class="receipt-true">
<button class="btn_login" formType="submit">保存</button>
</view>
</form>
editClick:function(event){
var that = this;
var id = event.currentTarget.dataset.editid;
wx.request({
url: 'https://shop.yunapply.com/home/shipping/edit?id='+id,
data: {},
method: 'GET',
success: function(res){
if(res.data.status == 0){
wx.showToast({
title: res.data.info,
icon: 'loading',
duration: 1500
})
}else{
that.setData({
"addressEdit": res.data.info,
})
}
},
fail:function(){
wx.showToast({
title: '服务器网络错误!',
icon: 'loading',
duration: 1500
})
}
})
},
public function edit($id)
{
$res = D('Shipping')->find($id);
$this->success($res,'',true);
}
that.setData({
"addressEdit": res.data.info,
})
}
addSubmit:function(e){
if(e.detail.value.mobile.length==0||e.detail.value.name.length==0 ||e.detail.value.address.length==0){
wx.showToast({
title: '收货人所有信息不得为空!',
icon: 'loading',
duration: 1500
})
}else if(e.detail.value.mobile.length != 11){
wx.showToast({
title: '请输入11位手机号码!',
icon: 'loading',
duration: 1500
})
}else{
wx.request({
url: 'https://shop.yunapply.com/home/shipping/save',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: "POST",
data:{id:e.detail.value.id,mobile:e.detail.value.mobile,name:e.detail.value.name,address:e.detail.value.address},
success: function(res) {
if(res.data.status == 0){
wx.showToast({
title: res.data.info,
icon: 'loading',
duration: 1500
})
}else{
wx.showToast({
title: res.data.info,
icon: 'success',
duration: 1000
})
setTimeout(function(){
wx.navigateTo({
url:'../address/index'
})
},1000)
}
},
fail:function(){
wx.showToast({
title: '服务器网络错误!',
icon: 'loading',
duration: 1500
})
}
})
}
}
url: 'https://shop.yunapply.com/home/shipping/save',
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
"Content-Type": "application/x-www-form-urlencoded"
data:{id:e.detail.value.id,mobile:e.detail.value.mobile,name:e.detail.value.name,address:e.detail.value.address},
public function save()
{
//$user_id
$user_id = 2;
if (IS_POST){
$shipping = D('Shipping');
if (!$shipping->create()){
$this->error($shipping->getError(),'',true);
}else{
if (is_numeric($_POST['id'])){
if ($shipping->editAddress($_POST['id'])){
$this->success('地址修改成功','',true);
}else{
$this->error('地址修改失败','',true);
}
}else{
if ($shipping->addAddress($user_id)){
$this->success('添加地址成功','',true);
}else{
$this->error('添加地址失败','',true);
}
}
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有