/** * * @authors Eric Hsiao * */ main = function () { //private menbers var KOLData = { "name": "不知道", "text": "冰花煎餃很簡單", "kv_img": "ralf.png", "kv_img_s": "ralf_s.png", "kv_img_s_name": "ralf_s_name.png", "tag": "名人推薦,麵類,台式", "ingredient": [ { "ingredient_name": "奇美 奇美冷凍熟水餃-高麗菜豬肉1275g", "ingredient_id": 1, "ingredient_img": "ralf_01.jpg", "salepage_url": "https://shop.pxmart.com.tw/SalePage/index/1403948", "salepage_id": 1403948, "sku_id": 1415926 }, { "ingredient_name": "義峰 義峰低筋麵粉1kg", "ingredient_id": 2, "ingredient_img": "ralf_02.jpg", "salepage_url": "https://shop.pxmart.com.tw/SalePage/index/1403234", "salepage_id": 1403234, "sku_id": 1415212 }, { "ingredient_name": "欣臨 金寶日式風味甜玉米濃湯305g", "ingredient_id": 3, "ingredient_img": "ralf_03.jpg", "salepage_url": "https://shop.pxmart.com.tw/SalePage/index/1402753", "salepage_id": 1402753, "sku_id": 1414731 } ], "kol": { "name": "全聯先生", "id": "Ralf", "index": "0", "UTM":"&utm_campaign=Ralf&utm_medium=KOLbuy&utm_source=web" }, "voice": { "source": "ralf.mp3", "subtitle": [ { "timecode": "00:00", "text": "每天都「不知道」煮什麼好?
看雙寶煮夫全聯先生怎麼快速出餐,一打二也不失誤!", "ingredient_id": [] }, { "timecode": "00:30", "text": "1.在平底鍋內倒入一些油,再將水餃排列好。", "ingredient_id": [ 1 ] }, { "timecode": "00:36", "text": "2.將10克低筋麵粉加入200cc水中,拌勻倒入鍋內。", "ingredient_id": [ 2 ] }, { "timecode": "00:44", "text": "3.蓋上鍋蓋,以中小火慢慢收乾水分,待水分收乾就完成了。", "ingredient_id": [] }, { "timecode": "00:59", "text": "4.隨心情搭配玉米濃湯或是酸辣湯,打個蛋花就上桌。", "ingredient_id": [ 3 ] } ] } }; //private methods function init() { console.log('main is loaded.'); // loadData(); getOrderURL(KOLData); loadData(); } function getOrderURL(_kolData) { var _ingredientData = _kolData.ingredient; var resuleData = []; _ingredientData.forEach(element => { // console.log(element); var _result = { "salepage_id": "", "sku_id": "", "qty": 1 }; _result.salepage_id = element.salepage_id; _result.sku_id = element.sku_id; if(_result.sku_id !== null){ resuleData.push(_result); } }); console.log(resuleData); var _utm = _kolData.kol.UTM; var _url = 'http://shop.pxmart.com.tw/v2/ShoppingCart/BatchInsert?data=' + encodeURIComponent(JSON.stringify(resuleData)) + _utm; console.log(_url); return _url; } function loadData() { // if (index < salepageData.length) { console.log('START index = ',index); var _data = salepageData[index]; var _result = { "salepage_id": "", "sku_id": "", "qty": 1 }; _result.salepage_id = _data.salepage_id; $.ajax({ type: "POST", url: "https://apigw.px.91app.tw/ec/V1/SalePage/GetMain", data: { "id": 1403948 }, dataType: "json", success: function (response) { console.log('================== response ==================='); console.log(response); if (response.Status == 'Success') { // var _skuId = response.Data.SkuList[0].SkuId; // _result.sku_id = _skuId; // resuleData.push(_result); // index++; // loadData(); } }, error: function (XMLHttpRequest, textStatus, errorThrown) { console.log("Status: " + textStatus + ", Error: " + errorThrown); } }); // } else { // console.log('COMPLETE', resuleData); // } } //constructor { $(document).ready(function () { init(); }); } //public return { } } main = new main();