info-base.js 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // pages/edit-info/info-base/info-base.js
  2. const cityData = require('../../../utils/picker.city.js')
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. // 时间选择器参数
  9. type: 2,
  10. startYear: 1980,
  11. endYear: 2030,
  12. cancelColor: "#888",
  13. color: "#f37b1d",
  14. setDateTime: "",
  15. result: "",
  16. // 页面信息参数
  17. mainInfo:{
  18. sname: "",
  19. sex: 1,
  20. place: "",
  21. birthday: "",
  22. height: "",
  23. eduStatus: 1,
  24. bestEdu: "",
  25. phoneNumber: "",
  26. email: "",
  27. qqNum: "",
  28. weChat: "",
  29. },
  30. uid:"",
  31. // 城市选择器
  32. proviceArr: [],
  33. cityArr: [],
  34. districtArr: [],
  35. value: [0, 0, 0],
  36. iconHidden: true,
  37. showPickerStatus: false,
  38. animationData: "",
  39. },
  40. // 选择教育状态
  41. eduStatusChange(e){
  42. var eduStatus = parseInt(e.detail.currentKey)
  43. console.log(eduStatus)
  44. this.setData({
  45. 'mainInfo.eduStatus': eduStatus
  46. })
  47. },
  48. // 表单提交和重置
  49. formSubmit: function (e) {
  50. for (let key in e.detail.value){
  51. this.setData({
  52. ['mainInfo.' + key + '']: e.detail.value[key]
  53. })
  54. }
  55. var _this = this
  56. wx.showModal({
  57. title: '提示',
  58. content: '确定提交修改的信息吗?',
  59. confirmColor:"#f37b1d",
  60. success(res) {
  61. if (res.confirm) {
  62. // 提交修改信息
  63. wx.request({
  64. url: getApp().globalData.baseURL + '/user/modify',
  65. method: 'POST',
  66. data: {
  67. "id": _this.data.uid,
  68. "data": _this.data.mainInfo
  69. },
  70. success(res) {
  71. if(res.statusCode==200){
  72. wx.showToast({
  73. title: '提交成功',
  74. icon: 'none',
  75. })
  76. }else{
  77. wx.showToast({
  78. title: '提交失败,请联系管理员',
  79. icon: 'none',
  80. })
  81. }
  82. }
  83. })
  84. } else if (res.cancel) {
  85. console.log('用户点击取消')
  86. }
  87. }
  88. })
  89. console.log('form发生了submit事件,携带数据为:', e.detail.value)
  90. },
  91. formReset: function () {
  92. console.log('form发生了reset事件')
  93. },
  94. // 选择性别
  95. sexChange(e){
  96. var sex = parseInt(e.detail.currentKey)
  97. console.log(sex)
  98. this.setData({
  99. 'mainInfo.sex': sex
  100. })
  101. },
  102. // 显示生日选择器
  103. show: function (e) {
  104. let type = Number(e.currentTarget.dataset.type);
  105. this.setData({
  106. cancelColor: "#888",
  107. color: "#f37b1d",
  108. setDateTime: "",
  109. startYear: 1980,
  110. endYear: 2005
  111. })
  112. this.dateTime.show();
  113. },
  114. // 改变时间
  115. change: function (e) {
  116. console.log(e)
  117. this.setData({
  118. 'mainInfo.birthday': e.detail.result
  119. })
  120. },
  121. /**
  122. * 生命周期函数--监听页面加载
  123. */
  124. onLoad: function (options) {
  125. //初始化城市选择器数据
  126. this.setData({
  127. proviceArr: this.toArr(cityData),
  128. cityArr: this.toArr(cityData[0].children),
  129. districtArr: this.toArr(cityData[0].children[0].children)
  130. })
  131. },
  132. onReady: function (options) {
  133. this.dateTime = this.selectComponent("#tui-dateTime-ctx")
  134. },
  135. /**
  136. * 生命周期函数--监听页面显示
  137. */
  138. onShow: function () {
  139. var _this = this
  140. try {
  141. var value = wx.getStorageSync('uid')
  142. if (value) {
  143. this.setData({
  144. uid: value
  145. });
  146. }
  147. } catch (e) {
  148. console.log(e)
  149. }
  150. // 获取主要信息
  151. wx.request({
  152. url: getApp().globalData.baseURL + '/user/',
  153. method: 'GET',
  154. data: {
  155. "id": _this.data.uid
  156. },
  157. success(res) {
  158. console.log(res.data)
  159. var data = _this.data.mainInfo
  160. if (res.data.data) {
  161. _this.setData({
  162. mainInfo: res.data.data,
  163. });
  164. } else {
  165. _this.setData({
  166. mainInfo: data,
  167. });
  168. }
  169. console.log(res)
  170. }
  171. })
  172. },
  173. toArr(object) {
  174. let arr = [];
  175. for (let i in object) {
  176. arr.push(object[i].name);
  177. }
  178. return arr;
  179. },
  180. /**
  181. * 城市选择器相关
  182. */
  183. //picker change切换事件
  184. columnPicker: function (e) {
  185. let value = e.detail.value;
  186. //如果两者下标不一致,表示滚动过
  187. if (this.data.value[0] !== value[0]) {
  188. this.setData({
  189. proviceArr: this.data.proviceArr,
  190. cityArr: this.toArr(cityData[value[0]].children),
  191. districtArr: this.toArr(cityData[value[0]].children[0].children),
  192. value: [value[0], 0, 0]
  193. })
  194. } else if (this.data.value[1] !== value[1]) {
  195. this.setData({
  196. proviceArr: this.data.proviceArr,
  197. cityArr: this.data.cityArr,
  198. districtArr: this.toArr(cityData[value[0]].children[value[1]].children),
  199. value: [value[0], value[1], 0]
  200. })
  201. } else {
  202. this.setData({
  203. value: value
  204. })
  205. }
  206. },
  207. //确定按钮
  208. picker: function (e) {
  209. let value = this.data.value;
  210. if (cityData.length > 0) {
  211. let provice = cityData[value[0]].name
  212. let city = cityData[value[0]].children[value[1]].name
  213. let district = cityData[value[0]].children[value[1]].children[value[2]].name
  214. this.setData({
  215. text: [provice, city, district],
  216. showPickerStatus: false,
  217. nativePlace: provice + ' ' + city + ' ' + district
  218. })
  219. }
  220. },
  221. // 显示picker-view
  222. showPicker: function () {
  223. var animation = wx.createAnimation({
  224. duration: 220,
  225. timingFunction: "linear",
  226. delay: 0
  227. })
  228. animation.translateY(500).step()
  229. this.setData({
  230. animationData: animation.export(),
  231. showPickerStatus: true
  232. })
  233. setTimeout(function () {
  234. animation.translateY(0).step()
  235. this.setData({
  236. animationData: animation.export()
  237. })
  238. }.bind(this), 200)
  239. },
  240. // 隐藏picker-view
  241. hidePicker: function () {
  242. this.setData({
  243. showPickerStatus: false
  244. })
  245. },
  246. })