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.

276 lines
7.8 KiB

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