wechat_addchild.js 11 KB

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