|
@@ -0,0 +1,143 @@
|
|
|
+// 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+'',
|
|
|
+ header: {
|
|
|
+ 'content-type': 'application/x-www-form-urlencoded'
|
|
|
+ },
|
|
|
+ data:{
|
|
|
+ userId: 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,"地址保存")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+})
|