index.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. const util = require("../../../utils/util")
  2. Page({
  3. data: {
  4. showData: false, //是否显示页面
  5. info: {},
  6. activiteInfo: {},
  7. orderId: '',
  8. childInfo: [],
  9. childArr: [],
  10. remark: '',
  11. mailAddress: '',
  12. userinfo: wx.getStorageSync('WXuserInfo'),
  13. cardTypeStr: '',
  14. clothesCode: [],
  15. shoesCode: [],
  16. showCodePopup: false,
  17. otype: 2,
  18. // 过敏信息
  19. // allergy: "无",
  20. // 饮食信息
  21. // special: "无",
  22. catesFlag: false,
  23. Passporturl: "",
  24. documentType: 0,
  25. // 身份证正面
  26. positive: "",
  27. // 身份证反面
  28. otherSide: '',
  29. // 户口本页
  30. Household: "",
  31. firstPagePath: '', //上一个页面路由地址
  32. information: false,
  33. idCard: false,
  34. allergy: '', //过敏是否
  35. diet: '', //是否禁忌
  36. bloodOrMedical: '', //是否特殊
  37. especiallyRemark: '', //是否特别备注
  38. photoType: 0,
  39. },
  40. onLoad: function (options) {
  41. // console.log(null==false);
  42. // console.log('options', options)
  43. let pages = getCurrentPages(); //页面对象
  44. let prevpage = pages[pages.length - 2]; //上一个页面对象
  45. let path = prevpage.route;
  46. this.setData({
  47. orderId: options.orderId || '',
  48. cardTypeStr: util.cardType(options.cardtype),
  49. firstPagePath: path
  50. })
  51. this.getOrderDetail();
  52. this.getDetail();
  53. },
  54. // 获取过敏信息
  55. // getallergy(e) {
  56. // console.log(e);
  57. // this.setData({
  58. // allergy: e.detail.value
  59. // })
  60. // // console.log(this.data.allergy);
  61. // },
  62. // 获取饮食禁忌
  63. // getdiet(e) {
  64. // this.setData({
  65. // taboo: e.detail.value
  66. // })
  67. // },
  68. // // 获取特殊血型
  69. // getspecial(e) {
  70. // // console.log(e);
  71. // this.setData({
  72. // special: e.detail.value
  73. // })
  74. // },
  75. getTaboo(e) {
  76. console.log(e);
  77. let index = e.currentTarget.dataset.index
  78. let type = e.currentTarget.dataset.name
  79. let value = e.detail.value
  80. let data = this.data.childArr
  81. data[index][type] = value
  82. this.setData({
  83. childArr: data,
  84. })
  85. },
  86. // 点击证件要求弹框
  87. certificates() {
  88. this.setData({
  89. catesFlag: true
  90. })
  91. },
  92. // 弹框点击确定
  93. sure() {
  94. this.setData({
  95. catesFlag: false
  96. })
  97. },
  98. // 上传护照信息
  99. upPassport(e) {
  100. let index = e.currentTarget.dataset.index
  101. let arr = this.data.childArr
  102. let that = this
  103. wx.chooseImage({
  104. count: 1,
  105. sizeType: ['compressed'],
  106. sourceType: ['album', 'camera'],
  107. success: function (res) {
  108. console.log(res);
  109. util.uploadFile("oss/policy", res.tempFilePaths[0], {
  110. type: "attendants"
  111. }, true).then((res) => {
  112. console.log(res);
  113. if (res.code == 0) {
  114. arr[index].passport = res.url
  115. that.setData({
  116. childArr: arr
  117. })
  118. // that.setData({
  119. // Passporturl: that.data.Passporturl
  120. // })
  121. // console.log(that.data.Passporturl);
  122. }
  123. });
  124. }
  125. })
  126. },
  127. // 切换证件类型
  128. bindinputTwo(e) {
  129. // console.log(e);
  130. this.setData({
  131. documentType: e.detail.value
  132. })
  133. },
  134. // 上传身份证正面
  135. upId(e) {
  136. let index = e.currentTarget.dataset.index
  137. let arr = this.data.childArr
  138. let that = this
  139. wx.chooseImage({
  140. count: 1,
  141. sizeType: ['compressed'],
  142. sourceType: ['album', 'camera'],
  143. success: function (res) {
  144. util.uploadFile("oss/policy", res.tempFilePaths[0], {
  145. type: "attendants"
  146. }, true).then((res) => {
  147. console.log(res);
  148. if (res.code == 0) {
  149. arr[index].idCardFront = res.url
  150. that.setData({
  151. childArr: arr
  152. })
  153. // that.data.positive = res.url
  154. // that.setData({
  155. // positive: that.data.positive
  156. // })
  157. // console.log(that.data.positive);
  158. }
  159. });
  160. }
  161. })
  162. },
  163. // 上传反面身份证
  164. upsideID(e) {
  165. let index = e.currentTarget.dataset.index
  166. let arr = this.data.childArr
  167. let that = this
  168. wx.chooseImage({
  169. count: 1,
  170. sizeType: ['compressed'],
  171. sourceType: ['album', 'camera'],
  172. success: function (res) {
  173. console.log(res);
  174. util.uploadFile("oss/policy", res.tempFilePaths[0], {
  175. type: "attendants"
  176. }, true).then((res) => {
  177. console.log(res);
  178. if (res.code == 0) {
  179. arr[index].idCardBack = res.url
  180. that.setData({
  181. childArr: arr
  182. })
  183. // that.data.otherSide = res.url
  184. // that.setData({
  185. // otherSide: that.data.otherSide
  186. // })
  187. // console.log(that.data.otherSide);
  188. }
  189. });
  190. }
  191. })
  192. },
  193. // 上传儿童户口本
  194. upHousehold(e) {
  195. let index = e.currentTarget.dataset.index
  196. let arr = this.data.childArr
  197. // console.log(index);
  198. let that = this
  199. wx.chooseImage({
  200. count: 1,
  201. sizeType: ['compressed'],
  202. sourceType: ['album', 'camera'],
  203. success: function (res) {
  204. console.log(res);
  205. util.uploadFile("oss/policy", res.tempFilePaths[0], {
  206. type: "attendants"
  207. }, true).then((res) => {
  208. console.log(res);
  209. if (res.code == 0) {
  210. arr[index].childPage = res.url
  211. that.setData({
  212. childArr: arr
  213. })
  214. // that.data.Household = res.url
  215. // that.setData({
  216. // Household: that.data.Household
  217. // })
  218. // console.log(that.data.Household);
  219. }
  220. });
  221. }
  222. })
  223. },
  224. // 删除图片
  225. delImage(e) {
  226. let arr = this.data.childArr
  227. let index = e.currentTarget.dataset.index
  228. // console.log(e.currentTarget.dataset.type=="Passporturl);
  229. let type = e.currentTarget.dataset.type
  230. console.log(arr[index], type);
  231. // let url = e.currentTarget.dataset.url
  232. //儿童护照
  233. if (type == "Passporturl") {
  234. arr[index].passport = ''
  235. this.setData({
  236. childArr: arr
  237. })
  238. } else if (type == "positive") { //正面
  239. arr[index].idCardFront = ''
  240. this.setData({
  241. childArr: arr
  242. })
  243. } else if (type == "otherSide") { //反面
  244. arr[index].idCardBack = ''
  245. this.setData({
  246. childArr: arr
  247. })
  248. } else if (type == "Household") { //儿童页
  249. arr[index].childPage = ''
  250. this.setData({
  251. childArr: arr
  252. })
  253. }
  254. },
  255. onShow: function () {
  256. },
  257. // 邮寄地址不可更改提示
  258. popTip() {
  259. util.showTips('订单已发货,无法修改地址。');
  260. },
  261. // 关闭弹窗
  262. close() {
  263. this.setData({
  264. showCodePopup: false
  265. })
  266. },
  267. // 打开尺码推荐弹窗
  268. CodeDetail() {
  269. this.setData({
  270. showCodePopup: true
  271. })
  272. },
  273. // 提交
  274. submit(e) {
  275. console.log(this.data.childArr);
  276. let that = this,
  277. data = {},
  278. arr = [];
  279. if (this.data.documentType == 0) {
  280. that.setData({
  281. photoType: 1
  282. })
  283. } else {
  284. that.setData({
  285. photoType: 2
  286. })
  287. }
  288. for (let i = 0; i < this.data.childArr.length; i++) {
  289. let obj = {};
  290. obj.id = this.data.childArr[i].id;
  291. console.log(obj.id);
  292. obj.oid = this.data.childArr[i].oid;
  293. obj.name = this.data.childArr[i].name;
  294. obj.height = this.data.childArr[i].height;
  295. obj.weight = this.data.childArr[i].weight;
  296. obj.bodyType = this.data.childArr[i].bodyType;
  297. obj.clothesSize = this.data.childArr[i].clothesSize;
  298. obj.shoesSize = this.data.childArr[i].shoesSize;
  299. obj.cardType = this.data.childArr[i].cardType
  300. obj.passport = this.data.childArr[i].passport == null ? '' : this.data.childArr[i].passport; //儿童护照
  301. obj.idCardFront = this.data.childArr[i].idCardFront == null ? '' : this.data.childArr[i].idCardFront; //儿童身份证正面
  302. obj.idCardBack = this.data.childArr[i].idCardBack == null ? '' : this.data.childArr[i].idCardBack; //儿童身份证反面
  303. obj.childPage = this.data.childArr[i].childPage == null ? '' : this.data.childArr[i].childPage; //儿童页
  304. obj.allergy = this.data.childArr[i].allergy == null ? '' : this.data.childArr[i].allergy;
  305. obj.diet = this.data.childArr[i].diet == null ? '' : this.data.childArr[i].diet;
  306. obj.bloodOrMedical = this.data.childArr[i].bloodOrMedical == null ? '' : this.data.childArr[i].bloodOrMedical;
  307. obj.especiallyRemark = this.data.childArr[i].especiallyRemark == null ? '' : this.data.childArr[i].especiallyRemark;
  308. obj.photoType = this.data.photoType;
  309. arr.push(obj)
  310. console.log(obj);
  311. if (util.isEmpty(obj.name)) {
  312. util.showTips('请填写 出行人' + (i + 1) + ' 的姓名。');
  313. return false;
  314. }
  315. if (util.isEmpty(obj.height) || util.isEmpty(obj.weight) || util.isEmpty(obj.bodyType)) {
  316. util.showTips('请补充 出行人' + (i + 1) + ' 的身高、体重和选择相对应的体型。');
  317. return false;
  318. }
  319. if (that.data.activiteInfo.clothesSize == 1 && util.isEmpty(obj.clothesSize)) {
  320. util.showTips('因活动需要,请选择 出行人' + (i + 1) + ' 的衣服尺码。');
  321. return false;
  322. }
  323. if (that.data.activiteInfo.needIdcard == 1 && util.isEmpty(obj.shoesSize)) {
  324. util.showTips('因活动需要,请选择 出行人' + (i + 1) + ' 的鞋码。');
  325. return false;
  326. }
  327. if (that.data.idCard) {
  328. if (util.isEmpty(obj.allergy)) {
  329. util.showTips('请填写 出行人' + (i + 1) + '是否有药物或食物过敏');
  330. return false;
  331. }
  332. if (util.isEmpty(obj.diet)) {
  333. util.showTips('请填写 出行人' + (i + 1) + '是否有饮食禁忌');
  334. return false;
  335. }
  336. if (util.isEmpty(obj.bloodOrMedical)) {
  337. util.showTips('请填写 出行人' + (i + 1) + '是否特殊血型/有无病史');
  338. return false;
  339. }
  340. if (util.isEmpty(obj.especiallyRemark)) {
  341. util.showTips('请填写 出行人' + (i + 1) + '是否有特别备注');
  342. return false;
  343. }
  344. }
  345. }
  346. if (that.data.activiteInfo.smailAddress == 'yes' && util.isEmpty(that.data.mailAddress)) {
  347. util.showTips('邮寄地址不能为空');
  348. return false;
  349. }
  350. if (that.data.activiteInfo.sremark == 'yes' && util.isEmpty(that.data.remark)) {
  351. util.showTips('备注信息不能为空');
  352. return false;
  353. }
  354. // data.idcards = JSON.stringify(arr);
  355. data.idcards = arr;
  356. data.mailAddress = that.data.mailAddress;
  357. data.orderid = that.data.orderId;
  358. data.remark = that.data.remark;
  359. util.ajax({
  360. func: "v2/order/attendants/save",
  361. data: data,
  362. method: 'POST'
  363. }, function (res) {
  364. console.log(res);
  365. if (res.code == 0) {
  366. util.showTips(res.reason);
  367. setTimeout(() => {
  368. if (that.data.firstPagePath == 'pages/order/orderDetailList/index') { //小程序码进入
  369. wx.redirectTo({
  370. url: '/pages/order/detail/index?orderid=' + that.data.orderId + '&otype=' + that.data.otype + '&presellStatus=0',
  371. })
  372. } else { //订单详情页进入
  373. wx.navigateBack({
  374. delta: 1
  375. })
  376. }
  377. }, 500);
  378. } else {
  379. util.showTips(res.reason);
  380. }
  381. })
  382. },
  383. // 修改邮寄地址
  384. chooseAddress() {
  385. this.setData({
  386. showAddress: true
  387. })
  388. },
  389. submitAddress(e) {
  390. let that = this,
  391. data = e.detail;
  392. this.setData({
  393. 'mailAddress': data.name + ' ' + data.mobile + ' ' + data.provincial + ' ' + data.address
  394. });
  395. },
  396. // 填写备注
  397. textareaInput(e) {
  398. let value = e.detail.value;
  399. this.setData({
  400. remark: value
  401. })
  402. },
  403. // 输入框填写/体型/尺码
  404. bindinput(e) {
  405. let index = e.currentTarget.dataset.index,
  406. type = e.currentTarget.dataset.name,
  407. value = e.detail.value,
  408. data = this.data.childArr;
  409. data[index][type] = value;
  410. console.log(e, data);
  411. if (type == 'clothesIndex') {
  412. data[index].clothesSize = data[index].clothesCode[value];
  413. }
  414. if (type == 'shoesIndex') {
  415. data[index].shoesSize = data[index].shoesCode[value];
  416. }
  417. this.setData({
  418. childArr: data
  419. })
  420. },
  421. // 获取年龄段的尺码
  422. satisfy(obj) {
  423. var nowDate = new Date(); // 当前时间
  424. var mouth = nowDate.getMonth() + 1;
  425. var day = nowDate.getDate();
  426. var year = nowDate.getFullYear() - 18;
  427. var oldDate = '';
  428. wx.getSystemInfo({
  429. success(res) {
  430. oldDate = res.platform == 'ios' ? new Date(year + '/' + mouth + '/' + day).getTime() : new Date(year + '-' + mouth + '-' + day).getTime()
  431. }
  432. })
  433. var newDate = new Date(obj.birthdayStr).getTime();
  434. // let ageType = oldDate < newDate ? true : false; // true 表示不满18
  435. if (oldDate < newDate) {
  436. obj.clothesCode = [110, 120, 130, 140, 150, 160, 165, 170, 175, 180, 185];
  437. obj.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];
  438. } else {
  439. if (obj.sex == 1) {
  440. obj.clothesCode = [165, 170, 175, 180, 185];
  441. obj.shoesCode = [39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49];
  442. } else {
  443. obj.clothesCode = [155, 160, 165, 170, 175];
  444. obj.shoesCode = [33, 34, 35, 36, 37, 38, 39, 40, 41];
  445. }
  446. }
  447. obj.clothesIndex = this.getCodeIndex(obj.clothesCode, obj.clothesSize);
  448. obj.idCardType = util.cardType(obj.cardType)
  449. obj.shoesIndex = this.getCodeIndex(obj.shoesCode, obj.shoesSize);
  450. return obj;
  451. },
  452. // 获取尺码索引
  453. getCodeIndex(arr, val) {
  454. let index = -1;
  455. arr.forEach((el, i) => {
  456. if (!util.isEmpty(val)) {
  457. if (el == val) {
  458. index = i;
  459. }
  460. } else {
  461. index = -1;
  462. }
  463. });
  464. return index;
  465. },
  466. // 获取出行人信息
  467. getDetail() {
  468. let that = this;
  469. util.ajax({
  470. func: "v2/order/attendants",
  471. load: false,
  472. data: {
  473. "orderid": that.data.orderId
  474. }
  475. }, function ({
  476. data,
  477. code
  478. }) {
  479. console.log(data);
  480. if (code == 0) {
  481. data.forEach((e) => {
  482. // sparent为0时是亲子营,articleType为1时满足条件
  483. // 不是亲子营且满足活动条件
  484. if (e.sparent != 0 && e.articleType) {
  485. that.setData({
  486. information: true,
  487. idCard: true
  488. })
  489. }
  490. // 非亲子营
  491. else if (e.sparent) {
  492. that.setData({
  493. idCard: true
  494. })
  495. } else if (e.sparent == 0) {
  496. that.setData({
  497. idCard: false
  498. })
  499. }
  500. })
  501. let arr = [];
  502. data.forEach(el => {
  503. // console.log(el);
  504. if (!util.isEmpty(el.attendants)) {
  505. el.attendants = JSON.parse(el.attendants)
  506. el.config = JSON.parse(el.config)
  507. el.attendants = that.satisfy(el.attendants[0]);
  508. el.attendants.oid = el.oid;
  509. el.attendants.passport = el.passport;
  510. el.attendants.idCardFront = el.idCardFront;
  511. el.attendants.idCardBack = el.idCardBack;
  512. el.attendants.childPage = el.childPage;
  513. el.attendants.allergy = el.allergy
  514. el.attendants.diet = el.diet
  515. el.attendants.bloodOrMedical = el.bloodOrMedical
  516. el.attendants.especiallyRemark = el.especiallyRemark
  517. arr.push(el.attendants)
  518. }
  519. });
  520. console.log(arr);
  521. that.setData({
  522. childArr: arr,
  523. showData: true
  524. })
  525. } else {
  526. util.showTips(res.reason + ' ,将自动返回上一页');
  527. setTimeout(() => {
  528. wx.navigateBack({
  529. delta: 1
  530. })
  531. }, 2000);
  532. }
  533. })
  534. },
  535. // 获取订单活动信息
  536. getOrderDetail() {
  537. let that = this;
  538. util.ajax({
  539. func: "v2/order/detail",
  540. load: false,
  541. data: {
  542. "orderid": that.data.orderId,
  543. otype: that.data.otype,
  544. }
  545. }, function (res) {
  546. console.log(res);
  547. if (res.code == 0) {
  548. that.setData({
  549. info: res.data,
  550. mailAddress: res.data.mailAddress || '',
  551. remark: res.data.remark || ''
  552. })
  553. that.getActiviteInfo(res.data.aid)
  554. } else {
  555. if (that.data.otype == 2) {
  556. that.setData({
  557. otype: 3
  558. })
  559. that.getOrderDetail()
  560. } else {
  561. util.showTips(res.reason);
  562. }
  563. }
  564. })
  565. },
  566. // 获取活动详情信息
  567. getActiviteInfo(aid) {
  568. let that = this;
  569. util.ajax({
  570. func: "v2/article/detail",
  571. load: false,
  572. data: {
  573. "aid": aid
  574. }
  575. }, function (res) {
  576. if (res.code == 0) {
  577. that.setData({
  578. activiteInfo: res.data
  579. })
  580. } else {
  581. util.showTips(res.reason);
  582. }
  583. })
  584. },
  585. errorImg() {
  586. this.data.info.logo = "/images/noimg.png";
  587. this.setData({
  588. info: this.data.info
  589. });
  590. },
  591. onShareAppMessage: function () {
  592. return {
  593. title: '为保证更好的参与活动,快来核对参与者信息吧~',
  594. path: '/pages/order/orderDetailList/index?aid=' + this.data.info.aid,
  595. imageUrl: '../images/share.png'
  596. }
  597. }
  598. })