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.

260 lines
7.2 KiB

2 years ago
  1. import {
  2. statue2number
  3. } from "~/utils/constant";
  4. export function formatDate(t) {
  5. return new Date(t).toLocaleDateString().replace(/\//g, '.');
  6. }
  7. export function dateCardFormatDate(date) {
  8. return date.getFullYear() + "-" + (date.getMonth() + 1).toString().padStart(2, '0') + "-" + date.getDate().toString().padStart(2, '0');
  9. }
  10. export function dateCountDown(date) {
  11. let days = Math.ceil((new Date(date)-new Date())/1000/24/60/60);
  12. return days;
  13. }
  14. export function addSeperetor(query) {
  15. if (
  16. query.substr(query.length - 1) != "&" &&
  17. query.substr(query.length - 1) != "?"
  18. )
  19. query += "&";
  20. return query;
  21. }
  22. export function exhibitionApi2CardType(apiExhibitions) {
  23. let exhibitionList = []
  24. for (let i = 0; i < apiExhibitions.length; i++) {
  25. const item = {
  26. "id" : apiExhibitions[i].id || '',
  27. "title" : apiExhibitions[i].name || '',
  28. "location" : (apiExhibitions[i].region || apiExhibitions[i].country || apiExhibitions[i].city ?
  29. ( apiExhibitions[i].region && apiExhibitions[i].region.name ? apiExhibitions[i].region.name : "") +
  30. " - " +
  31. (apiExhibitions[i].country && apiExhibitions[i].country.name ? apiExhibitions[i].country.name : "") +
  32. " - " +
  33. (apiExhibitions[i].city && apiExhibitions[i].city.name ? apiExhibitions[i].city.name : "") :
  34. ""),
  35. "rate" : apiExhibitions[i].rating || 0,
  36. "rateNumber" : apiExhibitions[i].reviewCount || 0,
  37. "exhibitNumber" : apiExhibitions[i].exhibitors || '',
  38. "visitorNumber" : apiExhibitions[i].visitors || '',
  39. "category" : [],
  40. "image" : apiExhibitions[i].logo || '',
  41. "description" : apiExhibitions[i].about || '',
  42. "startDate" : apiExhibitions[i].startdate || '',
  43. "endDate" : apiExhibitions[i].enddate || '',
  44. "favorite" : apiExhibitions[i].isLiked || '',
  45. "recommend" : apiExhibitions[i].isRecommend || '',
  46. "status" : statue2number[apiExhibitions[i].status.name] || 0,
  47. "saved" : false
  48. };
  49. item.category = apiExhibitions[i].categories;
  50. exhibitionList.push(item)
  51. }
  52. return exhibitionList;
  53. }
  54. export function savedExhibitionApi2CardType(apiExhibitions) {
  55. let exhibitionList = Array(apiExhibitions.length).fill(1);
  56. for (let i = 0; i < apiExhibitions.length; i++) {
  57. exhibitionList[i] = {};
  58. exhibitionList[i].id = apiExhibitions[i].id;
  59. exhibitionList[i].title = apiExhibitions[i].name;
  60. exhibitionList[i].location =
  61. (apiExhibitions[i].region || apiExhibitions[i].country || apiExhibitions[i].city ?
  62. ( apiExhibitions[i].region && apiExhibitions[i].region.name ? apiExhibitions[i].region.name : "") +
  63. " - " +
  64. (apiExhibitions[i].country && apiExhibitions[i].country.name ? apiExhibitions[i].country.name : "") +
  65. " - " +
  66. (apiExhibitions[i].city && apiExhibitions[i].city.name ? apiExhibitions[i].city.name : "") :
  67. "");
  68. exhibitionList[i].country = apiExhibitions[i].country.id
  69. exhibitionList[i].rate = apiExhibitions[i].rating;
  70. // exhibitionList[i].rate = Math.ceil(apiExhibitions[i].rating)
  71. exhibitionList[i].rateNumber = apiExhibitions[i].reviewCount;
  72. exhibitionList[i].exhibitNumber = apiExhibitions[i].exhibitors;
  73. exhibitionList[i].visitorNumber = apiExhibitions[i].visitors;
  74. exhibitionList[i].category = apiExhibitions[i].categories;
  75. exhibitionList[i].image = apiExhibitions[i].logo;
  76. exhibitionList[i].description = apiExhibitions[i].about;
  77. exhibitionList[i].startDate = apiExhibitions[i].startdate;
  78. exhibitionList[i].endDate = apiExhibitions[i].enddate;
  79. exhibitionList[i].favorite = apiExhibitions[i].isLiked;
  80. exhibitionList[i].recommend = apiExhibitions[i].isRecommend;
  81. exhibitionList[i].status = statue2number[apiExhibitions[i].status.name];
  82. exhibitionList[i].saved = false
  83. }
  84. return exhibitionList;
  85. }
  86. export async function getData(axios, langQuery) {
  87. let data;
  88. ({
  89. data
  90. } = await axios.get(
  91. "/trending/ads" + langQuery
  92. ).catch((err) => {
  93. console.error(err);
  94. }));
  95. let ads = data.ads;
  96. ({
  97. data
  98. } = await axios.get(
  99. "/trending/banner" + langQuery
  100. ).catch((err) => {
  101. console.error(err);
  102. }));
  103. let banner = data.banner;
  104. let exhibitions = data.exhibitions || [];
  105. ({
  106. data
  107. } = await axios.get(
  108. "/trending/services" + langQuery
  109. ).catch((err) => {
  110. console.error(err);
  111. }));
  112. let services = data.services;
  113. ({
  114. data
  115. } = await axios.get(
  116. "/trending/themes/exhibitions" + langQuery
  117. ).catch((err) => {
  118. console.error(err);
  119. }));
  120. let themes = data.themes;
  121. let themesTitle = data.title;
  122. ({
  123. data
  124. } = await axios.get(
  125. "/trending/themes/services" + langQuery
  126. ).catch((err) => {
  127. console.error(err);
  128. }));
  129. let serviceThemes = data.themes;
  130. let serviceThemesTitle = data.title;
  131. ({
  132. data
  133. } = await axios.get(
  134. "/trending/partnerships" + langQuery
  135. ).catch((err) => {
  136. console.error(err);
  137. }));
  138. let partnerships = data.partnerships;
  139. ({
  140. data
  141. } = await axios.get(
  142. "/trending/exhibitions/collections" +
  143. langQuery
  144. ).catch((err) => {
  145. console.error(err);
  146. }));
  147. let collections = data.collections;
  148. ({
  149. data
  150. } = await axios.get(
  151. "/trending/search/popular" + langQuery
  152. ).catch((err) => {
  153. console.error(err);
  154. }));
  155. let populars = data.search;
  156. var slogenQuery = "/trending/slogans" + langQuery;
  157. ({
  158. data
  159. } = await axios.get(
  160. slogenQuery
  161. ).catch((err) => {
  162. console.error(err);
  163. }));
  164. let slogan = data.slogan;
  165. let subslogan = data.subslogan;
  166. ({
  167. data
  168. } = await axios.get(
  169. "/trending/services/search/history" +
  170. langQuery
  171. ).catch((err) => {
  172. console.error(err);
  173. }));
  174. let servicesSearchs = data.searches;
  175. ({
  176. data
  177. } = await axios.get(
  178. "/trending/services/locations" + langQuery
  179. ).catch((err) => {
  180. console.error(err);
  181. }));
  182. let servicesLocations = data.locations;
  183. ({
  184. data
  185. } = await axios.get(
  186. "/trending/exhibitions/search/history" +
  187. langQuery
  188. ).catch((err) => {
  189. console.error(err);
  190. }));
  191. let exhibitionsSearchs = data.searches;
  192. ({
  193. data
  194. } = await axios.get(
  195. "trending/exhibitions/locations" +
  196. langQuery
  197. ).catch((err) => {
  198. console.error(err);
  199. }));
  200. let exhibitionsLocations = data.locations;
  201. exhibitionsLocations = exhibitionsLocations.filter(region => region.region != null);
  202. for (let i = 0; i < exhibitionsLocations.length; i++) {
  203. exhibitionsLocations[i].countries = exhibitionsLocations[i].countries.filter(country => country.country != null);
  204. for (let j = 0; j < exhibitionsLocations[i].countries.length; j++) {
  205. if (exhibitionsLocations[i].countries[j].cities != null ) {
  206. exhibitionsLocations[i].countries[j].cities = exhibitionsLocations[i].countries[j].cities.filter(city => city.city != null);
  207. }
  208. }
  209. }
  210. ({
  211. data
  212. } = await axios.get(
  213. "/trending/exhibitions/categories" +
  214. langQuery
  215. ).catch((err) => {
  216. console.error(err);
  217. }));
  218. let exhibitionsCategories = data.categories;
  219. const apiData = {
  220. ads,
  221. exhibitions,
  222. services,
  223. themes,
  224. themesTitle,
  225. serviceThemes,
  226. serviceThemesTitle,
  227. partnerships,
  228. collections,
  229. slogan,
  230. subslogan,
  231. populars,
  232. servicesSearchs,
  233. servicesLocations,
  234. exhibitionsSearchs,
  235. exhibitionsLocations,
  236. exhibitionsCategories,
  237. banner
  238. };
  239. return apiData;
  240. }