addcard.js 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. const util = require("../../../utils/util.js");
  2. const app = getApp();
  3. Page({
  4. data: {
  5. info:{},
  6. parents:[],
  7. endDate:"2019-01-01",
  8. birthday: "2010-01-01",
  9. sex: 1,
  10. cardTypeStr:"",
  11. cardType:"",
  12. parentid:0,
  13. mask:false,
  14. parentBirthday:'',
  15. clothesCode:[110,120,130,140,150,160,165,170,175,180,185],
  16. shoesCode:[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45],
  17. clothesIndex:'',
  18. shoesIndex:'',
  19. showCodePopup:false,
  20. needclothessize:'1',
  21. needShoeSize:'1'
  22. },
  23. onLoad: function (options) {
  24. console.log(options)
  25. options.cardtype = options.cardtype || 0;
  26. options.bodyType = options.bodytype;
  27. this.setData({ info: util.urlDecode(options), sex: options.sex || 1, birthday: options.birthday || "2010-01-01", cardTypeStr: util.cardType(options.cardtype), cardType: options.cardtype, parentid: options.parentid || 0,needclothessize:options.needclothessize==undefined?1:(options.needclothessize || 0),needShoeSize:options.needshoesize==undefined?1:(options.needshoesize || 0)});
  28. if (options) {
  29. this.satisfy();
  30. if (options.clothessize) {
  31. this.data.clothesCode.forEach((el,i) => {
  32. if (el==options.clothessize) {
  33. this.setData({clothesIndex:i})
  34. }
  35. });
  36. }
  37. if (options.shoessize) {
  38. this.data.shoesCode.forEach((el,i) => {
  39. if (el==options.shoessize) {
  40. this.setData({shoesIndex:i})
  41. }
  42. });
  43. }
  44. }
  45. this.setTitle();
  46. },
  47. onShow:function(){
  48. var val = wx.getStorageSync("parentid"), isDel = wx.getStorageSync("isDel");
  49. if (!util.isEmpty(val)){
  50. isDel && val == this.data.parentid ? val = 0 : val;
  51. if (isDel){
  52. wx.removeStorageSync("isDel");
  53. }
  54. this.setData({ parentid: val});
  55. wx.removeStorageSync("parentid");
  56. }
  57. this.getGuardian(true);
  58. },
  59. addParent:function(e){
  60. wx.navigateTo({
  61. url: '/pages/account/cards/person?' + util.toParam(e.currentTarget.dataset)
  62. })
  63. },
  64. getGuardian:function(load){
  65. var self = this;
  66. util.ajax({
  67. func:"user/idcardinfo_list",
  68. data: {type: 1},
  69. load: load
  70. },function(res){
  71. if (res.code == 0 && res.data.length > 0){
  72. self.data.parents = util.defaultIdcard(res.data);
  73. self.setData({ parents: self.data.parents});
  74. }
  75. });
  76. },
  77. setTitle: function (){
  78. wx.setNavigationBarTitle({
  79. title: (this.data.info.act == "add" ? "新增" : this.data.info.act == "edit" ? "修改" : "") +"出行人信息"
  80. })
  81. },
  82. selectCard:function(){
  83. var self = this;
  84. wx.showActionSheet({
  85. itemList: util.config.cardTypeArr,
  86. success: function (res) {
  87. self.setData({ cardType: res.tapIndex, cardTypeStr: util.cardType(res.tapIndex)});
  88. }
  89. })
  90. },
  91. // 判断是否成年
  92. satisfy() {
  93. var nowDate = new Date(); // 当前时间
  94. var mouth = nowDate.getMonth() + 1;
  95. var day = nowDate.getDate();
  96. var year = nowDate.getFullYear() - 18;
  97. var oldDate = '';
  98. wx.getSystemInfo({
  99. success (res) {
  100. oldDate = res.platform=='ios'?new Date(year + '/' + mouth + '/' + day).getTime():new Date(year + '-' + mouth + '-' + day).getTime()
  101. }
  102. })
  103. // var oldDate = new Date(year + '-' + mouth + '-' + day).getTime();
  104. var newDate = new Date(this.data.birthday).getTime();
  105. // let ageType = oldDate < newDate ? true : false; // true 表示不满18
  106. if (oldDate < newDate) {
  107. this.setData({clothesCode:[110,120,130,140,150,160,165,170,175,180,185],shoesCode:[20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45]})
  108. } else {
  109. if (this.data.sex==1) {
  110. this.setData({clothesCode:[165,170,175,180,185],shoesCode:[39,40,41,42,43,44,45,46,47,48,49]})
  111. } else {
  112. this.setData({clothesCode:[155,160,165,170,175],shoesCode:[33,34,35,36,37,38,39,40,41]})
  113. }
  114. }
  115. },
  116. selectCode(e){
  117. let type= e.currentTarget.dataset.type,index=e.detail.value;
  118. switch (type) {
  119. case "clothes":
  120. this.setData({clothesIndex:index,})
  121. break;
  122. case "shoes":
  123. this.setData({shoesIndex:index})
  124. break;
  125. }
  126. },
  127. // 关闭弹窗
  128. close(){
  129. this.setData({showCodePopup:false})
  130. },
  131. // 打开尺码推荐弹窗
  132. CodeDetail(){
  133. this.setData({showCodePopup:true})
  134. },
  135. radioChange:function(e){
  136. this.setData({parentid: e.detail.value,parentBirthday:e.detail.birthdayStr});
  137. },
  138. bindDateChange:function(e){
  139. this.setData({
  140. birthday: e.detail.value,
  141. clothesIndex:'',
  142. shoesIndex:''
  143. })
  144. this.satisfy()
  145. },
  146. changeSex(e){
  147. this.setData({
  148. sex: e.detail.value,
  149. clothesIndex:'',
  150. shoesIndex:''
  151. });
  152. this.satisfy()
  153. },
  154. del() {
  155. var self = this;
  156. wx.showModal({
  157. title: '温馨提示',
  158. content: '您确定不需要该儿童信息了吗?',
  159. confirmColor: '#EE3A43',
  160. success: function (res) {
  161. if (res.confirm) {
  162. util.ajax({
  163. func: "user/delete_idcardinfo",
  164. data: { id: self.data.info.id }
  165. }, function (data) {
  166. if(data.code == 0){
  167. wx.setStorageSync('reload',true);
  168. wx.navigateBack();
  169. }else
  170. util.showTips(data.reason);
  171. });
  172. }
  173. }
  174. });
  175. },
  176. formSubmit:function(e){
  177. var data = e.detail.value,parents= {};
  178. if(util.isEmpty(data.name)) {
  179. util.showTips('请填写您的姓名。');
  180. return false;
  181. }
  182. if (util.isEmpty(data.cardType)) {
  183. util.showTips('请选择证件的类型。');
  184. return false;
  185. }
  186. if (!util.identityCodeValid(data.cardType, data.idcard)) {
  187. util.showTips('请填写正确的' + util.cardType(data.cardType) + '。');
  188. return false;
  189. }
  190. if (util.ages(data['birthday']) != "儿童" || (util.getAge(data.birthday) < 3 || util.getAge(data.birthday) > 17)) {
  191. util.showTips('请输入3-17周岁以内的儿童身份证信息。');
  192. return false;
  193. }
  194. if (this.data.cardtype == '0' && !util.isEmpty(data['idcard']) && parseInt(data['idcard'].substr(16, 1)) % 2 != data['sex']) {
  195. util.showTips('选择的性别与身份证不符。');
  196. return false;
  197. }
  198. var nowYear = new Date().getFullYear();
  199. if (util.isEmpty(data['idcard']) && parseInt(nowYear - data['idcard'].substring(6, 10)) >= 18) {
  200. util.showTips('选择的身份类型与身份证不符。');
  201. return false;
  202. }
  203. if (util.isEmpty(data['height']) || /[^0-9]/g.test(data['height'])) {
  204. util.showTips('请填写数字类型的身高。');
  205. return false;
  206. }
  207. if (util.isEmpty(data['weight']) || /[^0-9]/g.test(data['weight'])) {
  208. util.showTips('请填写数字类型的体重。');
  209. return false;
  210. }
  211. if (util.isEmpty(data['bodyType'])) {
  212. util.showTips('请选择儿童体型,以便活动服装选择。');
  213. return false;
  214. }
  215. if (util.isEmpty(data['pid'])) {
  216. util.showTips('请添加或选择一个监护人,以便生成电子旅游合同。');
  217. return false;
  218. }
  219. this.data.parents.forEach(item => {
  220. if(item.id == data['pid']) {
  221. parents.birthday = item.birthdayStr
  222. }
  223. })
  224. if(util.getAge(parents.birthday) < 18){
  225. util.showTips('请选择18周岁以上的监护人。');
  226. return false;
  227. }
  228. data['clothesSize']=this.data.clothesCode[this.data.clothesIndex] || '';
  229. data['shoesSize']=this.data.shoesCode[this.data.shoesIndex] || '';
  230. data['position'] = "儿童";
  231. var url = this.data.info.act == "add" ? "user/add_idcardinfo" : "user/update_idcardinfo";
  232. util.ajax({
  233. func: url,
  234. data:data
  235. },function(res){
  236. if(res.code == 0){
  237. wx.setStorageSync("reload",true);
  238. wx.navigateBack();
  239. } else {
  240. wx.showToast({
  241. title: res.reason,
  242. icon: "none"
  243. });
  244. }
  245. });
  246. },
  247. prompt:function(){
  248. this.setData({mask:true})
  249. },
  250. maskBtn:function(){
  251. this.setData({mask:false})
  252. },
  253. cardBlur:function(e){
  254. let val = e.detail.value;
  255. if (this.data.cardType == '0' && util.identityCodeValid(0, val) ){
  256. var year = parseInt(val.substr(6,4));
  257. var month = parseInt(val.substr(10,2));
  258. var day = parseInt(val.substr(12,2));
  259. if(month<10) month = '0'+month;
  260. if(day<10) day = '0'+day;
  261. var birthday = year + '-' + month + '-' + day;
  262. this.setData({ birthday, sex: util.getSex(val).toString() });
  263. this.satisfy()
  264. }
  265. }
  266. })