index.js 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. const util = require('../../../utils/util.js');
  2. const app = getApp();
  3. Page({
  4. data: {
  5. num: 0, //套餐数量
  6. agreement: false, //同意合同
  7. pay: true, //同意微信支付
  8. qptype: 0,
  9. btype: -1, //上页面传入的活动类型 0(默认)-普通购买 1-预付 2-付尾款 3-候补购买
  10. recommender: '', //推荐人
  11. recommenderStatus: '',
  12. street: '', //街道社区
  13. streetStatus: '',
  14. atype: 0, //0活动1电商
  15. recommenderShow: false,
  16. recommenderShowText: '',
  17. datas: {}, //payinfo数据
  18. imgPath: util.config.imgPath,
  19. userInfo: app.globalData.userInfo,
  20. formData: {
  21. aid: '',
  22. sid: '',
  23. vid: '',
  24. cid: '',
  25. useCoin: 0,
  26. useBalance: 0,
  27. useUserCoin: 0,
  28. meals: '',
  29. unNeedBedNum: 0//不占床数
  30. },
  31. total: {//抵扣金额
  32. unNeedBedPrice: '0.00',//不占床
  33. coin: '0.00', //钱包
  34. sumCoin: '0.00',//抵用钱包总额
  35. coupons: '0.00', //现金券
  36. ldiscount: '0.00', //早鸟优惠价格
  37. mdiscount: '0.00', //会员折扣价
  38. price: '0.00', //总价
  39. sumBalance: '0.00', //账户余额
  40. ableBalance: '0.00', //账户余额可用
  41. },
  42. idcards: {},
  43. textarea: '', //备注
  44. phoneNum: '', //手机号码
  45. mailAddress: '', //邮寄地址
  46. shipAddress: '', //收货地址
  47. email: '', //邮箱
  48. orderCity: '', //城市
  49. familyCommittee: '',
  50. travelDates: '', //出行日期
  51. groupid: '', //拼团号
  52. shareId: '', //分享id
  53. paying: false, //支付中
  54. percent: 0,
  55. alone: 0, //0单独报名,1拼团
  56. initialSku: {},
  57. havePerson: false,
  58. sku: {
  59. quantity: 0, //购买数量
  60. sessions: {},
  61. meals: {},
  62. quota: 999, //限购
  63. },
  64. show: {
  65. address: false,
  66. vouche: false,
  67. integral: false
  68. },
  69. voucheConfig: {},
  70. maskShow: false,
  71. presellOpen: 0,
  72. military: 0,
  73. ageLimit: '',
  74. // 折扣弹窗选择内容
  75. radioChoose: {
  76. coin: 0,//抵用钱包
  77. ableBalance: 0,//账户余额
  78. babyCoin: 0,//宝贝币
  79. },
  80. unNeedBedShow: false,//占床弹窗
  81. unNeedBedNum: 0,//不占床数量
  82. coinShow: false,//抵用钱包弹窗
  83. useCoin: 0,//是否使用抵用钱包
  84. ableBalanceShow: false,//账户余额弹窗
  85. useAbleBalance: 0,//是否使用账户余额
  86. babyCoinShow: false,//宝贝币弹窗
  87. useBabyCoin: 0,//是否使用宝贝币
  88. contractShow: false,
  89. contractUrl: [],
  90. },
  91. onLoad(options) {
  92. console.log(options)
  93. wx.removeStorageSync('idcards');
  94. this.data.formData.aid = options.aid;
  95. this.setData({
  96. formData: this.data.formData,
  97. qptype: options.qptype || '',
  98. btype: options.btype,
  99. groupid: (!util.isEmpty(options.groupid) && options.groupid != 'null' && options.groupid != 'undefined') ? options.groupid : '',
  100. recommenderStatus: options.recommender,
  101. streetStatus: options.street,
  102. alone: options.createGroup != undefined ? options.createGroup : 0,
  103. initialSku: {
  104. sessionsIndex: parseInt(options.sessionsIndex),
  105. mealsIndex: parseInt(options.mealsIndex),
  106. quantity: parseInt(options.quantity)
  107. },
  108. atype: parseInt(options.atype),
  109. presellOpen: options.presellOpen,
  110. military: options.military,
  111. ageLimit: options.ageLimit
  112. });
  113. this.payinfo();
  114. if (util.isObjEmpty(options.recommender) || options.recommender == '0') {
  115. this.setData({
  116. recommenderShow: false
  117. })
  118. } else if (options.recommender == '1') {
  119. this.setData({
  120. recommenderShow: true,
  121. recommenderShowText: '请填写推荐人,没有填无'
  122. })
  123. } else if (options.recommender == '2') {
  124. this.setData({
  125. recommenderShow: true,
  126. recommenderShowText: '非必填,若有请填写'
  127. })
  128. }
  129. },
  130. onShow() {
  131. let idcards = wx.getStorageSync('idcards');
  132. this.data.formData.cid = !util.isObjEmpty(idcards) ? idcards.ids.join(",") : '';
  133. this.setData({
  134. idcards,
  135. formData: this.data.formData
  136. });
  137. this.setData({
  138. userInfo: app.globalData.userInfo
  139. });
  140. if (!util.isObjEmpty(this.data.sku.meals)) this.safe();
  141. },
  142. onUnload() {
  143. wx.removeStorageSync('idcards');
  144. },
  145. // 判断是否含有出行人信息
  146. getIdcardinfoList() {
  147. var self = this;
  148. util.ajax({
  149. func: "user/idcardinfo_list",
  150. data: {
  151. type: this.data.ctype == 0 ? 0 : -1
  152. },
  153. load: false
  154. }, function (res) {
  155. if (res.code == 0) {
  156. self.setData({
  157. havePerson: res.data.length > 0 ? true : false
  158. })
  159. } else {
  160. util.showTips(res.reason)
  161. }
  162. })
  163. },
  164. payinfo() {
  165. let that = this,
  166. userInfo = app.globalData.userInfo;
  167. util.ajax({
  168. func: "article/payinfo",
  169. data: {
  170. "aid": that.data.formData.aid,
  171. "qptype": that.data.qptype ? that.data.qptype : 0,
  172. 'sid': that.data.initialSku.sessionsIndex // 参数新增sid返回数据场次只有一条
  173. }
  174. }, function (res) {
  175. if (res.code == 0) {
  176. // res.data.remark = res.data.remark || (that.data.atype==0? "请填写家长特别叮嘱,若无则填写无。":res.data.sremark == 'yes'? '给卖家留言,非必填':'');
  177. // if (that.data.presellOpen ==1) {
  178. // that.data.total.price = util.toMoney(res.data.presellPrice, ',');
  179. // }
  180. let contractUrl = []
  181. // 展示不同合同图片url
  182. switch (res.data.agreement) {
  183. case 'default': //境内旅游合同
  184. contractUrl = util.config.imgUrl + '/doc/jingneihetong.pdf'
  185. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/jingneihetong1.png' }, { url: 'https://img.bbztx.com/miniProgram/baby/contract/jingneihetong2.png' },]
  186. break;
  187. case 'foreign': //境外旅游合同
  188. contractUrl = util.config.imgUrl + '/doc/jingwaihetong.pdf'
  189. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/jingwaihetong1.png' }, { url: 'https://img.bbztx.com/miniProgram/baby/contract/jingwaihetong2.png' },]
  190. break;
  191. case 'within': //沐童境内旅游合同
  192. contractUrl = util.config.imgUrl + '/doc/jingneimutong.pdf'
  193. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/jingneimutong.png' }]
  194. break;
  195. case 'leave': //沐童境外旅游合同
  196. contractUrl = util.config.imgUrl + '/doc/jingwaimutong.pdf'
  197. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/jingwaimutong.png' }]
  198. break;
  199. case 'pay': //知识付费协议
  200. contractUrl = util.config.imgUrl + '/doc/knowledge.pdf'
  201. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/knowledge.png' }]
  202. break;
  203. case 'bicycleDomestic': //沐童境内旅游合同(含骑行)
  204. contractUrl = util.config.imgUrl + '/doc/bicycleDomestic.pdf'
  205. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/bicycleDomestic.png' }]
  206. break;
  207. case 'bicycleAbroad': //沐童出境旅游合同(含骑行)
  208. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/bicycleAbroad.png' }]
  209. break;
  210. case 'within1': //境内旅游合同(沐童旅行社单日版)
  211. contractUrl = util.config.imgUrl + '/doc/singleDayContract.pdf'
  212. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/singleDayContract.png' }]
  213. break;
  214. case 'within1_bicycle': //境内旅游合同(沐童旅行社单日骑行版)
  215. contractUrl = util.config.imgUrl + '/doc/singleDayBicycle.pdf'
  216. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/singleDayBicycle.png' }]
  217. break;
  218. case 'within3': //境内旅游合同(沐童旅行社多日版)
  219. contractUrl = util.config.imgUrl + '/doc/manyDayContract.pdf'
  220. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/manyDayContract1.png' }, { url: 'https://img.bbztx.com/miniProgram/baby/contract/manyDayContract2.png' }]
  221. break;
  222. case 'within3_bicycle': //境内旅游合同(沐童旅行社多日骑行版)
  223. contractUrl = util.config.imgUrl + '/doc/manyDayBicycle.pdf'
  224. contractUrl = [{ url: 'https://img.bbztx.com/miniProgram/baby/contract/manyDayBicycle1.png' }, { url: 'https://img.bbztx.com/miniProgram/baby/contract/manyDayBicycle2.png' }]
  225. break;
  226. }
  227. that.setData({
  228. datas: res.data,
  229. contractUrl,//合同图片url
  230. userInfo,
  231. total: that.data.total,
  232. formData: that.data.formData,
  233. phoneNum: res.data.buyInfo.contactPhone || '',
  234. textarea: res.data.orderRemark || '',
  235. mailAddress: res.data.buyInfo.mailAddress || '',
  236. email: res.data.needEmail != 'no' ? res.data.buyInfo.email : '',
  237. street: res.data.buyInfo.street || ''
  238. });
  239. wx.reportAnalytics('enter_enlist', {
  240. aid: that.data.formData.aid,
  241. title: res.data.title
  242. });
  243. that.getSku();
  244. that.safe();
  245. that.getIdcardinfoList()
  246. that.shipInfo();
  247. } else if (res.code == 3003) {
  248. wx.showModal({
  249. title: '提示',
  250. content: res.reason,
  251. showCancel: false,
  252. success: function (data) {
  253. if (data.confirm) {
  254. wx.navigateBack();
  255. }
  256. }
  257. })
  258. } else {
  259. util.showTips(res.reason);
  260. }
  261. })
  262. },
  263. getSku() { //sku
  264. let sku = this.data.sku,
  265. info = this.data.datas,
  266. initialSku = this.data.initialSku;
  267. // sku.sessions = this.getSkuInfo(info.sessions, 0, 'sid', this.data.initialSku.sessionsIndex);
  268. sku.sessions = info.sessions[0]
  269. this.data.formData.sid = sku.sessions.sid;
  270. sku.meals = this.getSkuInfo(sku.sessions.alipays, 0, 'pid', this.data.initialSku.mealsIndex);
  271. sku.meals.originalPrice = util.toMoney(sku.meals.originalPrice)
  272. sku.meals.price = this.data.presellOpen == 0 ? util.toMoney(sku.meals.price) : util.toMoney(this.data.datas.presellPrice)
  273. sku.quantity = initialSku.quantity;
  274. sku.quota = this.data.btype == -1 ? (parseInt(sku.meals.actNum) < sku.meals.maxT ? parseInt(sku.meals.actNum) : sku.meals.maxT) : (parseInt(sku.meals.waitActNum) < sku.meals.maxT ? parseInt(sku.meals.waitActNum) : sku.meals.maxT);
  275. this.setData({
  276. sku,
  277. formData: this.data.formData
  278. })
  279. },
  280. // 循环获取场次信息
  281. getSkuInfo(arr, i, type, id) {
  282. if (arr.length > 0 && i < arr.length) {
  283. if (arr[i][type] == id) {
  284. return arr[i];
  285. } else {
  286. return this.getSkuInfo(arr, i + 1, type, id)
  287. }
  288. }
  289. },
  290. numAdd() {
  291. let sku = this.data.sku;
  292. if (sku.quantity >= sku.quota) {
  293. util.showTips("库存不足");
  294. } else {
  295. sku.quantity = parseInt(sku.quantity) + 1;
  296. this.setData({
  297. sku,
  298. unNeedBedNum: 0//儿童不占床数量
  299. });
  300. this.removeIdcards();
  301. this.safe();
  302. }
  303. },
  304. numReduce() {
  305. let sku = this.data.sku;
  306. if (sku.quantity <= 1) {
  307. util.showTips("至少选择1件");
  308. } else {
  309. sku.quantity = parseInt(sku.quantity) - 1;
  310. this.setData({
  311. sku,
  312. unNeedBedNum: 0//儿童不占床数量
  313. });
  314. this.removeIdcards();
  315. this.safe();
  316. }
  317. },
  318. numChange(e) {
  319. let sku = this.data.sku;
  320. if (parseInt(e.detail.value) > sku.quota) {
  321. util.showTips("库存不足");
  322. sku.quantity = sku.quota;
  323. } else if (parseInt(e.detail.value) <= 0 || util.isEmpty(e.detail.value)) {
  324. util.showTips("至少选择1件");
  325. sku.quantitym = 1;
  326. } else {
  327. sku.quantity = e.detail.value;
  328. }
  329. this.setData({
  330. sku,
  331. unNeedBedNum: 0//儿童不占床数量
  332. });
  333. this.removeIdcards();
  334. this.safe();
  335. },
  336. removeIdcards() {
  337. wx.removeStorageSync('idcards');
  338. this.setData({
  339. idcards: []
  340. })
  341. },
  342. openQuestion() {
  343. this.setData({
  344. maskShow: true
  345. })
  346. },
  347. maskClose() {
  348. this.setData({
  349. maskShow: false
  350. })
  351. },
  352. agree() {
  353. if (this.data.agreement) {
  354. this.setData({
  355. agreement: !this.data.agreement
  356. })
  357. } else {
  358. this.setData({
  359. contractShow: true,
  360. })
  361. }
  362. },
  363. // 已阅读按钮
  364. agreeContract() {
  365. this.setData({
  366. agreement: true,
  367. contractShow: false,
  368. })
  369. },
  370. choosePay() {
  371. this.setData({
  372. pay: !this.data.pay
  373. })
  374. },
  375. // 选择出行人
  376. chooseCard() {
  377. var quantity = this.data.sku.quantity;
  378. if (quantity > 0) {
  379. wx.navigateTo({
  380. url: '/pages/account/cards/index?quantity=' + quantity + '&mage=' + this.data.datas.mage + '&lage=' + this.data.datas.lage + '&sparent=' + this.data.datas.sparent + '&adultMinAge=' + this.data.datas.adultMinAge + '&adultMaxAge=' + this.data.datas.adultMaxAge + '&needClothesSize=' + this.data.datas.clothesSize + '&needShoeSize=' + this.data.datas.shoeSize + '&ageLimit=' + this.data.ageLimit + '&campSex=' + this.data.sku.meals.campSex + '&military=' + this.data.military + '&sid=' + this.data.sku.sessions.sid
  381. })
  382. } else {
  383. util.showTips('请选择场次或者套餐数量');
  384. }
  385. },
  386. // 查看数组是否有重复元素
  387. hasDuplicate(arr) {
  388. if (arr && arr.length > 0) {
  389. return new Set(arr).size !== arr.length;
  390. } else {
  391. return false
  392. }
  393. },
  394. safe(type, checked) {
  395. let that = this;
  396. that.data.formData.meals = that.data.sku.meals.pid + '|' + that.data.sku.quantity;
  397. that.data.formData.btype = this.data.btype != -1 ? this.data.btype : (this.data.presellOpen != 0 ? 1 : 0);
  398. if (type == 'useCoin') {//抵用钱包
  399. that.data.formData.useCoin = checked == 1 ? 1 : 0
  400. } else if (type == 'ableBalance') {//账户余额
  401. that.data.formData.useBalance = checked == 1 ? 1 : 0
  402. } else if (type == 'babyCoin') {//宝贝币
  403. that.data.formData.useUserCoin = checked == 1 ? 1 : 0
  404. } else if (type == 'unNeedBed') {//不占床数量
  405. // 不占床数量
  406. that.data.formData.unNeedBedNum = checked
  407. }
  408. util.ajax({
  409. func: "voucher/pay_mvoucher", //会员折扣,现金券,钱包
  410. data: that.data.formData,
  411. load: false
  412. }, function (res) {
  413. if (res.code == 0 && res.data != "") {
  414. let data = res.data;
  415. that.data.total.unNeedBedPrice = util.toMoney(data.unNeedBedPrice, ',');
  416. that.data.total.coin = util.toMoney(data.coin, ',');
  417. that.data.total.sumCoin = util.toMoney(data.sumCoin, ',');
  418. that.data.total.coupons = util.toMoney(data.price, ',');
  419. that.data.total.ldiscount = util.toMoney(data.ldiscount, ',');
  420. that.data.total.mdiscount = util.toMoney(data.mdiscount, ',');
  421. that.data.total.price = util.toMoney(data.totalFee, ',');
  422. that.data.total.sumBalance = util.toMoney(data.sumBalance, ',');
  423. that.data.total.sumBalanceNum = data.sumBalance;
  424. that.data.total.sumUserCoin = data.sumUserCoin || 0;
  425. that.data.total.userCoin = data.userCoin || 0;
  426. // 不占床规则
  427. that.data.total.childCount = res.childCount || 0;
  428. that.data.total.adultCount = res.adultCount || 0;
  429. that.data.total.unNeedBedMaxNum = data.unNeedBedMaxNum || 0;
  430. that.data.total.ableBalance = util.toMoney(data.ableBalance, ',');
  431. that.data.formData.vid = data.id || '';
  432. that.setData({
  433. total: that.data.total,
  434. formData: that.data.formData
  435. });
  436. } else {
  437. // that.clearSafe();
  438. }
  439. })
  440. },
  441. getPackId() {
  442. return (this.data.sku.meals.pid || '') + '|' + this.data.sku.quantity;
  443. },
  444. goCoupon() {
  445. var packIds = this.getPackId();
  446. if (this.data.datas.needIdcard != 'no' && util.isObjEmpty(this.data.idcards)) {
  447. util.showTips('请先选择购买儿童的身份信息。');
  448. return false;
  449. }
  450. this.data.show = {
  451. address: false,
  452. vouche: true,
  453. integral: false
  454. };
  455. let voucheConfig = {
  456. packIds: packIds,
  457. aid: this.data.formData.aid,
  458. sid: this.data.formData.sid,
  459. vid: this.data.formData.vid,
  460. cid: this.data.formData.cid
  461. }
  462. this.setData({
  463. voucheConfig,
  464. show: this.data.show
  465. })
  466. },
  467. // 弹出不占床选择
  468. showUnNeedBed(e) {
  469. if (this.data.datas.needIdcard != 'no' && util.isObjEmpty(this.data.idcards)) {
  470. util.showTips('请先选择购买儿童的身份信息。');
  471. return false;
  472. }
  473. this.setData({
  474. unNeedBedShow: !this.data.unNeedBedShow,
  475. })
  476. let type = e.currentTarget.dataset.type
  477. this.safe(type, this.data.unNeedBedNum)
  478. },
  479. // 弹出抵用钱包
  480. showCoin(e) {
  481. this.setData({
  482. coinShow: !this.data.coinShow,
  483. "radioChoose.coin": this.data.useCoin
  484. })
  485. let type = e.currentTarget.dataset.type
  486. this.safe(type, 1)
  487. },
  488. // 弹出账户余额
  489. showAbleBalance(e) {
  490. this.setData({
  491. ableBalanceShow: !this.data.ableBalanceShow,
  492. "radioChoose.ableBalance": this.data.useAbleBalance
  493. })
  494. let type = e.currentTarget.dataset.type
  495. this.safe(type, 1)
  496. },
  497. // 弹出宝贝币
  498. showBabyCoin(e) {
  499. this.setData({
  500. babyCoinShow: !this.data.babyCoinShow,
  501. "radioChoose.babyCoin": this.data.useBabyCoin
  502. })
  503. let type = e.currentTarget.dataset.type
  504. this.safe(type, 1)
  505. },
  506. goPay() {
  507. console.log('领队小程序传参', wx.getStorageSync("payOpenId"))
  508. var packIds = this.getPackId(),
  509. phoneNum = this.data.phoneNum,
  510. idcards = this.data.idcards,
  511. num = this.data.sku.quantity,
  512. datas = this.data.datas,
  513. userInfo = app.globalData.userInfo,
  514. email = this.data.email,
  515. orderCity = this.data.orderCity;
  516. if (util.isObjEmpty(this.data.sku.meals)) {
  517. util.showTips('请先选择场次套餐,再付款。');
  518. return false;
  519. }
  520. if (datas.needIdcard != 'no' && this.data.atype == 0) {
  521. if (idcards.ids) {
  522. if (idcards.ids.length == 0) {
  523. util.showTips('请先选择出行人的身份信息。');
  524. return false;
  525. } else if (idcards.ids.length != num) {
  526. util.showTips('请设置' + num + '人的身份信息。');
  527. return false;
  528. }
  529. } else {
  530. util.showTips('请先选择出行人的身份信息。');
  531. return false;
  532. }
  533. }
  534. if (datas.sphone == 'yes' && util.isPhone(phoneNum)) {
  535. util.showTips('请填写正确的用户联系手机号码。');
  536. return false;
  537. }
  538. if (datas.smailAddress == 'yes' && !this.data.mailAddress) {
  539. util.showTips(this.data.atype == 1 ? '请填写收货地址。' : '请填写邮寄信息。');
  540. return false;
  541. }
  542. // var myreg = /^([a-zA-Z0-9]+[_|\_|\.|-]+)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.|-]+)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/gi;
  543. if (datas.needEmail && datas.needEmail == 'yes' && !email) {
  544. util.showTips('请填写电子邮箱。');
  545. return false;
  546. }
  547. if (datas.orderCity && datas.orderCity == 1 && !orderCity) {
  548. util.showTips('请填写城市。');
  549. return false;
  550. }
  551. // if (datas.needEmail == 'yes' && !myreg.test(email)) {
  552. // util.showTips('请正确填写电子邮箱。');
  553. // return false;
  554. // }
  555. if (datas.familyCommittee == '1' && this.data.familyCommittee == '' && this.data.atype == 0) {
  556. util.showTips('请填写是否为家委会');
  557. return false;
  558. }
  559. if (this.data.streetStatus == '1' && this.data.street == '') {
  560. util.showTips('请填写街道社区,没有填无');
  561. return false;
  562. }
  563. if (this.data.recommenderStatus == '1' && this.data.recommender == '') {
  564. util.showTips('请填写推荐人,没有填无');
  565. return false;
  566. }
  567. if (this.data.recommenderStatus == '1' && this.data.recommender.length > 10) {
  568. util.showTips('请正确填写推荐人');
  569. return false;
  570. }
  571. if (datas.travelDates == 'yes' && !this.data.travelDates && this.data.atype == 0) {
  572. util.showTips('请选择出行日期。');
  573. return false;
  574. }
  575. if (this.data.atype == 0 && datas.sremark == 'yes' && this.data.textarea == '') {
  576. util.showTips('请填写家长叮嘱等备注信息。');
  577. return false;
  578. }
  579. if (datas.agreement && !this.data.agreement && this.data.atype == 0 && this.data.presellOpen == 0) {
  580. util.showTips('请认真阅读相关协议条款,并认可同意。');
  581. return false;
  582. }
  583. if (!this.data.paying) {
  584. // this.setData({ paying: true });
  585. this.WeChatPay();
  586. }
  587. console.log(this.data.formData);
  588. },
  589. WeChatPay() {
  590. // this.setData({
  591. // paying: true
  592. // });
  593. var data = {},
  594. getPackId = this.getPackId(),
  595. userInfo = app.globalData.userInfo,
  596. that = this,
  597. sku = this.data.sku;
  598. console.log(sku)
  599. data['meals'] = getPackId; //支付套餐字符串 如:pid|num,pid|num
  600. data['aid'] = this.data.formData.aid; //活动唯一标识
  601. data['sid'] = this.data.formData.sid; //场次id
  602. data['orderTitle'] = this.data.datas.title; //商品名
  603. data['phone'] = userInfo.phoneNum; //用户联系电话
  604. data['vid'] = this.data.formData.vid == -1 ? "" : this.data.formData.vid; //现金券id
  605. data['idcards'] = this.data.idcards.ids != undefined ? this.data.idcards.ids.join(",") : ""; //身份证信息 ,字符串多个","隔开 如: id1,id2 remark
  606. data['remark'] = this.data.textarea; //备注
  607. data['contactPhone'] = this.data.phoneNum; //联系手机号
  608. data['recommender'] = this.data.recommender; //推荐人
  609. data['street'] = this.data.street; //街道社区
  610. data['familyCommittee'] = this.data.familyCommittee; //街道社区
  611. data['travelDates'] = this.data.travelDates; //出行日期
  612. data['mailAddress'] = this.data.mailAddress; //邮寄地址
  613. data['openid'] = app.globalData.payOpenId; //微信用户的openid
  614. data['email'] = this.data.email || ''; //邮件地址
  615. data['orderCity'] = this.data.orderCity || ''; //城市
  616. data['unNeedBedNum'] = this.data.unNeedBedNum || ''; //不占床数量
  617. data['wallet'] = this.data.formData.useCoin;
  618. data['useBalance'] = this.data.formData.useBalance;
  619. data.useUserCoin = this.data.formData.useUserCoin;
  620. if (!util.isEmpty(this.data.groupid) && this.data.groupid != 'null' && this.data.groupid != 'undefined') {
  621. data['groupid'] = this.data.groupid; //拼团号
  622. }
  623. data['shareId'] = this.data.shareId; //分享id
  624. data['product'] = 0; //产品: 0(默认)-活动 1-年卡
  625. data.createGroup = this.data.alone;
  626. data.btype = this.data.btype != -1 ? this.data.btype : (this.data.presellOpen != 0 ? 1 : 0); //this.data.presellOpen ==1 ?1 : (this.data.presellOpen ==0 && sku.meals.actNum<=0 && sku.meals.waitActNum>0 ?3:0);
  627. data.orderid = '';
  628. let str = data.idcards
  629. console.log(str);
  630. let idCards = str.split(',');
  631. console.log(idCards, 'idCards');
  632. let obj = {}
  633. //是否重复 false不重复
  634. if (this.hasDuplicate(idCards)) {
  635. obj.isRepeat = true
  636. } else {
  637. obj.isRepeat = false
  638. }
  639. console.log(obj.isRepeat);
  640. if (this.data.atype != 1) {
  641. if (obj.isRepeat) {
  642. util.showTips('你选择的儿童中存在相同信息,请核对后重新选择')
  643. } else {
  644. util.WXPay(data, this.data.formData.aid, this.data.datas.title, that.data.alone, this.data.presellOpen).then(function (data) {
  645. that.setData({
  646. paying: false
  647. });
  648. wx.navigateTo({
  649. url: '/pages/order/success/index?orderid=' + data.orderid + '&alone=' + that.data.alone + '&presellOpen=' + that.data.presellOpen + '&btype=' + data.btype + '&tradeChannelWeixin=' + data.tradeChannelWeixin
  650. });
  651. }, function (res) {
  652. that.setData({
  653. paying: false
  654. });
  655. util.showTips(res.reason)
  656. });
  657. wx.reportAnalytics('gopay', {
  658. aid: that.data.aid,
  659. title: that.data.datas.title,
  660. });
  661. }
  662. } else {
  663. util.WXPay(data, this.data.formData.aid, this.data.datas.title, that.data.alone, this.data.presellOpen).then(function (data) {
  664. that.setData({
  665. paying: false
  666. });
  667. wx.navigateTo({
  668. url: '/pages/order/success/index?orderid=' + data.orderid + '&alone=' + that.data.alone + '&presellOpen=' + that.data.presellOpen + '&btype=' + data.btype + '&tradeChannelWeixin=' + data.tradeChannelWeixin
  669. });
  670. }, function (res) {
  671. that.setData({
  672. paying: false
  673. });
  674. util.showTips(res.reason)
  675. });
  676. wx.reportAnalytics('gopay', {
  677. aid: that.data.aid,
  678. title: that.data.datas.title,
  679. });
  680. }
  681. },
  682. // 抵用钱包选择
  683. coinChange(e) {
  684. console.log(e)
  685. this.setData({
  686. "radioChoose.coin": e.detail.value
  687. })
  688. },
  689. // 账户余额选择
  690. balanceChange(e) {
  691. console.log(e)
  692. this.setData({
  693. "radioChoose.ableBalance": e.detail.value
  694. })
  695. },
  696. unNeedBedChange(e) {
  697. if (parseInt(e.detail.value) > this.data.total.unNeedBedMaxNum) {
  698. // util.showTips("库存不足");
  699. this.data.unNeedBedNum = this.data.total.unNeedBedMaxNum;
  700. } else if (parseInt(e.detail.value) < 0 || util.isEmpty(e.detail.value)) {
  701. // util.showTips("不能小于0");
  702. this.data.unNeedBedNum = 0;
  703. } else {
  704. this.data.unNeedBedNum = e.detail.value;
  705. }
  706. this.setData({
  707. unNeedBedNum: this.data.unNeedBedNum
  708. });
  709. this.safe('unNeedBed', this.data.unNeedBedNum)
  710. },
  711. // 占床位加
  712. unNeedBedReduce() {
  713. if (this.data.unNeedBedNum <= 0) {
  714. // util.showTips("最小为零");
  715. } else {
  716. this.data.unNeedBedNum = parseInt(this.data.unNeedBedNum) - 1;
  717. this.setData({
  718. unNeedBedNum: this.data.unNeedBedNum
  719. });
  720. this.safe('unNeedBed', this.data.unNeedBedNum)
  721. }
  722. },
  723. // 占床位减
  724. unNeedBedAdd() {
  725. if (this.data.unNeedBedNum >= this.data.total.unNeedBedMaxNum) {
  726. // util.showTips("不可大于允许选择数");
  727. } else {
  728. this.data.unNeedBedNum = parseInt(this.data.unNeedBedNum) + 1;
  729. this.setData({
  730. unNeedBedNum: this.data.unNeedBedNum
  731. });
  732. this.safe('unNeedBed', this.data.unNeedBedNum)
  733. }
  734. },
  735. // 宝贝币选择
  736. babyCoinChange(e) {
  737. console.log(e)
  738. this.setData({
  739. "radioChoose.babyCoin": e.detail.value
  740. })
  741. },
  742. // 弹窗确认选择
  743. confirmSelection(e) {
  744. let type = e.currentTarget.dataset.type
  745. switch (type) {
  746. //占床
  747. case "unNeedBed":
  748. this.setData({ unNeedBedShow: false })
  749. break;
  750. case "useCoin":
  751. this.setData({ useCoin: this.data.radioChoose.coin, coinShow: false })
  752. this.safe(type, this.data.radioChoose.coin)
  753. break;
  754. case "ableBalance":
  755. this.setData({ useAbleBalance: this.data.radioChoose.ableBalance, ableBalanceShow: false })
  756. this.safe(type, this.data.radioChoose.ableBalance)
  757. break;
  758. case "babyCoin":
  759. this.setData({ useBabyCoin: this.data.radioChoose.babyCoin, babyCoinShow: false })
  760. this.safe(type, this.data.radioChoose.babyCoin)
  761. break;
  762. }
  763. },
  764. textarea(e) {
  765. this.setData({
  766. textarea: e.detail.value
  767. });
  768. },
  769. phoneNum(e) {
  770. this.setData({
  771. phoneNum: e.detail.value
  772. });
  773. },
  774. chooseAddress() {
  775. this.data.show = {
  776. address: true,
  777. vouche: false,
  778. integral: false
  779. };
  780. this.setData({
  781. show: this.data.show
  782. });
  783. },
  784. submitAddress(e) {
  785. let data = e.detail;
  786. data.address = data.address.replace(/\s+/g, ' ')
  787. this.setData({
  788. mailAddress: data.name + ' ' + data.mobile + ' ' + data.provincial + ' ' + data.address
  789. });
  790. this.shipInfo();
  791. },
  792. shipInfo() {
  793. if (this.data.mailAddress) {
  794. let address = this.data.mailAddress.split(' ');
  795. let addressInfo = address[2].split('/');
  796. let shipAddress = {
  797. userName: address[0],
  798. telNumber: address[1],
  799. provinceName: addressInfo[0],
  800. cityName: addressInfo[1],
  801. countyName: addressInfo[2],
  802. detailInfo: address[3],
  803. }
  804. this.setData({
  805. shipAddress
  806. });
  807. }
  808. },
  809. // 优惠券id
  810. changeVouche(e) {
  811. this.data.formData.vid = e.detail;
  812. this.setData({
  813. formData: this.data.formData
  814. });
  815. this.safe();
  816. },
  817. // 推荐人
  818. recommender(e) {
  819. this.setData({
  820. recommender: util.trim(e.detail.value)
  821. });
  822. },
  823. // 街道社区
  824. streetInput(e) {
  825. this.setData({
  826. street: util.trim(e.detail.value)
  827. });
  828. },
  829. // 邮箱
  830. email(e) {
  831. this.setData({
  832. email: util.spaceTrim(e.detail.value)
  833. });
  834. let userInfo = app.globalData.userInfo;
  835. userInfo.email = util.spaceTrim(e.detail.value);
  836. wx.setStorageSync('WXuserInfo', userInfo);
  837. },
  838. // 城市
  839. cityValue(e) {
  840. this.setData({
  841. orderCity: e.detail.value
  842. });
  843. },
  844. // 家委会
  845. familyCommittee(e) {
  846. this.setData({
  847. familyCommittee: util.trim(e.detail.value)
  848. });
  849. },
  850. bindDateChange(e) {
  851. this.setData({
  852. travelDates: e.detail.value
  853. });
  854. },
  855. openDoc() {
  856. this.setData({
  857. contractShow: true,
  858. })
  859. },
  860. integral() {
  861. if (this.data.datas.needIdcard != 'no' && util.isObjEmpty(this.data.idcards)) {
  862. util.showTips('请先选择购买儿童的身份信息。');
  863. return false;
  864. }
  865. this.data.show = {
  866. address: false,
  867. vouche: false,
  868. integral: true
  869. };
  870. this.setData({
  871. show: this.data.show,
  872. integralConfig: {
  873. idcards: this.data.idcards,
  874. sid: this.data.formData.sid,
  875. aid: this.data.formData.aid
  876. }
  877. });
  878. },
  879. close(e) {
  880. this.data.show[e.currentTarget.dataset.name] = false;
  881. this.setData({
  882. show: this.data.show
  883. })
  884. },
  885. onShareAppMessage() {
  886. return {
  887. title: '分享自@宝贝走天下微信小程序',
  888. path: '/pages/home/index'
  889. }
  890. }
  891. })