Advertisement
Guest User

Branch Johnny antes de hacer arreglo en categorias

a guest
Dec 1st, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 93.14 KB | None | 0 0
  1. <template>
  2. <div class="customers">
  3. <!-- <navbar></navbar> -->
  4. <div v-if="sections.navbar" id="navbar">
  5. <nav class="navbar navbar-default">
  6. <img id="logo" src="~@/assets/logotarget.png" alt="targetmoda">
  7. <div class="container">
  8. <div class="navbar-header">
  9. <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar">
  10. <span class="sr-only">Toggle navigation</span>
  11. <span class="icon-bar"></span>
  12. <span class="icon-bar"></span>
  13. <span class="icon-bar"></span>
  14. </button>
  15. </div>
  16.  
  17. <div id="navbar" class="collapse navbar-collapse">
  18. <!-- <ul class="nav navbar-nav">
  19. <li><router-link to="/">Home</router-link></li>
  20. <li><router-link to="/products">Productos</router-link></li>
  21. </ul> -->
  22.  
  23. <!-- <qty></qty> -->
  24. <div v-on:click="handler('cart')" id="cart-badge" class="button-logout">
  25. <button type="button" class="btn btn-large" title="Ir al carrito">
  26. <!-- <router-link to="/cart"><span class="glyphicon glyphicon-shopping-cart btn-large" aria-hidden="true"></span> <span v-model="badgeItems" class="badge"> {{ badge }}</span></router-link> -->
  27. <span class="icon-Mi_carrito-02 size-3x coral" aria-hidden="true"></span><br><span v-model="badgeItems" class="badge"> {{ badge }}</span>
  28. </button>
  29. </div>
  30. <div v-on:click="syncApp" class="button-logout">
  31. <button type="button" class="btn btn-large" title="Sincronizar aplicación">
  32. <span class="icon-Sincronizar-02 size-3x coral" aria-hidden="true"></span><br><span class="text-uppercase x-small coral">Sincronizar</span>
  33. </button>
  34. </div>
  35. <div v-on:click="goToSection('orders')" class="button-logout">
  36. <button type="button" class="btn btn-large" title="Ver pedidos">
  37. <span class="icon-Pedidos-02 size-3x coral" aria-hidden="true"></span><br><span class="text-uppercase x-small coral">Pedidos</span>
  38. </button>
  39. </div>
  40. <div v-on:click="logout" class="button-logout">
  41. <button type="button" class="btn btn-large" title="Salir y cerrar sesión">
  42. <span class="icon-Salir-02 size-3x coral" aria-hidden="true"></span><br><span class="text-uppercase x-small coral" style="margin-left:10px;">Salir</span>
  43. </button>
  44. </div>
  45. </div>
  46. </div>
  47. </nav>
  48. <div id="success-add-to-cart" class="flash-message">
  49. <div class="alert alert-success">
  50. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  51. <strong>¡Agregado satisfactoriamente!</strong>
  52. </div>
  53. </div>
  54. <div id="success-downloaded-csv" class="flash-message">
  55. <div class="alert alert-success">
  56. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  57. <strong>¡CSV descargado satisfactoriamente!</strong>
  58. </div>
  59. </div>
  60. <div id="error-downloaded-csv" class="flash-message">
  61. <div class="alert alert-danger">
  62. <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
  63. <strong>Error al descargar el CSV</strong>
  64. </div>
  65. </div>
  66. </div>
  67. <div v-if="sections.thanks" id="thanks">
  68. <div class="row">
  69. <div class="jumbotron" style="box-shadow: 2px 2px 4px #000000;">
  70. <h4 class="text-center">El pedido se finalizó y guardó correctamente. <br> Por favor no olvides enviarnos el pedido una vez tengas conexión a Internet</h4>
  71. <center><div class="btn-group" style="margin-top:50px;">
  72. <!-- <div class="btn btn-success"><router-link to="/products">Seguir comprando</router-link></div> -->
  73. <div v-on:click="goToSection('products'), emptyQuoute" class="btn btn-success" id="thanks-keep">Seguir comprando</div>
  74. </div></center>
  75. </div>
  76. </div>
  77. </div>
  78.  
  79. <!-- INDEX Checkout -->
  80. <div v-if="sections.checkout" id="checkout">
  81. <div id="checkout-content">
  82.  
  83. <!-- BREADCRUMBS -->
  84. <div class="page-header">
  85.  
  86. <span v-on:click="goToSection('products')" class="pointerHand">Carrito</span>
  87. >
  88. <span class="active-step">Check Out</span>
  89. >
  90. <span>Pedido finalizado</span>
  91. </div>
  92. <!-- /BREADCRUMBS/ -->
  93.  
  94. <!-- CHECKOUT Body -->
  95. <div class="row grid-divider">
  96. <!-- LEFT Column -->
  97. <div id="order-box" class="col-md-7">
  98. <div class="col-padding">
  99. <h3>TU PEDIDO</h3>
  100. <h4>*Despliegue las categorías para aplicar descuentos individualmente a los productos que seleccionó </h4>
  101. <div v-for="(value, key, index) in categories" class="panel-group">
  102.  
  103. <div class="panel panel-default">
  104. <div class="panel-heading">
  105. <h4 class="panel-title">
  106. <a :href="'#' + key.replace(/[\s\W]/g, '')">{{ key }}<!--<span v-show="!isEmpty(value)"class="caret"></span--></a>
  107. <div class="discount-box">
  108. <label :for="'discount_' + key.replace(/[\s\W]/g, '')">Descuento</label>
  109. <input type="number" min="0" class="discount-input"
  110. :id="'discount_' + key.replace(/[\s\W]/g, '')" @change="setCategoryDiscount(key)" placeholder="%">
  111. </div>
  112. </h4>
  113. </div>
  114. <div :id="key.replace(/[\s\W]/g, '')" class="panel-collapse">
  115.  
  116. <!-- <div v-for="(valueK, keyK, indexK) in value" class="panel-body"> -->
  117. <div class="panel-body">
  118.  
  119.  
  120. <div class="border-box">
  121. <table :class="'table table-hover table-condensed table_cat_' + key.replace(/\s/g, '')">
  122. <!-- <table style="display:none" :class="'table table-hover table-condensed'"> -->
  123. <thead>
  124. <tr>
  125. <th class="col-xs-2">Foto</th>
  126. <th class="col-xs-2">Producto</th>
  127. <th class="col-xs-1">Precio</th>
  128. <th class="col-xs-1">Cantidad</th>
  129. <th class="col-xs-1">% Desc.</th>
  130. <th class="text-center col-xs-1">Subtotal</th>
  131. </tr>
  132. </thead>
  133. <tbody>
  134. <!-- <tr v-if="checkProductParentCat(valueP.data.categories, key.replace(/\s/g, ''))" v-for="(valueP, keyP, indexP) in sessionProductsData"> -->
  135. <tr v-if="fetchCategories()" v-for="(valueP, keyP, indexP) in sessionProductsData">
  136. categories --> {{valueP.data.categories}}
  137. <td data-th="Product">
  138. <div class="row">
  139. <div class="col-sm-2 hidden-xs">
  140. <img class="product-image" v-bind:src="'file://' + valueP.data.images[0].local_src" alt="" />
  141. </div>
  142. </div>
  143. </td>
  144. <td data-th="Product">
  145. <div class="row">
  146. <div class="col-sm-10">
  147.  
  148. <div class="nomargin title-table">
  149. <input :id="'checkbox_' + keyP" type="checkbox" :value="keyP.replace(/\s/g, '')" checked>
  150. {{valueP.data.title}}
  151. </div>
  152. <!-- <h4 class="nomargin">{{keyK}}</h4> -->
  153. </div>
  154. </div>
  155. </td>
  156. <input type="hidden" class="show_table_desc" :value="key.replace(/\s/g, '')"/>
  157. <td data-th="Quantity">
  158. <div class="text-center price-table">${{valueP.data.price}}</div>
  159. </td>
  160. <td data-th="Quantity">
  161. <span class="form-control text-center">{{valueP.data.qty}}</span>
  162. </td>
  163. <td data-th="Quantity">
  164. <input type="number" min="0"
  165. :class="'form-control text-center discount-input-' + keyP.replace(/\s/g, '')"
  166. :id="'discount_' + keyP.replace(/\s/g, '')" placeholder="%"
  167. value="" @change="setProductDiscount(keyP.replace(/\s/g, ''))">
  168. </td>
  169.  
  170. <td style="padding-top:4%" data-th="Subtotal" class="text-center" v-if="valueP.data.subtotal > 0">
  171. <strike>${{ valueP.data.price * valueP.data.qty }}<br></strike>
  172. ${{ valueP.data.subtotal }}</td>
  173. <td style="padding-top:4%" data-th="Subtotal" class="text-center" v-else>
  174. ${{ valueP.data.price * valueP.data.qty }}
  175. </td>
  176. </tr>
  177.  
  178. </tbody>
  179. <tfoot>
  180.  
  181. </tfoot>
  182. </table>
  183. </div>
  184.  
  185.  
  186. <div class="panel panel-default">
  187. <!-- <div class="panel-heading">
  188. <h4 class="panel-title">
  189. <a data-toggle="collapse" :href="'#' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')">{{ keyK }}<span v-show="!isEmpty(valueK)"class="caret"></span></a>
  190. <div class="discount-box">
  191. <label :for="'discount_' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')">Descuento </label>
  192. <input type="number"
  193. min="0" :class="'discount-input-' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')" :id="'discount_' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')"
  194. @change="setCategoryDiscount(key + '_' + keyK)" placeholder="%">
  195. </div>
  196. </h4>
  197. </div> -->
  198. </div>
  199. <div class="panel panel-default">
  200. <!-- <div class="panel-heading">
  201. <h4 class="panel-title">
  202. <a data-toggle="collapse" :href="'#' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')">{{ keyK }}<span v-show="!isEmpty(valueK)"class="caret"></span></a>
  203. <div class="discount-box">
  204. <label :for="'discount_' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')">Descuento </label>
  205. <input type="number"
  206. min="0" :class="'discount-input-' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')" :id="'discount_' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')"
  207. @change="setCategoryDiscount(key + '_' + keyK)" placeholder="%">
  208. </div>
  209. </h4>
  210. </div> -->
  211.  
  212. <!-- <div :id="key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '')" class="panel-collapse collapse">
  213. <div v-for="(valueM, keyM, indexM) in valueK" class="panel-body">
  214. <div class="border-box">
  215. <table style="display:none" :class="'table table-hover table-condensed table_cat_' + keyM">
  216. <thead>
  217. <tr>
  218. <th class="col-xs-2">Foto</th>
  219. <th class="col-xs-2">Producto</th>
  220. <th class="col-xs-1">Precio</th>
  221. <th class="col-xs-1">Cantidad</th>
  222. <th class="col-xs-2">% Desc.</th>
  223. <th class="text-center col-xs-1">Subtotal</th>
  224. </tr>
  225. </thead>
  226. <tbody>
  227. <tr v-if="valuePQ.data.categories[0].replace(/\s/g, '') === keyM.replace(/\s/g, '')" v-for="(valuePQ, keyPQ, indexPQ) in sessionProductsData">
  228. <td data-th="Product">
  229. <div class="row">
  230. <div class="col-sm-2 hidden-xs">
  231. <img class="product-image" v-bind:src="'file://' + valuePQ.data.images[0].local_src" alt="" />
  232. </div>
  233. </div>
  234. </td>
  235. <td data-th="Product">
  236. <div class="row">
  237. <div class="col-sm-10">
  238.  
  239. <div class="nomargin title-table">
  240. <input :id="'checkbox_' + keyPQ" type="checkbox" :value="keyPQ.replace(/\s/g, '')" checked>
  241. {{valuePQ.data.title}}
  242. </div>
  243.  
  244. </div>
  245. </div>
  246. </td>
  247. <input type="hidden" class="show_table_desc" :value="valuePQ.data.categories[0].replace(/\s/g, '')"/>
  248. <td data-th="Quantity">
  249. <div class="text-center price-table">${{valuePQ.data.price}}</div>
  250. </td>
  251. <td data-th="Quantity">
  252. <span class="form-control text-center">{{valuePQ.data.qty}}</span>
  253. </td>
  254. <td data-th="Quantity">
  255. <input class="form-control text-center" type="number" min="0"
  256. :class="'discount-input-' + keyPQ.replace(/\s/g, '')"
  257. :id="'discount_' + keyPQ.replace(/\s/g, '')" placeholder="%"
  258. value="" @change="setProductDiscount(keyPQ.replace(/\s/g, ''))">
  259.  
  260. </td>
  261.  
  262. <td style="padding-top:4%" data-th="Subtotal" class="text-center" v-if="valuePQ.data.subtotal > 0">
  263. <strike>${{ valuePQ.data.price * valuePQ.data.qty }}<br></strike>
  264. ${{ valuePQ.data.subtotal }}</td>
  265. <td style="padding-top:4%" data-th="Subtotal" class="text-center" v-else>
  266. ${{ valuePQ.data.price * valuePQ.data.qty }}
  267. </td>
  268. </tr>
  269. </tbody>
  270. <tfoot>
  271.  
  272. </tfoot>
  273. </table>
  274. </div>
  275.  
  276. <div class="">
  277. <div class="panel-heading last-child-cat">
  278. <h4 class="panel-title">
  279. <span>{{ keyM }}</span>
  280. <div class="discount-box">
  281. <label :for="'discount_' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '') + '_' + keyM.replace(/[\s\W]/g, '')">Descuento </label>
  282. <input type="number" min="0" :class="'discount-input-' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '') + '_' + keyM.replace(/[\s\W]/g, '')" :id="'discount_' + key.replace(/[\s\W]/g, '') + '_' + keyK.replace(/[\s\W]/g, '') + '_' + keyM.replace(/[\s\W]/g, '')" @change="setCategoryDiscount(key + '_' + keyK + '_' + keyM)" placeholder="%">
  283. </div>
  284. </h4>
  285.  
  286.  
  287. </div>
  288. </div>
  289. </div>
  290. </div> -->
  291. </div>
  292. </div>
  293. </div>
  294. </div>
  295.  
  296. </div>
  297. <div class="panel-group">
  298. <div class="panel panel-default">
  299. <div style="border-top:solid 1px #ccc"class="panel-heading">
  300. <div class="total-order"><strong>Total ${{totalCart}}</strong></div>
  301. </div>
  302. </div>
  303. </div>
  304.  
  305. </div>
  306. </div>
  307. <!-- /LEFT Column/ -->
  308.  
  309. <!-- RIGHT Column -->
  310. <div class="col-md-5">
  311. <div class="col-padding">
  312. <div class="panel-group">
  313. </div>
  314. <div class="order-box">
  315. </div>
  316. <div class="col-padding">
  317. <h3>NOTAS</h3>
  318. <p>Por favor, ingrese información a tener en cuenta sobre este pedido.</p>
  319. <div class="form-group">
  320. <textarea class="form-control" rows="2" cols="5" id="notes"></textarea>
  321. </div>
  322. </div>
  323. <div class="col-padding">
  324. <h3>ENVÍO</h3>
  325. <p>¿Desea unificar los envíos con pedidos pendientes?</p>
  326. <input type="radio" class="unify-pendings" name="unify-pendings" value="si">
  327. <label for="unify-yes"> Sí </label>
  328.  
  329. <input type="radio" class="unify-pendings" name="unify-pendings" value="no">
  330. <label for="unify-yes"> No </label>
  331.  
  332. <p>¿Desea unificar los envíos con pedidos de PREVENTA?</p>
  333. <input type="radio" class="unify-presale" name="unify-presale" value="si">
  334. <label for="unify-yes"> Sí </label>
  335.  
  336. <input type="radio" class="unify-presale" name="unify-presale" value="no">
  337. <label for="unify-yes"> No </label>
  338. </div>
  339. <!-- <div class="h-divider-large"></div> -->
  340. <div class="col-padding">
  341. <h3>TIEMPO DE ENTREGA</h3>
  342. <!-- <div class="h-divider"></div> -->
  343. <p>La demora de entrega de productos en STOCK es de 10 días hábiles.</p>
  344. <div v-on:click="placeLocalOrder" class="btn btn-success btn-make-order">
  345.  
  346. FINALIZAR PEDIDO
  347.  
  348. </div>
  349. </div>
  350. </div>
  351. </div>
  352. <!-- /RIGHT Column/ -->
  353.  
  354.  
  355. </div>
  356. <!-- /CHECKOUT Body/ -->
  357.  
  358. </div>
  359. </div>
  360. <!-- /INDEX Checkout/ -->
  361.  
  362. <!-- VIEW Order -->
  363. <div v-if="sections.orderDetail">
  364. <div class="container">
  365. <div v-if="!orderDetail.pushed">
  366. <h2>Orden N° {{ orderDetail._id }}</h2>
  367. <hr>
  368. <table class="table table-hover table-condensed">
  369. <thead>
  370. <tr>
  371. <th style="width:50%">Producto</th>
  372. <th style="width:15%">Precio</th>
  373. <th style="width:8%">Cantidad</th>
  374. <th style="width:27%" class="text-center">Subtotal</th>
  375. </tr>
  376. </thead>
  377. <tbody>
  378. <tr v-for="product in orderProducts" >
  379. <td data-th="Product">
  380. <div class="row">
  381. <div class="col-sm-2 hidden-xs"><img class="img-responsive" v-bind:src="'file://' + product.images[0].local_src" alt="" /></div>
  382. <div class="col-sm-10">
  383. <h4 class="nomargin">{{ product.title }}</h4>
  384. <p v-html="product.short_description"></p>
  385. </div>
  386. </div>
  387. </td>
  388. <td data-th="Price" class="price">${{ product.price }}</td>
  389. <td data-th="Quantity">{{ product.quantity }}</td>
  390. <td data-th="Subtotal" class="text-center subtotal">${{ product.price * product.quantity }}</td>
  391. </tr>
  392. </tbody>
  393. </table>
  394. </div>
  395. <div v-else>
  396. <h2>Orden N° {{ orderDetail.order.id }}</h2>
  397. <hr>
  398. <table class="table table-hover table-condensed">
  399. <thead>
  400. <tr>
  401. <th style="width:50%">Producto</th>
  402. <th style="width:15%">Precio</th>
  403. <th style="width:8%">Cantidad</th>
  404. <th style="width:27%" class="text-center">Subtotal</th>
  405. </tr>
  406. </thead>
  407. <tbody>
  408. <tr v-for="product in orderProducts" >
  409. <td data-th="Product">
  410. <div class="row">
  411. <div class="col-sm-2 hidden-xs"><img class="img-responsive" v-bind:src="'file://' + product.images[0].local_src" alt="" /></div>
  412. <div class="col-sm-10">
  413. <h4 class="nomargin">{{ product.title }}</h4>
  414. <p v-html="product.short_description"></p>
  415. </div>
  416. </div>
  417. </td>
  418. <td data-th="Price" class="price">${{ product.price }}</td>
  419. <td data-th="Quantity">{{ product.quantity }}</td>
  420. <td data-th="Subtotal" class="text-center subtotal">${{ product.subtotal }}</td>
  421. </tr>
  422. </tbody>
  423. </table>
  424. </div>
  425. <div v-on:click="goToSection('orders')" class="btn btn-warning"><i class="glyphicon glyphicon-arrow-left"></i>Volver a compras</div>
  426. </div>
  427. </div>
  428. <!--/ VIEW Order /-->
  429.  
  430. <!-- INDEX Orders -->
  431. <div v-if="sections.orders" id="orders">
  432. <div class="container">
  433. <h1 class="text-center">PEDIDOS</h1>
  434. <hr class="hr-title">
  435. <div class="row">
  436. <div v-if="pendingOrders.length">
  437. <h2>Órdenes pendientes</h2>
  438. <table class="table table-hover table-condensed">
  439. <thead>
  440. <tr class="border-bottom">
  441. <th style="width:10%">N°</th>
  442. <th style="width:20%" class="text-center">Cliente</th>
  443. <th style="width:20%" class="text-center">Fecha</th>
  444. <th style="width:20%" class="text-center">Total</th>
  445. <th style="width:10%" class="text-center">Estado</th>
  446. <th style="width:20%"></th>
  447. </tr>
  448. </thead>
  449. <tbody>
  450. <tr v-for="(order, key, index) in pendingOrders">
  451. <td data-th="Order">{{ order._id }}</td>
  452. <td data-th="Customer" class="text-center">{{ order.customer.display_name }}</td>
  453. <td data-th="Date" class="text-center">{{ dateFormat(order.created, 'dd/mm/yyyy HH:MM:ss') }}</td>
  454. <td data-th="Total" class="text-center subtotal">${{ order.total }}</td>
  455. <td data-th="Status" class="text-center">No enviado</td>
  456. <td class="actions text-center" data-th="">
  457. <button v-on:click="viewOrder(order)" class="button-action-order" title="Ver detalle">
  458. <span class="glyphicon icon-Ver-01 coral size-2x" aria-hidden="true"></span>
  459. </button>
  460. <button v-on:click="authorizeOrder(!order.authorized, key)" class="button-action-order" :title="order.authorized ? 'Cancelar envío de la orden' : 'Autorizar envío de la orden'">
  461. <span :class="'glyphicon ' + (order.authorized ? 'glyphicon-ok' : 'glyphicon-remove') + ' coral size-2x'" aria-hidden="true"></span>
  462. </button>
  463. <button v-on:click="removeOrder(order._id, order._rev)" class="button-action-order" title="Eliminar orden">
  464. <span class="glyphicon icon-Eliminar-01 coral size-2x" aria-hidden="true"></span>
  465. </button>
  466. </td>
  467. </tr>
  468. </tbody>
  469. </table>
  470. </div>
  471. <div v-if="pushedOrders.length">
  472. <h2>Órdenes enviadas</h2>
  473. <table class="table table-hover table-condensed">
  474. <thead>
  475. <tr class="border-bottom">
  476. <th style="width:10%">N°</th>
  477. <th style="width:20%" class="text-center">Cliente</th>
  478. <th style="width:20%" class="text-center">Fecha</th>
  479. <th style="width:20%" class="text-center">Total</th>
  480. <th style="width:10%" class="text-center">Estado</th>
  481. <th style="width:20%"></th>
  482. </tr>
  483. </thead>
  484. <tbody>
  485. <tr v-for="order in pushedOrders">
  486. <td data-th="Order">{{ order.order.id }}</td>
  487. <td data-th="Customer" class="text-center">{{ order.order.customer.username }}</td>
  488. <td data-th="Date" class="text-center">{{ dateFormat(order.order.created_at, 'dd/mm/yyyy HH:MM:ss') }}</td>
  489. <td data-th="Total" class="text-center subtotal">${{ order.order.total }}</td>
  490. <td data-th="Status" class="text-center">Enviado</td>
  491. <td class="actions text-center" data-th="">
  492. <button v-on:click="viewOrder(order)" class="button-action-order" title="Ver detalle">
  493. <span class="icon-Ver-01 coral size-2x" aria-hidden="true"></span>
  494. </button>
  495. <button v-on:click="downloadCSV(order)" class="button-action-order" title="Descargar CSV">
  496. <span class="icon-Descargar-01 coral size-2x" aria-hidden="true"></span>
  497. </button>
  498. </td>
  499. </tr>
  500. </tbody>
  501. </table>
  502. </div>
  503. </div>
  504. <div v-on:click="goToSection('products')" class="btn btn-warning"><i class="glyphicon glyphicon-arrow-left"></i>Volver al catálogo</div>
  505. </div>
  506. </div>
  507. <!--/ INDEX Orders /-->
  508.  
  509. <!-- INDEX Cart -->
  510. <div v-if="sections.cart" id="cart">
  511. <div id="cart-content">
  512. <table class="table table-hover table-condensed">
  513. <thead>
  514. <tr>
  515. <th >PRODUCTO</th>
  516. <th style="width:10%"></th>
  517. <th style="width:30%"></th>
  518. <th style="width:10%">PRECIO</th>
  519. <th style="width:8%">CANTIDAD</th>
  520. <th style="width:22%" class="text-center">Total</th>
  521. <th style="width:10%"></th>
  522. </tr>
  523. </thead>
  524. <tbody>
  525. <tr v-for="(value, key, index) in sessionProductsData">
  526. <td >
  527. <div v-on:click="deleteCartProductById(key)" class="btn box-delete-product">
  528. <span v-bind="dataBindCartProducts(key, 'delete')" class="glyphicon glyphicon-remove-circle" aria-hidden="true"></span>
  529. </div>
  530. </td>
  531. <td data-th="Product">
  532. <div class="row">
  533. <div class="col-sm-2 hidden-xs">
  534. <img class="product-image" v-bind:src="'file://' + value.data.images[0].local_src" alt="" />
  535. </div>
  536. </div>
  537. </td>
  538. <td>
  539. <div class="col-sm-10">
  540. <span class="nomargin">{{value.data.title}}</span>
  541. </div>
  542. </td>
  543. <td data-th="Price" class="price">${{value.data.price}}</td>
  544. <td data-th="Quantity">
  545. <input type="number" class="form-control text-center" :class="cartQty(key)" :step="value.data.step" v-model="value.data.qty" @change="itemQtyCart($event, value.data.id)">
  546. </td>
  547. <td data-th="Subtotal" :class="cartSubtotal(key)" class="text-center subtotal">${{ value.data.price * value.data.qty }}</td>
  548. <td class="actions" data-th="Subtotal"></td>
  549. </tr>
  550. </tbody>
  551. <tfoot></tfoot>
  552. </table>
  553. </div>
  554. <div class="col-sm-5">
  555. <div class="col-padding">
  556. <h3>TOTAL</h3>
  557. <div class="order-box">
  558. <table class="table table-hover table-condensed">
  559. <thead>
  560. <tr>
  561. <th style="width:80%"></th>
  562. <th style="width:10%"></th>
  563. </tr>
  564. </thead>
  565. <tbody>
  566. <tr>
  567. <td data-th="Product">
  568. <div class="row">
  569. <div class="col-sm-10">
  570. <h4 class="nomargin">Subtotal</h4>
  571. </div>
  572. </div>
  573. </td>
  574. <td data-th="Product">
  575. <div class="row">
  576. <div class="col-sm-10">
  577. <h4 class="nomargin">${{totalCart}}</h4>
  578. </div>
  579. </div>
  580. </td>
  581. </tr>
  582. <tr>
  583. <td data-th="Product">
  584. <div class="row">
  585. <div class="col-sm-10">
  586. <h4 class="nomargin">Total</h4>
  587. </div>
  588. </div>
  589. </td>
  590. <td data-th="Product">
  591. <div class="row">
  592. <div class="col-sm-10">
  593. <h4 class="nomargin">${{totalCart}}</h4>
  594. </div>
  595. </div>
  596. </td>
  597. </tr>
  598. <tr>
  599. <td data-th="Product"></td>
  600. <td></td>
  601. </tr>
  602. </tbody>
  603. <tfoot></tfoot>
  604. </table>
  605. <div class="row">
  606. <div v-on:click="saveQuoteToSession" class="btn btn-success go-to-checkout">
  607. CHECK OUT
  608. </div>
  609. </div>
  610. <div class="row">
  611. <div v-on:click="goToSection('products')" class="btn btn-warning go-to-products"><i class="fa fa-angle-left"></i>SEGUIR COMPRANDO</div>
  612. </div>
  613. </div>
  614. </div>
  615. </div>
  616. </div>
  617. <!-- /INDEX Cart/ -->
  618.  
  619. <div v-if="sections.products" class="products">
  620. <!-- <navbar></navbar> -->
  621. <div id="products-content">
  622. <nav class="devsite-section-nav devsite-nav nocontent" style="left: auto; max-height: 643px; position: relative; top: 0px;">
  623. <div id="client-box">
  624. <span>CLIENTE </span>
  625. <p>Seleccione el cliente del que va a realizar el pedido </p>
  626. </div>
  627. <select class="customerSelect" v-model="sellerCustomerSelected">
  628. <option value="">Seleccione un cliente</option>
  629. <option v-for="customer in sellerCustomers" v-on:click="setCustomer(customer.ID)" v-bind:value="customer.ID">{{ customer.display_name }} | {{ customer.user_email }}</option>
  630. </select>
  631. <ul class="devsite-nav-list devsite-nav-expandable">
  632. <div id="search-input" class="container">
  633. <div class="row">
  634. <div class="col-md-2">
  635. <span>BUSCADOR </span>
  636. <p>Utilice el buscador para encontrar productos rápidamente </p>
  637. <div id="custom-search-input">
  638. <div class="input-group col-md-12">
  639. <input v-model="sku" type="text" class="form-control input-lg" placeholder="Ingrese su búsqueda" />
  640. <span class="input-group-btn">
  641. <button v-bind:disabled="!sku" v-on:click="filterSearch" class="btn btn-info btn-lg" type="button">
  642. <i class="glyphicon glyphicon-search"></i>
  643. </button>
  644. </span>
  645. </div>
  646. </div>
  647. </div>
  648. </div>
  649. </div>
  650. <!-- CATEGORIES -->
  651. <li class="devsite-nav-item devsite-nav-item-heading1">
  652. <span class="devsite-nav-title devsite-nav-title-no-path" track-type="leftNav" track-name="expandNavSectionNoLink" track-metadata-position="0">
  653. <div id="categories-box">
  654. <span >CATEGORÍAS</span>
  655. <p>Seleccione una categoría para comenzar a comprar </p>
  656. </div>
  657. </span>
  658. </li>
  659. <div class="dropdown pointerHand">
  660. <ul id="cats" v-for="(value, key, index) in categories" class="upperCase head-ul-first devsite-nav-item devsite-nav-item-heading">
  661. <li v-if="!isEmpty(value)">
  662. <div v-on:click="pagination(key, 'categories')" v-bind:id="key"
  663. class="devsite-nav-title devsite-nav-title-no-path dropdown-toggle"
  664. track-type="leftNav"
  665. track-name="expandNavSectionNoLink"
  666. track-metadata-position="0"
  667. data-toggle="dropdown" aria-haspopup="true" aria-expanded="true"
  668. >{{ key }}<span class="caret"></span></div>
  669. <ul class="head-ul-first devsite-nav-item devsite-nav-item-heading dropdown-menu" data-toggle="dropdown" aria-haspopup="true" v-bind:aria-labelledby="key" aria-expanded="true" >
  670. <li v-for="(valueK, keyK, indexK) in value" v-if="!isEmpty(value)" class="head-ul-second devsite-nav-item devsite-nav-item-heading ">
  671. <span v-on:click="changeColor(keyK), pagination(keyK, 'categories')" v-bind:id="keyK"
  672. class="devsite-nav-title devsite-nav-title-no-path"
  673. track-type="leftNav"
  674. track-name="expandNavSectionNoLink"
  675. track-metadata-position="0"
  676. data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
  677. {{ keyK }}
  678. <span class="caret"></span>
  679. </span>
  680. <ul class="head-ul-second devsite-nav-item devsite-nav-item-heading lowerCase ">
  681. <li class="devsite-nav-li" v-on:click="pagination(keyM, 'categories')" v-bind:id="keyM" v-for="(valueM, keyM, indexM) in valueK" v-if="!isEmpty(valueK)">
  682. {{ keyM }}
  683. </li>
  684. </ul>
  685. </li>
  686. <li v-else>
  687. <span class="devsite-nav-title devsite-nav-title-no-path" track-type="leftNav" track-name="expandNavSectionNoLink" track-metadata-position="0">
  688. {{ keyK }}
  689. </span>
  690. </li>
  691. </ul>
  692. </li>
  693. <li v-else>
  694. <span class="devsite-nav-title devsite-nav-title-no-path" track-type="leftNav" track-name="expandNavSectionNoLink" track-metadata-position="0">
  695. {{ key }}
  696. </span>
  697. </li>
  698. </ul>
  699. </div>
  700. <li class="devsite-nav-item devsite-nav-item-heading1">
  701. <span class="devsite-nav-title devsite-nav-title-no-path" track-type="leftNav" track-name="expandNavSectionNoLink" track-metadata-position="0">
  702. <div id="filtros-box">
  703. <span >FILTROS</span>
  704. <p>Seleccione una opción para filtrar</p>
  705. </div>
  706. <select @change="filterByType($event)" class="customerSelect" >
  707. <option :value="null" disabled selected>Seleccione un filtro</option>
  708. <option
  709. v-for="filter in filtersList"
  710. :value="filter.param + ',' + filter.condition + ',' + filter.selector"
  711. >
  712. {{ filter.title }}
  713. </option>
  714. </select>
  715. </span>
  716. <br>
  717. <div id="filtros-box">
  718. <span >FILTRO POR PRECIO</span>
  719. </div>
  720. <div>
  721. <br><br><br>
  722. <vue-slider @callback="cb" ref="slider4" v-bind="priceRange" v-model="priceRange.value"></vue-slider>
  723. </div>
  724. </li>
  725. </ul>
  726. </nav>
  727. <div v-show="productsAlert" id="products-alert" class="alert alert-info">No hay categorías selecionadas o la categoría que seleccionó no tiene productos.</div>
  728. <paginate id="products" name="itemsData" :per="8" :list="items" class="row list-group">
  729. <li v-for="(item, key) in paginated('itemsData')" class="item col-xs-3 col-lg3">
  730. <div class="thumbnail">
  731. <img :id="'img_' + item.id" data-toggle="modal" :data-target="'#modal_' + item.id" class="group list-group-image" v-bind:src="'file://' + item.images[0].local_src" alt="" />
  732. <div class="caption">
  733. <div class="">
  734. <h5 style="float:left" class="group inner list-group-item-heading">{{ item.title }}</h5>
  735. <span style="float:right" >${{ item.price }}</span>
  736. </div>
  737. <p v-html="'<br>' + item.short_description + 'Stock: ' + item.stock_quantity" class="group inner list-group-item-text">
  738. <br>
  739. </p>
  740. <div class="row">
  741. <div class="col-xs-12 col-md-12">
  742. <button v-on:click="decQty(item)" class="glyphicon glyphicon-minus btn btn-xs btn-default"></button>
  743. <span>{{ itemQty(item) }}</span>
  744. <button v-on:click="addQty(item)" class="glyphicon glyphicon-plus btn btn-xs btn-default"></button>
  745. </div>
  746. <div class="col-xs-12 col-md-12">
  747. <div v-on:click.prevent="getDataBind($event, item.id)" v-bind="dataBind(item.id, item)" class="btn btn-success add-cart-btn">Agregar al carrito</div>
  748. </div>
  749. </div>
  750. </div>
  751. </div>
  752. <div v-bind:id="'modal_' + item.id" class="modal fade" role="dialog">
  753. <div class="thumbnail">
  754. <img data-toggle="modal" :data-target="'#modal_' + item.id" class="group list-group-image" v-bind:src="'file://' + item.images[0].local_src" alt="" />
  755. <div class="caption">
  756. <div class="">
  757. <h5 style="float:left" class="group inner list-group-item-heading">{{ item.title }}</h5>
  758. <span style="float:right" >${{ item.price }}</span>
  759. </div>
  760.  
  761. <p v-html="'<br>' + item.short_description" class="group inner list-group-item-text"></p>
  762. <div class="row">
  763. <div class="col-xs-12 col-md-12">
  764. <button v-on:click="decQty(item)" class="glyphicon glyphicon-minus btn btn-xs btn-default"></button>
  765. <span>{{ itemQty(item) }}</span>
  766. <button v-on:click="addQty(item)" class="glyphicon glyphicon-plus btn btn-xs btn-default"></button>
  767. </div>
  768. <div class="col-xs-12 col-md-12">
  769. <div v-on:click.prevent="getDataBind($event, item.id)" v-bind="dataBind(item.id, item)" class="btn btn-success">Añadir al carrito</div>
  770. </div>
  771. </div>
  772. <div class="col-xs-12 col-md-6">
  773. <p class="lead">{{ item.categories[0] }}</p>
  774. </div>
  775. </div>
  776. </div>
  777. </div>
  778. </li>
  779. </paginate>
  780. <div id="pages">
  781. <paginate-links class="pagination" for="itemsData" :limit="10" :show-step-links="true" ></paginate-links>
  782. </div>
  783. </div>
  784. </div>
  785. <div v-show="!isUserLoggedAttr && !sections.setup" id="login-container">
  786. <div class="col-lg-4 col-md-3 col-sm-2"></div>
  787. <div class="col-lg-4 col-md-6 col-sm-8">
  788. <div class="logo">
  789. <img src="~@/assets/logotarget.png" alt="Logo" >
  790. </div>
  791. <form v-on:submit.prevent="submitForm">
  792. <div class="row loginbox">
  793. <div class="col-lg-12">
  794. <span class="singtext" >Ingresar </span>
  795. </div>
  796. <div class="col-lg-12 col-md-12 col-sm-12">
  797. <input v-model="username" class="form-control" type="email" placeholder="Ingresá tu email" >
  798. </div>
  799. <div class="col-lg-12 col-md-12 col-sm-12">
  800. <input v-model="password" class="form-control" type="password" placeholder="Ingresá tu contraseña" >
  801. </div>
  802. <div class="col-lg-12 col-md-12 col-sm-12">
  803. <button v-bind:disabled="!isFormValid()" class="btn submitButton">Enviar</button>
  804. <div v-show="loginError" class="col-lg-12">
  805. <p class="text-center singtext14Red" >Password y / o usuario incorrectos. </p>
  806. </div>
  807. </div>
  808. <div v-show="showUsersSessions" class="">
  809. <div class="col-lg-12">
  810. <p class="text-center singtext14Black" >Seleccione un usuario para ingresar </p>
  811. </div>
  812. <ul v-for="(value, key, index) in usersSessionsList.docs">
  813. <li> <a v-on:click.prevent="usePreviousUser(value.email)" href="#">{{ value.nicename }} - {{ value.email }} </a> </li>
  814. </ul>
  815. </div>
  816. </div>
  817. </form>
  818. </div>
  819. </div>
  820. <div v-if="sections.setup" id="app-setup">
  821. <h1 class="text-center">¡Bienvenido a Target Moda!</h1>
  822. <h2 class="text-center">A continuación iniciará la instalación de la Aplicación</h2>
  823. <button v-on:click.once="initSetup" type="button" class="btn btn-lg btn-primary center-block">Comenzar</button>
  824. <p class="text-center" style="margin-top:32px;" >{{ setupInit }}</p>
  825. <p class="text-center">{{ productsInit }}</p>
  826. <p class="text-center">{{ productsComplete }}</p>
  827. <p class="text-center">{{ categoriesInit }}</p>
  828. <p class="text-center">{{ categoriesComplete }}</p>
  829. <p class="text-center">{{ customersInit }}</p>
  830. <p class="text-center">{{ customersComplete }}</p>
  831. <p class="text-center">{{ directoriesInit }}</p>
  832. <p class="text-center">{{ directoriesComplete }}</p>
  833. <p class="text-center">{{ imagesInit }}</p>
  834. <p class="text-center">{{ imagesComplete }}</p>
  835. <p class="text-center">{{ setupComplete }}</p>
  836. <p></p>
  837. <button v-show="appInstalled" v-on:click="goToSection('products')" type="button" class="btn btn-lg btn-primary center-block">Entrar</button>
  838. </div>
  839. <div v-if="logged" id="app-content">
  840. <table class="table table-striped">
  841. <thead>
  842. <tr>
  843. <th>Id</th>
  844. <th>Last Name</th>
  845. <th>Email</th>
  846. <th></th>
  847. </tr>
  848. </thead>
  849. <tbody>
  850. <tr v-for="customer in customerst">
  851. <td> {{ customer.id }} </td>
  852. <td> {{ customer.username }} </td>
  853. <td> {{ customer.email }} </td>
  854. </tr>
  855. </tbody>
  856. </table>
  857. </div>
  858. <div v-show="loading" class="loading">Loading&#8230;</div>
  859. </div>
  860. </template>
  861.  
  862. <script>
  863. // import WooCommerceAPI from 'woocommerce-api'
  864. // import Vue from 'vue'
  865. import Navbar from './Elements/Navbar'
  866. import Filters from './Elements/Filters'
  867. import Syncprocess from './Syncprocess'
  868. import store from '../store'
  869. import vueSlider from 'vue-slider-component'
  870. var SHA256 = require('crypto-js/sha256.js')
  871. const remote = require('electron').remote
  872.  
  873. export default {
  874. name: 'customers',
  875. components: { Navbar, Filters, vueSlider },
  876. data () {
  877. return {
  878. sections: {
  879. login: false,
  880. setup: false,
  881. products: false,
  882. orders: false,
  883. orderDetail: false,
  884. cart: false,
  885. checkout: false,
  886. thanks: false,
  887. navbar: false
  888. },
  889. usersSessionsList: {},
  890. showUsersSessions: false,
  891. setupInit: '',
  892. productsInit: '',
  893. productsComplete: '',
  894. categoriesInit: '',
  895. categoriesComplete: '',
  896. customersInit: '',
  897. customersComplete: '',
  898. directoriesInit: '',
  899. directoriesComplete: '',
  900. imagesInit: '',
  901. imagesComplete: '',
  902. setupComplete: '',
  903. appInstalled: false,
  904. isUserLoggedAttr: false,
  905. customerst: [],
  906. auth: [],
  907. username: '',
  908. password: '',
  909. loginError: false,
  910. sku: '',
  911. logged: false,
  912. productsSync: '',
  913. badge: 0,
  914. // cartObject: {},
  915. // PRODUCTS & FILTERS
  916. categories: [],
  917. collapse: true,
  918. categoriesDiscounts: [],
  919. items: [],
  920. pendingOrders: [],
  921. pushedOrders: [],
  922. orderDetail: {},
  923. orderProducts: [],
  924. products: {},
  925. // items: ['Item One', 'Item Two', 'Item Three', 'Item Four', 'Item Five', 'Item Six', 'Item Seven', 'Item Eight', 'Item Nine', 'Item Ten', 'Item Eleven', 'Item Twelve', 'Item Thirteen'],
  926. paginate: ['itemsData'],
  927. priceRange: {
  928. value: ['0', '100'],
  929. width: '100%',
  930. height: 4,
  931. dotSize: 14,
  932. min: 1,
  933. max: 100,
  934. interval: 3,
  935. disabled: false,
  936. show: true,
  937. tooltip: 'always',
  938. piecewise: true,
  939. data: [
  940. '0',
  941. '100',
  942. '300',
  943. '500',
  944. '800',
  945. '1000',
  946. '5000',
  947. '8000',
  948. '10000'
  949. ]
  950. },
  951. total: 10,
  952. // END PRODUCTS & FILTERS
  953. // sessionProducts: this.$session.get('target-cart'),
  954. sessionProductsData: {},
  955. quoteProducts: this.$session.get('target-quote'),
  956. sessionUserData: this.$session.get('user-session'),
  957. sellerCustomers: {},
  958. sellerCustomerSelected: '',
  959. totalCart: 0,
  960. section: this.$session.get('target-current-step'),
  961. error: false,
  962. dateFormat: require('dateformat'),
  963. loading: false,
  964. productsAlert: false,
  965. filtersList: [
  966. {
  967. 'param': 'asc',
  968. 'condition': '$eq',
  969. 'selector': 'sku',
  970. 'title': 'Predeterminado'
  971. },
  972. {
  973. 'param': 'desc',
  974. 'selector': 'sku',
  975. 'condition': '$gt',
  976. 'title': 'Novedades'
  977. },
  978. {
  979. 'param': 'asc',
  980. 'selector': 'price',
  981. 'condition': '$gt',
  982. 'title': 'Menor Precio'
  983. },
  984. {
  985. 'param': 'desc',
  986. 'selector': 'price',
  987. 'condition': '$gt',
  988. 'title': 'Mayor Precio'
  989. },
  990. {
  991. 'param': '50',
  992. 'selector': 'stock_quantity',
  993. 'condition': '$gt',
  994. 'title': 'Más de 50 unidades'
  995. },
  996. {
  997. 'param': '100',
  998. 'selector': 'stock_quantity',
  999. 'condition': '$gt',
  1000. 'title': 'Más de 100 unidades'
  1001. },
  1002. {
  1003. 'param': '200',
  1004. 'selector': 'stock_quantity',
  1005. 'condition': '$gt',
  1006. 'title': 'Más de 200 unidades'
  1007. },
  1008. {
  1009. 'param': '300',
  1010. 'selector': 'stock_quantity',
  1011. 'condition': '$gt',
  1012. 'title': 'Más de 300 unidades'
  1013. },
  1014. {
  1015. 'param': '400',
  1016. 'selector': 'stock_quantity',
  1017. 'condition': '$gt',
  1018. 'title': 'Más de 400 unidades'
  1019. },
  1020. {
  1021. 'param': '500',
  1022. 'selector': 'stock_quantity',
  1023. 'condition': '$gt',
  1024. 'title': 'Más de 500 unidades'
  1025. }
  1026. ]
  1027. }
  1028. },
  1029. methods: {
  1030. checkProductParentCat: function (catProdArray, parentCat) {
  1031. var sizeCat = catProdArray.length
  1032. console.log('!!! array cat', catProdArray)
  1033. console.log('cat prod en el if', catProdArray[sizeCat - 1])
  1034. console.log('parentCat en el if', parentCat)
  1035. var resParentCat = parentCat.replace('%', '_')
  1036. console.log('resParentCat en el if', resParentCat)
  1037.  
  1038. catProdArray.map(function (obj, index) {
  1039. console.log('index', index, 'object', obj)
  1040. if (obj.replace(/\s/g, '') === resParentCat.replace(/\s/g, '')) {
  1041. return true
  1042. }
  1043. })
  1044. // $('#' + resParentCat.replace(/\s/g, '')).show()
  1045. // this.showDiscTable()
  1046. // if (catProdArray[sizeCat - 1].replace(/\s/g, '') === resParentCat.replace(/\s/g, '')) {
  1047. // console.log('cat prod en el if', catProdArray[sizeCat - 1])
  1048. // console.log('parentCat en el if', resParentCat)
  1049. // return true
  1050. // } else {
  1051. // return false
  1052. // }
  1053. // for (var i = 0; i <= sizeCat; i++) {
  1054. // if (catProdArray[i].replace(/\s/g, '') === parentCat) {
  1055. // return true
  1056. // }
  1057. // }
  1058. },
  1059. downloadCSV: function (order) {
  1060. var fileName = 'order_' + order._id + '.csv'
  1061. Syncprocess.createCSV(order.order.line_items).then((csv) => {
  1062. Syncprocess.downloadCSV(fileName, csv).then((result) => {
  1063. console.log(result)
  1064. $('#success-downloaded-csv').fadeIn().delay(1000).fadeOut(2000)
  1065. }).catch((err) => {
  1066. console.log(err)
  1067. $('#error-downloaded-csv').fadeIn().delay(1000).fadeOut(2000)
  1068. })
  1069. }).catch((err) => {
  1070. console.log(err)
  1071. $('#error-downloaded-csv').fadeIn().delay(1000).fadeOut(2000)
  1072. })
  1073. },
  1074. showDiscTable: function () {
  1075. // var collapse = this.collapse
  1076. // console.log(collapse)
  1077. // var tableShow = $('.show_table_desc').val()
  1078. // $('.table_cat_' + tableShow).show()
  1079. $('.show_table_desc').each(function (i, obj) {
  1080. console.log('CLASE table_cat_', obj.value)
  1081. $('.table_cat_' + obj.value).show()
  1082. })
  1083. // $('#order-box div').removeClass('collpase')
  1084. // console.log(event)
  1085. // console.log(parentLevel)
  1086. },
  1087. filterByType: function (event) {
  1088. // selector, condition, param
  1089. let self = this
  1090. let optionValue = event.target.value
  1091. // let sort = {}
  1092. let skuSort = true
  1093. let dataQuery = optionValue.split(',')
  1094. var param = dataQuery[0].trim()
  1095. var condition = dataQuery[1].trim()
  1096. var selector = dataQuery[2].trim()
  1097. var sortParam = ''
  1098. if (selector === 'stock_quantity') {
  1099. param = parseInt(param)
  1100. skuSort = false
  1101. } else if (selector === 'price' || selector === 'sku') {
  1102. skuSort = true
  1103. param = '"' + param + '"'
  1104. sortParam = JSON.parse('{"' + selector + '": ' + param + '}')
  1105. console.log('MOSTRAME SORT', sortParam)
  1106. }
  1107. // sortParam = JSON.parse('{"sku": "desc" }')
  1108. // sortParam = JSON.parse('{"price": "' + param + '"}')
  1109. // sort.push(sortParam)
  1110. var query = JSON.parse('{"' + selector + '":{"' + condition + '":' + param + '}}')
  1111. // console.log('EVENT TARGET', param, condition, selector)
  1112. // console.log('MOSTRAME EL QUERY', query)
  1113. // console.log('QUERY FILTERS', query)
  1114. self.loading = true
  1115. if (skuSort) {
  1116. store.filtersByPriceAndSku(sortParam).then(function (result) {
  1117. if (self.isEmpty(result.docs)) {
  1118. self.productsAlert = true
  1119. self.loading = false
  1120. } else {
  1121. self.productsAlert = false
  1122. self.loading = false
  1123. $('#pages').show()
  1124. }
  1125. self.items = result.docs
  1126. self.products = result.docs
  1127. })
  1128. } else {
  1129. store.filtersByType(query).then(function (result) {
  1130. if (self.isEmpty(result.docs)) {
  1131. self.productsAlert = true
  1132. self.loading = false
  1133. } else {
  1134. self.productsAlert = false
  1135. self.loading = false
  1136. $('#pages').show()
  1137. }
  1138. self.items = result.docs
  1139. self.products = result.docs
  1140. })
  1141. }
  1142. },
  1143. itemQtyCart: function (event, id) {
  1144. var items = this.$session.get('target-cart')
  1145. items[id].data.qty = event.target.valueAsNumber
  1146. if (event.target.valueAsNumber < items[id].data.step) {
  1147. items[id].data.qty = items[id].data.step
  1148. } else if (event.target.valueAsNumber % items[id].data.step !== 0) {
  1149. items[id].data.qty = event.target.valueAsNumber - (event.target.valueAsNumber % items[id].data.step)
  1150. }
  1151. this.$session.set('target-cart', items)
  1152. this.sessionProductsData = this.$session.get('target-cart')
  1153. this.jQuerySetBadge(this.sessionProductsData)
  1154. this.getCartSessionItems()
  1155. this.$forceUpdate()
  1156. },
  1157. checkCategories: function (id) {
  1158. console.log(id)
  1159. if ($('#' + id + ':checkbox:checked').length > 0) {
  1160. console.log('está checkeado')
  1161. $('.' + id + '_child').prop('checked', true)
  1162. } else {
  1163. $('.' + id + '_child').prop('checked', false)
  1164. }
  1165. // console.log('parent!!!', event.target)
  1166. // console.log('event clikc!', event.target.id)
  1167. // jQuery(this).closest('tr').find('[type=checkbox]').prop('checked', true);
  1168. },
  1169. setProductDiscount: function (id) {
  1170. let inputValue = $('#discount_' + id).val()
  1171. this.sessionProductsData[id].data.discount_product = inputValue
  1172. this.sessionProductsData[id].data.subtotal = this.sessionProductsData[id].data.price * this.sessionProductsData[id].data.qty - this.sessionProductsData[id].data.price * this.sessionProductsData[id].data.qty * this.sessionProductsData[id].data.discount_product / 100
  1173.  
  1174. var sessionProducts = this.$session.get('target-quote')
  1175. var total = 0
  1176. var count = 0
  1177.  
  1178. // Apply discounts to products in this.sessionProductsData
  1179. for (var index in this.sessionProductsData) {
  1180. if (this.sessionProductsData[index].data.discount_product > 0) {
  1181. sessionProducts.order.line_items[count].total = this.sessionProductsData[index].data.subtotal
  1182. total += this.sessionProductsData[index].data.subtotal
  1183. } else if (this.sessionProductsData[index].data.discount_category > 0) {
  1184. sessionProducts.order.line_items[count].total = this.sessionProductsData[index].data.subtotal
  1185. total += this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty - this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty * this.sessionProductsData[index].data.discount_category / 100
  1186. } else {
  1187. this.sessionProductsData[index].data.subtotal = 0
  1188. total += this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty
  1189. }
  1190. count++
  1191. }
  1192.  
  1193. sessionProducts.total = total
  1194. this.totalCart = total
  1195. this.$session.set('target-quote', sessionProducts)
  1196.  
  1197. this.$forceUpdate()
  1198. },
  1199. setCategoryDiscount: function (input) {
  1200. console.log('target-quote', this.$session.get('target-quote'))
  1201. // Recursively apply discounts on DOM
  1202. let inputAttribute = input.replace(/[\s\W]/g, '')
  1203. let inputValue = $('#discount_' + inputAttribute).val()
  1204. // $('.parent_cat_disc_' + input).val(inputValue)
  1205. $('input[class^=discount-input-' + inputAttribute + ']').val(inputValue)
  1206.  
  1207. // Save Categories Discounts in this.categoriesDiscounts
  1208. var scope = input.split('_')
  1209. var exist = false
  1210.  
  1211. this.categoriesDiscounts.map((discount, i) => {
  1212. var matches = []
  1213. for (var j = scope.length - 1; j >= 0; j--) {
  1214. matches.push(false)
  1215. }
  1216. for (var k = scope.length - 1; k >= 0; k--) {
  1217. if (discount.scope[k] === scope[k]) {
  1218. matches[k] = true
  1219. }
  1220. }
  1221. if (matches.indexOf(false) === -1) {
  1222. this.categoriesDiscounts[i] = {scope: scope, discount: inputValue}
  1223. exist = true
  1224. }
  1225. })
  1226.  
  1227. if (!exist || this.categoriesDiscounts.length === 0) {
  1228. this.categoriesDiscounts.push({scope: scope, discount: inputValue})
  1229. }
  1230.  
  1231. var sessionProducts = this.$session.get('target-quote')
  1232. var total = 0
  1233. var count = 0
  1234.  
  1235. // Apply discounts to products in this.sessionProductsData
  1236. for (var index in this.sessionProductsData) {
  1237. var categories = this.sessionProductsData[index].data.categories
  1238. var matches = []
  1239. this.categoriesDiscounts.map((discount, j) => {
  1240. categories.map((category, k) => {
  1241. if (discount.scope[discount.scope.length - 1] === category) {
  1242. matches.push(discount)
  1243. }
  1244. })
  1245. })
  1246. var specificity = 0
  1247. matches.map((match) => {
  1248. if (match.scope.length > specificity) {
  1249. this.sessionProductsData[index].data.discount_category = match.discount
  1250. specificity = match.scope.length
  1251. }
  1252. })
  1253. if (this.sessionProductsData[index].data.discount_product > 0) {
  1254. sessionProducts.order.line_items[count].total = this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty - this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty * this.sessionProductsData[index].data.discount_product / 100
  1255. total += this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty - this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty * this.sessionProductsData[index].data.discount_product / 100
  1256. } else if (this.sessionProductsData[index].data.discount_category > 0) {
  1257. this.sessionProductsData[index].data.subtotal = this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty - this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty * this.sessionProductsData[index].data.discount_category / 100
  1258. sessionProducts.order.line_items[count].total = this.sessionProductsData[index].data.subtotal
  1259. total += this.sessionProductsData[index].data.subtotal
  1260. } else {
  1261. this.sessionProductsData[index].data.subtotal = 0
  1262. total += this.sessionProductsData[index].data.price * this.sessionProductsData[index].data.qty
  1263. }
  1264. count++
  1265. }
  1266.  
  1267. sessionProducts.total = total
  1268. this.totalCart = total
  1269. this.$session.set('target-quote', sessionProducts)
  1270.  
  1271. this.$forceUpdate()
  1272. },
  1273. changeColor: function (event) {
  1274. console.log('cateeeeee', this.categories)
  1275. let targetId = event.replace(/\s/g, '')
  1276. console.log('eventooo', targetId)
  1277. // let targetId = event.currentTarget.id
  1278. $('#products-content ul').css('color', '#000 !important')
  1279. $('.dropdown li').css('color', '#000 !important')
  1280. $('.dropdown div').css('color', '#000 !important')
  1281. $('#' + targetId).css('color', '#f2696c')
  1282. console.log('CHANGECOLOR', targetId)
  1283. return 'esteId'
  1284. },
  1285. setUsersSessions: function () {
  1286. let self = this
  1287. store.findByTypeInSession('user_session').then(function (usersInDB) {
  1288. self.usersSessionsList = usersInDB
  1289. console.log('usersInDB ->>>>>->>->>', usersInDB)
  1290. if (usersInDB.docs.length > 0) {
  1291. self.showUsersSessions = true
  1292. }
  1293. console.log('usersInDB LENGH ->>>>>->>->>', usersInDB.docs.length)
  1294. })
  1295. },
  1296. usePreviousUser: function (email) {
  1297. console.log('EMAILLLLL', email)
  1298. this.username = email
  1299. },
  1300. initSetup: function (event) {
  1301. event.disabled = true
  1302. this.setupInit = 'Ha comenzado la instalación ...'
  1303. this.productsInit = 'Sincronizando productos'
  1304. var p1 = new Promise((resolve, reject) => {
  1305. Syncprocess.countSyncWC('products').then((result) => {
  1306. var numProducts = result
  1307. Syncprocess.initProductsWC(numProducts).then((result) => {
  1308. this.productsComplete = 'Productos sincronizados'
  1309. this.directoriesInit = 'Creando directorios de imágenes'
  1310. Syncprocess.initProductImages().then((result) => {
  1311. this.directoriesComplete = 'Directorios creados'
  1312. this.imagesInit = 'Sincronizando imágenes'
  1313. Syncprocess.downloadProductImages().then((result) => {
  1314. this.imagesComplete = 'Imágenes sincronizadas'
  1315. this.appInstalled = true
  1316. resolve('OK')
  1317. }).catch((err) => {
  1318. console.log('ERROR get Images', err)
  1319. })
  1320. }).catch((err) => {
  1321. console.log('ERROR create Images Directories', err)
  1322. })
  1323. }).catch((err) => {
  1324. console.log('ERROR get Products', err)
  1325. })
  1326. }).catch((err) => {
  1327. console.log('ERROR count Products', err)
  1328. })
  1329. })
  1330. var p2 = new Promise((resolve, reject) => {
  1331. this.categoriesInit = 'Sincronizando categorías'
  1332. Syncprocess.initCategoriesWC().then((result) => {
  1333. this.categoriesComplete = 'Categorías sincronizadas'
  1334. resolve('OK')
  1335. }).catch((err) => {
  1336. console.log('ERROR get Categories:', err)
  1337. })
  1338. })
  1339. var p3 = new Promise((resolve, reject) => {
  1340. this.customersInit = 'Sincronizando clientes'
  1341. var sellerId = this.$session.get('user-session')._id
  1342. Syncprocess.initCustomersWC(sellerId).then((result) => {
  1343. this.sellerCustomers = result.docs
  1344. this.customersComplete = 'Clientes sincronizados'
  1345. resolve('OK')
  1346. }).catch((err) => {
  1347. console.log('ERROR get Customers:', err)
  1348. })
  1349. })
  1350. Promise.all([p1, p2, p3]).then(data => {
  1351. console.log('Install COMPLETE')
  1352. Syncprocess.setupComplete().then((result) => {
  1353. this.setupComplete = 'Instalación finalizada con éxito'
  1354. this.appInstalled = true
  1355. this.isUserLoggedAttr = true
  1356. })
  1357. }).catch((err) => {
  1358. console.log('ERROR install complete:', err)
  1359. })
  1360. },
  1361. handler: function (arg1) {
  1362. this.goToSection(arg1)
  1363. this.setCartItems()
  1364. this.getCartSessionItems()
  1365. },
  1366. logout: function () {
  1367. var window = remote.getCurrentWindow()
  1368. let user = this.$session.get('user-session')
  1369. let userId = user._id
  1370. store.logout(userId)
  1371. store.logout('customers_seller_' + userId)
  1372. console.log(this.$session.get('user-session'))
  1373. this.$session.destroy('user-session')
  1374. console.log(this.$session.get('user-session'))
  1375. window.close()
  1376. // customers_seller_
  1377. // id
  1378. },
  1379. badgeItems: function (qty) {
  1380. this.badge = qty
  1381. },
  1382. getSellerCustomers: function () {
  1383. var self = this
  1384. store.findByType('seller_customer').then((result) => {
  1385. console.log('seller customerssss', result)
  1386. self.sellerCustomers = result.docs
  1387. })
  1388. },
  1389. setCustomer: function (customerId) {
  1390. this.sellerCustomerSelected = customerId
  1391. },
  1392. setCartItems: function () {
  1393. console.log('entro set cartitmes!')
  1394. this.sessionProductsData = this.$session.get('target-cart')
  1395. },
  1396. setCartQtyItems: function (cartSession) {
  1397. let qty = 0
  1398. console.log(typeof cartSession)
  1399. Object.keys(cartSession).map(function (objectKey, index) {
  1400. var value = cartSession[objectKey]
  1401. console.log('nav bar QTY---->', value)
  1402. qty += parseInt(value.data.qty)
  1403. console.log('nav bar QTY---->', value.data.qty)
  1404. })
  1405. console.log('var QTY navbar!!!!', qty)
  1406. this.badgeItems(qty)
  1407. },
  1408. itemQty: function (item) {
  1409. if (typeof item.qty === 'undefined') {
  1410. return item.step
  1411. }
  1412. return item.qty
  1413. },
  1414. decQty: function (item) {
  1415. item.qty -= item.step
  1416. if (item.qty <= 0) {
  1417. item.qty = item.step
  1418. }
  1419. this.$forceUpdate()
  1420. },
  1421. addQty: function (item) {
  1422. if (typeof item.qty === 'undefined') {
  1423. item.qty = item.step
  1424. }
  1425. item.qty += item.step
  1426. this.$forceUpdate()
  1427. },
  1428. emptyQuoute: function () {
  1429. this.$session.set('target-cart', {})
  1430. this.$session.set('target-quote', {})
  1431. },
  1432. goToSection: function (to) {
  1433. for (var section in this.sections) {
  1434. this.sections[section] = false
  1435. if (section === to) {
  1436. this.sections[section] = true
  1437. }
  1438. }
  1439. if (this.appInstalled && this.isUserLoggedAttr) {
  1440. this.sections.navbar = true
  1441. }
  1442. },
  1443. setCurrentStep: function (section, to = null) {
  1444. console.log('section', section)
  1445. console.log('TO', to)
  1446. $(section).hide()
  1447. if (to !== null) {
  1448. $(to).show()
  1449. if (this.appInstalled) {
  1450. $('#navbar').show()
  1451. }
  1452. }
  1453. },
  1454. // customer sellers
  1455. getCustomersBySellerId: function () {
  1456. let self = this
  1457. let userSession = this.$session.get('user-session')
  1458. // if (typeof userSession === 'undefined') {
  1459. // this.$session.set('user-session', {})
  1460. // console.log('user session no definida la crea', userSession)
  1461. // }
  1462. // let sellerId = userSession._id
  1463. let sellerId = userSession._id
  1464. store.getDataSessionById('customers_seller_' + sellerId).then(function (customerSellerRes) {
  1465. console.log('STOREEEE data sesuib get', customerSellerRes)
  1466. console.log('66666666lo tengo en sesion customerSeller ', customerSellerRes.data)
  1467. self.sellerCustomers = customerSellerRes.data
  1468. })
  1469. },
  1470. setCustomerSeller: function (id) {
  1471. let self = this
  1472. let addCustomerSeller = {}
  1473. addCustomerSeller = self.sessionUserData
  1474. console.log('addCustomerSellerDDDDDDDD', addCustomerSeller)
  1475. let clientToSeller = addCustomerSeller
  1476. clientToSeller['customer_seller_id'] = id
  1477. self.$session.set('user-session', addCustomerSeller)
  1478. console.log('ADD CUSTOMER', this.sessionUserData)
  1479. // store.createSession(userSession)
  1480. },
  1481. dataBind: function (id, item) {
  1482. // item.qty = 0
  1483. let itemString = JSON.stringify(item)
  1484. // console.log(id)
  1485. return {
  1486. [`data-product-${id}`]: itemString
  1487. }
  1488. },
  1489. jQuerySetBadge: function (cartSession) {
  1490. let qty = 0
  1491. Object.keys(cartSession).map(function (objectKey, index) {
  1492. var value = cartSession[objectKey]
  1493. qty += value.data.qty
  1494. })
  1495. if (qty === 0) {
  1496. this.totalCart = 0
  1497. }
  1498. $(document).ready(function () {
  1499. $('.badge').text(qty)
  1500. })
  1501. },
  1502. getDataBind: function (event, id) {
  1503. // let self = this
  1504. $('#success-add-to-cart').fadeIn(500)
  1505. let element = event.currentTarget
  1506. let data = element.getAttribute('data-product-' + id)
  1507. let productById = this.$session.get('target-cart')
  1508. data = JSON.parse(data)
  1509. console.log('data producto', data)
  1510. console.log('data productById', productById)
  1511. console.log('data EL ID', id)
  1512. if (typeof productById[id] !== 'undefined' || productById.length > 0) {
  1513. // let insertData = []
  1514. console.log('ProductId', productById)
  1515. console.log('Id', id)
  1516. if (typeof data.qty === 'undefined') {
  1517. console.log('cantidad no definida', productById[id].data.qty)
  1518. data.qty = data.step
  1519. }
  1520. data.qty += productById[id].data.qty
  1521. productById[id] = {data}
  1522. this.$session.set('target-cart', productById)
  1523. this.jQuerySetBadge(this.$session.get('target-cart'))
  1524. } else {
  1525. if (typeof data.qty === 'undefined') {
  1526. data.qty = data.step
  1527. }
  1528. productById[id] = {data}
  1529. console.log('entra al else EL ID', id)
  1530. this.$session.set('target-cart', productById)
  1531. this.jQuerySetBadge(this.$session.get('target-cart'))
  1532. }
  1533. console.log('CART OBJECT', productById)
  1534. var cart = $('#cart-badge')
  1535. setTimeout(function () {
  1536. cart.addClass('shake-cart')
  1537. }, 50)
  1538. cart.removeClass('shake-cart')
  1539. $('#success-add-to-cart').fadeIn().delay(1000).fadeOut(2000)
  1540. },
  1541. cb: function (val) {
  1542. setTimeout(() => {
  1543. this.pagination(val, 'price')
  1544. }, 2000)
  1545. console.log(val)
  1546. },
  1547. incrementTotal: function () {
  1548. this.total++
  1549. },
  1550. // end products
  1551. // login
  1552. isFormValid: function () {
  1553. return this.username !== '' && this.password !== ''
  1554. },
  1555. decodeHtml: function (html) {
  1556. var txt = unescape(html)
  1557. return txt
  1558. },
  1559. submitForm: function () {
  1560. if (!this.isFormValid()) {
  1561. return false
  1562. } else {
  1563. this.authUser()
  1564. // this.logged = true
  1565. }
  1566. },
  1567. // end login
  1568. // images
  1569. initImages: function () {
  1570. Syncprocess.initProductImages().then((result) => {
  1571. console.log('Init Images Promise:', result)
  1572. }).catch(function (err) {
  1573. console.log(err)
  1574. })
  1575. },
  1576. getImages: function () {
  1577. Syncprocess.getProductImages().then((result) => {
  1578. console.log('Get Images Promise:', result)
  1579. }).catch(function (err) {
  1580. console.log(err)
  1581. })
  1582. },
  1583. downloadImages: function () {
  1584. Syncprocess.downloadProductImages().then((result) => {
  1585. console.log('Download Images Promise:', result)
  1586. }).catch(function (err) {
  1587. console.log(err)
  1588. })
  1589. },
  1590. // end images
  1591. getProducts: function () {
  1592. Syncprocess.getProducts().then((result) => {
  1593. console.log('Get Products:', result)
  1594. }).catch((err) => {
  1595. console.log(err)
  1596. })
  1597. },
  1598. // orders - Quote
  1599. cartQty: function (id) {
  1600. let qtyClass = 'cart-qty-' + id
  1601. return qtyClass
  1602. },
  1603. cartSubtotal: function (id) {
  1604. let subTotalClass = 'cart-subtotal-' + id
  1605. return subTotalClass
  1606. },
  1607. updateCartProductById: function (id) {
  1608. console.log('UPDATE CART PRODUCT', id)
  1609. let cartQty = $('.cart-qty-' + id).val()
  1610. let sessionProducts = this.$session.get('target-cart')
  1611. sessionProducts[id].data.qty = parseInt(cartQty)
  1612. console.log('UPDATE CART sessionProducts', sessionProducts)
  1613. this.$session.set('target-cart', sessionProducts)
  1614. this.setCartItems()
  1615. this.getCartSessionItems()
  1616. this.sessionProductsData = this.$session.get('target-cart')
  1617. this.jQuerySetBadge(sessionProducts)
  1618. },
  1619. deleteCartProductById: function (id) {
  1620. // let cartQty = $('.cart-qty-' + id).val()
  1621. let productsToDelete = {}
  1622. let sessionProducts = this.$session.get('target-cart')
  1623. delete sessionProducts[id]
  1624. productsToDelete = sessionProducts
  1625. this.$session.set('target-cart', {})
  1626. this.$session.set('target-cart', productsToDelete)
  1627. // this.setCartItems()
  1628. this.getCartSessionItems()
  1629. this.jQuerySetBadge(sessionProducts)
  1630. this.sessionProductsData = this.$session.get('target-cart')
  1631. // $('.cart-qty-' + id).parent().parent().hide('fade')
  1632. },
  1633. saveQuoteToSession: function () {
  1634. // let sessionProducts = this.sessionProductsData
  1635. let sessionProducts = this.$session.get('target-cart')
  1636. let quote = this.$session.get('target-quote')
  1637. let data = {}
  1638. let user = this.$session.get('user-session')
  1639.  
  1640. if (typeof quote === 'undefined') {
  1641. this.$session.set('target-quote', {})
  1642. }
  1643. let lineItems = []
  1644. Object.keys(sessionProducts).map(function (objectKey, index) {
  1645. var value = sessionProducts[objectKey]
  1646. lineItems.push({ product_id: value.data.id, quantity: value.data.qty })
  1647. console.log('PRODUCTOS EN EL CARRITO--->', value.data.id)
  1648. })
  1649. console.log('lineitemssss', lineItems)
  1650. console.log('USER - SESSION', user.customer_seller_id)
  1651. var customerId = this.sellerCustomerSelected
  1652. var customerObj
  1653. store.getDoc(customerId).then((result) => {
  1654. if (!result) {
  1655. customerId = user.customer_seller_id
  1656. customerObj = {display_name: 'No especificado'}
  1657. } else {
  1658. customerId = result.ID
  1659. customerObj = result
  1660. }
  1661. console.log('Find Customer by ID:', result)
  1662. console.log('Total Cart:', this.totalCart)
  1663. data = {
  1664. order: {
  1665. payment_details: {
  1666. method_id: 'bacs',
  1667. method_title: 'Pago a coordinar',
  1668. paid: true
  1669. },
  1670. billing_address: {
  1671. first_name: '',
  1672. last_name: '',
  1673. address_1: '',
  1674. address_2: '',
  1675. city: '',
  1676. state: '',
  1677. postcode: '',
  1678. country: '',
  1679. email: '',
  1680. phone: ''
  1681. },
  1682. shipping_address: {
  1683. first_name: '',
  1684. last_name: '',
  1685. address_1: '',
  1686. address_2: '',
  1687. city: '',
  1688. state: '',
  1689. postcode: '',
  1690. country: ''
  1691. },
  1692. customer_id: customerId,
  1693. line_items: lineItems,
  1694. shipping_lines: []
  1695. },
  1696. user: user,
  1697. customer: customerObj,
  1698. total: this.totalCart,
  1699. authorized: false,
  1700. pushed: false,
  1701. created: new Date()
  1702. }
  1703. this.$session.set('target-quote', data)
  1704. console.log(data)
  1705. })
  1706. this.goToSection('checkout')
  1707. },
  1708. placeLocalOrder: function () {
  1709. let self = this
  1710. console.log('placeORder', self.quoteProducts)
  1711. // self.saveOrders(self.quoteProducts)
  1712. var totalCart = this.$session.get('target-quote')
  1713. totalCart.totalCart = this.totalCart
  1714. self.saveOrders(totalCart)
  1715. // vaciar el quote y el cart
  1716. self.$session.set('target-cart', {})
  1717. self.$session.set('target-quote', {})
  1718. $(document).ready(function () {
  1719. $('.badge').text(0)
  1720. })
  1721. // redirección a thanks
  1722. // self.$router.push('/thanks')
  1723. this.goToSection('thanks')
  1724. },
  1725. fetchOrders: function () {
  1726. store.findAllOrders().then((result) => {
  1727. var orders = result.rows
  1728. var pushedOrders = []
  1729. var pendingOrders = []
  1730. orders.map((order) => {
  1731. if (order.doc.pushed) {
  1732. pushedOrders.push(order.doc)
  1733. } else {
  1734. pendingOrders.push(order.doc)
  1735. }
  1736. })
  1737. this.pushedOrders = pushedOrders
  1738. this.pendingOrders = pendingOrders
  1739. console.log('GET pendingOrders:', this.pendingOrders)
  1740. console.log('GET pushedOrders:', this.pushedOrders)
  1741. })
  1742. },
  1743. saveOrders: function (data) {
  1744. Syncprocess.saveOrders(data).then((result) => {
  1745. console.log('Saved Order:', result)
  1746. this.fetchOrders()
  1747. }).catch((err) => {
  1748. console.log(err)
  1749. })
  1750. },
  1751. pushOrders: function () {
  1752. this.loading = true
  1753. Syncprocess.pushOrders().then((result) => {
  1754. console.log('Pushed Orders:', result)
  1755. this.fetchOrders()
  1756. this.loading = false
  1757. }).catch((err) => {
  1758. this.loading = false
  1759. console.log(err)
  1760. })
  1761. },
  1762. removeOrder: function (id, rev) {
  1763. store.removeOrder(id, rev).then((result) => {
  1764. console.log('Removed Order:', result)
  1765. this.fetchOrders()
  1766. }).catch((err) => {
  1767. console.log(err)
  1768. })
  1769. },
  1770. pushOrder: function (order) {
  1771. this.loading = true
  1772. Syncprocess.pushOrder(order).then((result) => {
  1773. console.log('Pushed Order:', result)
  1774. this.fetchOrders()
  1775. this.loading = false
  1776. }).catch((err) => {
  1777. this.loading = false
  1778. console.log(err)
  1779. })
  1780. },
  1781. viewOrder: function (order) {
  1782. this.orderProducts = []
  1783. console.log('Order:', order)
  1784. order.order.line_items.map((product) => {
  1785. store.getDoc(product.product_id.toString()).then((result) => {
  1786. console.log('Order Product:', result)
  1787. result.quantity = product.quantity
  1788. result.subtotal = product.subtotal
  1789. this.orderProducts.push(result)
  1790. })
  1791. })
  1792. this.orderDetail = order
  1793. this.goToSection('orderDetail')
  1794. },
  1795. authorizeOrder: function (authorization, pos) {
  1796. this.pendingOrders[pos].authorized = authorization
  1797. store.updateOrder(this.pendingOrders[pos]).then((result) => {
  1798. this.fetchOrders()
  1799. console.log(result)
  1800. }).catch((err) => {
  1801. console.log('ERROR:', err)
  1802. })
  1803. },
  1804. // end orders
  1805. isUserLogged: function () {
  1806. let self = this
  1807. return store.findByTypeInSession('user_session').then(function (resSessionUser) {
  1808. console.log('lo tengo en sesion LOGIN ', resSessionUser.docs.length)
  1809. if (resSessionUser.docs.length) {
  1810. let userSession = self.$session.get('user-session')
  1811. if (typeof userSession === 'undefined') {
  1812. self.$session.set('user-session', resSessionUser)
  1813. }
  1814. console.log('lo tengo en sesion ', userSession)
  1815. // self.$router.push('/products')
  1816. self.isUserLoggedAttr = true
  1817. $(document).ready(function () {
  1818. $('.products').show()
  1819. $('#navbar').show()
  1820. // $('#thanks').hide()
  1821. // $('#checkout').hide()
  1822. // $('#cart').hide()
  1823. // $('#navbar').show()
  1824. // $('#login-container').show()
  1825. })
  1826. // return Promise.resolve(true)
  1827. // oculto login
  1828. // redirijo
  1829. } else {
  1830. // muestro login
  1831. // return Promise.resolve(false)
  1832. self.isUserLoggedAttr = false
  1833. }
  1834. })
  1835. },
  1836. authUser: function () {
  1837. let self = this
  1838. let userSession = {}
  1839. if (!self.isFormValid()) {
  1840. return false
  1841. } else {
  1842. // chequearlo en sesion primero
  1843. // store.findByTypeInSession('user_session').then(function (resSessionUser) {
  1844. // console.log('busca al usuario en la db de la sesion', resSessionUser)
  1845. // })
  1846. // self.setCurrentStep('products')
  1847. // store.findByTypeInSession('user_session').then(function (resSessionUser) {
  1848. store.findUserSessionByEmail(self.username).then(function (resSessionUser) {
  1849. console.log('busca al usuario en la db de la sesion', resSessionUser)
  1850. // if (typeof resSessionUser === 'undefined' || resSessionUser.docs.length === 0) {
  1851. if (typeof resSessionUser === 'undefined' || resSessionUser.length === 0) {
  1852. store.findUserByEmail(self.username).then(function (result) {
  1853. console.log('resultado ', result)
  1854. if (result != null && result.status === 'ok') {
  1855. // utilizo la data del usuario y lo logueo internamente
  1856. // guardarlo en sesiòn
  1857. console.log(result.status)
  1858. console.log(result)
  1859. var userData = result.user
  1860. // result._id = userData.id.toString()
  1861. userSession._id = userData.id.toString()
  1862. userSession.nickname = userData.nickname
  1863. userSession.nicename = userData.nicename
  1864. userSession.username = userData.username
  1865. userSession.password = SHA256(self.password).toString()
  1866. userSession.email = userData.email
  1867. userSession.displayname = userData.displayname
  1868. userSession.session_type = 'user_session'
  1869. userSession.customer_seller_id = ''
  1870. self.$session.set('user-session', userSession)
  1871. store.createSession(userSession)
  1872.  
  1873. if (!self.appInstalled) {
  1874. console.log('App no instalada')
  1875. self.goToSection('setup')
  1876. } else {
  1877. self.isUserLoggedAttr = true
  1878. self.syncApp()
  1879. self.goToSection('products')
  1880. }
  1881. // self.isUserLoggedAttr = true
  1882. // self.syncApp()
  1883. // self.goToSection('login', 'products')
  1884. } else {
  1885. console.log('entra acá si el usuario no está en la DB')
  1886. self.$http.get('http://targetmoda2.braintlylabs.com/home/carrito/api/user/generate_auth_cookie/?insecure=cool&username=' + self.username + '&password=' + self.password)
  1887. .then(function (response) {
  1888. // logica de guardado del usuario en la DB
  1889. var userObj = response.data
  1890. console.log(userObj)
  1891. if (userObj.status === 'ok') {
  1892. var userData = userObj.user
  1893. console.log('UserData', userData)
  1894. console.log('userObj', userObj)
  1895. userObj._id = userData.id.toString()
  1896. userSession._id = userData.id.toString()
  1897. userSession.nickname = userData.nickname
  1898. userSession.nicename = userData.nicename
  1899. userSession.username = userData.username
  1900. userSession.password = SHA256(self.password).toString()
  1901. userSession.email = userData.email
  1902. userSession.displayname = userData.displayname
  1903. self.$session.set('user-session', userSession)
  1904. userSession.session_type = 'user_session'
  1905. userSession.customer_seller_id = ''
  1906. store.createSession(userSession)
  1907. console.log('App instalada:', self.appInstalled)
  1908. if (!self.appInstalled) {
  1909. console.log('App no instalada')
  1910. self.goToSection('setup')
  1911. } else {
  1912. self.isUserLoggedAttr = true
  1913. self.syncApp()
  1914. self.goToSection('products')
  1915. }
  1916. // console.log('check user', store.findUserByEmail(userData.id.email))
  1917. // guardarlo en sesión
  1918. // store.create(userObj)
  1919. // store.createSession(userSession)
  1920. }
  1921. self.auth = response.data
  1922. setTimeout(() => {
  1923. // this.logged = true
  1924. // #/register tener en cuenta esto
  1925. // self.$router.push('/products')
  1926. }, 1000)
  1927. })
  1928. }
  1929. })
  1930. } else {
  1931. let userSession = self.$session.get('user-session')
  1932. if (typeof userSession === 'undefined') {
  1933. self.$session.set('user-session', resSessionUser)
  1934. }
  1935.  
  1936. console.log('DATA SESSION DB ->>>>>>>', resSessionUser)
  1937. console.log('lo tengo en sesion else! ', userSession)
  1938. if (!self.appInstalled) {
  1939. console.log('App no instalada')
  1940. self.goToSection('setup')
  1941. } else {
  1942. console.log('Entra aca para loguearse y luego ir aproductos')
  1943. console.log('RECIBO EL USUARIO ->>>>>>>', resSessionUser)
  1944. console.log('RECIBO EL passowrd del form->>>>>>>', self.password)
  1945. if (SHA256(self.password).toString() === resSessionUser.password) {
  1946. self.isUserLoggedAttr = true
  1947. self.loginError = false
  1948. self.syncApp()
  1949. self.goToSection('products')
  1950. } else {
  1951. self.loginError = true
  1952. console.log('password incorrecto')
  1953. }
  1954. }
  1955. // self.isUserLoggedAttr = true
  1956. // self.syncApp()
  1957. // self.goToSection('login', 'products')
  1958. // oculto login
  1959. // redirijo
  1960. }
  1961. })
  1962. }
  1963. },
  1964. syncApp: function () {
  1965. this.pagination()
  1966. this.fetchCategories()
  1967. this.fetchOrders()
  1968. this.getSellerCustomers()
  1969. this.pushOrders()
  1970. console.log('Products:', this.sessionProductsData)
  1971. // this.getSeller()
  1972. let cartSession = this.$session.get('target-cart')
  1973. let userSession = this.$session.get('user-session')
  1974. // this.$session.remove('target-cart')
  1975. if (typeof cartSession === 'undefined') {
  1976. console.log('session no definida la crea')
  1977. this.$session.start()
  1978. this.$session.set('target-cart', {})
  1979. } else if (typeof userSession === 'undefined') {
  1980. console.log('user session no definida la crea')
  1981. // this.$session.start()
  1982. this.$session.set('user-session', {})
  1983. }
  1984. this.getCartSessionItems()
  1985. Syncprocess.init().then(function (result) {
  1986. console.log('iniiiit', result)
  1987. })
  1988. },
  1989. // end auth users
  1990. // FILTERS BEGINS
  1991. isEmpty: function (element) {
  1992. let check
  1993. Object.keys(element).length === 0 ? check = true : check = false
  1994. // console.log('check vacio', check)
  1995. return check
  1996. },
  1997. // pagination: function () {
  1998. // var self = this
  1999. // store.filters({categories: {$all: ['Anillos']}}).then(function (result) {
  2000. // console.log('FILTROS', result.docs)
  2001. // self.items = result.docs
  2002. // self.products = result.docs
  2003. // })
  2004. // },
  2005. pagination: function (id, type = 'categories') {
  2006. // let self = this
  2007. console.log(id)
  2008. if (type === 'categories') {
  2009. this.filterCategories(id)
  2010. } else {
  2011. this.filterPrice(id)
  2012. }
  2013. // store.filters({categories: {$all: [id]}}).then(function (result) {
  2014. // console.log('ESTA EMPTY', self.isEmpty(result.docs))
  2015. // if (self.isEmpty(result.docs)) {
  2016. // self.pagination('Anillos')
  2017. // }
  2018. // self.items = result.docs
  2019. // self.products = result.docs
  2020. // })
  2021. },
  2022. filterPrice: function (value) {
  2023. let self = this
  2024. self.loading = true
  2025. store.productFiltByPrice(value).then(function (result) {
  2026. console.log('priceeee', result)
  2027. self.items = result.docs
  2028. self.products = result.docs
  2029. self.loading = false
  2030. })
  2031. },
  2032. filterSearch: function () {
  2033. let self = this
  2034. // $('.loading').show()
  2035. self.loading = true
  2036. store.filterSearch(self.sku).then(function (result) {
  2037. if (self.isEmpty(result.docs)) {
  2038. console.log('esta vacio!!!!')
  2039. // $('.loading').hide()
  2040. self.loading = false
  2041. self.productsAlert = true
  2042. } else {
  2043. self.loading = false
  2044. self.productsAlert = false
  2045. console.log('FILTER SKU!!', result.docs)
  2046. // $('.loading').hide()
  2047. }
  2048. self.items = result.docs
  2049. self.products = result.docs
  2050. })
  2051. },
  2052. filterCategories: function (id) {
  2053. console.log('FILTER CATES', id)
  2054. let self = this
  2055. store.filters({categories: {$all: [id]}}).then(function (result) {
  2056. if (self.isEmpty(result.docs)) {
  2057. console.log('esta vacio')
  2058. // self.pagination('Anillos')
  2059. // $('#pages').hide()
  2060. // $('#products-alert').show()
  2061. self.productsAlert = true
  2062. } else {
  2063. // $('#products-alert').hide()
  2064. self.productsAlert = false
  2065. $('#pages').show()
  2066. }
  2067. self.items = result.docs
  2068. self.products = result.docs
  2069. })
  2070. },
  2071. fetchCategories: function () {
  2072. var self = this
  2073. self.loading = true
  2074. store.findByType('category').then(function (catsWC) {
  2075. // let categoriesWC = catsWC.docs
  2076. self.categories = self.arrangeCategories(catsWC.docs)
  2077. console.log('todas las categorias', self.categories)
  2078. self.loading = false
  2079. })
  2080. },
  2081. arrangeCategories: function (categories, parent = 0) {
  2082. let self = this
  2083. let result = {}
  2084. categories.filter(function (category) {
  2085. if (category.parent === parent) {
  2086. result[category.name] = self.arrangeCategories(categories, category.id)
  2087. }
  2088. })
  2089. return result
  2090. },
  2091. // CATEGORIES - DROPDOWN
  2092. catDropdown: function (classTo) {
  2093. console.log('hizo click!!!!!!')
  2094. console.log('tocaaaaaa', classTo)
  2095. $('.dropdown-submenu a.' + classTo).next('ul').toggle(function (e) {
  2096. e.stopPropagation()
  2097. e.preventDefault()
  2098. })
  2099. // e.stopPropagation()
  2100. // e.preventDefault()
  2101. },
  2102. // FILTERS ENDS
  2103. // CART
  2104. setTotal: function (value, qty) {
  2105. let total = value * qty
  2106. this.totalCart = total
  2107. console.log('TOTAL EN SET TOTAL', total)
  2108. },
  2109. getCartSessionItems: function () {
  2110. let self = this
  2111. let cartSession = this.$session.get('target-cart')
  2112. let qty = 0
  2113. let total = 0
  2114. // let price = 0
  2115. Object.keys(cartSession).map(function (objectKey, index) {
  2116. var value = cartSession[objectKey]
  2117. console.log('PRODUCTOS EN EL CARRITO--->', cartSession[objectKey])
  2118. qty += parseInt(value.data.qty)
  2119. total = self.setTotal(parseInt(value.data.price), qty)
  2120. })
  2121. // total = price
  2122. console.log('var QTY !!!!', qty)
  2123. console.log('var TOTAL !!!!', total)
  2124. // self.totalCart = total
  2125. // this.badgeItems(qty)
  2126. },
  2127. dataBindCartProducts: function (id, name, item = null) {
  2128. return {
  2129. [`data-${name}-product-${id}`]: id
  2130. }
  2131. },
  2132. // CART ENDS
  2133. wooAuth () {
  2134. }
  2135. },
  2136. created: function () {
  2137. this.loading = false
  2138. this.setUsersSessions()
  2139. let cartSession = this.$session.get('target-cart')
  2140. let userSession = this.$session.get('user-session')
  2141. store.findById('app_setup').then((result) => {
  2142. console.log('App installed:', result)
  2143. if (result) {
  2144. this.appInstalled = true
  2145. }
  2146. })
  2147. if (this.appInstalled) {
  2148. this.pagination()
  2149. this.fetchCategories()
  2150. // this.$session.remove('user-session')
  2151. if (typeof cartSession === 'undefined') {
  2152. console.log('session no definida la crea')
  2153. this.$session.start()
  2154. this.$session.set('target-cart', {})
  2155. } else if (typeof userSession === 'undefined') {
  2156. console.log('user session no definida la crea')
  2157. // this.$session.start()
  2158. this.$session.set('user-session', {})
  2159. }
  2160. // this.setCartQtyItems(cartSession)
  2161. this.getCartSessionItems()
  2162. Syncprocess.init().then(function (result) {
  2163. console.log('iniiiit', result)
  2164. })
  2165. }
  2166. console.log('cart sesiooo', this.$session.get('target-cart'))
  2167. if (typeof cartSession !== 'undefined') {
  2168. this.setCartQtyItems(cartSession)
  2169. }
  2170. // PRODUCTS & FILTERS
  2171. console.log('SESION ALL', this.$session.getAll())
  2172. }
  2173. }
  2174. </script>
  2175.  
  2176. <!-- Add "scoped" attribute to limit CSS to this component only -->
  2177. <style scoped>
  2178. ul{
  2179. list-style-type: none !important;
  2180. }
  2181. #checkout .btn-make-order{
  2182. width: 100%;
  2183. }
  2184. .last-child-cat{
  2185. border-color:transparent !important;
  2186. background-color:transparent !important;
  2187. padding-left:5%;
  2188. }
  2189. .discount-box {margin-left:2%;display: inline;}
  2190. .discount-box input{width: 10%;}
  2191. .checkbox{margin-right: 2%;}
  2192. #thanks-keep {background-color: #000 !important}
  2193.  
  2194. .flash-message{display:none}
  2195. .shake-cart {
  2196. animation: shake 0.82s cubic-bezier(.36,.07,.19,.97) both;
  2197. transform: translate3d(0, 0, 0);
  2198. backface-visibility: hidden;
  2199. perspective: 1000px;
  2200. }
  2201.  
  2202. @keyframes shake {
  2203. 10%, 90% {
  2204. transform: translate3d(-1px, 0, 0);
  2205. }
  2206.  
  2207. 20%, 80% {
  2208. transform: translate3d(2px, 0, 0);
  2209. }
  2210.  
  2211. 30%, 50%, 70% {
  2212. transform: translate3d(-4px, 0, 0);
  2213. }
  2214.  
  2215. 40%, 60% {
  2216. transform: translate3d(4px, 0, 0);
  2217. }
  2218.  
  2219. }
  2220. .panel-default>.panel-heading{
  2221. background: none;
  2222. }
  2223. .total-order{
  2224. float: right;
  2225. height: 60px;
  2226. margin: 0px 40px 0px 0px;
  2227. /* border-top:1px solid #ccc; */
  2228. /* width: 100%; */
  2229. }
  2230. .panel {
  2231. border:none;
  2232. -webkit-box-shadow: none;
  2233. }
  2234. .price-table{
  2235. border:none !important;
  2236. padding-top:40%;
  2237. -webkit-box-shadow: none !important;
  2238. }
  2239. .table td {
  2240. font-family: 'Montserrat-Light' !important;
  2241. }
  2242. .title-table{
  2243. margin-top:21%;
  2244. }
  2245. </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement