add_parent.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. // pages/add_parent/add_parent.js
  2. const app = getApp();
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. baseImgUrl: app.globalData.baseImgUrl,
  9. isAddParents:false,
  10. role:'',
  11. isRole:false,
  12. hiddenModel: false,
  13. roleList: [],
  14. parentList:[
  15. {
  16. str:'爸爸',
  17. status:''
  18. },
  19. {
  20. str: '妈妈',
  21. status: ''
  22. },
  23. {
  24. str: '爷爷',
  25. status: ''
  26. },
  27. {
  28. str: '奶奶',
  29. status: ''
  30. },
  31. {
  32. str: '外公',
  33. status: ''
  34. },
  35. {
  36. str: '外婆',
  37. status: ''
  38. },
  39. {
  40. str: '其他',
  41. status: ''
  42. },
  43. ]
  44. },
  45. /**
  46. * 生命周期函数--监听页面加载
  47. */
  48. onLoad: function (options) {
  49. this.setData(options)
  50. },
  51. /**
  52. * 生命周期函数--监听页面初次渲染完成
  53. */
  54. onReady: function () {
  55. },
  56. /**
  57. * 生命周期函数--监听页面显示
  58. */
  59. onShow: function () {
  60. this.getParents();
  61. },
  62. /**
  63. * 生命周期函数--监听页面隐藏
  64. */
  65. onHide: function () {
  66. },
  67. /**
  68. * 生命周期函数--监听页面卸载
  69. */
  70. onUnload: function () {
  71. },
  72. /**
  73. * 页面相关事件处理函数--监听用户下拉动作
  74. */
  75. onPullDownRefresh: function () {
  76. },
  77. /**
  78. * 页面上拉触底事件的处理函数
  79. */
  80. onReachBottom: function () {
  81. },
  82. /**
  83. * 用户点击右上角分享
  84. */
  85. onShareAppMessage: function () {
  86. },
  87. /**
  88. * 家长列表
  89. */
  90. getParents:function(){
  91. const { vipId } = this.data;
  92. const postData = { fn: this.getParents, param: { ...arguments } }
  93. app.post('/api/parents/parents/V2/parentsRoleList', { vipId}, 0, postData).then(res => {
  94. const { roleList } = res.data;
  95. this.setData({ roleList})
  96. })
  97. },
  98. /**
  99. * 展示角色
  100. */
  101. clickShow:function(){
  102. const { isRole}=this.data;
  103. this.setData({ isRole:!isRole})
  104. },
  105. /**
  106. * 选择角色
  107. */
  108. selectRole:function(e){
  109. const { parentList, role, isRole}=this.data;
  110. const {idx,str}=e.currentTarget.dataset;
  111. // const {role } = e.currentTarget.dataset
  112. console.log(e)
  113. var temp={};
  114. for (var i in parentList) {
  115. temp[`parentList[${i}].status`] = '';
  116. }
  117. temp[`parentList[${idx}].status`] = parentList[idx].status == '' ?'active':'';
  118. this.setData(temp)
  119. this.setData({ role: str,isRole:!isRole})
  120. },
  121. /**
  122. * 跳转添加家长
  123. */
  124. skipParents:function(){
  125. const { isAddParents}=this.data;
  126. this.setData({ isAddParents: !isAddParents})
  127. },
  128. /**
  129. * 提示框隐藏
  130. */
  131. allShowModel: function () {
  132. this.setData({ hiddenModel: false })
  133. },
  134. showModel:function(e){
  135. const { id } = e.currentTarget.dataset
  136. this.setData({ hiddenModel: true, roleUserId:id})
  137. },
  138. /**
  139. * 解绑家长
  140. */
  141. checkCtl:function(){
  142. const { roleUserId, vipId}=this.data;
  143. var that=this;
  144. const postData = { fn: this.getParents, param: { ...arguments } }
  145. app.post('/api/parents/parents/V2/untieParentsRole', { roleUserId, vipId }, 0, postData).then(res => {
  146. that.setData({ hiddenModel: false })
  147. that.getParents();
  148. wx.showToast({
  149. title: '解绑成功',
  150. icon: 'none',
  151. duration: 1000
  152. })
  153. })
  154. },
  155. /**
  156. * input
  157. */
  158. inputCtl: function (e) {
  159. const mobileExp = /^1[0-9]{10}$/;
  160. const { temp = {}, type } = e.currentTarget.dataset
  161. const { value } = e.detail
  162. temp[type] = value;
  163. const { phone, parents } = temp;
  164. if (type == 'phone') {
  165. this.setData({ phone })
  166. } else if (type == 'parents') {
  167. return this.setData({ parents })
  168. }
  169. },
  170. /**
  171. * 添加家长
  172. */
  173. saveParents:function(){
  174. const mobileExp = /^1[0-9]{10}$/;
  175. const postData = { fn: this.saveParents, param: { ...arguments } }
  176. var _that = this;
  177. const { phone, parents, role, vipId, isAddParents} = this.data;
  178. console.log(phone, parents, role, vipId);
  179. if (!phone) {
  180. wx.showToast({
  181. title: '手机号码不能为空',
  182. icon: 'none'
  183. })
  184. return
  185. } else if (!mobileExp.test(phone)) {
  186. wx.showToast({
  187. title: '手机号码位数不对',
  188. icon: 'none',
  189. duration: 1000
  190. })
  191. return
  192. }
  193. if (!role) {
  194. wx.showToast({
  195. title: '请选择家长角色',
  196. icon: 'none'
  197. })
  198. return
  199. }
  200. if (!parents) {
  201. wx.showToast({
  202. title: '请输入家长姓名',
  203. icon: 'none'
  204. })
  205. return
  206. }
  207. app.post('/api/parents/parents/V2/addParentsRole', {
  208. vipId,
  209. phone,
  210. roleName:role,
  211. name: parents
  212. }, 0, postData).then(res => {
  213. wx.showToast({
  214. title: '添加成功',
  215. icon: 'none',
  216. duration: 1000
  217. })
  218. _that.setData({ isAddParents: !isAddParents });
  219. _that.getParents();
  220. // setTimeout((function callback() {
  221. // wx.navigateBack({});
  222. // }).bind(this), 2000);
  223. })
  224. }
  225. })