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.

261 lines
11KB

  1. // Reference array sent to dynamic staticRenderFns
  2. var staticRenderFns = [];
  3. Vue.component('order-product', {
  4. mixins: [mixinTemplate],
  5. props: ['template', 'keyItem', 'orderProduct', 'editionMode'],
  6. computed: {},
  7. mounted: function () {
  8. this.setFields()
  9. log(this);
  10. },
  11. methods: {
  12. setFields: function () {
  13. var app = this;
  14. fields = ['fieldQuantity', 'fieldProduct'];
  15. fields.forEach(function (field) {
  16. if($(app.$refs[field]).length) {
  17. var name = $(app.$refs[field]).prop('name');
  18. var id = $(app.$refs[field]).prop('id');
  19. name = name.replace(/__name__/g, app.keyItem);
  20. id = id.replace(/__name__/g, app.keyItem);
  21. $(app.$refs[field]).prop('name', name);
  22. $(app.$refs[field]).prop('id', id);
  23. }
  24. });
  25. },
  26. updateOrderProducts: function () {
  27. log(this.editionMode);
  28. this.$parent.updateOrderProducts();
  29. },
  30. deleteOrderProduct: function () {
  31. $(this.$refs.fieldQuantity).val(0);
  32. this.$parent.updateOrderProducts();
  33. },
  34. modalExist:function(modalId){
  35. return this.$parent.modalExist(modalId);
  36. },
  37. modalAddRedeliveryOrderProduct:function () {
  38. $(this.$parent.$refs['addRedeliveryOrderProductFormOrderProduct']).val(this.orderProduct.id);
  39. $(this.$parent.$refs['addRedeliveryOrderProductFormTitle']).val(this.orderProduct.title);
  40. $(this.$parent.$refs['addRedeliveryOrderProductFormUnit']).val(this.orderProduct.unit).trigger('change');
  41. $(this.$parent.$refs['addRedeliveryOrderProductFormQuantityProduct']).val(this.orderProduct.quantityProduct);
  42. $(this.$parent.$refs['addRedeliveryOrderProductFormQuantityOrder']).val(this.orderProduct.quantityOrder);
  43. $('#modal-add-redelivery-order-product').modal('show');
  44. },
  45. modalAddReductionCredit:function () {
  46. $(this.$parent.$refs['addReductionCreditFormTitle']).val(this.orderProduct.title);
  47. $(this.$parent.$refs['addReductionCreditFormValue']).val(this.orderProduct.priceWithTaxAndReduction);
  48. $(this.$parent.$refs['addReductionCreditFormBehaviorTaxRate']).val('tax-included').trigger('change');
  49. $('#modal-add-reduction-credit').modal('show');
  50. }
  51. }
  52. });
  53. appOrder = new Vue({
  54. el: '#lc-order-edit',
  55. delimiters: ['${', '}'],
  56. computed: {
  57. deliveryAddressHtml: function () {
  58. log(this.order.deliveryAddress);
  59. return this.order.deliveryAddress;
  60. }
  61. },
  62. data() {
  63. return Object.assign(
  64. {
  65. templateTest: window.templateTest,
  66. orderProducts: [],
  67. order: [],
  68. orderPaymentFormMeanPayment: null,
  69. orderPaymentFormAmount: null,
  70. orderPaymentFormPaidAt:null,
  71. orderPaymentFormReference:null,
  72. orderPaymentFormComment:null,
  73. orderPaymentFormId: null,
  74. deliveryType: null,
  75. isLoading: true,
  76. addProductId: null,
  77. editionMode: true,
  78. addProductQuantity: null,
  79. sectionsArray: [
  80. {
  81. name: 'cart',
  82. nameDisplay: 'Panier'
  83. },
  84. {
  85. name: 'addresses',
  86. nameDisplay: 'Adresses'
  87. },
  88. {
  89. name: 'delivery',
  90. nameDisplay: 'Livraisons'
  91. }
  92. ]
  93. })/*, window.appOrderProductFamilyValues)*/;
  94. },
  95. mounted: function () {
  96. this.updateOrder(window.orderObject);
  97. this.preventFormSubmit();
  98. //log($(this.$el).find('#orderProductsForm').replace(/__name__/g, 0));
  99. },
  100. methods: {
  101. modalExist:function(modalId){
  102. if($(modalId).length>0){
  103. return true;
  104. }else{
  105. return false;
  106. }
  107. },
  108. preventFormSubmit: function (){
  109. $('#lc-order-edit').keypress(function(e) {
  110. if (e.which == 13) {
  111. e.preventDefault();
  112. }
  113. });
  114. },
  115. switchEditionMode: function(){
  116. if(this.editionMode) {
  117. this.editionMode = false;
  118. }else {
  119. this.editionMode = true;
  120. }
  121. },
  122. /*
  123. //TODO Sélection groupé à utiliser pr les remboursements
  124. modalAddGroupRedeliveryOrderProduct: function (){
  125. log(this.order.orderProducts);
  126. $('#orderProductsAction').find('.order-product-checkbox:checked').each(function (i,checkbox) {
  127. log($(checkbox).val());
  128. });
  129. $(this.$parent.$refs['addRedeliveryOrderProductFormOrderProduct']).val(this.orderProduct.id);
  130. $(this.$parent.$refs['addRedeliveryOrderProductFormTitle']).val(this.orderProduct.title);
  131. $(this.$parent.$refs['addRedeliveryOrderProductFormUnit']).val(this.orderProduct.unit).trigger('change');
  132. $(this.$parent.$refs['addRedeliveryOrderProductFormQuantityProduct']).val(this.orderProduct.quantityProduct);
  133. $(this.$parent.$refs['addRedeliveryOrderProductFormQuantityOrder']).val(this.orderProduct.quantityOrder);
  134. $('#modal-add-redelivery-order-product').modal('show');
  135. },*/
  136. addProductToOrder: function () {
  137. this.postForm('#addProductToOrderForm', false);
  138. },
  139. addOrderPayment: function () {
  140. if($('#order_payment_meanPayment').val() == 'credit'){
  141. if(window.confirm("Vous allez débitez le compte prépayév, êtes vous sur ?")){
  142. this.postForm('#orderPaymentForm', '#modal-order-payment');
  143. }
  144. }else{
  145. this.postForm('#orderPaymentForm', '#modal-order-payment');
  146. }
  147. $('#modal-order-payment').find('#order_payment_id').val('');
  148. },
  149. editOrderPayment:function(id){
  150. this.setOrderPaymentFormValues(this.order.orderPayments[id])
  151. $('#modal-order-payment').modal("show")
  152. },
  153. setOrderPaymentFormValues(orderPayment = false) {
  154. if (orderPayment)this.orderPaymentFormId = orderPayment['id'];
  155. else this.orderPaymentFormId = null;
  156. if (orderPayment) $(this.$refs["meanPaymentSelect"]).val(orderPayment['meanPayment']).trigger('change');
  157. else $(this.$refs["meanPaymentSelect"]).val(false).trigger('change');
  158. if (orderPayment) this.orderPaymentFormAmount = orderPayment['amount'];
  159. else this.orderPaymentFormAmount = null;
  160. if (orderPayment) this.orderPaymentFormPaidAt = orderPayment['paidAt'];
  161. else this.orderPaymentFormPaidAt = false;
  162. if (orderPayment) this.orderPaymentFormReference = orderPayment['reference'];
  163. else this.orderPaymentFormReference = null;
  164. if (orderPayment) this.orderPaymentFormComment = orderPayment['comment'];
  165. this.orderPaymentFormComment = null;
  166. },
  167. modalDeleteOrderPayment:function(id){
  168. $(this.$refs['deleteOrderPaymentId']).val(id);
  169. $('#modal-delete-order-payment').modal("show")
  170. },
  171. deleteOrderPayment: function () {
  172. this.postForm('#deleteOrderPaymentForm', '#modal-delete-order-payment');
  173. },
  174. updateOrderProducts: function () {
  175. this.postForm('#orderProductsForm', false);
  176. },
  177. updateOrderInvoiceAddress: function () {
  178. this.postForm('#orderInvoiceAddressForm', '#modal-order-invoice-address');
  179. },
  180. updateOrderDeliveryAddress: function () {
  181. this.postForm('#orderDeliveryAddressForm', '#modal-order-delivery-address', true);
  182. },
  183. updateOrderDeliveryAvailability: function () {
  184. this.postForm('#orderDeliveryAvailabilityForm', '#modal-order-delivery-availability');
  185. },
  186. addOrderReductionCart: function () {
  187. this.postForm('#addOrderReductionCartForm', '#modal-add-order-reduction-cart');
  188. },
  189. modalDeleteOrderReductionCart: function (id) {
  190. log($(this.$refs['deleteOrderReductionCartId']));
  191. $(this.$refs['deleteOrderReductionCartId']).val(id);
  192. $('#modal-delete-reduction-cart').modal("show")
  193. },
  194. deleteOrderReductionCart: function () {
  195. this.postForm('#deleteOrderReductionCartForm', '#modal-delete-reduction-cart');
  196. },
  197. modalDeleteOrderReductionCredit: function (id) {
  198. $(this.$refs['deleteOrderReductionCreditId']).val(id);
  199. $('#modal-delete-reduction-credit').modal("show")
  200. },
  201. deleteOrderReductionCredit: function () {
  202. this.postForm('#deleteOrderReductionCreditForm', '#modal-delete-reduction-credit');
  203. },
  204. addOrderReductionCredit: function () {
  205. this.postForm('#addOrderReductionCreditForm', '#modal-add-order-reduction-credit');
  206. },
  207. addRedeliveryOrderProduct: function () {
  208. this.postForm('#addRedeliveryOrderProductForm', '#modal-add-redelivery-order-product');
  209. },
  210. addReductionCredit: function () {
  211. this.postForm('#addReductionCreditForm', '#modal-add-reduction-credit');
  212. },
  213. sendPaymentLink: function(){
  214. this.postForm('#orderSendPaymentLinkForm', '#modal-order-send-payment-link');
  215. },
  216. gotoPaymentLink: function(){
  217. this.postForm('#orderSendPaymentLinkForm', '#modal-order-send-payment-link');
  218. },
  219. postForm: function (formId, modalId, refresh =false) {
  220. var app = this;
  221. if(checkFormValidity(formId)) {
  222. this.isLoading = true;
  223. if (modalId) $(modalId).modal('hide');
  224. $.ajax({
  225. url: $(formId).prop('action'),
  226. method: "POST",
  227. data: $(formId).serialize(),
  228. dataType: "json",
  229. success: function (response) {
  230. setFlashMessages(response.flashMessages);
  231. app.updateOrder(response.data);
  232. if(refresh)window.location.reload();
  233. }
  234. });
  235. }
  236. },
  237. updateOrder: function (orderObject) {
  238. this.orderProducts = orderObject.orderProducts;
  239. this.order = orderObject;
  240. this.isLoading = false;
  241. },
  242. },
  243. watch: {}
  244. });