guardianInfo.js 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. const app = getApp();
  2. const request = require('../../utils/request.js');
  3. const tools = require('../../utils/tools.js');
  4. import Toast from '../../miniprogram_npm/@vant/weapp/toast/toast';
  5. Page({
  6. data: {
  7. arr: [{
  8. name: '',
  9. phone: '',
  10. userid: '',
  11. password: ''
  12. }],
  13. flag: false,
  14. readonly: false
  15. },
  16. onNameChange(e) {
  17. console.log(e)
  18. this.setData({
  19. ['arr[' + e.target.dataset.index + '].name']: e.detail
  20. })
  21. },
  22. ontelChange(e) {
  23. this.setData({
  24. ['arr[' + e.target.dataset.index + '].phone']: e.detail
  25. })
  26. },
  27. onUseridChange(e) {
  28. this.setData({
  29. ['arr[' + e.target.dataset.index + '].userid']: e.detail
  30. })
  31. },
  32. onPasswordChange(e) {
  33. this.setData({
  34. ['arr[' + e.target.dataset.index + '].password']: e.detail
  35. })
  36. },
  37. add() {
  38. if (this.data.arr.length > 2) {
  39. wx.showToast({
  40. title: '最多3个哦',
  41. duration: 2000, //显示时长
  42. mask: true, //是否显示透明蒙层,防止触摸穿透,默认:false
  43. // icon:'warn', //图标,支持"success"、"loading"
  44. })
  45. return;
  46. }
  47. let arr = this.data.arr;
  48. arr.push({
  49. name: '',
  50. phone: '',
  51. userid: '',
  52. password: ''
  53. });
  54. this.setData({
  55. arr
  56. })
  57. },
  58. async getGuardianInfo() {
  59. let options = {
  60. url: 'resource/miniapp/user/getJhrList',
  61. data: {
  62. openId: wx.getStorageSync('openid'),
  63. type: app.globalData.type
  64. },
  65. method: 'post'
  66. }
  67. let res = await request.query(options);
  68. if (res.data.code == 200) {
  69. this.setData({
  70. arr: res.data.data.length > 0 ? res.data.data : [{
  71. name: '',
  72. phone: '',
  73. userid: '',
  74. password: ''
  75. }]
  76. })
  77. } else {
  78. Toast.fail(res.data.msg);
  79. }
  80. },
  81. async save(e) {
  82. if (e.target.dataset.item.name || e.target.dataset.item.phone || e.target.dataset.item.userid || e.target.dataset.item.password) {
  83. let jhrList = [];
  84. jhrList.push(e.target.dataset.item)
  85. let url = (e.target.dataset.item.id && this.data.arr[0].id) ? 'resource/miniapp/user/updateJhrInfo' : 'resource/miniapp/user/addJhrInfo';
  86. let editObj = {
  87. jhrList
  88. };
  89. let addObj = {
  90. jhrList,
  91. openId: wx.getStorageSync('openid'),
  92. type: app.globalData.type
  93. };
  94. console.log(e.target.dataset.item.id);
  95. console.log(this.data.arr[0].id);
  96. console.log((e.target.dataset.item.id || this.data.arr[0].id))
  97. let data = (e.target.dataset.item.id && this.data.arr[0].id) ? editObj : addObj;
  98. let options = {
  99. url,
  100. data,
  101. method: 'post'
  102. }
  103. let res = await request.query2(options);
  104. if (res.data.code === 200) {
  105. wx.showModal({
  106. title: '提示',
  107. content: '保存成功',
  108. showCancel: false,
  109. success: (res) => {
  110. if (res.confirm) {
  111. this.getGuardianInfo();
  112. }
  113. }
  114. })
  115. } else {
  116. Toast.fail(res.data.msg);
  117. }
  118. } else {
  119. Toast.fail('请至少填写一项信息');
  120. }
  121. },
  122. async delete(e) {
  123. if (!e.target.dataset.item.id) {
  124. this.data.arr.splice(e.target.dataset.index, 1);
  125. this.setData({
  126. arr: this.data.arr.length === 0 ? [{
  127. name: '',
  128. phone: '',
  129. userid: '',
  130. password: ''
  131. }] : this.data.arr
  132. })
  133. return false;
  134. }
  135. let options = {
  136. url: 'resource/miniapp/user/deleteJhrInfo',
  137. data: {
  138. jhrId: e.target.dataset.item.id
  139. },
  140. method: 'post'
  141. }
  142. let res = await request.query(options);
  143. if (res.data.code === 200) {
  144. wx.showModal({
  145. title: '提示',
  146. content: '删除成功',
  147. showCancel: false,
  148. success: (res) => {
  149. if (res.confirm) {
  150. this.getGuardianInfo();
  151. }
  152. }
  153. })
  154. } else {
  155. Toast.fail(res.data.msg);
  156. }
  157. },
  158. onShow: function () {
  159. if (!wx.getStorageSync('userId')) {
  160. wx.showModal({
  161. title: '提示',
  162. content: '请扫描二维码进入小程序',
  163. showCancel: false,
  164. success: (res) => {
  165. if (res.confirm) {
  166. wx.navigateTo({
  167. url: '/pages/login/login',
  168. })
  169. }
  170. }
  171. })
  172. return false;
  173. }
  174. tools.isLogin().then((res) => {
  175. this.getGuardianInfo();
  176. this.setData({
  177. readonly: app.globalData.type === 'jhdx' ? false : true
  178. })
  179. }, (error) => {
  180. console.log(error);
  181. })
  182. }
  183. })