Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

896 lines
36KB

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