選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

206 行
7.2KB

  1. var app = new Vue({
  2. el: '#app-order-order',
  3. data: {
  4. step: 'date',
  5. producer: null,
  6. date: null,
  7. dateFormat: null,
  8. distribution: null,
  9. pointsSale: [],
  10. pointSaleActive: null,
  11. codePointSale: '',
  12. products: [],
  13. comment: '',
  14. creditCheckbox: false,
  15. credit: 0,
  16. orderSuccess: false,
  17. calendar: {
  18. mode: 'single',
  19. attrs: [],
  20. themeStyles: {
  21. wrapper: {
  22. background: '#BB8757',
  23. color: '#fafafa',
  24. },
  25. header: {
  26. padding: '10px 10px',
  27. },
  28. headerHorizontalDivider: {
  29. borderTop: 'solid rgba(255, 255, 255, 0.2) 1px',
  30. width: '80%',
  31. },
  32. weekdays: {
  33. color: 'white',
  34. fontWeight: '600',
  35. padding: '10px 10px',
  36. fontSize: '2rem'
  37. },
  38. weeks: {
  39. padding: '0 15px 15px 15px',
  40. },
  41. dayContent: function(object) {
  42. var style = {
  43. fontSize: '2rem',
  44. padding: '20px',
  45. };
  46. if(object.isHovered || object.isFocus) {
  47. style.backgroundColor = '#F39C12' ;
  48. }
  49. return style ;
  50. },
  51. },
  52. formats: {
  53. dayPopover: 'DD/MM/YYYY'
  54. }
  55. },
  56. },
  57. mounted: function() {
  58. if($('#distribution-date').size()) {
  59. this.date = new Date($('#distribution-date').html()) ;
  60. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  61. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  62. + this.date.getFullYear() ;
  63. }
  64. this.init() ;
  65. },
  66. methods: {
  67. getDate: function() {
  68. return this.formatDate(this.date) ;
  69. },
  70. formatDate: function(date) {
  71. if(date) {
  72. return date.getFullYear() + '-'
  73. + ('0' + (date.getMonth() +1)).slice(-2) + '-'
  74. + ('0' + date.getDate()).slice(-2) ;
  75. }
  76. return false ;
  77. },
  78. formatPrice: function(price) {
  79. var isNumberRegExp = new RegExp(/^[-+]?[0-9]+(\.[0-9]+)*$/);
  80. if(isNumberRegExp.test(price) && price > 0) {
  81. return Number(price).toFixed(2).replace('.',',')+' €' ;
  82. }
  83. return '--' ;
  84. },
  85. getPointSale: function(idPointSale) {
  86. for(var key in this.pointsSale) {
  87. if(this.pointsSale[key].id == idPointSale) {
  88. return this.pointsSale[key] ;
  89. }
  90. }
  91. },
  92. init: function() {
  93. axios.get("ajax-infos",{params: {date : this.getDate()}})
  94. .then(response => {
  95. this.producer = response.data.producer ;
  96. this.credit = response.data.credit ;
  97. this.calendar.attrs = [] ;
  98. var distributions = response.data.distributions ;
  99. if(distributions.length) {
  100. for(var i= 0; i < distributions.length; i++) {
  101. this.calendar.attrs.push({
  102. highlight: {
  103. backgroundColor: '#00A65A',
  104. },
  105. dates: distributions[i].date,
  106. }) ;
  107. }
  108. }
  109. if(response.data.distribution) {
  110. this.distribution = response.data.distribution ;
  111. }
  112. if(response.data.points_sale) {
  113. this.pointsSale = response.data.points_sale ;
  114. }
  115. if(response.data.products) {
  116. this.products = response.data.products ;
  117. }
  118. });
  119. },
  120. changeStep: function(step) {
  121. this.step = step ;
  122. if(step == 'point-sale') {
  123. this.init() ;
  124. }
  125. },
  126. dayClick: function(day) {
  127. this.date = day.date ;
  128. this.dateFormat = ('0' + this.date.getDate()).slice(-2)+ '/'
  129. + ('0' + (this.date.getMonth() +1)).slice(-2) + '/'
  130. + this.date.getFullYear() ;
  131. this.init() ;
  132. this.changeStep('point-sale') ;
  133. },
  134. pointSaleClick: function(event) {
  135. this.pointSaleActive = this.getPointSale(event.currentTarget.getAttribute('data-id-point-sale')) ;
  136. this.changeStep('products') ;
  137. },
  138. productQuantityClick: function(product, quantity) {
  139. if( this.products[product.index].quantity_form + quantity >= 0 &&
  140. ( !this.products[product.index].quantity_remaining ||
  141. this.products[product.index].quantity_form + quantity <= this.products[product.index].quantity_remaining
  142. )) {
  143. this.products[product.index].quantity_form += quantity ;
  144. }
  145. },
  146. oneProductOrdered: function() {
  147. for(var key in this.products) {
  148. if(this.products[key].quantity_form > 0) {
  149. return true ;
  150. }
  151. }
  152. return false ;
  153. },
  154. countProductOrdered: function() {
  155. var count = 0 ;
  156. for(var key in this.products) {
  157. if(this.products[key].quantity_form > 0) {
  158. count += this.products[key].quantity_form ;
  159. }
  160. }
  161. return count ;
  162. },
  163. priceTotal: function() {
  164. var price = 0 ;
  165. for(var key in this.products) {
  166. if(this.products[key].quantity_form > 0) {
  167. price += this.products[key].quantity_form * this.products[key].price ;
  168. }
  169. }
  170. return this.formatPrice(price) ;
  171. },
  172. confirmClick: function() {
  173. var productsArray = {} ;
  174. for(var key in this.products) {
  175. if( this.products[key].quantity_form != null &&
  176. this.products[key].quantity_form > 0) {
  177. productsArray[this.products[key].id] = this.products[key].quantity_form ;
  178. }
  179. }
  180. axios.post('ajax-create', {
  181. Order: {
  182. id_distribution : this.distribution.id,
  183. id_point_sale: this.pointSaleActive.id,
  184. comment: this.comment
  185. },
  186. code_point_sale: this.codePointSale,
  187. products: productsArray,
  188. use_credit: this.creditCheckbox
  189. }).then(response => {
  190. if(response.data.status == 'success') {
  191. this.orderSuccess = true ;
  192. }
  193. });
  194. }
  195. }
  196. });