kids_information.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. // pages/kids_information/kids_information.js
  2. const { formatEncrypt} = require('../../utils/util.js')
  3. const app = getApp()
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. options: {},
  10. baseImgUrl: app.globalData.baseImgUrl,
  11. isShowPickerModel: false,
  12. phone:'',
  13. patriarchName:'',
  14. homeAddress:'',
  15. studyPlanName:'',
  16. isAddChild:0,
  17. studentImg:'',
  18. isAdd:false,
  19. imgUrl:'',
  20. school: '',
  21. childName: '',
  22. parentName: '',
  23. sex: 0,
  24. grade: '',
  25. parentRole:'',
  26. pickerData: [
  27. {
  28. actIndex: 1,
  29. list: ['学前', '一年级', '二年级', '三年级', '四年级', '五年级', '六年级']
  30. },
  31. {
  32. actIndex: 0,
  33. list: ['语文', '数学', '英文']
  34. },
  35. {
  36. actIndex: 0,
  37. list: ['男', '女']
  38. },
  39. {
  40. actIndex: 0,
  41. list: ['基础', '巩固','培优']
  42. },
  43. {
  44. actIndex: 0,
  45. list: ['爸爸', '妈妈', '爷爷','奶奶','外公','外婆','其他']
  46. }
  47. ],
  48. pickerIndex: null
  49. },
  50. /**
  51. * 生命周期函数--监听页面加载
  52. */
  53. onLoad: function (options) {
  54. this.setData(options)
  55. // console.log(options)
  56. if (!options.vipId) {
  57. const userId = app.globalData.userId || wx.getStorageSync('userId')
  58. const vipId = app.globalData.parentVipId || wx.getStorageSync(`parentVipId-${userId}`)
  59. options.vipId = vipId
  60. options.userId = userId
  61. this.setData({ options });
  62. }
  63. },
  64. /**
  65. * 生命周期函数--监听页面初次渲染完成
  66. */
  67. onReady: function () {
  68. },
  69. /**
  70. * 生命周期函数--监听页面显示
  71. */
  72. onShow: function () {
  73. const { isAddChild } = this.data;
  74. if (isAddChild == 0) {
  75. this.getInformation()
  76. }
  77. if (isAddChild == 1){
  78. var list = wx.getStorageSync('list');
  79. var arr = [];
  80. for (var i in list) {
  81. arr = arr.concat(list[i].bookList)
  82. }
  83. var bookList = [];
  84. for (var i in arr) {
  85. bookList.push({ bookId: arr[i].bookId, subject: arr[i].subject, bookName: arr[i].bookName, })
  86. }
  87. console.log(bookList)
  88. if (bookList.length>0){
  89. this.setData({ isAdd:true });
  90. }else{
  91. this.setData({ isAdd: false });
  92. }
  93. this.setData({ bookList });
  94. }
  95. },
  96. /**
  97. * 生命周期函数--监听页面隐藏
  98. */
  99. onHide: function () {
  100. },
  101. /**
  102. * 生命周期函数--监听页面卸载
  103. */
  104. onUnload: function () {
  105. },
  106. /**
  107. * 页面相关事件处理函数--监听用户下拉动作
  108. */
  109. onPullDownRefresh: function () {
  110. },
  111. /**
  112. * 页面上拉触底事件的处理函数
  113. */
  114. onReachBottom: function () {
  115. },
  116. /**
  117. * 用户点击右上角分享
  118. */
  119. onShareAppMessage: function () {
  120. },
  121. /**
  122. * 路由跳转
  123. */
  124. redirectCtl: app.redirectCtl,
  125. /**
  126. * 路由跳转
  127. */
  128. navigateCtl: app.navigateCtl,
  129. /**
  130. * 添加教辅
  131. */
  132. addTeaching:function(){
  133. const { vipId, grade, isAddChild, isAdd}=this.data;
  134. const { imgUrl, childName, sex, parentName, phone, courseName,school, family, studyPlan, parentRole} = this.data;
  135. var obj = {vipId,imgUrl,childName,sex,parentName,phone,courseName,grade,school,family,studyPlan,parentRole};
  136. var that=this;
  137. if (isAddChild!=1){
  138. if (grade) {
  139. that.navigateCtl({ url: 'teaching', method: { vipId, grade, isAddChild, obj: JSON.stringify(obj) } }, true)
  140. } else {
  141. wx.showToast({
  142. title: '请先选择年级',
  143. icon: 'none'
  144. })
  145. }
  146. }else{
  147. if (grade) {
  148. that.navigateCtl({ url: 'teaching', method: { grade, isAddChild, isAdd} }, true)
  149. } else {
  150. wx.showToast({
  151. title: '请先选择年级',
  152. icon: 'none'
  153. })
  154. }
  155. }
  156. },
  157. /**
  158. * 获取个人信息
  159. */
  160. getInformation: function (e) {
  161. const postData = { fn: this.getInformation, param: { ...arguments } }
  162. const { vipId, school } = this.data
  163. app.post('/api/parents/parents/V2/getMyChildInfo', { vipId }, 0, postData).then(res => {
  164. // console.log(res.data)
  165. this.setData({ ...res.data })
  166. if (school && school != '' && res.data.school != school) {
  167. this.setData({ school:school })
  168. }
  169. })
  170. },
  171. /**
  172. * 修改个人信息
  173. */
  174. updateInfor: function (obj, type) {
  175. const postData = { fn: this.updateInfor, param: { ...arguments } }
  176. app.post('/api/parents/parents/V2/upMyChildInfo', obj, 0, postData).then(res => {
  177. wx.showToast({
  178. title: '保存成功',
  179. icon: 'none'
  180. })
  181. if (type == 1) {
  182. this.setData(obj)
  183. }
  184. })
  185. },
  186. /**
  187. * 上传头像
  188. */
  189. uploadHeadIconCtl: function () {
  190. wx.chooseImage({
  191. count: 1,
  192. success: res => {
  193. this.uploadImage(res.tempFilePaths[0])
  194. },
  195. fail: res => {
  196. // wx.showToast({
  197. // title: '选择拍照或者相册失败',
  198. // icon: 'none'
  199. // })
  200. }
  201. })
  202. },
  203. /**
  204. * 上传头像接口
  205. */
  206. uploadImage: function (file) {
  207. app.uploadFile('/api/common/common/uploadForm', file, {}).then(res => {
  208. let { filePath } = JSON.parse(res).data.pics[0];
  209. console.log(filePath);
  210. this.setData({ imgUrl: filePath})
  211. // this.updateInfor({
  212. // imageKey: filePath
  213. // }, 1)
  214. })
  215. },
  216. /**
  217. * input
  218. */
  219. inputCtl: function (e) {
  220. const mobileExp = /^1[0-9]{10}$/;
  221. const { temp = {}, type } = e.currentTarget.dataset
  222. const { value } = e.detail
  223. temp[type] = value;
  224. const { parentName, family,phone,childName } = temp;
  225. console.log(parentName)
  226. if (type == 'phone') {
  227. if (value != '') {
  228. if (!mobileExp.test(value)) {
  229. wx.showToast({
  230. title: '手机号码位数不对',
  231. icon: 'none',
  232. duration: 2000
  233. })
  234. return this.setData({ phone})
  235. } else {
  236. return this.setData({ phone })
  237. }
  238. }
  239. } else if (type == 'childName') {
  240. // if (value != '') {
  241. return this.setData({ childName })
  242. // }
  243. } else if (type == 'parentName') {
  244. // if (value != '') {
  245. return this.setData({ parentName })
  246. // }
  247. } else if (type == 'family') {
  248. if (value != '') {
  249. return this.setData({ family })
  250. }
  251. }
  252. // if (this.data[type] != value) {
  253. // this.updateInfor({ [type]: e.detail.value })
  254. // }
  255. },
  256. /**
  257. * picker
  258. */
  259. pickerCtl: function (e) {
  260. const { temp = {}, type, index } = e.currentTarget.dataset
  261. this.setData({
  262. pickerIndex: index,
  263. isShowPickerModel: true
  264. })
  265. },
  266. /**
  267. * picker选择列
  268. */
  269. checkPickerModel: function (e) {
  270. const { index } = e.currentTarget.dataset
  271. let { temp = {}, pickerIndex, pickerData } = this.data
  272. let { actIndex, list } = pickerData[pickerIndex]
  273. let str = `pickerData[${pickerIndex}].actIndex`;
  274. console.log(index, pickerIndex)
  275. // if (index < 0) {
  276. if (pickerIndex == 0) {
  277. if (this.data['grade'] != list[actIndex]) {
  278. temp['grade'] = list[index]
  279. // this.setData({ grade: list[actIndex] })
  280. }
  281. } else if (pickerIndex == 1) {
  282. if (this.data['courseName'] != list[actIndex]) {
  283. temp['courseName'] = list[index]
  284. // this.setData({ courseName: list[actIndex]})
  285. }
  286. } else if (pickerIndex == 2) {
  287. // if (this.data['sex'] != actIndex + 1) {
  288. temp['sex'] = index + 1
  289. console.log(list[index])
  290. // this.setData({ sex: actIndex + 1 })
  291. // }
  292. } else if (pickerIndex == 3) {
  293. if (this.data['studyPlan'] != list[actIndex]) {
  294. temp['studyPlan'] = list[index]
  295. // this.setData({ studyPlan: list[actIndex] })
  296. }
  297. } else if (pickerIndex == 4) {
  298. if (this.data['parentRole'] != list[actIndex]) {
  299. temp['parentRole'] = list[index]
  300. // this.setData({ parentRole: list[actIndex] })
  301. }
  302. }
  303. // }else {
  304. // temp[str] = index
  305. // }
  306. temp['isShowPickerModel'] = false
  307. this.setData(temp)
  308. },
  309. // 更新孩子列表缓存
  310. updateChild:function(){
  311. const postData = { fn: this.updateChild, param: { ...arguments } }
  312. app.post('/api/parents/parents/V2/getMyInfo', {}, 0, postData).then(res => {
  313. const { childList, imgUrl, userId, userName } = res.data;
  314. if (childList.length > 0) {
  315. wx.setStorageSync(`parentVipList-${userId}`, childList)
  316. }
  317. })
  318. },
  319. /**
  320. * 添加孩子
  321. */
  322. addChildren:function(){
  323. const postData = { fn: this.addChildren, param: { ...arguments } }
  324. var _that = this;
  325. const { imgUrl, childName, sex, parentName, phone, grade, school, type, parentRole, bookList, libId} = this.data;
  326. // console.log(imgUrl, childName, sex, parentName, phone, grade, school, type, bookList, libId);
  327. if (!childName) {
  328. wx.showToast({
  329. title: '请输入孩子姓名',
  330. icon: 'none'
  331. })
  332. return
  333. }
  334. if (!parentName) {
  335. wx.showToast({
  336. title: '请输入家长姓名',
  337. icon: 'none'
  338. })
  339. return
  340. }
  341. if (!grade) {
  342. wx.showToast({
  343. title: '请输入年级',
  344. icon: 'none'
  345. })
  346. return
  347. }
  348. if (!school) {
  349. wx.showToast({
  350. title: '请输入在读学校',
  351. icon: 'none'
  352. })
  353. return
  354. }
  355. if (!parentRole) {
  356. wx.showToast({
  357. title: '请输入家长角色',
  358. icon: 'none'
  359. })
  360. return
  361. }
  362. app.post('/api/parents/parents/V2/addChildV1', {
  363. imgUrl,
  364. childName:formatEncrypt(childName),
  365. sex,
  366. parentName:formatEncrypt(parentName),
  367. phone:formatEncrypt(phone),
  368. grade,
  369. school,
  370. type,
  371. parentRole,
  372. bookList,
  373. libId
  374. }, 0, postData).then(res => {
  375. _that.updateChild()
  376. wx.showToast({
  377. title: '添加成功',
  378. icon: 'none',
  379. duration: 1000
  380. })
  381. wx.removeStorageSync('list')
  382. setTimeout((function callback() {
  383. wx.navigateBack({
  384. delta: 3
  385. })
  386. }).bind(this), 500);
  387. })
  388. },
  389. /**
  390. * 保存
  391. */
  392. saveInfo: function () {
  393. const postData = { fn: this.saveInfo, param: { ...arguments } }
  394. const { vipId } = this.data;
  395. var _that=this;
  396. const { imgUrl, childName, sex, parentName, phone, courseName, grade, school, family, studyPlan, parentRole,bookList} = this.data;
  397. // console.log(childName, sex, parentName, phone, courseName, grade, school, family, studyPlan, parentRole, bookList);
  398. if (!childName) {
  399. wx.showToast({
  400. title: '请输入孩子姓名',
  401. icon: 'none'
  402. })
  403. return
  404. }
  405. if (!parentName) {
  406. wx.showToast({
  407. title: '请输入家长姓名',
  408. icon: 'none'
  409. })
  410. return
  411. }
  412. if (!grade) {
  413. wx.showToast({
  414. title: '请输入年级',
  415. icon: 'none'
  416. })
  417. return
  418. }
  419. if (!school) {
  420. wx.showToast({
  421. title: '请输入在读学校',
  422. icon: 'none'
  423. })
  424. return
  425. }
  426. if (!parentRole) {
  427. wx.showToast({
  428. title: '请输入家长角色',
  429. icon: 'none'
  430. })
  431. return
  432. }
  433. // if (!mobileExp.test(phone)) {
  434. // wx.showToast({
  435. // title: '手机号码位数不对',
  436. // icon: 'none'
  437. // })
  438. // return
  439. // }
  440. app.post('/api/parents/parents/V2/upMyChildInfoV1', {
  441. vipId,
  442. imgUrl,
  443. childName:formatEncrypt(childName),
  444. sex,
  445. parentName:formatEncrypt(parentName),
  446. phone:formatEncrypt(phone),
  447. courseName,
  448. grade,
  449. school,
  450. studyPlan,
  451. parentRole,
  452. bookList
  453. }, 0, postData).then(res => {
  454. _that.updateChild()
  455. wx.showToast({
  456. title: '保存成功',
  457. icon:'none',
  458. duration:1000
  459. })
  460. setTimeout((function callback() {
  461. wx.navigateBack({
  462. delta: 2
  463. })
  464. }).bind(this), 500);
  465. })
  466. }
  467. })