main.js 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. /**
  2. *
  3. * @authors Eric Hsiao
  4. *
  5. */
  6. main = function () {
  7. //private menbers
  8. var KOLData = {
  9. "name": "不知道",
  10. "text": "冰花煎餃很簡單",
  11. "kv_img": "ralf.png",
  12. "kv_img_s": "ralf_s.png",
  13. "kv_img_s_name": "ralf_s_name.png",
  14. "tag": "名人推薦,麵類,台式",
  15. "ingredient": [
  16. {
  17. "ingredient_name": "奇美 奇美冷凍熟水餃-高麗菜豬肉1275g",
  18. "ingredient_id": 1,
  19. "ingredient_img": "ralf_01.jpg",
  20. "salepage_url": "https://shop.pxmart.com.tw/SalePage/index/1403948",
  21. "salepage_id": 1403948,
  22. "sku_id": 1415926
  23. },
  24. {
  25. "ingredient_name": "義峰 義峰低筋麵粉1kg",
  26. "ingredient_id": 2,
  27. "ingredient_img": "ralf_02.jpg",
  28. "salepage_url": "https://shop.pxmart.com.tw/SalePage/index/1403234",
  29. "salepage_id": 1403234,
  30. "sku_id": 1415212
  31. },
  32. {
  33. "ingredient_name": "欣臨 金寶日式風味甜玉米濃湯305g",
  34. "ingredient_id": 3,
  35. "ingredient_img": "ralf_03.jpg",
  36. "salepage_url": "https://shop.pxmart.com.tw/SalePage/index/1402753",
  37. "salepage_id": 1402753,
  38. "sku_id": 1414731
  39. }
  40. ],
  41. "kol": {
  42. "name": "全聯先生",
  43. "id": "Ralf",
  44. "index": "0",
  45. "UTM":"&utm_campaign=Ralf&utm_medium=KOLbuy&utm_source=web"
  46. },
  47. "voice": {
  48. "source": "ralf.mp3",
  49. "subtitle": [
  50. {
  51. "timecode": "00:00",
  52. "text": "每天都「不知道」煮什麼好?<br>看雙寶煮夫全聯先生怎麼快速出餐,一打二也不失誤!",
  53. "ingredient_id": []
  54. },
  55. {
  56. "timecode": "00:30",
  57. "text": "1.在平底鍋內倒入一些油,再將水餃排列好。",
  58. "ingredient_id": [
  59. 1
  60. ]
  61. },
  62. {
  63. "timecode": "00:36",
  64. "text": "2.將10克低筋麵粉加入200cc水中,拌勻倒入鍋內。",
  65. "ingredient_id": [
  66. 2
  67. ]
  68. },
  69. {
  70. "timecode": "00:44",
  71. "text": "3.蓋上鍋蓋,以中小火慢慢收乾水分,待水分收乾就完成了。",
  72. "ingredient_id": []
  73. },
  74. {
  75. "timecode": "00:59",
  76. "text": "4.隨心情搭配玉米濃湯或是酸辣湯,打個蛋花就上桌。",
  77. "ingredient_id": [
  78. 3
  79. ]
  80. }
  81. ]
  82. }
  83. };
  84. //private methods
  85. function init() {
  86. console.log('main is loaded.');
  87. // loadData();
  88. getOrderURL(KOLData);
  89. loadData();
  90. }
  91. function getOrderURL(_kolData) {
  92. var _ingredientData = _kolData.ingredient;
  93. var resuleData = [];
  94. _ingredientData.forEach(element => {
  95. // console.log(element);
  96. var _result = { "salepage_id": "", "sku_id": "", "qty": 1 };
  97. _result.salepage_id = element.salepage_id;
  98. _result.sku_id = element.sku_id;
  99. if(_result.sku_id !== null){
  100. resuleData.push(_result);
  101. }
  102. });
  103. console.log(resuleData);
  104. var _utm = _kolData.kol.UTM;
  105. var _url = 'http://shop.pxmart.com.tw/v2/ShoppingCart/BatchInsert?data=' + encodeURIComponent(JSON.stringify(resuleData)) + _utm;
  106. console.log(_url);
  107. return _url;
  108. }
  109. function loadData() {
  110. // if (index < salepageData.length) {
  111. console.log('START index = ',index);
  112. var _data = salepageData[index];
  113. var _result = { "salepage_id": "", "sku_id": "", "qty": 1 };
  114. _result.salepage_id = _data.salepage_id;
  115. $.ajax({
  116. type: "POST",
  117. url: "https://apigw.px.91app.tw/ec/V1/SalePage/GetMain",
  118. data: { "id": 1403948 },
  119. dataType: "json",
  120. success: function (response) {
  121. console.log('================== response ===================');
  122. console.log(response);
  123. if (response.Status == 'Success') {
  124. // var _skuId = response.Data.SkuList[0].SkuId;
  125. // _result.sku_id = _skuId;
  126. // resuleData.push(_result);
  127. // index++;
  128. // loadData();
  129. }
  130. },
  131. error: function (XMLHttpRequest, textStatus, errorThrown) {
  132. console.log("Status: " + textStatus + ", Error: " + errorThrown);
  133. }
  134. });
  135. // } else {
  136. // console.log('COMPLETE', resuleData);
  137. // }
  138. }
  139. //constructor
  140. {
  141. $(document).ready(function () {
  142. init();
  143. });
  144. }
  145. //public
  146. return {
  147. }
  148. }
  149. main = new main();