index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. const util = require("../../../utils/util.js");
  2. const app = getApp();
  3. Page({
  4. data: {
  5. makeTask:false,//是否为做任务
  6. taskId:'',
  7. list: [],
  8. isSelected: true,
  9. datas:{},
  10. ctype:0,
  11. msgType:0, //出行人信息/购买信息的默认显示项
  12. defaultType:0,//仅用于宝贝币任务的默认选中项
  13. showAddress:false,
  14. info:{
  15. contactPhone:'',
  16. mailAddress:'',
  17. email:'',
  18. street:''
  19. },
  20. accordWithAge:true
  21. },
  22. onLoad:function(options){
  23. console.log(options)
  24. if (!util.isObjEmpty(options)){
  25. this.setData({ datas: options, isSelected: (options.quantity ? false : true), ctype: options.sparent == 0 ? 1 : 0,msgType:options.defaultType,defaultType:options.defaultType,makeTask:options.makeTask,taskId:options.taskId });
  26. }
  27. let that = this;
  28. if (getCurrentPages().length == 1) {
  29. // var getLocation = util.promise();
  30. // getLocation.then(function (value) {
  31. if (that.data.msgType==1) {
  32. that.submit()
  33. } else {
  34. that.getList(true);
  35. }
  36. that.setData({ currentPages: getCurrentPages().length })
  37. // }, function (error) {
  38. // });
  39. } else {
  40. if (that.data.msgType==1) {
  41. that.submit()
  42. } else {
  43. that.getList(true);
  44. }
  45. }
  46. },
  47. onShow: function () {
  48. if (wx.getStorageSync("reload")){
  49. wx.removeStorageSync("reload");
  50. if (this.data.msgType==1) {
  51. this.submit()
  52. } else {
  53. this.getList(false);
  54. }
  55. }else{
  56. this.setData({ list: this.defaultIdcard(this.data.list) });
  57. }
  58. },
  59. onPullDownRefresh: function() {
  60. var self = this;
  61. wx.showNavigationBarLoading();
  62. setTimeout(function () {
  63. self.getList(false);
  64. wx.hideNavigationBarLoading();
  65. wx.stopPullDownRefresh();
  66. }, 1500);
  67. },
  68. getList: function (load) {
  69. var self = this;
  70. util.ajax({
  71. func: "user/idcardinfo_list",
  72. data: { type: this.data.ctype == 0 ? 0 : -1 },
  73. load: load
  74. }, function (res) {
  75. if(res.code == 0){
  76. if (res.data.length>0 && self.data.isSelected) {
  77. res.data.map((el,i) => {
  78. if (!util.isEmpty(el.name) && !util.isEmpty(el.idcard) && !util.isEmpty(el.height) && !util.isEmpty(el.weight) && el.bodyType !=null && !util.isEmpty(el.clothesSize) && !util.isEmpty(el.shoesSize)) {
  79. el.perfect=0
  80. } else {
  81. el.perfect=1
  82. }
  83. });
  84. if (self.data.makeTask&&self.data.defaultType==0&&self.data.ctype == 0) {
  85. util.finishCoinTask(self.data.taskId).then(res=>{
  86. util.showTips(res,3000);
  87. self.setData({makeTask:false})
  88. })
  89. }
  90. }
  91. if (res.data.length<=0 && !self.data.isSelected) {
  92. let obj = {currentTarget:{dataset:{act:'add',needclothessize:self.data.datas.needClothesSize,needshoesize:self.data.datas.needShoeSize}}}
  93. self.addCard(obj)
  94. }
  95. self.setData({ list: self.defaultIdcard(res.data) });
  96. }else{
  97. util.showTips(res.reason)
  98. }
  99. });
  100. },
  101. setTabbar(e){
  102. let index = e.currentTarget.dataset.index;
  103. this.setData({ msgType: index});
  104. if (index==1) {
  105. this.submit()
  106. }else{
  107. this.getList(true);
  108. }
  109. },
  110. // 儿童/亲子
  111. swtichTab(e){
  112. let index = e.currentTarget.dataset.index;
  113. this.data.ctype = index;
  114. this.setData({ ctype: this.data.ctype, list: [] });
  115. this.getList(true);
  116. },
  117. defaultIdcard: function (data) {
  118. if (typeof (data) == "undefined"){
  119. return "";
  120. }
  121. var idcards = wx.getStorageSync("idcards") || [], ids = "";
  122. for (var i in data) {
  123. data[i]['cardTypeStr'] = util.cardType(data[i]['cardType']);
  124. if (!util.isObjEmpty(data[i]['parent'])) {
  125. data[i]['parent']['cardTypeStr'] = util.cardType(data[i]['parent']['cardType']);
  126. }
  127. data[i]['default'] = false;
  128. if (!util.isObjEmpty(idcards) && !util.isObjEmpty(idcards.ids)){
  129. ids = idcards.ids.join(",");
  130. if (ids.indexOf(",") != -1) {
  131. if (ids.indexOf(data[i].id) != -1) {
  132. data[i]['default'] = true;
  133. }
  134. } else if(idcards.ids.length > 0) {
  135. if (data[i].id == ids) {
  136. data[i]['default'] = true;
  137. }
  138. }
  139. }
  140. }
  141. return data;
  142. },
  143. addCard: function (e) {
  144. if(this.data.ctype == 0){
  145. wx.navigateTo({
  146. url: "/pages/account/cards/addcard?" + util.toParam(e.currentTarget.dataset)
  147. });
  148. }else{
  149. wx.navigateTo({
  150. url: "/pages/account/cards/single?" + util.toParam(e.currentTarget.dataset)
  151. });
  152. }
  153. },
  154. checkboxChange:function(e){
  155. if (this.data.isSelected){
  156. return false;
  157. }
  158. var self = this, typeA = "", newArr = { ids: [], names: [], idCards: [], parentNames: [] }, arr = e.detail.value, count = arr.length, idcards = wx.getStorageSync("idcards") || [],tipArticle='';
  159. if (count > self.data.datas.quantity) {
  160. arr.pop();
  161. }
  162. let index = '';
  163. for (var i in arr) {
  164. var val = arr[i].split("|");
  165. newArr['ids'].push(val[0]);
  166. newArr['names'].push(val[1]);
  167. newArr['parentNames'].push(val[2]);
  168. newArr['idCards'].push(val[8]);
  169. if (this.data.ctype == 0 && util.isEmpty(val[2])){//监护人
  170. typeA = 1;
  171. }
  172. if (util.isEmpty(val[3]) || util.isEmpty(val[4]) || util.isEmpty(val[5])) {//体型身高
  173. typeA = 2;
  174. }
  175. if (this.data.ctype == 0 && val[6] == 1) {//内部评估
  176. typeA = 3;
  177. }
  178. if (self.data.datas.military!=1 && this.data.ctype == 0 && (util.ages(val[7]) != "儿童" || (util.getAge(val[7]) < self.data.datas.mage || util.getAge(val[7]) > self.data.datas.lage))){//单飞儿童年龄
  179. typeA = 4;
  180. }
  181. if (self.data.datas.military!=1 && this.data.ctype == 1 && util.ages(val[7]) == "儿童" && (util.getAge(val[7]) < self.data.datas.mage || util.getAge(val[7]) > self.data.datas.lage)) {//亲子儿童年龄
  182. typeA = 5;
  183. }
  184. if (this.data.ctype == 1 && util.ages(val[7]) == "成人" && (util.getAge(val[7]) < self.data.datas.adultMinAge || util.getAge(val[7]) > self.data.datas.adultMaxAge)) {//亲子成人年龄
  185. typeA = 6;
  186. }
  187. if (self.data.datas.needClothesSize==1 && util.isEmpty(val[10])) {
  188. typeA = 7;
  189. }
  190. if (self.data.datas.needShoeSize==1 && util.isEmpty(val[11])) {
  191. typeA = 8;
  192. }
  193. index = val[9];
  194. this.getChildAge(val[12]).then((res)=>{
  195. let arr=self.data.datas.ageLimit.split('-')
  196. if (self.data.datas.military==1 && (util.isEmpty(val[12]) || arr[0]>res.data || res.data>arr[1])) {
  197. typeA = 9;
  198. }
  199. },(res)=>{
  200. tipArticle=res.reason;
  201. typeA = 9;
  202. })
  203. if (self.data.datas.military==1 && (self.data.datas.campSex==1 ||self.data.datas.campSex==0) && self.data.datas.campSex != val[13]) {
  204. typeA = 10;
  205. }
  206. }
  207. let timer = setTimeout(() => {
  208. if (typeA == 1){
  209. wx.showModal({
  210. title: '提示',
  211. content: '请先编辑儿童的监护人,以便生成电子合同!',
  212. showCancel:false,
  213. confirmColor: '#ee3a43',
  214. confirmText:'确定'
  215. });
  216. self.setData({ list: self.defaultIdcard(self.data.list) });
  217. return false;
  218. }
  219. if (typeA == 2) {
  220. wx.showModal({
  221. title: '提示',
  222. content: '请补充数字类型的身高、体重和选择相对应的体型。',
  223. showCancel: false,
  224. confirmColor: '#ee3a43',
  225. confirmText:'确定'
  226. });
  227. self.setData({ list: self.defaultIdcard(self.data.list) });
  228. return false;
  229. }
  230. if (typeA == 3) {
  231. wx.showModal({
  232. title: '提示',
  233. content: '经过内部综合评估,目前我们的服务专业性暂时无法满足您的孩子正向成长的实际需求,对此我们深表遗憾。',
  234. showCancel: false,
  235. confirmColor: '#ee3a43',
  236. confirmText: '确定'
  237. });
  238. self.setData({ list: self.defaultIdcard(self.data.list) });
  239. return false;
  240. }
  241. if (typeA == 4) {
  242. wx.showModal({
  243. title: '提示',
  244. content: '本活动适合' + self.data.datas.mage + '-' + self.data.datas.lage + '岁的儿童报名,此儿童年龄不符,请检查。',
  245. showCancel: false,
  246. confirmColor: '#ee3a43',
  247. confirmText: '确定'
  248. });
  249. self.setData({ list: self.defaultIdcard(self.data.list) });
  250. return false;
  251. }
  252. if (typeA == 5) {
  253. wx.showModal({
  254. title: '提示',
  255. content: '本活动适合' + self.data.datas.mage + '-' + self.data.datas.lage + '岁的儿童报名,此儿童年龄不符,请检查。',
  256. showCancel: false,
  257. confirmColor: '#ee3a43',
  258. confirmText: '确定'
  259. });
  260. self.setData({ list: self.defaultIdcard(self.data.list) });
  261. return false;
  262. }
  263. if (typeA == 6) {
  264. wx.showModal({
  265. title: '提示',
  266. content: '本活动适合' + self.data.datas.adultMinAge + '-' + self.data.datas.adultMaxAge + '岁的成人报名,此成人年龄不符,请检查。',
  267. showCancel: false,
  268. confirmColor: '#ee3a43',
  269. confirmText: '确定'
  270. });
  271. self.setData({ list: self.defaultIdcard(self.data.list) });
  272. return false;
  273. }
  274. if (typeA == 7) {
  275. wx.showModal({
  276. title: '提示',
  277. content: '因活动需要,请补充该出行人衣服尺码',
  278. showCancel: false,
  279. confirmColor: '#ee3a43',
  280. confirmText: '确定'
  281. });
  282. self.setData({ list: self.defaultIdcard(self.data.list) });
  283. return false;
  284. }
  285. if (typeA == 8) {
  286. wx.showModal({
  287. title: '提示',
  288. content: '因活动需要,请补充该出行人鞋码',
  289. showCancel: false,
  290. confirmColor: '#ee3a43',
  291. confirmText: '确定'
  292. });
  293. self.setData({ list: self.defaultIdcard(self.data.list) });
  294. return false;
  295. }
  296. if (typeA == 9) {
  297. wx.showModal({
  298. title: '提示',
  299. content: tipArticle || '本活动适合' + self.data.datas.ageLimit + '岁的儿童报名,此儿童年龄不符,请检查。',
  300. showCancel: false,
  301. confirmColor: '#ee3a43',
  302. confirmText: '确定'
  303. });
  304. self.setData({ list: self.defaultIdcard(self.data.list) });
  305. return false;
  306. }
  307. if (typeA == 10){
  308. wx.showModal({
  309. title: '提示',
  310. content: `当前选择的排期只允许${self.data.datas.campSex==0?'女生':'男生'}报名`,
  311. showCancel:false,
  312. confirmColor: '#ee3a43',
  313. confirmText:'确定'
  314. });
  315. self.setData({ list: self.defaultIdcard(self.data.list) });
  316. return false;
  317. }
  318. let list = self.data.list;
  319. if(index && list[index].overdue == 1){ //overdue 3个月未修改 ——1是 0否(成人忽略)
  320. wx.showModal({
  321. title: '提示',
  322. content: '请再次确认儿童或成人的身高、体重、体型是否正确?后续将根据这个选择衣服尺码',
  323. cancelText:'编辑',
  324. cancelColor:'#ee3a43',
  325. confirmText:'确认正确',
  326. confirmColor:'#ee3a43',
  327. success: function(res) {
  328. if (res.confirm) {//确认正确
  329. wx.setStorageSync("idcards", newArr);
  330. if (count > self.data.datas.quantity){
  331. self.setData({ list: self.defaultIdcard(self.data.list) });
  332. wx.showModal({
  333. title: '提示',
  334. content: '您购买' + self.data.datas.quantity + '份,请选择' + self.data.datas.quantity +'名儿童或成人的身份信息!',
  335. cancelText:'关闭提示',
  336. confirmText:'继续返回',
  337. confirmColor:'#EE3A43',
  338. success: function (res) {
  339. if (res.confirm) {
  340. wx.navigateBack();
  341. }
  342. }
  343. });
  344. } else if (arr.length == self.data.datas.quantity){
  345. self.clearVids();
  346. wx.navigateBack();
  347. }
  348. }else if(res.cancel){//编辑
  349. let listdata = list[index];
  350. let dataset = {};
  351. dataset['act'] = "edit";
  352. dataset['birthday'] = listdata.birthdayStr;
  353. dataset['cardtype'] = listdata.cardType;
  354. dataset['height'] = listdata.height;
  355. dataset['id'] = listdata.id;
  356. dataset['idcard'] = listdata.idcard;
  357. dataset['name'] = listdata.name;
  358. if (this.data.ctype == 0) dataset['parentid'] = listdata.parent.id || '';
  359. dataset['sex'] = listdata.sex;
  360. dataset['weight'] = listdata.weight;
  361. wx.navigateTo({
  362. url: "/pages/account/cards/" + (this.data.ctype == 0? "addcard?":"single?") + util.toParam(dataset)
  363. });
  364. }
  365. }
  366. })
  367. }else{
  368. wx.setStorageSync("idcards", newArr);
  369. self.common(count,arr.length);
  370. }
  371. clearTimeout(timer);
  372. }, 200);
  373. console.log(arr,newArr)
  374. },
  375. // 获取儿童年龄
  376. getChildAge(id){
  377. let that=this;
  378. return new Promise(function (resolve, reject) {
  379. util.ajax({
  380. func: "v2/order/age",
  381. data: {
  382. sid:that.data.datas.sid,
  383. id:id
  384. },
  385. load:false
  386. }, function (res) {
  387. if (res.code==0) {
  388. resolve(res);
  389. } else {
  390. reject(res);
  391. }
  392. })
  393. })
  394. },
  395. clearVids:function(){
  396. let idcards = wx.getStorageSync("idcards") || [];
  397. if (idcards['ids'].length == 1){
  398. wx.removeStorageSync('vids');
  399. }
  400. },
  401. common:function(count,arrLength){
  402. var self = this;
  403. if (count > self.data.datas.quantity){
  404. self.setData({ list: self.defaultIdcard(self.data.list) });
  405. wx.showModal({
  406. title: '提示',
  407. content: '您购买' + self.data.datas.quantity + '份,请选择' + self.data.datas.quantity +'名儿童的身份信息!',
  408. cancelText:'关闭提示',
  409. confirmText:'继续返回',
  410. confirmColor:'#EE3A43',
  411. success: function (res) {
  412. if (res.confirm) {
  413. wx.navigateBack();
  414. }
  415. }
  416. });
  417. } else if (count == self.data.datas.quantity){
  418. self.clearVids();
  419. wx.navigateBack();
  420. }
  421. },
  422. // 提交购买信息
  423. submit(e){
  424. let that=this,info=this.data.info,type=e?true:false;
  425. if (!util.isEmpty(info.contactPhone) && util.isPhone(info.contactPhone)) {
  426. util.showTips('手机号格式不正确');
  427. return false;
  428. }
  429. var myreg = /^([a-zA-Z0-9]+[_|\_|\.|-]+)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-]+)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
  430. if (!util.isEmpty(info.email) && !myreg.test(info.email)) {
  431. util.showTips('电子邮箱格式不正确');
  432. return false;
  433. }
  434. info.mailAddress = info.mailAddress || '';
  435. info.street = info.street || '';
  436. util.ajax({
  437. func: "v2/user/buy/info",
  438. data: type?info:{},
  439. method:type?'post':'get'
  440. }, function (res) {
  441. if (res.code==0) {
  442. if (type) {
  443. if (!that.data.makeTask) {
  444. util.showTips(res.reason)
  445. }
  446. if (that.data.makeTask&&that.data.defaultType==1&&type) {
  447. let haveEmpty=true;
  448. for (const key in info) {
  449. if (Object.hasOwnProperty.call(info, key) && util.isEmpty(info[key])) {
  450. haveEmpty=false;
  451. }
  452. }
  453. if (haveEmpty) {
  454. util.finishCoinTask(that.data.taskId).then(res=>{
  455. util.showTips(res,3000);
  456. that.setData({makeTask:false})
  457. })
  458. }
  459. }
  460. } else {
  461. that.setData({info:res.data})
  462. }
  463. } else {
  464. util.showTips(res.reason)
  465. }
  466. })
  467. },
  468. // 获取购买信息
  469. getAddressInfo(){
  470. let that=this;
  471. util.ajax({
  472. func: "",
  473. }, function (res) {
  474. if (res.code==0) {
  475. that.setData({info:res.data})
  476. } else {
  477. util.showTips(res.reason)
  478. }
  479. })
  480. },
  481. chooseAddress(){
  482. this.setData({showAddress:true})
  483. },
  484. bindInfo(e){
  485. let type=e.currentTarget.dataset.type,value=e.detail.value;
  486. switch (type) {
  487. case "contactPhone":
  488. this.data.info.contactPhone=value;
  489. break;
  490. case "email":
  491. this.data.info.email=value;
  492. break;
  493. case "street":
  494. this.data.info.street=value;
  495. break;
  496. }
  497. this.setData({info:this.data.info})
  498. },
  499. // 邮寄地址
  500. submitAddress(e){
  501. let data = e.detail;
  502. data.address=data.address.replace(/\s+/g,' ')
  503. this.setData({ 'info.mailAddress': data.name + ' ' + data.mobile + ' ' + data.provincial + ' ' + data.address});
  504. },
  505. close(){
  506. this.setData({showAddress:false})
  507. },
  508. onShareAppMessage() {
  509. return {
  510. title: '儿童的身份信息',
  511. path: '/pages/account/cards/index'
  512. }
  513. }
  514. })