Ei kuvausta
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-old 23KB

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