...
|
...
|
@@ -3,6 +3,7 @@ |
|
|
import ReactNative from 'react-native';
|
|
|
import SeckillService from '../../services/SeckillService';
|
|
|
const Platform = require('Platform');
|
|
|
const moment = require('moment');
|
|
|
|
|
|
const {
|
|
|
SET_HOST,
|
...
|
...
|
@@ -14,9 +15,19 @@ const { |
|
|
QUERY_PRODUCT_LIST_SUCCESS,
|
|
|
QUERY_PRODUCT_LIST_FAILURE,
|
|
|
|
|
|
QUERY_REMIND_LIST_REQUEST,
|
|
|
QUERY_REMIND_LIST_SUCCESS,
|
|
|
QUERY_REMIND_LIST_FAILURE,
|
|
|
|
|
|
ADD_CANCEL_USER_REMINDER_REQUEST,
|
|
|
ADD_CANCEL_USER_REMINDER_SUCCESS,
|
|
|
ADD_CANCEL_USER_REMINDER_FAILURE,
|
|
|
|
|
|
UPDATE_SECKILL_PRODUCT_VO_LIST,
|
|
|
UPDATE_SECKILL_PRODUCT_LIST,
|
|
|
} = require('../../constants/actionTypes').default;
|
|
|
|
|
|
let curActivityId = 0;
|
|
|
/**
|
|
|
* [时间缺0补0]
|
|
|
*/
|
...
|
...
|
@@ -38,7 +49,6 @@ export function queryActivityRequest() { |
|
|
}
|
|
|
|
|
|
export function queryActivitySuccess(json) {
|
|
|
console.log('cccccc');
|
|
|
return {
|
|
|
type: QUERY_ACTIVITY_SUCCESS,
|
|
|
payload: json
|
...
|
...
|
@@ -72,12 +82,59 @@ export function queryProductListFailure(error) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRemindListRequest() {
|
|
|
return {
|
|
|
type: QUERY_REMIND_LIST_REQUEST
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRemindListSuccess(json) {
|
|
|
return {
|
|
|
type: QUERY_REMIND_LIST_SUCCESS,
|
|
|
payload: json
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRemindListFailure(error) {
|
|
|
return {
|
|
|
type: QUERY_REMIND_LIST_FAILURE,
|
|
|
payload: error
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function addCancelUserReminderRequest() {
|
|
|
return {
|
|
|
type: ADD_CANCEL_USER_REMINDER_REQUEST
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function addCancelUserReminderSuccess(message) {
|
|
|
return {
|
|
|
type: ADD_CANCEL_USER_REMINDER_SUCCESS,
|
|
|
payload: message
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function addCancelUserReminderFailure(message) {
|
|
|
return {
|
|
|
type: ADD_CANCEL_USER_REMINDER_FAILURE,
|
|
|
payload: message
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function updateSecKillProductVoList(json) {
|
|
|
return {
|
|
|
type: UPDATE_SECKILL_PRODUCT_VO_LIST,
|
|
|
payload: json
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function updateSecKillProductList(json) {
|
|
|
return {
|
|
|
type: UPDATE_SECKILL_PRODUCT_LIST,
|
|
|
payload: json
|
|
|
}
|
|
|
}
|
|
|
/*
|
|
|
* 秒杀时间栏
|
|
|
*/
|
...
|
...
|
@@ -92,13 +149,17 @@ export function getSeckillQueryActivity() { |
|
|
let processedTimeInfo = parseActivityTimeLsit(json);
|
|
|
dispatch(queryActivitySuccess(processedTimeInfo.newQueryActivityInfo));
|
|
|
let focusActivity = processedTimeInfo.focusActivity;
|
|
|
dispatch(getSeckillProductList(focusActivity.activityId));
|
|
|
curActivityId = focusActivity.activityId;
|
|
|
if (Date.now() < focusActivity.startTime) {
|
|
|
dispatch(getSeckillRemindList(curActivityId));
|
|
|
} else {
|
|
|
dispatch(getSeckillProductList(curActivityId));
|
|
|
}
|
|
|
} else {
|
|
|
dispatch(queryActivityFailure({error:'来晚啦~秒杀已结束'}));
|
|
|
}
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log('bbbb');
|
|
|
dispatch(queryActivityFailure(error));
|
|
|
});
|
|
|
};
|
...
|
...
|
@@ -107,40 +168,287 @@ export function getSeckillQueryActivity() { |
|
|
/*
|
|
|
* 秒杀商品列表
|
|
|
*/
|
|
|
export function getSeckillProductList(activityId = 1) {
|
|
|
export function getSeckillProductList(activityId = curActivityId) {
|
|
|
curActivityId = activityId;
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, seckill} = getState();
|
|
|
|
|
|
dispatch(queryProductListRequest());
|
|
|
return new SeckillService(app.host).fetchQueryProductList(activityId)
|
|
|
|
|
|
let queryProductList = (activityId) => {
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryRemindList} = seckill;
|
|
|
queryRemindList = queryRemindList.toJS();
|
|
|
return new SeckillService(app.host).fetchQueryProductList(activityId)
|
|
|
.then(json => {
|
|
|
let productList = productAddFlag(json, queryRemindList);
|
|
|
dispatch(queryProductListSuccess(productList, queryRemindList));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(queryProductListFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
queryProductList(activityId);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
queryProductList(activityId);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getSeckillRemindList(activityId = curActivityId) {
|
|
|
curActivityId = activityId;
|
|
|
return (dispatch, getState) => {
|
|
|
dispatch(queryRemindListRequest());
|
|
|
|
|
|
let queryRemindList = (activityId, uid) => {
|
|
|
let {app} = getState();
|
|
|
return new SeckillService(app.host).fetchQueryRemindList(activityId, uid)
|
|
|
.then(json => {
|
|
|
dispatch(queryRemindListSuccess(json));
|
|
|
dispatch(getSeckillProductList(activityId));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(queryRemindListFailure(error));
|
|
|
dispatch(getSeckillProductList(activityId));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
queryRemindList(activityId, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
queryRemindList(activityId, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function addCancelUserReminder(method='app.seckill.addUserReminder', activityId=0, productSkn=0, uid=0, secKillId=0, okTip='', failTip='') {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryProductList} = seckill;
|
|
|
dispatch(addCancelUserReminderRequest());
|
|
|
return new SeckillService(app.host).addCancelUserReminder(method,activityId,productSkn,uid,secKillId)
|
|
|
.then(json => {
|
|
|
console.log('22222222222222');
|
|
|
console.log(json);
|
|
|
dispatch(queryProductListSuccess(json));
|
|
|
//更新提醒状态
|
|
|
let remindFlag;
|
|
|
if (method === 'app.seckill.addUserReminder') {
|
|
|
remindFlag = true;
|
|
|
} else {
|
|
|
remindFlag = false;
|
|
|
}
|
|
|
queryProductList = queryProductList.toJS();
|
|
|
let curActivity = {};
|
|
|
console.log('99999999');
|
|
|
console.log(queryProductList);
|
|
|
queryProductList.forEach((productItem, i) => {
|
|
|
if (productItem.id === secKillId) {
|
|
|
productItem.remindFlag = remindFlag;
|
|
|
}
|
|
|
});
|
|
|
console.log('5555555');
|
|
|
console.log(queryProductList);
|
|
|
dispatch(updateSecKillProductList(queryProductList));
|
|
|
dispatch(addCancelUserReminderSuccess(okTip));
|
|
|
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(queryProductListFailure(error));
|
|
|
console.log('error');
|
|
|
console.log(error);
|
|
|
dispatch(addCancelUserReminderFailure(failTip));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
|
|
|
export function clickActivityTimeItem(activity) {
|
|
|
curActivityId = activity.activityId;
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryActivityInfo} = seckill;
|
|
|
queryActivityInfo = queryActivityInfo.toJS();
|
|
|
let curActivity = {};
|
|
|
queryActivityInfo.secKillProductVoList.forEach((activityTimeItem, i) => {
|
|
|
if (activityTimeItem.activityId === activity.activityId) {
|
|
|
curActivity = activityTimeItem;
|
|
|
activityTimeItem.focus = true;
|
|
|
} else {
|
|
|
activityTimeItem.focus = false;
|
|
|
}
|
|
|
});
|
|
|
dispatch(updateSecKillProductVoList(queryActivityInfo.secKillProductVoList));
|
|
|
dispatch(getSeckillProductList(activity.activityId));
|
|
|
if (Date.now() < curActivity.startTime) {
|
|
|
dispatch(getSeckillRemindList(curActivityId));
|
|
|
} else {
|
|
|
dispatch(getSeckillProductList(curActivityId));
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function clickProductItem(product) {
|
|
|
return (dispatch, getState) => {
|
|
|
if (!product.secKillSku || product.secKillSku.length == 0) {
|
|
|
return;
|
|
|
}
|
|
|
let skn = product.secKillSku[0].productSkn;
|
|
|
//
|
|
|
let url = `http://m.yohobuy.com?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${skn}", "is_seckill": "Y","tags_filter":""}}`;
|
|
|
ReactNative.NativeModules.YH_CommonHelper.jumpWithUrl(url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function clickRemindBtn(product) {
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
if (!product.secKillSku || product.secKillSku.length == 0) {
|
|
|
return;
|
|
|
}
|
|
|
console.log('333333');
|
|
|
|
|
|
let skn = product.secKillSku[0].productSkn;
|
|
|
let actionName,
|
|
|
action,
|
|
|
params,
|
|
|
on_off,
|
|
|
method;
|
|
|
let okTip,
|
|
|
failTip,
|
|
|
result;
|
|
|
// default
|
|
|
on_off = true;
|
|
|
action = 'go.addSecKill';
|
|
|
method = 'app.seckill.addUserReminder';
|
|
|
params = {
|
|
|
skn: skn,
|
|
|
startTime: product.startTime,
|
|
|
productName: product.productName,
|
|
|
};
|
|
|
okTip = '设置提醒成功,将在开抢3分钟前提醒';
|
|
|
failTip = '设置提醒失败';
|
|
|
|
|
|
if (product.remindFlag) {
|
|
|
on_off = false;
|
|
|
action = 'go.delSecKill';
|
|
|
okTip = '取消提醒成功';
|
|
|
failTip = '取消提醒失败';
|
|
|
method = 'app.seckill.cancelUserReminder';
|
|
|
}
|
|
|
let queryRemindList = (uid) => {
|
|
|
ReactNative.NativeModules.YH_SeckillHelper.remindTip({
|
|
|
method: action,
|
|
|
arguments: params,
|
|
|
})
|
|
|
.then(flag => {
|
|
|
|
|
|
})
|
|
|
.then(flag => { //成功
|
|
|
console.log('method');
|
|
|
console.log(method);
|
|
|
dispatch(addCancelUserReminder(method, product.activityId, skn,uid, product.id, okTip, failTip));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
};
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
console.log('1111');
|
|
|
queryRemindList(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
console.log('22222');
|
|
|
console.log(error);
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
queryRemindList(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function refreshList() {
|
|
|
return (dispatch, getState) => {
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryActivityInfo,queryProductList} = seckill;
|
|
|
if (curActivityId !== 0) {
|
|
|
dispatch(getSeckillRemindList(curActivityId));
|
|
|
} else {
|
|
|
dispatch(getSeckillQueryActivity());
|
|
|
}
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 秒杀商品 添加 自定义属性
|
|
|
* ----------------------------------------
|
|
|
* 已开抢
|
|
|
* product.over [APP,H5: 1.已抢光 2.过了endTime]
|
|
|
* product.isSeckill [APP,H5 秒杀中, 与over互斥]
|
|
|
* 抢购中:
|
|
|
* product.over
|
|
|
* product.isSeckill
|
|
|
* 即将开抢:
|
|
|
* product.wait = true
|
|
|
* product.remindFlag = true [APP: 已添加提醒]
|
|
|
* product.remindFalg = false [APP: 默认提醒状态]
|
|
|
* Product.hideRemind = true [APP: queryRemindList接口失败的情况下]
|
|
|
*/
|
|
|
function productAddFlag(productList, remindList) {
|
|
|
let now = Date.now();
|
|
|
|
|
|
productList
|
|
|
.sort((a, b) => b.orderBy - a.orderBy)
|
|
|
.forEach(product => {
|
|
|
let startTime = product.startTime * 1000; // s to ms
|
|
|
let endTime = product.endTime * 1000;
|
|
|
|
|
|
product.remindFlag = false;
|
|
|
product.readableTime = moment.unix(product.startTime).format('MM月DD日 HH:mm');
|
|
|
|
|
|
if (now < startTime) { // 未开抢
|
|
|
product.wait = true;
|
|
|
product.isSeckill = true;
|
|
|
|
|
|
if (!remindList) {
|
|
|
product.hideRemind = true;
|
|
|
} else if (remindList.length) {
|
|
|
for (let i = 0, j = remindList.length; i < j; i++) {
|
|
|
if (remindList[i].productSkn === product.productSkn) { // remind on;
|
|
|
product.remindFlag = true;
|
|
|
remindList.splice(i, 1);
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
} else if (product.secKillStatus === 0 || (now > endTime)) { // 确实已抢光, 过了秒杀时间
|
|
|
product.over = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return productList;
|
|
|
}
|
|
|
|
|
|
|
|
|
function parseActivityTimeLsit(json, focusTime=0) {
|
|
|
let currentTime = json && json.currentTime ? json.currentTime * 1000 : Date.new();
|
|
|
let secKillProductVoList = json && json.secKillProductVoList ? json.secKillProductVoList : [];
|
...
|
...
|
@@ -200,7 +508,6 @@ function parseActivityTimeLsit(json, focusTime=0) { |
|
|
activityTimeItem.focus = true;
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
i = i - 1;
|
|
|
}
|
|
|
|
...
|
...
|
|