...
|
...
|
@@ -2,6 +2,8 @@ |
|
|
|
|
|
import ReactNative from 'react-native';
|
|
|
import SeckillService from '../../services/SeckillService';
|
|
|
import Immutable, {Map} from 'immutable';
|
|
|
|
|
|
const Platform = require('Platform');
|
|
|
const moment = require('moment');
|
|
|
|
...
|
...
|
@@ -16,9 +18,9 @@ const { |
|
|
QUERY_PRODUCT_LIST_SUCCESS,
|
|
|
QUERY_PRODUCT_LIST_FAILURE,
|
|
|
|
|
|
QUERY_REMIND_LIST_REQUEST,
|
|
|
QUERY_REMIND_LIST_SUCCESS,
|
|
|
QUERY_REMIND_LIST_FAILURE,
|
|
|
QUERY_PRODUCT_AND_REMIND_LIST_REQUEST,
|
|
|
QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS,
|
|
|
QUERY_PRODUCT_AND_REMIND_LIST_FAILURE,
|
|
|
|
|
|
ADD_CANCEL_USER_REMINDER_REQUEST,
|
|
|
ADD_CANCEL_USER_REMINDER_SUCCESS,
|
...
|
...
|
@@ -84,22 +86,22 @@ export function queryProductListFailure(error) { |
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRemindListRequest() {
|
|
|
export function queryProductAndRemindListRequest() {
|
|
|
return {
|
|
|
type: QUERY_REMIND_LIST_REQUEST
|
|
|
type: QUERY_PRODUCT_AND_REMIND_LIST_REQUEST
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRemindListSuccess(json) {
|
|
|
export function queryProductAndRemindListSuccess(json) {
|
|
|
return {
|
|
|
type: QUERY_REMIND_LIST_SUCCESS,
|
|
|
type: QUERY_PRODUCT_AND_REMIND_LIST_SUCCESS,
|
|
|
payload: json
|
|
|
}
|
|
|
}
|
|
|
|
|
|
export function queryRemindListFailure(error) {
|
|
|
export function queryProductAndRemindListFailure(error) {
|
|
|
return {
|
|
|
type: QUERY_REMIND_LIST_FAILURE,
|
|
|
type: QUERY_PRODUCT_AND_REMIND_LIST_FAILURE,
|
|
|
payload: error
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -168,7 +170,7 @@ export function getSeckillQueryActivity(inStartTime = 0) { |
|
|
let focusActivity = processedTimeInfo.focusActivity;
|
|
|
curActivityId = focusActivity.activityId;
|
|
|
if (Date.now() < focusActivity.startTime) {
|
|
|
dispatch(getSeckillRemindList(curActivityId));
|
|
|
dispatch(getSeckillProductRemindList(curActivityId));
|
|
|
} else {
|
|
|
dispatch(getSeckillProductList(curActivityId));
|
|
|
}
|
...
|
...
|
@@ -188,69 +190,57 @@ export function getSeckillQueryActivity(inStartTime = 0) { |
|
|
export function getSeckillProductList(activityId = curActivityId) {
|
|
|
curActivityId = activityId;
|
|
|
return (dispatch, getState) => {
|
|
|
|
|
|
dispatch(queryProductListRequest());
|
|
|
|
|
|
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);
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryRemindList} = seckill;
|
|
|
queryRemindList = queryRemindList.toJS();
|
|
|
return new SeckillService(app.host).fetchQueryProductList(activityId)
|
|
|
.then(json => {
|
|
|
let productList = [];
|
|
|
if (queryRemindList && queryRemindList.length > 0) {
|
|
|
productList = productAddFlag(json, queryRemindList);
|
|
|
} else {
|
|
|
productList = productAddFlag(json);
|
|
|
}
|
|
|
dispatch(queryProductListSuccess(productList));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
queryProductList(activityId);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
dispatch(queryProductListFailure(error));
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
export function getSeckillRemindList(activityId = curActivityId) {
|
|
|
/*
|
|
|
* 秒杀商品列表
|
|
|
*/
|
|
|
export function getSeckillProductRemindList(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));
|
|
|
})
|
|
|
let queryProductRemindList = (activityId, uid) => {
|
|
|
dispatch(queryProductAndRemindListRequest());
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryProductList} = seckill;
|
|
|
Promise.all([
|
|
|
new SeckillService(app.host).fetchQueryProductList(activityId),
|
|
|
new SeckillService(app.host).fetchQueryRemindList(activityId, uid),
|
|
|
]).then(result => {
|
|
|
let productList = result[0];
|
|
|
let remindList = result[1];
|
|
|
productList = productAddFlag(productList, remindList);
|
|
|
dispatch(queryProductAndRemindListSuccess({productList,remindList}));
|
|
|
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(queryRemindListFailure(error));
|
|
|
dispatch(getSeckillProductList(activityId));
|
|
|
dispatch(queryProductAndRemindListFailure(error));
|
|
|
});
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
queryRemindList(activityId, uid);
|
|
|
queryProductRemindList(activityId, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
queryRemindList(activityId, uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
dispatch(getSeckillProductList(activityId));
|
|
|
});
|
|
|
};
|
|
|
}
|
...
|
...
|
@@ -276,9 +266,8 @@ export function addCancelUserReminder(method='app.seckill.addUserReminder', acti |
|
|
productItem.remindFlag = remindFlag;
|
|
|
}
|
|
|
});
|
|
|
dispatch(updateSecKillProductList(queryProductList));
|
|
|
dispatch(addCancelUserReminderSuccess(okTip));
|
|
|
|
|
|
dispatch(updateSecKillProductList(queryProductList));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
dispatch(addCancelUserReminderFailure(failTip));
|
...
|
...
|
@@ -304,7 +293,7 @@ export function clickActivityTimeItem(activity) { |
|
|
});
|
|
|
dispatch(updateSecKillProductVoList(queryActivityInfo.secKillProductVoList));
|
|
|
if (Date.now() < curActivity.startTime) {
|
|
|
dispatch(getSeckillRemindList(curActivityId));
|
|
|
dispatch(getSeckillProductRemindList(curActivityId));
|
|
|
} else {
|
|
|
dispatch(getSeckillProductList(curActivityId));
|
|
|
}
|
...
|
...
|
@@ -325,39 +314,56 @@ export function clickProductItem(product) { |
|
|
|
|
|
export function clickRemindBtn(product) {
|
|
|
return (dispatch, getState) => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
queryRemindList(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
dispatch(getSeckillProductRemindList(product.activityId));
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
|
|
|
|
|
|
if (!product.secKillSku || product.secKillSku.length == 0) {
|
|
|
return;
|
|
|
}
|
|
|
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) => {
|
|
|
let {app, seckill} = getState();
|
|
|
let {queryProductList} = seckill;
|
|
|
if (!product.secKillSku || product.secKillSku.length == 0) {
|
|
|
return;
|
|
|
}
|
|
|
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';
|
|
|
}
|
|
|
|
|
|
ReactNative.NativeModules.YH_SeckillHelper.remindTip({
|
|
|
method: action,
|
|
|
arguments: params,
|
...
|
...
|
@@ -373,19 +379,6 @@ export function clickRemindBtn(product) { |
|
|
});
|
|
|
};
|
|
|
|
|
|
ReactNative.NativeModules.YH_CommonHelper.uid()
|
|
|
.then(uid => {
|
|
|
queryRemindList(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
ReactNative.NativeModules.YH_CommonHelper.login()
|
|
|
.then(uid => {
|
|
|
queryRemindList(uid);
|
|
|
})
|
|
|
.catch(error => {
|
|
|
|
|
|
});
|
|
|
});
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -452,7 +445,6 @@ function productAddFlag(productList, remindList) { |
|
|
product.over = true;
|
|
|
}
|
|
|
});
|
|
|
|
|
|
return productList;
|
|
|
}
|
|
|
|
...
|
...
|
|