You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

order-order.js 33KB

5 years ago
5 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
3 years ago
3 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. var app = new Vue({
  2. el: '#app-order-order',
  3. data() {
  4. return Object.assign({
  5. order: null,
  6. loading: false,
  7. loadingInit: true,
  8. step: null,
  9. producer: null,
  10. user: null,
  11. date: null,
  12. dateFormat: null,
  13. distributions: [],
  14. distribution: null,
  15. pointsSale: [],
  16. pointSaleActive: null,
  17. pointSaleActiveId: null,
  18. pointsSaleCodes: [],
  19. products: [],
  20. categories: [],
  21. categoryCurrent: null,
  22. comment: '',
  23. creditCheckbox: false,
  24. paymentMethod: 'onsite',
  25. useCredit: false,
  26. errors: [],
  27. disableConfirmButton: false,
  28. delivery: false,
  29. deliveryAddress: null,
  30. urlLogin: '#',
  31. producerOptionOrderEntryPoint: null,
  32. calendar: {
  33. columns: this.isMobile() ? 1 : 2,
  34. mode: 'single',
  35. attrs: [],
  36. availableDates: [],
  37. themeStyles: {
  38. wrapper: {
  39. background: '#F7F7F7',
  40. color: '#333',
  41. border: 'solid 1px #e0e0e0'
  42. },
  43. header: {
  44. padding: '10px 10px',
  45. },
  46. headerHorizontalDivider: {
  47. borderTop: 'solid rgba(255, 255, 255, 0.2) 1px',
  48. width: '80%',
  49. },
  50. weekdays: {
  51. color: 'gray',
  52. fontWeight: '600',
  53. padding: '10px 10px',
  54. fontSize: '2rem'
  55. },
  56. weeks: {
  57. padding: '0 15px 15px 15px',
  58. },
  59. dayContent: function (object) {
  60. var style = {
  61. fontSize: '1.4rem',
  62. padding: app.isMobile() ? '18px' : '20px',
  63. };
  64. return style;
  65. },
  66. },
  67. masks: {
  68. //dayPopover: 'DD/MM/YYYY'
  69. dayPopover: ''
  70. }
  71. }
  72. }, window.appInitValues);
  73. },
  74. mounted: function() {
  75. this.initDate();
  76. this.init('first');
  77. },
  78. methods: {
  79. initDate: function() {
  80. var dateDefined = $('#order-distribution-date').size() || $('#distribution-date').size() ;
  81. if(dateDefined && (this.producerOptionOrderEntryPoint != 'point-sale' || this.pointSaleActiveId)) {
  82. if($('#order-distribution-date').size()) {
  83. this.date = new Date($('#order-distribution-date').html()) ;
  84. }
  85. else {
  86. this.date = new Date($('#distribution-date').html()) ;
  87. }
  88. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  89. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  90. + this.date.getFullYear() ;
  91. }
  92. },
  93. getDate: function() {
  94. return this.formatDate(this.date) ;
  95. },
  96. formatDate: function(date) {
  97. if(date) {
  98. return date.getFullYear() + '-'
  99. + ('0' + (date.getMonth() +1)).slice(-2) + '-'
  100. + ('0' + date.getDate()).slice(-2) ;
  101. }
  102. return false ;
  103. },
  104. formatPrice: formatPrice,
  105. getPointSale: function(idPointSale) {
  106. for(var key in this.pointsSale) {
  107. if(this.pointsSale[key].id == idPointSale) {
  108. return this.pointsSale[key] ;
  109. }
  110. }
  111. },
  112. getPointSaleKey: function(idPointSale) {
  113. for(var key in this.pointsSale) {
  114. if(this.pointsSale[key].id == idPointSale) {
  115. return key ;
  116. }
  117. }
  118. },
  119. getProduct: function(idProduct) {
  120. for(var key in this.products) {
  121. if(this.products[key].id == idProduct) {
  122. return this.products[key] ;
  123. }
  124. }
  125. },
  126. init: function(type, oldStep, step) {
  127. var app = this ;
  128. this.loading = true ;
  129. if(app.isChangeState('date', 'date', 'point-sale')) {
  130. app.pointSaleActive = null ;
  131. app.products = [] ;
  132. }
  133. axios.get("ajax-infos",{params: {
  134. date : this.getDate(),
  135. pointSaleId: this.pointSaleActiveId ? this.pointSaleActiveId : (this.pointSaleActive ? this.pointSaleActive.id : 0)
  136. }})
  137. .then(function(response) {
  138. app.calendar.attrs = [];
  139. app.calendar.availableDates = [];
  140. var distributions = response.data.distributions;
  141. app.distributions = distributions;
  142. if (distributions.length) {
  143. var arrayDate;
  144. var highlightStyle = {
  145. style: {
  146. background: 'white',
  147. border: 'solid 2px #198754'
  148. },
  149. contentStyle: {
  150. color: '#198754'
  151. }
  152. };
  153. for (var i = 0; i < distributions.length; i++) {
  154. app.calendar.attrs.push({
  155. highlight: highlightStyle,
  156. dates: distributions[i].date
  157. });
  158. arrayDate = distributions[i].date.split('-');
  159. app.calendar.availableDates.push({
  160. highlight: highlightStyle,
  161. start: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]),
  162. end: new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2])
  163. });
  164. }
  165. }
  166. if(response.data.leave_period) {
  167. leavePeriodStartDateArray = response.data.leave_period.start.split('-');
  168. leavePeriodEndDateArray = response.data.leave_period.end.split('-');
  169. app.calendar.attrs.push({
  170. highlight: {
  171. style: {
  172. background: '#E09F3E'
  173. },
  174. contentStyle: {
  175. color: 'white'
  176. }
  177. },
  178. dates: {
  179. start: new Date(leavePeriodStartDateArray[0], leavePeriodStartDateArray[1] - 1, leavePeriodStartDateArray[2]),
  180. end: new Date(leavePeriodEndDateArray[0], leavePeriodEndDateArray[1] - 1, leavePeriodEndDateArray[2])
  181. },
  182. popover: {
  183. label: 'En congé',
  184. hideIndicator: true,
  185. isInteractive: true
  186. },
  187. });
  188. }
  189. if (response.data.distribution) {
  190. app.distribution = response.data.distribution;
  191. }
  192. var orders = [];
  193. if (response.data.orders) {
  194. orders = response.data.orders;
  195. }
  196. if (orders.length) {
  197. for (var i = 0; i < orders.length; i++) {
  198. arrayDate = orders[i].date_distribution.split('-');
  199. var dateOrder = new Date(arrayDate[0], arrayDate[1] - 1, arrayDate[2]);
  200. if (app.isAvailableDate(dateOrder)) {
  201. app.calendar.attrs.push({
  202. highlight: {
  203. style: {
  204. background: '#198754'
  205. },
  206. contentStyle: {
  207. color: 'white'
  208. }
  209. },
  210. popover: {
  211. label: orders[i].pointSale.name + ' (' + app.formatPrice(orders[i].amount_total)+')',
  212. hideIndicator: true,
  213. isInteractive: true
  214. },
  215. dates: orders[i].date_distribution
  216. });
  217. }
  218. }
  219. }
  220. app.producer = response.data.producer;
  221. app.user = response.data.user;
  222. app.useCredit = response.data.producer.use_credit_checked_default;
  223. if (response.data.points_sale) {
  224. app.pointsSale = [];
  225. var orderPointSale = 0;
  226. for (var key in response.data.points_sale) {
  227. response.data.points_sale[key].order = orderPointSale++;
  228. app.pointsSale[response.data.points_sale[key].id] = response.data.points_sale[key];
  229. if(!app.pointsSaleCodes[response.data.points_sale[key].id]) {
  230. app.pointsSaleCodes[response.data.points_sale[key].id] = '';
  231. Vue.set(app.pointsSaleCodes, response.data.points_sale[key].id, '');
  232. }
  233. }
  234. }
  235. if(app.pointSaleActiveId) {
  236. app.pointSaleActive = app.getPointSale(app.pointSaleActiveId);
  237. }
  238. if(app.pointSaleActive) {
  239. if(app.producer.credit
  240. && app.pointSaleActive.payment_method_credit
  241. && (app.pointSaleActive.credit_functioning == 'mandatory'
  242. || (app.pointSaleActive.credit_functioning == 'user' && app.user.credit_active)
  243. || (app.pointSaleActive.credit_functioning == 'optional' && response.data.producer.use_credit_checked_default))) {
  244. app.paymentMethod = 'credit';
  245. }
  246. else if(app.pointSaleActive.payment_method_onsite) {
  247. app.paymentMethod = 'onsite';
  248. }
  249. else if(app.pointSaleActive.payment_method_online) {
  250. app.paymentMethod = 'online';
  251. }
  252. }
  253. if(app.isChangeState('point-sale', 'point-sale', 'date')) {
  254. app.date = null ;
  255. app.dateFormat = null ;
  256. }
  257. // update order
  258. var updateOrder = false ;
  259. if(app.isChangeState('date', 'point-sale', 'products')
  260. || app.isChangeState('date', 'date', 'point-sale')
  261. || app.isChangeState('point-sale', 'date', 'products')
  262. || app.isChangeState('point-sale', 'point-sale', 'date')) {
  263. updateOrder = true ;
  264. }
  265. if(updateOrder) {
  266. app.updateOrder(response);
  267. }
  268. if(type == 'first') {
  269. if(app.getDate() && app.pointSaleActive) {
  270. app.step = 'products' ;
  271. if(response.data.products) {
  272. app.products = response.data.products;
  273. }
  274. app.updateOrder(response);
  275. }
  276. else if(app.producer.option_order_entry_point == 'point-sale') {
  277. app.step = 'point-sale' ;
  278. }
  279. else if(app.getDate() && app.producer && app.producer.option_order_entry_point == 'date') {
  280. app.step = 'point-sale' ;
  281. }
  282. else {
  283. app.step = 'date' ;
  284. }
  285. }
  286. if(response.data.categories) {
  287. app.categories = response.data.categories ;
  288. for(keyCategory in response.data.categories) {
  289. var category = response.data.categories[keyCategory];
  290. if(category.id && app.countProductsByCategory(category)) {
  291. app.setCategoryCurrent(category, true) ;
  292. break;
  293. }
  294. }
  295. }
  296. setTimeout(function() {
  297. app.responsive();
  298. opendistrib_products();
  299. }, 500);
  300. app.loading = false ;
  301. app.loadingInit = false ;
  302. });
  303. },
  304. updateOrder: function(response) {
  305. var app = this;
  306. if(response.data.products) {
  307. app.products = response.data.products;
  308. }
  309. app.order = null ;
  310. if(response.data.order) {
  311. app.order = response.data.order ;
  312. app.comment = app.order.comment ;
  313. if(app.order.delivery_address && app.order.delivery_address.length > 0) {
  314. app.deliveryAddress = app.order.delivery_address ;
  315. }
  316. app.pointSaleActive = app.getPointSale(response.data.order.id_point_sale) ;
  317. }
  318. else {
  319. app.comment = null ;
  320. app.deliveryAddress = null ;
  321. if(app.user.address && app.user.address.length > 0) {
  322. app.deliveryAddress = app.user.address ;
  323. }
  324. }
  325. },
  326. isMobile: function() {
  327. var width_window = parseInt($(window).width());
  328. return width_window <= 768;
  329. },
  330. responsive: function() {
  331. var app = this;
  332. app.responsiveApply();
  333. $(window).resize(function() {
  334. app.responsiveApply();
  335. });
  336. },
  337. responsiveApply: function() {
  338. var $td_summary = $('#products tr.total td.summary');
  339. if(this.isMobile()) {
  340. $td_summary.attr('colspan', 3);
  341. }
  342. else {
  343. $td_summary.attr('colspan', 4);
  344. }
  345. },
  346. isChangeState: function(entryPoint, oldStep, newStep) {
  347. return this.producer
  348. && entryPoint == this.producer.option_order_entry_point
  349. && oldStep == this.oldStep
  350. && newStep == this.step ;
  351. },
  352. nextStep: function() {
  353. this.errors = [] ;
  354. var oldStep = this.step ;
  355. var nextStep = null ;
  356. // par point de vente
  357. if(this.producer && this.producer.option_order_entry_point == 'point-sale') {
  358. if(oldStep == 'point-sale') {
  359. nextStep = 'date' ;
  360. }
  361. else if(oldStep == 'date') {
  362. nextStep = 'products' ;
  363. }
  364. }
  365. // par date
  366. else {
  367. if(oldStep == 'date') {
  368. nextStep = 'point-sale' ;
  369. }
  370. else if(oldStep == 'point-sale') {
  371. nextStep = 'products' ;
  372. }
  373. }
  374. if(nextStep) {
  375. this.changeStep(nextStep) ;
  376. }
  377. },
  378. changeStep: function(step) {
  379. this.errors = [] ;
  380. var oldStep = this.step ;
  381. this.oldStep = oldStep ;
  382. if(oldStep == 'products' && step == 'payment') {
  383. this.checkProducts() ;
  384. }
  385. if(!this.errors.length) {
  386. this.step = step ;
  387. this.init('basic', oldStep, step) ;
  388. }
  389. },
  390. dayClickList: function(event) {
  391. var dateStr = event.currentTarget.getAttribute('data-distribution-date') ;
  392. var dateObject = new Date(dateStr.replace(/-/g, "/")) ;
  393. if(this.isAvailableDate(dateObject)) {
  394. this.dayClickEvent(dateObject) ;
  395. }
  396. },
  397. dayClick: function(day) {
  398. if(this.isAvailableDate(day.date)) {
  399. this.dayClickEvent(day.date) ;
  400. }
  401. },
  402. dayClickEvent: function(date) {
  403. this.date = date ;
  404. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  405. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  406. + this.date.getFullYear() ;
  407. this.nextStep() ;
  408. },
  409. isAvailableDate: function(date) {
  410. for(var key in this.calendar.availableDates) {
  411. if(date.getTime() == this.calendar.availableDates[key].start.getTime()) {
  412. return true ;
  413. }
  414. }
  415. return false ;
  416. },
  417. pointSaleClick: function(event) {
  418. var app = this ;
  419. var idPointSale = event.currentTarget.getAttribute('data-id-point-sale') ;
  420. var hasCode = event.currentTarget.getAttribute('data-code') ;
  421. if(hasCode) {
  422. axios.get('ajax-validate-code-point-sale',{params: {
  423. idPointSale: idPointSale,
  424. code: this.pointsSaleCodes[idPointSale]
  425. }}).then(function(response) {
  426. if(response.data) {
  427. app.pointsSale[app.getPointSaleKey(idPointSale)].invalid_code = false ;
  428. app.validatePointSale(idPointSale) ;
  429. }
  430. else {
  431. app.pointsSale[app.getPointSaleKey(idPointSale)].invalid_code = true ;
  432. Vue.set(app.pointsSaleCodes, idPointSale, '');
  433. }
  434. }) ;
  435. }
  436. else {
  437. this.validatePointSale(idPointSale) ;
  438. }
  439. },
  440. validatePointSale: function(idPointSale) {
  441. this.pointSaleActive = this.getPointSale(idPointSale) ;
  442. if(this.pointSaleActive.credit_functioning == 'mandatory' || (this.pointSaleActive.credit_functioning == 'user' && this.user.credit_active)) {
  443. this.useCredit = true ;
  444. }
  445. this.nextStep() ;
  446. },
  447. productQuantityClick: function(product, quantity) {
  448. if( this.products[product.index].quantity_form + quantity >= 0 &&
  449. (this.products[product.index].quantity_form + quantity <= (this.products[product.index].quantity_remaining * this.products[product.index].coefficient_unit) ||
  450. !this.products[product.index].quantity_max)
  451. ) {
  452. var theQuantity = parseFloat(this.products[product.index].quantity_form) + parseFloat(quantity);
  453. this.products[product.index].quantity_form = parseFloat(theQuantity.toFixed(2)) ;
  454. }
  455. },
  456. oneProductOrdered: function() {
  457. for(var key in this.products) {
  458. if(this.products[key].quantity_form > 0) {
  459. return true ;
  460. }
  461. }
  462. return false ;
  463. },
  464. countProductOrdered: function() {
  465. var count = 0 ;
  466. for(var key in this.products) {
  467. if(this.products[key].quantity_form > 0) {
  468. if(this.products[key].unit != 'piece') {
  469. count ++ ;
  470. }
  471. else {
  472. count += this.products[key].quantity_form ;
  473. }
  474. }
  475. }
  476. return count ;
  477. },
  478. priceTotal: function(format) {
  479. var price = 0 ;
  480. for(var key in this.products) {
  481. var quantity = this.products[key].quantity_form;
  482. if(quantity > 0) {
  483. price += (quantity / this.products[key].unit_coefficient) * this.getBestProductPrice(this.products[key].id, this.products[key].quantity_form);
  484. }
  485. }
  486. if(format) {
  487. return this.formatPrice(price) ;
  488. }
  489. else {
  490. return numberDecimals(price, 2) ;
  491. }
  492. },
  493. productHasPrice: function(product) {
  494. return product.prices && product.prices.length > 0;
  495. },
  496. productHasPriceWithFromQuantity: function(product) {
  497. if(this.productHasPrice(product)) {
  498. for(var i = 0; i < product.prices.length; i++) {
  499. if(product.prices[i].from_quantity > 0) {
  500. return true;
  501. }
  502. }
  503. }
  504. return false;
  505. },
  506. getBestProductPrice: function(idProduct, theQuantity) {
  507. var thePriceWithTax = 9999;
  508. var product = this.getProduct(idProduct);
  509. var pricesArray = product.prices;
  510. var unitCoefficient = product.unit_coefficient;
  511. if(theQuantity) {
  512. theQuantity = theQuantity / unitCoefficient;
  513. }
  514. for(var i = 0; i < pricesArray.length ; i++) {
  515. var priceWithTax = pricesArray[i].price_with_tax;
  516. var fromQuantity = pricesArray[i].from_quantity;
  517. if(priceWithTax < thePriceWithTax && fromQuantity <= theQuantity) {
  518. thePriceWithTax = priceWithTax;
  519. }
  520. }
  521. if(thePriceWithTax == 9999) {
  522. return 0;
  523. }
  524. else {
  525. return thePriceWithTax;
  526. }
  527. },
  528. isPaymentMethodOnsiteActive: function() {
  529. return this.pointSaleActive && this.pointSaleActive.payment_method_onsite
  530. && !this.isPaymentMethodCreditActiveFunctioningUser(true)
  531. && !this.isPaymentMethodCreditActiveFunctioningMandatory();
  532. },
  533. isPaymentMethodCreditActive: function() {
  534. return this.isPaymentMethodCreditActiveFunctioningOptional()
  535. || this.isPaymentMethodCreditActiveFunctioningMandatory()
  536. || this.isPaymentMethodCreditActiveFunctioningUser(true);
  537. },
  538. isPaymentMethodCreditActiveCheckBase: function() {
  539. return this.producer && this.producer.credit
  540. && this.pointSaleActive && this.pointSaleActive.payment_method_credit;
  541. },
  542. isPaymentMethodCreditActiveFunctioningUser: function(userCreditActive) {
  543. return this.isPaymentMethodCreditActiveCheckBase()
  544. && this.pointSaleActive.credit_functioning == 'user'
  545. && this.user && this.user.credit_active == userCreditActive;
  546. },
  547. isPaymentMethodCreditActiveFunctioningMandatory: function() {
  548. return this.isPaymentMethodCreditActiveCheckBase()
  549. && this.pointSaleActive.credit_functioning == 'mandatory';
  550. },
  551. isPaymentMethodCreditActiveFunctioningOptional: function() {
  552. return this.isPaymentMethodCreditActiveCheckBase()
  553. && this.pointSaleActive.credit_functioning == 'optional';
  554. },
  555. isPaymentMethodOnlineActive: function() {
  556. return this.producer && this.producer.online_payment
  557. && this.pointSaleActive && this.pointSaleActive.payment_method_online
  558. && !this.isPaymentMethodCreditActiveFunctioningUser(true)
  559. && !this.isPaymentMethodCreditActiveFunctioningMandatory()
  560. },
  561. errorCreditMandatoryAndLimit: function() {
  562. return this.user
  563. && this.pointSaleActive
  564. && this.pointSaleActive.payment_method_credit
  565. && (this.pointSaleActive.credit_functioning == 'mandatory'
  566. || (this.pointSaleActive.credit_functioning == 'user' && this.user.credit_active))
  567. && !this.checkCreditLimit(this.order);
  568. },
  569. confirmClick: function() {
  570. var app = this ;
  571. // delivery
  572. if(app.pointSaleActive.is_home_delivery && !app.deliveryAddress) {
  573. this.errors = [] ;
  574. this.errors.push('Veuillez saisir une adresse de livraison.') ;
  575. opendistrib_scroll('page-title');
  576. return false ;
  577. }
  578. // montant minimum de commande
  579. if(app.pointSaleActive.minimum_order_amount > 0 && app.priceTotal() < app.pointSaleActive.minimum_order_amount) {
  580. this.errors = [] ;
  581. this.errors.push('Le montant minimum de commande est de '+app.formatPrice(app.pointSaleActive.minimum_order_amount)+' pour ce point de vente.') ;
  582. opendistrib_scroll('page-title');
  583. return false ;
  584. }
  585. // guest form
  586. var $signupGuestForm = $('#signup-guest form') ;
  587. if($signupGuestForm.length > 0 && !$signupGuestForm.valid()) {
  588. $signupGuestForm.submit() ;
  589. return false ;
  590. }
  591. var user = false ;
  592. if(this.producer.option_allow_order_guest && !this.user) {
  593. user = {
  594. email: $('#signupguest-email').val(),
  595. password: $('#signupguest-password').val(),
  596. firstname: $('#signupguest-firstname').val(),
  597. lastname: $('#signupguest-lastname').val(),
  598. phone: $('#signupguest-phone').val(),
  599. } ;
  600. }
  601. // products
  602. var productsArray = {} ;
  603. for(var key in this.products) {
  604. if( this.products[key].quantity_form != null &&
  605. this.products[key].quantity_form > 0) {
  606. productsArray[this.products[key].id] = this.products[key].quantity_form ;
  607. }
  608. }
  609. app.disableConfirmButton = true ;
  610. axios.post('ajax-process', {
  611. Order: {
  612. id_distribution : this.distribution.id,
  613. id_point_sale: this.pointSaleActive.id,
  614. comment: this.comment,
  615. delivery_home: this.pointSaleActive.is_home_delivery,
  616. delivery_address: this.deliveryAddress
  617. },
  618. code_point_sale: this.pointsSaleCodes[this.pointSaleActive.id],
  619. products: productsArray,
  620. payment_method: this.paymentMethod,
  621. user: user
  622. }).then(function(response) {
  623. if(response.data.status == 'success') {
  624. app.errors = [] ;
  625. if(response.data.redirect && response.data.redirect.length > 0) {
  626. window.location.href = response.data.redirect ;
  627. }
  628. else {
  629. window.location.href = opendistrib_base_url(true)+'order/confirm?idOrder='+response.data.idOrder ;
  630. }
  631. }
  632. else {
  633. app.errors = response.data.errors ;
  634. window.scroll(0, $('#page-title').offset().top) ;
  635. app.disableConfirmButton = false ;
  636. }
  637. });
  638. },
  639. checkProducts: function() {
  640. if(!this.oneProductOrdered()) {
  641. this.errors.push('Veuillez sélectionner au moins un produit.') ;
  642. }
  643. },
  644. checkCreditLimit: function(order) {
  645. var total = this.priceTotal() ;
  646. if(order != null) {
  647. total = this.priceTotal() - order.amount_paid ;
  648. }
  649. return this.producer.credit_limit == null || (this.producer.credit_limit != null && (this.user.credit - total >= this.producer.credit_limit)) ;
  650. },
  651. isProductAvailable: function(product) {
  652. return product.productDistribution && product.productDistribution[0] && product.productDistribution[0].active == 1;
  653. },
  654. countProductsByCategory: function(category) {
  655. var count = 0 ;
  656. for(var i = 0 ; i < this.products.length ; i++) {
  657. if(this.products[i].id_product_category == category.id && this.isProductAvailable(this.products[i])) {
  658. count ++ ;
  659. }
  660. }
  661. return count ;
  662. },
  663. countSelectedProductsByCategory: function(category) {
  664. var count = 0 ;
  665. for(var key in this.products) {
  666. if(this.products[key].quantity_form > 0 && this.products[key].id_product_category == category.id) {
  667. count ++ ;
  668. }
  669. }
  670. return count ;
  671. },
  672. setCategoryCurrent: function(category, first) {
  673. var idScroll = false;
  674. if(this.categoryCurrent && this.categoryCurrent.id == category.id && !first) {
  675. this.categoryCurrent = null ;
  676. }
  677. else {
  678. this.categoryCurrent = category ;
  679. if(!first) {
  680. idScroll = 'category'+this.categoryCurrent.id;
  681. }
  682. }
  683. setTimeout(function() {
  684. opendistrib_products();
  685. }, 500);
  686. if(idScroll) {
  687. setTimeout(opendistrib_scroll, 250, idScroll);
  688. }
  689. }
  690. },
  691. computed : {
  692. orderedPointsSale: function() {
  693. var orderedPointsSaleArray = this.pointsSale.sort(function(a, b) {
  694. if(a.position > b.position) {
  695. return 1 ;
  696. }
  697. else {
  698. return -1 ;
  699. }
  700. }) ;
  701. return orderedPointsSaleArray ;
  702. }
  703. },
  704. updated: function () {
  705. var app = this;
  706. this.$nextTick(function () {
  707. if(app.step == 'products' && !app.user && app.producer.option_allow_order_guest) {
  708. $("#signup-guest form").validate({
  709. rules: {
  710. 'SignupForm[email]': {
  711. 'email': true,
  712. 'required': true,
  713. 'minlength': 8,
  714. 'maxlength': 255
  715. },
  716. 'SignupForm[password]': {
  717. 'required': true,
  718. 'minlength': 8,
  719. "maxlength": 255
  720. },
  721. 'SignupForm[firstname]': {
  722. 'required': true,
  723. 'minlength': 2,
  724. "maxlength": 255
  725. },
  726. 'SignupForm[lastname]': {
  727. 'required': true,
  728. 'minlength': 2,
  729. "maxlength": 255
  730. },
  731. 'SignupForm[phone]': {
  732. 'required': true,
  733. 'minlength': 2,
  734. "maxlength": 255
  735. },
  736. },
  737. messages: {
  738. 'SignupForm[email]' : {
  739. 'required': 'Ce champs est requis.',
  740. 'email' : 'Email invalide.'
  741. },
  742. 'SignupForm[password]' : {
  743. 'required': 'Ce champs est requis.',
  744. },
  745. 'SignupForm[firstname]' : {
  746. 'required': 'Ce champs est requis.',
  747. },
  748. 'SignupForm[lastname]' : {
  749. 'required': 'Ce champs est requis.',
  750. },
  751. 'SignupForm[phone]' : {
  752. 'required': 'Ce champs est requis.',
  753. },
  754. }
  755. }) ;
  756. }
  757. });
  758. }
  759. });
  760. Vue.component('step-date',{
  761. props: [
  762. 'step',
  763. 'pointSaleActive',
  764. 'dateFormat',
  765. 'changeStep',
  766. 'producer',
  767. 'first',
  768. ],
  769. data: function() {
  770. return {
  771. } ;
  772. },
  773. template: '#template-step-date',
  774. methods: {
  775. }
  776. }) ;
  777. Vue.component('step-point-sale',{
  778. props: [
  779. 'step',
  780. 'pointSaleActive',
  781. 'changeStep',
  782. 'producer',
  783. 'first',
  784. ],
  785. data: function() {
  786. return {
  787. } ;
  788. },
  789. template: '#template-step-point-sale',
  790. methods: {
  791. }
  792. }) ;