Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

244 строки
4.9 KiB

  1. import apollo from "@/lib/apollo.js";
  2. async function GetDetailProduct(id, token = "") {
  3. var res = await apollo.query(
  4. `
  5. query($input : ID!){
  6. product(id:$input){
  7. data{
  8. id
  9. attributes{
  10. Company{
  11. data{
  12. attributes{
  13. Name
  14. }
  15. }
  16. }
  17. Category{
  18. data{
  19. attributes{
  20. Name
  21. }
  22. }
  23. }
  24. Name
  25. Description
  26. Product_parts{
  27. data{
  28. attributes{
  29. Name
  30. Part_Code
  31. Product_prices{
  32. data{
  33. attributes{
  34. Price
  35. }
  36. }
  37. }
  38. }
  39. }
  40. }
  41. Stock
  42. Discount
  43. Machine
  44. Dimension
  45. Structure
  46. Voltage
  47. Image{
  48. data{
  49. attributes{
  50. url
  51. }
  52. }
  53. }
  54. Product_colors{
  55. data{
  56. attributes{
  57. Color
  58. Image{
  59. data{
  60. attributes{
  61. url
  62. }
  63. }
  64. }
  65. }
  66. }
  67. }
  68. Product_prices{
  69. data{
  70. attributes{
  71. Price
  72. region{
  73. data{
  74. attributes{
  75. Name
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84. }
  85. }
  86. `,
  87. token, {
  88. "input": id
  89. }
  90. );
  91. return res;
  92. }
  93. async function GetProductImgColor(id, token = "") {
  94. var res = await apollo.query(
  95. `
  96. query($input: ID!) {
  97. productImageColors(where:{id:$input}) {
  98. id
  99. name
  100. img{
  101. url
  102. }
  103. }
  104. }
  105. `,
  106. token, {
  107. "input": id
  108. }
  109. );
  110. return res;
  111. }
  112. async function GetProductCategory(token=''){
  113. var res = await apollo.query(
  114. `
  115. query{
  116. productCategories{
  117. data{
  118. attributes{
  119. Name
  120. }
  121. }
  122. }
  123. }
  124. `,token
  125. );
  126. return res;
  127. }
  128. async function GetProductOthers(company,category,current,pageSize=999,page=1,token=""){
  129. var allProduct= '';
  130. category.forEach(i => {
  131. allProduct = allProduct+`
  132. ${i.replace(' ','_')}:products(pagination:{pageSize:${pageSize},page:${(i.toLowerCase()==current)?page:1}} filters:{Category:{Name:{containsi:"${i}"}} Company:{id:{eq:$input}}}){
  133. meta{
  134. pagination{
  135. pageCount
  136. total
  137. }
  138. }
  139. data{
  140. id
  141. attributes{
  142. Name
  143. Image{
  144. data{
  145. attributes{
  146. url
  147. }
  148. }
  149. }
  150. Discount
  151. Stock
  152. Product_prices{
  153. data{
  154. attributes{
  155. Price
  156. region{
  157. data{
  158. attributes{
  159. Name
  160. }
  161. }
  162. }
  163. }
  164. }
  165. }
  166. }
  167. }
  168. }
  169. `;
  170. });
  171. var res = await apollo.query(
  172. `
  173. query($input : ID!){
  174. ${allProduct}
  175. }
  176. `,token,{
  177. input:company,
  178. }
  179. );
  180. return res;
  181. }
  182. async function GetProduct(company,category,pageSize=999,page=1, token = "") {
  183. var res = await apollo.query(
  184. `
  185. query($input : ID! $cat: String!){
  186. products(pagination:{pageSize:${pageSize},page:${page}} filters:{Category:{Name:{eq:$cat}} Company:{id:{eq:$input}}}){
  187. meta{
  188. pagination{
  189. pageCount
  190. total
  191. }
  192. }
  193. data{
  194. id
  195. attributes{
  196. Name
  197. Image{
  198. data{
  199. attributes{
  200. url
  201. }
  202. }
  203. }
  204. Product_prices{
  205. data{
  206. attributes{
  207. Price
  208. region{
  209. data{
  210. attributes{
  211. Name
  212. }
  213. }
  214. }
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. }
  222. `,
  223. token,
  224. {
  225. input:company,
  226. cat:category,
  227. }
  228. );
  229. return res;
  230. }
  231. module.exports = {
  232. GetProductImgColor: GetProductImgColor,
  233. GetProduct: GetProduct,
  234. GetProductCategory:GetProductCategory,
  235. //detail
  236. GetDetailProduct: GetDetailProduct,
  237. GetProductOthers:GetProductOthers,
  238. };