C端小程序
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

207 satır
4.1 KiB

  1. const util = require("../../utils/util.js");
  2. const Http = require("../../utils/HttpBasics");
  3. const config = require("../../config/config");
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. date: '1988-03-12',
  10. flag: 1,
  11. flagsex: 0,
  12. items: [
  13. { name: 1, value: '男', checked: false },
  14. { name: 2, value: '女', checked: false },
  15. ]
  16. },
  17. /**
  18. * 获得生日
  19. */
  20. bindDateChange: function (e) {
  21. console.log('picker发送选择改变,携带值为', e.detail.value);
  22. console.log(typeof (e.detail.value))
  23. this.setData({
  24. date: e.detail.value,
  25. flag: 2
  26. })
  27. },
  28. address: function () {
  29. let that = this;
  30. wx.chooseLocation({
  31. success: function (res) {
  32. console.log(res);
  33. that.setData({
  34. name: res.name,
  35. address: res,
  36. })
  37. },
  38. fail: function (error) {
  39. console.log(error)
  40. },
  41. complete: function (data) {
  42. console.log(data);
  43. }
  44. })
  45. },
  46. formSubmit: function (e) {
  47. console.log(e);
  48. let that = this;
  49. /**
  50. * sex
  51. * 0 保密
  52. * 1 男
  53. * 2 女
  54. */
  55. if (that.data.flagsex == 0) {
  56. var sex = 0;
  57. } else {
  58. var sex = that.data.sex;
  59. }
  60. if (that.data.address) {
  61. var address = JSON.stringify(that.data.address);
  62. }
  63. else {
  64. var address = null;
  65. }
  66. console.log(e.detail.value.username)
  67. if (e.detail.value.username) {
  68. var username = e.detail.value.username;
  69. } else if (that.data.username) {
  70. var username = that.data.username;
  71. }
  72. else {
  73. var username = null;
  74. }
  75. if (that.data.flag == 2 && that.data.date) {
  76. var birthdate = new Date(that.data.date).getTime();
  77. } else {
  78. var birthdate = null;
  79. }
  80. console.log(username);
  81. console.log(address);
  82. console.log(sex);
  83. console.log(birthdate);
  84. if (username == null || address == null || sex == 0 || birthdate == null) {
  85. wx.showModal({
  86. title: '提示',
  87. content: '请输入完整的用户信息',
  88. showCancel: false
  89. })
  90. } else {
  91. Http.post({
  92. url: config.api.updateInfo,
  93. data: {
  94. sex: sex,
  95. address: address,
  96. name: username,
  97. birthdate: birthdate,
  98. }
  99. })
  100. .then(res => {
  101. console.log(res);
  102. wx.showModal({
  103. title: '提示',
  104. content: '修改成功',
  105. showCancel: false,
  106. success: function (res) {
  107. wx.switchTab({
  108. url: '/pages/user/index',
  109. })
  110. }
  111. })
  112. })
  113. }
  114. },
  115. radioChange: function (e) {
  116. console.log(e.detail.value)
  117. this.setData({
  118. sex: e.detail.value,
  119. flagsex: 1
  120. })
  121. },
  122. /**
  123. * 生命周期函数--监听页面加载
  124. */
  125. onLoad: function (options) {
  126. let that = this;
  127. that.setData({
  128. username: options.name,
  129. sex: options.sex,
  130. date: util.fmtDate(parseInt(options.birthdate)),
  131. name: JSON.parse(options.address).name,
  132. address: JSON.parse(options.address),
  133. flag: 2
  134. });
  135. if (options.sex == "1") {
  136. var checked = 'items[' + 0 + '].checked'
  137. that.setData({
  138. [checked]: true
  139. })
  140. that.setData({
  141. flagsex: 1
  142. })
  143. } else if (options.sex == "2") {
  144. var checked = 'items[' + 1 + '].checked'
  145. that.setData({
  146. [checked]: true
  147. })
  148. that.setData({
  149. flagsex: 1
  150. })
  151. console.log(that.data.items);
  152. }
  153. },
  154. /**
  155. * 生命周期函数--监听页面初次渲染完成
  156. */
  157. onReady: function () {
  158. },
  159. /**
  160. * 生命周期函数--监听页面显示
  161. */
  162. onShow: function () {
  163. console.log("oShow")
  164. },
  165. /**
  166. * 生命周期函数--监听页面隐藏
  167. */
  168. onHide: function () {
  169. },
  170. /**
  171. * 生命周期函数--监听页面卸载
  172. */
  173. onUnload: function () {
  174. },
  175. /**
  176. * 页面相关事件处理函数--监听用户下拉动作
  177. */
  178. onPullDownRefresh: function () {
  179. },
  180. /**
  181. * 页面上拉触底事件的处理函数
  182. */
  183. onReachBottom: function () {
  184. },
  185. /**
  186. * 用户点击右上角分享
  187. */
  188. onShareAppMessage: function () {
  189. }
  190. })