123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- // pages/my/address/addSite/addSite.js
- const app = getApp();
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- type: false,
- resultInfo: {
- name: '',
- phone: '',
- address: '',
- checked: false
- },
- name: '',
- phone: '',
- address: '',
- checked4: false,
- id:""
- },
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad: function (options) {
- var type = options.parmise == 'add' ? true : false;
- console.log(options.parmise);
- if(!type){
- var parmise = JSON.parse(options.parmise)
-
- this.setData({
- type: type,
- resultInfo: {
- name: parmise.username,
- phone: parmise.phone,
- address: parmise.address,
- checked4: parmise.is_default == 1 ? true : false
- },
- name: parmise.username,
- phone: parmise.phone,
- address: parmise.address,
- checked4: parmise.is_default == 1 ? true : false,
- id:parmise.id,
- })
- }else{
- this.setData({type: type})
- }
- if (this.data.type) {
- wx.setNavigationBarTitle({
- title: '添加新地址',
- })
- } else {
- wx.setNavigationBarTitle({
- title: '编辑地址',
- })
- }
- },
- onChange(e) {
- console.log(e);
- this.setData({
- checked4: e.detail
- })
- this.data.resultInfo.checked = this.data.checked4
- },
- input1(e) {
- console.log(this.data.resultInfo.name);
- this.setData({
- name: e.detail
- })
- this.data.resultInfo.name = this.data.name
- if (this.data.resultInfo.name != '') {
- this.setData({
- checked1: true
- })
- } else {
- this.setData({
- checked1: false
- })
- }
- },
- input2(e) {
- this.setData({
- phone: e.detail
- })
- this.data.resultInfo.phone = this.data.phone
- if (this.data.resultInfo.phone != '') {
- this.setData({
- checked2: true
- })
- } else {
- this.setData({
- checked2: false
- })
- }
- },
- input3(e) {
- this.setData({
- address: e.detail
- })
- this.data.resultInfo.address = this.data.address
- if (this.data.resultInfo.address != '') {
- this.setData({
- checked3: true
- })
- } else {
- this.setData({
- checked3: false
- })
- }
- console.log(this.data.checked1, this.data.checked2, this.data.checked3);
- },
- addAddress() {
- var that = this;
- app.api.useApi(app.globalData.baseAppUrl + "api/address/create", {
- username: that.data.resultInfo.name,
- phone: that.data.resultInfo.phone,
- address: that.data.resultInfo.address,
- is_default: that.data.resultInfo.checked
- }, "post").then(function (res) {
- if (res.original.code != 200) {
- wx.showLoading({
- title: res.original.message.msg,
- })
- } else {
- wx.navigateTo({
- url: '/pages/my/address/address',
- })
- }
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 2000);
- }).catch(function (err) {
- console.log(222);
- })
- },
- del(e) {
- console.log(e);
- app.api.useApi(app.globalData.baseAppUrl + "api/address/del", {
- id:e.target.dataset.id,
- }, "post").then(function (res) {
- if (res.original.code != 200) {
- wx.showLoading({
- title: res.original.message.msg,
- })
- } else {
- wx.navigateTo({
- url: '/pages/my/address/address',
- })
- }
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 2000);
- }).catch(function (err) {
- console.log(222);
- })
- },
- updateaddr(e){
- var that = this;
- app.api.useApi(app.globalData.baseAppUrl + "api/address/update", {
- username: that.data.resultInfo.name,
- phone: that.data.resultInfo.phone,
- address: that.data.resultInfo.address,
- is_default: that.data.resultInfo.checked,
- id:e.target.dataset.id,
- }, "post").then(function (res) {
- if (res.original.code != 200) {
- wx.showLoading({
- title: res.original.message.msg,
- })
- } else {
- wx.navigateTo({
- url: '/pages/my/address/address',
- })
- }
- setTimeout(function () {
- wx.hideLoading({
- success: (res) => { },
- })
- }, 2000);
- }).catch(function (err) {
- console.log(222);
- })
- }
- })
|