kids_information.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. // pages/kids_information/kids_information.js
  2. import { routers, viewImage, sharePage, isFn, getGlobalVal, formatDateTime, formateNumber,curatorName,formatEncrypt } from '../../utils/util.js'
  3. import { AddChild,AddChildV1} from '../../utils/api.js'
  4. const { navigateTo, redirectTo, navigateBack } = routers()
  5. const { globalData, saveUserInfo, getWxloginCode, checkStatus } = getApp()
  6. const { baseImgUrl, thumbnail } = globalData
  7. const app = getApp()
  8. Page({
  9. /**
  10. * 页面的初始数据
  11. */
  12. data: {
  13. options: {},
  14. baseImgUrl,
  15. isShowPickerModel: false,
  16. phone:'',
  17. patriarchName:'',
  18. homeAddress:'',
  19. studyPlanName:'',
  20. isAddChild:0,
  21. studentImg:'',
  22. isAdd:false,
  23. imgUrl:'',
  24. school: '',
  25. childName: '',
  26. parentName: '',
  27. sex: 0,
  28. grade: '',
  29. parentRole:'',
  30. pickerData: [
  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. actIndex: 0,
  49. list: ['爸爸', '妈妈', '爷爷','奶奶','外公','外婆','其他']
  50. }
  51. ],
  52. pickerIndex: null
  53. },
  54. /**
  55. * 生命周期函数--监听页面加载
  56. */
  57. onLoad: function (options) {
  58. this.setData(options)
  59. console.log(options)
  60. },
  61. /**
  62. * 生命周期函数--监听页面初次渲染完成
  63. */
  64. onReady: function () {
  65. const obj = { navigateTo, redirectTo, navigateBack, viewImage }
  66. for (const i in obj) {
  67. this[i] = obj[i]
  68. }
  69. },
  70. /**
  71. * 生命周期函数--监听页面显示
  72. */
  73. onShow: function () {
  74. var list = wx.getStorageSync('list');
  75. var bookList = [];
  76. for (var i in list) {
  77. bookList = bookList.concat(list[i].bookList)
  78. }
  79. console.log(bookList)
  80. // var bookList = [];
  81. // for (var i in arr) {
  82. // bookList.push({ bookId: arr[i].bookId, subject: arr[i].subject, bookName: arr[i].bookName, })
  83. // }
  84. // if (bookList.length>0){
  85. // this.setData({ isAdd:true });
  86. // }else{
  87. // this.setData({ isAdd: false });
  88. // }
  89. this.setData({ bookList });
  90. },
  91. /**
  92. * 生命周期函数--监听页面隐藏
  93. */
  94. onHide: function () {
  95. },
  96. /**
  97. * 生命周期函数--监听页面卸载
  98. */
  99. onUnload: function () {
  100. },
  101. /**
  102. * 页面相关事件处理函数--监听用户下拉动作
  103. */
  104. onPullDownRefresh: function () {
  105. },
  106. /**
  107. * 页面上拉触底事件的处理函数
  108. */
  109. onReachBottom: function () {
  110. },
  111. /**
  112. * 用户点击右上角分享
  113. */
  114. onShareAppMessage: function () {
  115. },
  116. /**
  117. * 路由跳转
  118. */
  119. redirectCtl: app.redirectCtl,
  120. /**
  121. * 路由跳转
  122. */
  123. navigateCtl: app.navigateCtl,
  124. /**
  125. * 添加教辅
  126. */
  127. addTeaching:function(){
  128. const { vipId, grade, isAddChild, isAdd}=this.data;
  129. const { imgUrl, childName, sex, parentName, phone, courseName,school, family, studyPlan, parentRole} = this.data;
  130. var obj = {vipId,imgUrl,childName,sex,parentName,phone,courseName,grade,school,family,studyPlan,parentRole};
  131. var that=this;
  132. if (isAddChild!=1){
  133. if (grade) {
  134. that.navigateCtl({ url: 'teaching', method: { vipId, grade, isAddChild, obj: JSON.stringify(obj) } }, true)
  135. } else {
  136. wx.showToast({
  137. title: '请先选择年级',
  138. icon: 'none'
  139. })
  140. }
  141. }else{
  142. if (grade) {
  143. that.navigateCtl({ url: 'teaching', method: { grade, isAddChild, isAdd} }, true)
  144. } else {
  145. wx.showToast({
  146. title: '请先选择年级',
  147. icon: 'none'
  148. })
  149. }
  150. }
  151. },
  152. /**
  153. * 上传头像
  154. */
  155. uploadHeadIconCtl: function () {
  156. wx.chooseImage({
  157. count: 1,
  158. success: res => {
  159. this.uploadImage(res.tempFilePaths[0])
  160. },
  161. fail: res => {
  162. // wx.showToast({
  163. // title: '选择拍照或者相册失败',
  164. // icon: 'none'
  165. // })
  166. }
  167. })
  168. },
  169. /**
  170. * 上传头像接口
  171. */
  172. uploadImage: function (file) {
  173. app.uploadFile('/api/common/common/uploadForm', file, {}).then(res => {
  174. let { filePath } = JSON.parse(res).data.pics[0];
  175. console.log(filePath);
  176. this.setData({ imgUrl: filePath})
  177. // this.updateInfor({
  178. // imageKey: filePath
  179. // }, 1)
  180. })
  181. },
  182. /**
  183. * input
  184. */
  185. inputCtl: function (e) {
  186. const mobileExp = /^1[0-9]{10}$/;
  187. const { temp = {}, type } = e.currentTarget.dataset
  188. const { value } = e.detail
  189. temp[type] = value;
  190. const { parentName, family,phone,childName } = temp;
  191. // console.log(parentName)
  192. if (type == 'phone') {
  193. if (value != '') {
  194. if (!mobileExp.test(value)) {
  195. wx.showToast({
  196. title: '手机号码位数不对',
  197. icon: 'none',
  198. duration: 2000
  199. })
  200. return this.setData({ phone})
  201. } else {
  202. return this.setData({ phone })
  203. }
  204. }
  205. } else if (type == 'childName') {
  206. // if (value != '') {
  207. return this.setData({ childName })
  208. // }
  209. } else if (type == 'parentName') {
  210. // if (value != '') {
  211. return this.setData({ parentName })
  212. // }
  213. } else if (type == 'family') {
  214. if (value != '') {
  215. return this.setData({ family })
  216. }
  217. }
  218. },
  219. /**
  220. * picker
  221. */
  222. pickerCtl: function (e) {
  223. const { temp = {}, type, index } = e.currentTarget.dataset
  224. this.setData({
  225. pickerIndex: index,
  226. isShowPickerModel: true
  227. })
  228. },
  229. /**
  230. * 取消
  231. */
  232. cancel:function(){
  233. wx.navigateBack({})
  234. },
  235. /**
  236. * picker选择列
  237. */
  238. checkPickerModel: function (e) {
  239. const { index } = e.currentTarget.dataset
  240. let { temp = {}, pickerIndex, pickerData } = this.data
  241. let { actIndex, list } = pickerData[pickerIndex]
  242. let str = `pickerData[${pickerIndex}].actIndex`;
  243. console.log(index, pickerIndex)
  244. // if (index < 0) {
  245. if (pickerIndex == 0) {
  246. if (this.data['grade'] != list[actIndex]) {
  247. temp['grade'] = list[index]
  248. // this.setData({ grade: list[actIndex] })
  249. }
  250. } else if (pickerIndex == 1) {
  251. if (this.data['courseName'] != list[actIndex]) {
  252. temp['courseName'] = list[index]
  253. // this.setData({ courseName: list[actIndex]})
  254. }
  255. } else if (pickerIndex == 2) {
  256. // if (this.data['sex'] != actIndex + 1) {
  257. temp['sex'] = Number(index) + 1
  258. // console.log(String(index) )
  259. // this.setData({ sex: actIndex + 1 })
  260. // }
  261. } else if (pickerIndex == 3) {
  262. if (this.data['studyPlan'] != list[actIndex]) {
  263. temp['studyPlan'] = list[index]
  264. // this.setData({ studyPlan: list[actIndex] })
  265. }
  266. } else if (pickerIndex == 4) {
  267. if (this.data['parentRole'] != list[actIndex]) {
  268. temp['parentRole'] = list[index]
  269. // this.setData({ parentRole: list[actIndex] })
  270. }
  271. }
  272. // }else {
  273. // temp[str] = index
  274. // }
  275. temp['isShowPickerModel'] = false
  276. this.setData(temp)
  277. },
  278. /**
  279. * 添加孩子
  280. */
  281. addChildren:function(cb){
  282. const continuousFn = { fn: this.addChildren, param: { ...arguments } }
  283. var that = this;
  284. const { childName, parentName, phone, grade, school, parentRole, imgUrl, sex, bookList, classId='',className} = this.data;
  285. // console.log(childName, parentName, phone, grade, school, parentRole, imgUrl, sex, bookList, classId);
  286. if (!childName) {
  287. wx.showToast({
  288. title: '请输入学生姓名',
  289. icon: 'none'
  290. })
  291. return
  292. }
  293. if (!parentName) {
  294. wx.showToast({
  295. title: '请输入家长姓名',
  296. icon: 'none'
  297. })
  298. return
  299. }
  300. if (!phone) {
  301. wx.showToast({
  302. title: '请输入手机号',
  303. icon: 'none'
  304. })
  305. return
  306. }
  307. if (!grade) {
  308. wx.showToast({
  309. title: '请输入年级',
  310. icon: 'none'
  311. })
  312. return
  313. }
  314. if (!school) {
  315. wx.showToast({
  316. title: '请输入在读学校',
  317. icon: 'none'
  318. })
  319. return
  320. }
  321. if (!parentRole) {
  322. wx.showToast({
  323. title: '请输入家长角色',
  324. icon: 'none'
  325. })
  326. return
  327. }
  328. AddChildV1({ data: {
  329. childName:formatEncrypt(childName),
  330. parentName:formatEncrypt(parentName),
  331. phone:formatEncrypt(phone),
  332. grade,
  333. school:formatEncrypt(school),
  334. parentRole,
  335. imgUrl,
  336. sex:Number(sex),
  337. bookList,
  338. classId
  339. }, continuousFn }).then(res => {
  340. wx.showToast({
  341. title: '添加成功',
  342. duration: 1000
  343. })
  344. wx.removeStorageSync('list')
  345. setTimeout((function callback() {
  346. wx.navigateBack({
  347. delta: 2
  348. })
  349. }).bind(this), 1000);
  350. if (isFn(cb)) cb()
  351. }).catch(res => {
  352. if (isFn(cb)) cb()
  353. })
  354. },
  355. })