Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

laptopdetails.js 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593
  1. function startDetails() {
  2. // http://127.0.0.1:5502/productdetails.html?productId=106633230000024
  3. if (window.location.search.split('=')[0] == '') {
  4. window.location.href = "/notfound.html";
  5. return;
  6. }
  7. let productId = window.location.href.split('=')[1].split('&')[0].split('#')[0];
  8. console.log(productId);
  9. let itemtagscombinationRes = null;
  10. let labels = {};
  11. let isThereInLabel = {};
  12. let currentComb = null;
  13. let group = {};
  14. let loadingActions = {
  15. addLoader() {
  16. $('.loadingCall').removeClass('d-none');
  17. $('.mainContanierProduct').addClass('d-none');
  18. },
  19. removeLoader() {
  20. $('.loadingCall').addClass('d-none');
  21. $('.mainContanierProduct').removeClass('d-none');
  22. }
  23. }
  24. let currentClick = null;
  25. if (productId) {
  26. loadingActions.addLoader();
  27. updateProductId(productId);
  28. getProductDetails(productId);
  29. appendSpecs(productId)
  30. } else {
  31. window.location.href = "/notfound.html"
  32. }
  33. function updateProductId(val) {
  34. $('#productidtag').val(val);
  35. }
  36. function updateItemId(val) {
  37. $('#itemidtag').val(val);
  38. }
  39. let specification_wrap_action = {
  40. remove() {
  41. $('.specification-wrap').addClass('d-none');
  42. },
  43. add() {
  44. $('.specification-wrap').removeClass('d-none');
  45. }
  46. }
  47. let description_action = {
  48. addVal(value) {
  49. $('.description-wrap > p').html(value);
  50. },
  51. removeVal(value) {
  52. $('.description-wrap > p').html('');
  53. }
  54. }
  55. function getSpecsItemHTML({ name, des, itemid, id }) {
  56. return `<div id="${id}" data-specitemid="${itemid}" class="">
  57. <div class="row border-bottom">
  58. <div class="col-sm-6 bg-gray-3 py-2">
  59. ${name}
  60. </div>
  61. <div class="col-sm-6 py-2">
  62. ${des}
  63. </div>
  64. </div>
  65. </div>`;
  66. }
  67. // function getSpecsItemHTML({name,des,itemid,id}){
  68. // return ` <tr id="${id}" data-specitemid="${itemid}">
  69. // <td style="width:200px">${name}</td>
  70. // <td class="">${des}</td>
  71. // </tr>`;
  72. // }
  73. async function appendSpecs(id) {
  74. let resData = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/itemspecifications/itemid/${id}`, true);
  75. if (resData.isError) {
  76. $('.productdetailstabs').addClass('d-none');
  77. $('.specContainerleft').html('')
  78. $('.specContainerRight').html('')
  79. return;
  80. }
  81. $('.productdetailstabs ').removeClass('d-none');
  82. const res = resData.response;
  83. console.log(JSON.parse(res.result));
  84. const data = JSON.parse(res.result);
  85. console.log(data);
  86. let html = '';
  87. let leftHtml = '';
  88. let rightHtml = '';
  89. if (data.length == 0) {
  90. $('.productdetailstabs ').addClass('d-none');
  91. $('.specContainerleft').html('')
  92. $('.specContainerRight').html('')
  93. return;
  94. }
  95. for (let i = 0; i < data.length; i++) {
  96. const { specificationname, specificationitemid, itemid, description } = data[i];
  97. if ((i + 1) % 2 == 0) {
  98. rightHtml += getSpecsItemHTML({
  99. name: specificationname, id: specificationitemid, itemid, des: description
  100. })
  101. } else {
  102. leftHtml += getSpecsItemHTML({
  103. name: specificationname, id: specificationitemid, itemid, des: description
  104. });
  105. }
  106. }
  107. $('.specContainerleft').html(leftHtml)
  108. $('.specContainerRight').html(rightHtml)
  109. }
  110. function getParentHTML(name, productid, id, isMain) {
  111. return `<div data-parentidgroup="${name?.replace(" ", '')}-parent" class="pb-2 groupingitems_search ${name?.replace(" ", '')}-parent">
  112. <h5 class="py-2 smallHeadingProductDetails">${name}</h5>
  113. <div class="d-flex gap-2 flex-lg-row flex-wrap ${id}container" data-tagid="${id}">
  114. </div>
  115. </div>`;
  116. }
  117. function onClickHandler(e) {
  118. $(e).parent().find('.borderselector').removeClass('borderselector');
  119. $(e).addClass('borderselector')
  120. }
  121. function getChildHTML(tagid, name, isTrue) {
  122. return `
  123. <div data-type="${tagid}-${name}" data-tagiditem="${tagid}" class="specsmallcard optiontaganwi ${isTrue ? 'borderselector' : ''} card text-center small-font cursor-pointer p-3">
  124. ${name}
  125. </div> `
  126. }
  127. function addeventlisteners() {
  128. $('.optiontaganwi').each(function (i, el) {
  129. $(el).click(function (e) {
  130. debugger;
  131. $('#quantity').val(1);
  132. $(e.target).parent().find('.borderselector').removeClass('borderselector');
  133. $(e.target).addClass('borderselector');
  134. searchComb();
  135. currentClick = e.target;
  136. getAllCombination();
  137. })
  138. });
  139. }
  140. function updateDetailsByObj(obj) {
  141. $('.productname').html(obj.itemname)
  142. let [currencySymbol, amount] = getCurrencySymbol(obj?.pricelist||0);
  143. $('.price').html(obj.pricelist ?`${currencySymbol}${amount}'`:'');
  144. appendSpecs(obj.itemid)
  145. $('#skudetailitem').val(obj.sku)
  146. $('.des_productdes').html(obj.itemdescription);
  147. $('#addtocart').attr('data-qty', obj.quantity);
  148. debugger;
  149. let defaultImg = obj.itemimageurl ? imgServerNameBuild(obj.itemimageurl) : `./dist/assets/imgs/nophoto.png`;
  150. console.log(obj.itemimageurl, 'obj.itemimageurlobj.itemimageurlobj.itemimageurl');
  151. $('.productDetailsMain > img').attr('src', defaultImg);
  152. updateItemId(obj.itemid);
  153. if (!obj.pricelist) {
  154. $('.buynow').attr('disabled', true);
  155. $('#addtocart').attr('disabled', true);
  156. } else {
  157. $('.buynow').attr('disabled', false);
  158. $('#addtocart').attr('disabled', false);
  159. }
  160. }
  161. function searchComb() {
  162. let valuesSelected = [];
  163. $('.optiontaganwi').removeClass('disabled-option-item')
  164. $('#addtocart').removeClass('disabled');
  165. $('.msgErrorDetailsItem').addClass('d-none');
  166. $('.borderselector,border_selector').each(function (i, el) {
  167. console.log($(el).html())
  168. let val = $(el).data('tagiditem');
  169. valuesSelected.push(val);
  170. });
  171. let labelRecord = {};
  172. for (let label in labels) {
  173. labelRecord[label] = false;
  174. }
  175. console.log(labelRecord);
  176. specification_wrap_action.add();
  177. console.log(group);
  178. let unFiler = null;
  179. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  180. const currItem = itemtagscombinationRes[i];
  181. const { tagids } = currItem;
  182. let isTrue = true;
  183. let labelFilter = labelRecord;
  184. for (let i = 0; i < valuesSelected.length; i++) {
  185. if (!tagids.includes(valuesSelected[i])) {
  186. isTrue = false
  187. unFiler = labelFilter;
  188. break;
  189. }
  190. labelFilter[group[valuesSelected[i]]] = true;
  191. }
  192. if (isTrue) {
  193. console.log(itemtagscombinationRes[i], 'itemtagscombinationRes[i]');
  194. const { quantity } = itemtagscombinationRes[i];
  195. if (quantity >= $('#quantity').val() && quantity >= 1) {
  196. currentComb = itemtagscombinationRes[i];
  197. // $('.productname').html(itemtagscombinationRes[i].itemname)
  198. // $('.price').html(itemtagscombinationRes[i].pricelist);
  199. // location.hash = itemtagscombinationRes[i].itemname.trim();
  200. // appendSpecs(itemtagscombinationRes[i].itemid)
  201. history.replaceState(null, null, `#itemid=${itemtagscombinationRes[i].itemid}#${itemtagscombinationRes[i].itemname.trim()}`);
  202. // $('#skudetailitem').val(itemtagscombinationRes[i].sku)
  203. // $('.des_productdes').html(itemtagscombinationRes[i].itemdescription);
  204. updateDetailsByObj(itemtagscombinationRes[i]);
  205. } else {
  206. let name = itemtagscombinationRes[i].itemname.split('-')[0];
  207. $('#addtocart').addClass('disabled');
  208. let itemsName = name;
  209. $('.borderselector').each(function (i, e) {
  210. itemsName += ` ${$(e).html().trim()}`;
  211. });
  212. updateItemId(null);
  213. let defaultImg = itemtagscombinationRes[i].itemimageurl ? imgServerNameBuild(itemtagscombinationRes[i].itemimageurl) : `./dist/assets/imgs/nophoto.png`;
  214. console.log(itemtagscombinationRes[i].itemimageurl, 'obj.itemimageurlobj.itemimageurlobj.itemimageurl');
  215. $('.productDetailsMain > img').attr('src', defaultImg);
  216. specification_wrap_action.remove();
  217. $('#skudetailitem').val(-1)
  218. $('.productname').html(itemsName)
  219. history.replaceState(null, null, `#`);
  220. $('.msgErrorDetailsItem').removeClass('d-none');
  221. $('.des_productdes').html('');
  222. $('.price').html('');
  223. }
  224. initAddToCart()
  225. return;
  226. }
  227. }
  228. alert("j");
  229. let name = itemtagscombinationRes[0].itemname.split('-')[0];
  230. let itemsName = name;
  231. $('.borderselector').each(function (i, e) {
  232. itemsName += `- ${$(e).html().trim()}`;
  233. })
  234. specification_wrap_action.remove();
  235. $('.productname').html(itemsName)
  236. $('#skudetailitem').val(-1)
  237. $('.price').html('');
  238. $('#addtocart').addClass('disabled');
  239. $('.msgErrorDetailsItem').removeClass('d-none');
  240. initAddToCart()
  241. }
  242. function getAllCombination() {
  243. debugger;
  244. const currClickAttr = $(currentClick).html().trim();
  245. let isThere = [];
  246. for (let item in isThereInLabel) {
  247. let { tagnames } = isThereInLabel[item];
  248. if (tagnames.includes(currClickAttr)) {
  249. isThere.push(isThereInLabel[item])
  250. }
  251. }
  252. if (!isThere.length) {
  253. let curr = $(currentClick).parents('.groupingitems_search').data('parentidgroup');
  254. $('.groupingitems_search').each(function (i, e) {
  255. const id = $(e).data('parentidgroup');
  256. if (id != curr) {
  257. $(e).find('.optiontaganwi').addClass('disabled-option-item');
  258. }
  259. });
  260. return;
  261. }
  262. let selected = [];
  263. $('.borderselector').each(function (i, e) {
  264. selected.push($(e).html().trim())
  265. });
  266. // console.log(selected);
  267. // console.log(isThere);
  268. let ishashObj = {};
  269. for (let i = 0; i < isThere.length; i++) {
  270. let { tagnames, tagids } = isThere[i];
  271. tagnames = tagnames.split('|');
  272. tagids = tagids.split('|');
  273. for (let j = 0; j < tagnames.length; j++) {
  274. if (!ishashObj[tagnames[j]]) {
  275. ishashObj[tagnames[j]] = tagids[j];
  276. }
  277. }
  278. }
  279. console.log(ishashObj);
  280. // for(let i=0;i<itemtagscombinationRes.length;i++){
  281. // }
  282. }
  283. async function getProductDetails(id) {
  284. debugger;
  285. let resData = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/productattributelist/productid/${id}`, true);
  286. if (resData.isError) {
  287. loadingActions.removeLoader();
  288. alert(resData.errorMsg.message);
  289. return;
  290. }
  291. let res = resData.response;
  292. res = JSON.parse(res.result);
  293. console.log(res, 'productattributelist');
  294. if (!res) {
  295. loadingActions.removeLoader();
  296. return;
  297. };
  298. let html = '';
  299. for (let i = 0; i < res.length; i++) {
  300. const currItem = res[i];
  301. // parenttagid means under what label
  302. // tag id means it know unquie id
  303. const { parentattribute, parenttagid, tagid, attribute, productid } = currItem;
  304. if (labels[parentattribute]) {
  305. labels[parentattribute].items.push({
  306. attribute,
  307. tagid: tagid
  308. });
  309. } else {
  310. labels[parentattribute] = {
  311. id: parenttagid,
  312. items: [{
  313. attribute,
  314. tagid: tagid
  315. }]
  316. };
  317. html += getParentHTML(parentattribute, productid, parenttagid, i == 0);
  318. }
  319. }
  320. $('#spec-container-details').html(html);
  321. // console.log(labels,'labels');
  322. let childIds = [];
  323. for (let item in labels) {
  324. let { id, items } = labels[item];
  325. // $(`[data-tagid=${id}]`)
  326. let html = '';
  327. for (let i = 0; i < items.length; i++) {
  328. const { attribute, tagid } = items[i]
  329. childIds.push(tagid);
  330. group[attribute] = item;
  331. html += getChildHTML(tagid, attribute, i == 0);
  332. }
  333. $(`[data-tagid="${id}"]`).html(html);
  334. }
  335. itemtagscombinationRes = await API_SERVICES_ACTIONS.getAPIService(`apis/v4/bizgaze/integrations/products/getitemwithoutbranch/productid/${id}`, true);
  336. itemtagscombinationRes = JSON.parse(itemtagscombinationRes.response.result);
  337. console.log(itemtagscombinationRes, "conductt");
  338. let valuesSelected = [];
  339. $('.borderselector').each(function (i, el) {
  340. let val = $(el).html();
  341. valuesSelected.push(val.trim());
  342. });
  343. let searchParams = window.location.search.split("&");
  344. let skuId = window.location.hash.split('#')[1].split('=')[1];
  345. // skuId = skuId.split('=')[1]
  346. let isGo = true;
  347. for (let i = 0; i < itemtagscombinationRes.length; i++) {
  348. const currItem = itemtagscombinationRes[i];
  349. const { tagnames, sku, itemid } = currItem;
  350. isThereInLabel[tagnames] = itemtagscombinationRes[i];
  351. let isTrue = true;
  352. if (isGo) {
  353. // for(let i=0;i<valuesSelected.length;i++){
  354. // if(!tagnames.includes(valuesSelected[i])){
  355. // isTrue = false
  356. // }
  357. // }
  358. if (i != 0) {
  359. isTrue = false
  360. }
  361. if (isTrue) {
  362. console.log(itemtagscombinationRes[i], 'itemtagscombinationRes[i]');
  363. currentComb = itemtagscombinationRes[i];
  364. updateDetailsByObj(itemtagscombinationRes[i]);
  365. isGo = false;
  366. let { tagnames, tagids, pricelist } = itemtagscombinationRes[i];
  367. tagids = tagids.split('|');
  368. tagnames = tagnames.split('|');
  369. $('.optiontaganwi').removeClass('borderselector');
  370. for (let i = 0; i < tagids.length; i++) {
  371. $(`[data-tagiditem="${tagids[i]}"]`).addClass('borderselector');
  372. }
  373. // tagiditem
  374. }
  375. }
  376. }
  377. if (isGo && itemtagscombinationRes.length != 0) {
  378. console.log(itemtagscombinationRes[0]);
  379. let { tagnames, tagids, pricelist } = itemtagscombinationRes[0];
  380. tagids = tagids.split('|');
  381. tagnames = tagnames.split('|');
  382. $('.optiontaganwi').removeClass('borderselector');
  383. currentComb = itemtagscombinationRes[0];
  384. // updateItemId(itemtagscombinationRes[0].itemid);
  385. for (let i = 0; i < tagids.length; i++) {
  386. $(`[data-type="${tagids[i]}-${tagnames[i]}"]`).addClass('borderselector');
  387. // $(`[data-type="${tagids[i]}-Eucalyptus Green"]`).removeClass('borderselector');
  388. // $(`[data-type="${tagids[i]}-Desert Brown"]`).removeClass('borderselector');
  389. // $(`[data-type="${tagids[i]}-Deep Sea Blue"]`).removeClass('borderselector');
  390. }
  391. // $('.price').html(pricelist);
  392. // $('.des_productdes').html(itemtagscombinationRes[0].itemdescription);
  393. // appendSpecs(itemtagscombinationRes[0].itemid);
  394. updateDetailsByObj(itemtagscombinationRes[0]);
  395. //console.log(childIds);
  396. //
  397. }
  398. //getAllCombination()
  399. // for(let i=0;i<itemtagscombinationRes.length;i++){
  400. // const {tagnames} = itemtagscombinationRes[i];
  401. // }
  402. $('#spec-container-details').children().find('.specsmallcard').removeClass('specsmallcard');
  403. addeventlisteners();
  404. loadingActions.removeLoader();
  405. return;
  406. // let resTwo = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/itemtagscombination/productid/${id}`);
  407. //let html = '';
  408. let attributesObj = {};
  409. for (let i = 0; i < res.length; i++) {
  410. const { parentattribute, tagid, productid } = res[i];
  411. // let attributes = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/productattributelist/parenttagid/${tagid}`);
  412. // attributesObj[tagid] = JSON.parse(attributes.data.result);
  413. // console.log(attributes.data.result,tagid);
  414. html += getParentHTML(parentattribute, productid, tagid, i == 0);
  415. }
  416. $('#spec-container-details').html(html);
  417. // let attributes = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/productattributelist/parenttagid/${tagid}`);
  418. return;
  419. for (let attr in attributesObj) {
  420. const arr = attributesObj[attr];
  421. let html = '';
  422. for (let i = 0; i < arr.length; i++) {
  423. const { attribute, tagid } = arr[i];
  424. html += getChildHTML(tagid, attribute, i == 0);
  425. }
  426. $(`[data-tagid="${attr}"]`).html(html);
  427. }
  428. let defaultValues = await postStatAPIService(`${SERVERNAME}/apis/v4/bizgaze/integrations/products/sellableitemlist/productid/${id}`);
  429. defaultValues = JSON.parse(defaultValues.data.result);
  430. let { itemname, price } = defaultValues[0];
  431. $('.productname').html(itemname);
  432. $('.price').html(price)
  433. $('#spec-container-details').children().slice(1).find('.specsmallcard').removeClass('specsmallcard');
  434. // getQuantityById(id)
  435. }
  436. }
  437. startDetails();