No Description
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.

laptopdetails.js 19KB

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