addSite.js 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // pages/my/address/addSite/addSite.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. type: false,
  9. resultInfo: {
  10. name: '',
  11. phone: '',
  12. address: '',
  13. checked: false
  14. },
  15. name: '',
  16. phone: '',
  17. address: '',
  18. checked4: false,
  19. id:""
  20. },
  21. /**
  22. * 生命周期函数--监听页面加载
  23. */
  24. onLoad: function (options) {
  25. var type = options.parmise == 'add' ? true : false;
  26. console.log(options.parmise);
  27. if(!type){
  28. var parmise = JSON.parse(options.parmise)
  29. this.setData({
  30. type: type,
  31. resultInfo: {
  32. name: parmise.username,
  33. phone: parmise.phone,
  34. address: parmise.address,
  35. checked4: parmise.is_default == 1 ? true : false
  36. },
  37. name: parmise.username,
  38. phone: parmise.phone,
  39. address: parmise.address,
  40. checked4: parmise.is_default == 1 ? true : false,
  41. id:parmise.id,
  42. })
  43. }else{
  44. this.setData({type: type})
  45. }
  46. if (this.data.type) {
  47. wx.setNavigationBarTitle({
  48. title: '添加新地址',
  49. })
  50. } else {
  51. wx.setNavigationBarTitle({
  52. title: '编辑地址',
  53. })
  54. }
  55. },
  56. onChange(e) {
  57. console.log(e);
  58. this.setData({
  59. checked4: e.detail
  60. })
  61. this.data.resultInfo.checked = this.data.checked4
  62. },
  63. input1(e) {
  64. console.log(this.data.resultInfo.name);
  65. this.setData({
  66. name: e.detail
  67. })
  68. this.data.resultInfo.name = this.data.name
  69. if (this.data.resultInfo.name != '') {
  70. this.setData({
  71. checked1: true
  72. })
  73. } else {
  74. this.setData({
  75. checked1: false
  76. })
  77. }
  78. },
  79. input2(e) {
  80. this.setData({
  81. phone: e.detail
  82. })
  83. this.data.resultInfo.phone = this.data.phone
  84. if (this.data.resultInfo.phone != '') {
  85. this.setData({
  86. checked2: true
  87. })
  88. } else {
  89. this.setData({
  90. checked2: false
  91. })
  92. }
  93. },
  94. input3(e) {
  95. this.setData({
  96. address: e.detail
  97. })
  98. this.data.resultInfo.address = this.data.address
  99. if (this.data.resultInfo.address != '') {
  100. this.setData({
  101. checked3: true
  102. })
  103. } else {
  104. this.setData({
  105. checked3: false
  106. })
  107. }
  108. console.log(this.data.checked1, this.data.checked2, this.data.checked3);
  109. },
  110. addAddress() {
  111. var that = this;
  112. app.api.useApi(app.globalData.baseAppUrl + "api/address/create", {
  113. username: that.data.resultInfo.name,
  114. phone: that.data.resultInfo.phone,
  115. address: that.data.resultInfo.address,
  116. is_default: that.data.resultInfo.checked
  117. }, "post").then(function (res) {
  118. if (res.original.code != 200) {
  119. wx.showLoading({
  120. title: res.original.message.msg,
  121. })
  122. } else {
  123. wx.navigateTo({
  124. url: '/pages/my/address/address',
  125. })
  126. }
  127. setTimeout(function () {
  128. wx.hideLoading({
  129. success: (res) => { },
  130. })
  131. }, 2000);
  132. }).catch(function (err) {
  133. console.log(222);
  134. })
  135. },
  136. del(e) {
  137. console.log(e);
  138. app.api.useApi(app.globalData.baseAppUrl + "api/address/del", {
  139. id:e.target.dataset.id,
  140. }, "post").then(function (res) {
  141. if (res.original.code != 200) {
  142. wx.showLoading({
  143. title: res.original.message.msg,
  144. })
  145. } else {
  146. wx.navigateTo({
  147. url: '/pages/my/address/address',
  148. })
  149. }
  150. setTimeout(function () {
  151. wx.hideLoading({
  152. success: (res) => { },
  153. })
  154. }, 2000);
  155. }).catch(function (err) {
  156. console.log(222);
  157. })
  158. },
  159. updateaddr(e){
  160. var that = this;
  161. app.api.useApi(app.globalData.baseAppUrl + "api/address/update", {
  162. username: that.data.resultInfo.name,
  163. phone: that.data.resultInfo.phone,
  164. address: that.data.resultInfo.address,
  165. is_default: that.data.resultInfo.checked,
  166. id:e.target.dataset.id,
  167. }, "post").then(function (res) {
  168. if (res.original.code != 200) {
  169. wx.showLoading({
  170. title: res.original.message.msg,
  171. })
  172. } else {
  173. wx.navigateTo({
  174. url: '/pages/my/address/address',
  175. })
  176. }
  177. setTimeout(function () {
  178. wx.hideLoading({
  179. success: (res) => { },
  180. })
  181. }, 2000);
  182. }).catch(function (err) {
  183. console.log(222);
  184. })
  185. }
  186. })