C端小程序
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

209 line
4.2 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. if (e.detail.value.username) {
  67. var username = e.detail.value.username;
  68. } else if (that.data.username) {
  69. var username = that.data.username;
  70. }
  71. else {
  72. var username = null;
  73. }
  74. if (that.data.flag == 2 && that.data.date) {
  75. var birthdate = new Date(that.data.date).getTime();
  76. } else {
  77. var birthdate = null;
  78. }
  79. console.log(username);
  80. console.log(address);
  81. console.log(sex);
  82. console.log(birthdate);
  83. if (username == null || address == null || sex == 0 || birthdate == null) {
  84. wx.showModal({
  85. title: '提示',
  86. content: '请输入完整的用户信息',
  87. showCancel: false
  88. })
  89. } else {
  90. Http.post({
  91. url: config.api.updateInfo,
  92. data: {
  93. sex: sex,
  94. address: address,
  95. name: username,
  96. birthdate: birthdate,
  97. }
  98. })
  99. .then(res => {
  100. console.log(res);
  101. wx.showModal({
  102. title: '提示',
  103. content: '修改成功',
  104. showCancel: false,
  105. success: function (res) {
  106. wx.switchTab({
  107. url: '/pages/user/index',
  108. })
  109. }
  110. })
  111. })
  112. }
  113. },
  114. radioChange: function (e) {
  115. console.log(e.detail.value)
  116. this.setData({
  117. sex: e.detail.value,
  118. flagsex: 1
  119. })
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function (options) {
  125. let that = this;
  126. that.setData({
  127. username: options.name,
  128. sex: options.sex,
  129. date: util.fmtDate(parseInt(options.birthdate)),
  130. name: JSON.parse(options.address).name,
  131. address: JSON.parse(options.address),
  132. flag: 2
  133. });
  134. if (options.sex == "1") {
  135. console.log(that.data.items);
  136. that.data.items[0].checked = true;
  137. var checked = 'items[' + 0 + '].checked'
  138. that.setData({
  139. [checked]: true
  140. })
  141. that.setData({
  142. flagsex: 1
  143. })
  144. } else if (options.sex == "2") {
  145. that.data.items[1].checked = true;
  146. var checked = 'items[' + 1 + '].checked'
  147. that.setData({
  148. [checked]: true
  149. })
  150. that.setData({
  151. flagsex: 1
  152. })
  153. console.log(that.data.items);
  154. }
  155. },
  156. /**
  157. * 生命周期函数--监听页面初次渲染完成
  158. */
  159. onReady: function () {
  160. },
  161. /**
  162. * 生命周期函数--监听页面显示
  163. */
  164. onShow: function () {
  165. console.log("oShow")
  166. },
  167. /**
  168. * 生命周期函数--监听页面隐藏
  169. */
  170. onHide: function () {
  171. },
  172. /**
  173. * 生命周期函数--监听页面卸载
  174. */
  175. onUnload: function () {
  176. },
  177. /**
  178. * 页面相关事件处理函数--监听用户下拉动作
  179. */
  180. onPullDownRefresh: function () {
  181. },
  182. /**
  183. * 页面上拉触底事件的处理函数
  184. */
  185. onReachBottom: function () {
  186. },
  187. /**
  188. * 用户点击右上角分享
  189. */
  190. onShareAppMessage: function () {
  191. }
  192. })