No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

853 líneas
33KB

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