person.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. const util = require("../../../utils/util.js");
  2. const app = getApp();
  3. Page({
  4. data:{
  5. info:[],
  6. birthday: "2010-01-01",
  7. sex: 1,
  8. cardTypeStr: "",
  9. cardType: "",
  10. },
  11. onLoad:function(options){
  12. options.cardtype = options.cardtype || 0;
  13. this.setData({ info: options, sex: options.sex || 1, birthday: options.birthday || "2010-01-01", cardTypeStr: util.cardType(options.cardtype), cardType: options.cardtype,});
  14. this.setTitle();
  15. },
  16. setTitle: function () {
  17. wx.setNavigationBarTitle({
  18. title: (this.data.info.act == "add" ? "新增" : this.data.info.act == "edit" ? "修改" : "") + "监护人信息"
  19. });
  20. },
  21. selectCard: function () {
  22. var self = this;
  23. wx.showActionSheet({
  24. itemList: util.config.cardTypeArr,
  25. success: function (res) {
  26. self.setData({ cardType: res.tapIndex, cardTypeStr: util.cardType(res.tapIndex) });
  27. }
  28. })
  29. },
  30. changeSex(e) {
  31. this.setData({ sex: e.detail.value });
  32. },
  33. del: function (e) {
  34. var self = this;
  35. wx.showModal({
  36. title: '温馨提示',
  37. content: '您确定不需要该监护人信息了吗?',
  38. success: function (res) {
  39. if (res.confirm) {
  40. util.ajax({
  41. func: "user/delete_idcardinfo",
  42. data: { id: self.data.info.id }
  43. }, function (data) {
  44. util.showTips(data.code == 0 ? '身份信息删除成功。' : data.reason);
  45. wx.setStorageSync("isDel", true);
  46. wx.navigateBack();
  47. });
  48. }
  49. }
  50. });
  51. },
  52. bindDateChange: function (e) {
  53. this.setData({
  54. birthday: e.detail.value
  55. })
  56. },
  57. formSubmit: function (e) {
  58. var data = e.detail.value;
  59. if (util.isEmpty(data.name)) {
  60. util.showTips('请填写您的姓名。');
  61. return false;
  62. }
  63. if (util.isEmpty(data.cardType)) {
  64. util.showTips('请选择证件的类型。');
  65. return false;
  66. }
  67. if (!util.identityCodeValid(data.cardType, data.idcard)) {
  68. util.showTips('请填写正确的' + util.cardType(data.cardType) + '。');
  69. return false;
  70. }
  71. if (util.getAge(data.birthday) < 18) {
  72. util.showTips('监护人年龄必须在18周岁以上,请检查出生日期!');
  73. return false;
  74. }
  75. if (this.data.cardtype == '0' && !util.isEmpty(data['idcard']) && parseInt(data['idcard'].substr(16, 1)) % 2 != data['sex']) {
  76. util.showTips('选择的性别与身份证不符。');
  77. return false;
  78. }
  79. var nowYear = new Date().getFullYear();
  80. if (util.isEmpty(data['idcard']) && parseInt(nowYear - data['idcard'].substring(6, 10)) >= 18) {
  81. util.showTips('选择的身份类型与身份证不符。');
  82. return false;
  83. }
  84. data['position'] = "成人";
  85. var url = this.data.info.act == "add" ? "user/add_idcardinfo" : "user/update_idcardinfo";
  86. util.ajax({
  87. func: url,
  88. data: data
  89. }, function (res) {
  90. if (res.code == 0) {
  91. if (res.data){
  92. wx.setStorageSync("parentid",res.data);
  93. }
  94. wx.navigateBack();
  95. }else{
  96. util.showTips(res.reason);
  97. }
  98. });
  99. },
  100. cardBlur:function(e){
  101. let val = e.detail.value;
  102. if (this.data.cardType == '0' && util.identityCodeValid(0, val)) {
  103. var year = parseInt(val.substr(6, 4));
  104. var month = parseInt(val.substr(10, 2));
  105. var day = parseInt(val.substr(12, 2));
  106. if (month < 10) month = '0' + month;
  107. if (day < 10) day = '0' + day;
  108. var birthday = year + '-' + month + '-' + day;
  109. this.setData({ birthday, sex: util.getSex(val).toString() });
  110. }
  111. }
  112. })