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 31KB

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