123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- // customized/pages/address/add/add.js
- let app = getApp();
- let host = app.globalData.servsers; // 请求的url
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- name:'',
- phone:'',
- region: ['上海市', '上海市', '黄浦区'],
- detailAddress:'',
- switchChecked:false, //是否默认
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- },
- /**
- * 生命周期函数--监听页面初次渲染完成
- */
- onReady: function () {
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow: function () {
- },
- /**
- * 生命周期函数--监听页面隐藏
- */
- onHide: function () {
- },
- /**
- * 生命周期函数--监听页面卸载
- */
- onUnload: function () {
- },
- /**
- * 页面相关事件处理函数--监听用户下拉动作
- */
- onPullDownRefresh: function () {
- },
- /**
- * 页面上拉触底事件的处理函数
- */
- onReachBottom: function () {
- },
- /**
- * 用户点击右上角分享
- */
- onShareAppMessage: function () {
- },
- bindRegionChange(e) {
- console.log('picker发送选择改变,携带值为', e.detail.value)
- this.setData({
- region: e.detail.value
- })
- },
- switchChange(e){
- this.setData({
- switchChecked: e.detail.value
- })
- },
- nameChange(e){
- this.setData({
- name: e.detail.value
- })
- },
- phoneChange(e) {
- this.setData({
- phone: e.detail.value
- })
- },
- addressInput(e){ // 详细地址
- console.log(e)
- this.setData({
- detailAddress: e.detail.value
- })
- },
- addAddress(){ // 保存地址
- let that =this;
- if(!that.data.name){
- wx.showToast({
- title: '收货人没有输入',
- icon:"none"
- });
- return
- }
- if(!that.data.phone){
- wx.showToast({
- title: '手机号码没有输入',
- icon: "none"
- });
- return
- }
- if (!that.data.detailAddress) {
- wx.showToast({
- title: '详细地址没有输入',
- icon: "none"
- });
- return
- }
- wx.request({
- url: host +'/adressapi/insertadd',
- header: {
- 'content-type': 'application/x-www-form-urlencoded'
- },
- data:{
- user_id: app.globalData.user_id, //'oovpNwjlsY6xx8ceCebFa1dOLd9E', //app.globalData.user_id,
- consignee: that.data.name, //收货人
- province:that.data.region[0],
- city: that.data.region[1],
- area: that.data.region[2],
- adress:that.data.detailAddress,
- phone:that.data.phone,
- adress_flag: that.data.switchChecked ? 0 : 1 // 是否默认 0是 1 否
- },
- success(res){
- console.log(res,"地址保存")
- wx.showToast({
- title: '地址添加成功',
- icon:'none',
- success(){
- setTimeout(()=>{
- wx.navigateBack({
- delta: 1
- })
- },1000)
-
- }
- })
-
- }
- })
- },
- getEditAddress(){ // 获取编辑的地址
- let address = wx.getStorageSync('address'),
- name = address.consignee,
- phone =address.phone,
- region = [address.province,address.city,address.area],
- detailAddress =address.adress,
- switchChecked = address.switchChecked;
- console.log(address)
- this.setData({
- name:name,
- phone:phone,
- region: region,
- detailAddress: detailAddress,
- switchChecked: switchChecked
- })
- }
- })
|