single.js 7.6 KB

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