Authored by 陈轩

im fix

... ... @@ -4,7 +4,7 @@ const _ = require('lodash');
const crypto = global.yoho.crypto;
const config = global.yoho.config;
const ImAPI = new global.yoho.ApiBase(config.domains.imCs, {
const ImService = new global.yoho.ApiBase(config.domains.imCs, {
name: 'im',
cache: global.yoho.cache,
useCache: false
... ... @@ -29,7 +29,7 @@ exports.saveMessage = (uid, conversationId, content) => {
};
return ImAPI.post('/api/leavemessage/saveLeavemessage', params);
return ImService.post('/api/leavemessage/saveLeavemessage', params);
};
... ... @@ -54,7 +54,7 @@ exports.fetchImHistory = (uid, endTime, pageSize, startTime) => {
val && (params[key] = val);
});
return ImAPI.get('/api/conversationMessage/pageList', params)
return ImService.get('/api/conversationMessage/pageList', params)
.then(result => {
return result;
}, () => {
... ... @@ -83,7 +83,7 @@ exports.fetchOrderList = (uid, createTimeBegin) => {
val && (params[key] = val);
});
return ImAPI.get('/api/order/queryLastTenOrder', params);
return ImService.get('/api/order/queryLastTenOrder', params);
};
... ... @@ -117,5 +117,18 @@ exports.saveEvalute = (uid, conversationId, promoter, stars) => {
stars
};
return ImAPI.post('/api/evalute/saveEvalute', params);
return ImService.post('/api/evalute/saveEvalute', params);
};
/**
* 获取全球购的订单
*/
exports.queryGlobalOrder = uid => {
let params = {
uid
};
return ImService.get('/api/order/queryGlobalOrder', params);
};
... ...
... ... @@ -131,3 +131,20 @@ exports.saveEvalute = (req, res) => {
};
exports.queryGlobalOrder = (req, res) => {
const uid = req.user.uid;
let emptyOrder = {
code: 200,
data: []
};
imApi.queryGlobalOrder(uid)
.then(result=> {
res.json(result);
}, () => {
res.json(emptyOrder);
});
};
... ...
... ... @@ -21,7 +21,8 @@ const authGuard = require('../../doraemon/middleware/auth');
router.get('/im', chat.appAdapter, authGuard, chat.page);
router.get('/im/fetchHistory', chat.fetchHistory);
router.get('/getOrders', chat.getOrders);
router.get('/order-list', chat.fetchOrders);
router.get('/im/global-list', chat.queryGlobalOrder);
router.get('/im/order-list', chat.fetchOrders);
router.post('/leavemsg/save.json', chat.saveMSG);
router.post('/im/saveEvalute', chat.saveEvalute);
... ...
... ... @@ -41,11 +41,11 @@
<div class="icon"></div>
<p class="menu-name">相册</p>
</div>
<div class="icon-wrap order" data-trigger="order-list">
<div class="icon-wrap order" data-trigger="order-list" data-type="order">
<div class="icon"></div>
<p class="menu-name">订单</p>
</div>
<div class="icon-wrap broad-order" data-trigger="order-list" data-param="international">
<div class="icon-wrap broad-order" data-trigger="order-list" data-type="global">
<div class="icon"></div>
<p class="menu-name">境外订单</p>
</div>
... ...
... ... @@ -28,10 +28,10 @@ module.exports = {
service: 'http://service.yoho.cn/',
liveApi: 'http://api.live.yoho.cn/',
singleApi: 'http://single.yoho.cn/',
// imSocket: 'ws://imsocket.yohobuy.com:10000',
// imSocket: 'ws://imsocket.yohobuy.com:10240',
imSocket: 'wss://imsocket.yohobuy.com:443',
imCs: 'http://imhttp.yohobuy.com/api',
imServer: 'http://imhttp.yohobuy.com:60201/imserver-web'
imCs: 'http://192.168.102.18:60101/imweb-client-web/',
imServer: 'http://192.168.102.18:60201/im-server-web/'
},
subDomains: {
host: '.m.yohobuy.com',
... ...
... ... @@ -10,7 +10,9 @@ import appBridge from 'yoho-app';
import {time} from './time';
import {api} from './store';
import {RatingView, LeaveMSGView, OrderListView } from './view';
import qs from 'yoho-qs';
var qs = require('yoho-qs');
var socket = require('./socket-chat'),
socketConf = require('./socket-config');
... ... @@ -161,7 +163,9 @@ var chat = {
self.leaveMSGView.trigger('show.LeaveMSGView');
})
.on('click.orderList', '[data-trigger=order-list]', function() {
self.orderListView.trigger('show.OderListView');
let orderType = $(this).data('type') || '';
self.orderListView.trigger('show.OderListView', [orderType]);
})
.on('click.chat.switchServer', '[data-action=change-human]', function() {
self.switchService('human');
... ...
... ... @@ -61,8 +61,10 @@ let api = {
* TODO:
* 1. 目前接口不支持分页
*/
fetchOrders: function() {
return $.get('/service/order-list');
fetchOrders: function(type) {
let url = `/service/im/${type}-list`;
return $.get(url);
},
// 获取10条历史记录
... ...
... ... @@ -5,6 +5,7 @@ const loading = require('../../plugin/loading'),
require('../../common');
import {EventEmitter, api} from './store';
import qs from 'yoho-qs';
const LeaveMSGView = function(elem) {
... ... @@ -156,8 +157,20 @@ const OrderListView = function(elem) {
this.$localOrders = this.$elem.find('[data-tab=local]');
this.$globalOrders = this.$elem.find('[data-tab=global]');
// 分页数据
this.state = {
global: {
curCount: 0,
totalCount: null
},
order: {
curCount: 0,
totalCount: null
}
};
this.bindEvents();
this.fetchOrders();
// this.fetchOrders();
};
OrderListView.prototype = $.extend({}, EventEmitter.prototype, {
... ... @@ -173,7 +186,9 @@ OrderListView.prototype = $.extend({}, EventEmitter.prototype, {
});
// 被通知显示,执行显示
this.on('show.OderListView', $.proxy(this.toggleHide, this, false));
this.on('show.OderListView', (event, type) => {
self.toggleHide(false, type);
});
},
/**
... ... @@ -203,25 +218,53 @@ OrderListView.prototype = $.extend({}, EventEmitter.prototype, {
* @param boolean willHide;
* @return this
*/
toggleHide: function(willHide) {
toggleHide: function(willHide, type) {
this.$elem.toggleClass('chat-page-hide', willHide);
if (!willHide) {
let orderState = this.state[type];
let {totalCount} = orderState;
totalCount === null && this.fetchOrderByType(type, orderState);
if (type === 'global') {
this.$globalOrders.show();
this.$localOrders.hide();
} else if (type === 'order') {
this.$globalOrders.hide();
this.$localOrders.show();
}
} else {
this.$globalOrders.hide();
this.$localOrders.hide()
}
return this;
},
fetchOrderByType: function(type, orderState) {
let self = this;
let $order = type === 'global' ? this.$globalOrders : this.$localOrders;
/**
* method: 获取订单
*/
fetchOrders: function() {
const self = this;
let {totalCount} = orderState;
return api.fetchOrders().done(result => {
let html = self.orderListT({orders: result.data});
// TODO: 分页
if (totalCount === null) { // 还未加载数据
api.fetchOrders(type).done(
result => {
let html = self.orderListT({
orders: result.data
});
self.$localOrders.append(html);
lazyLoad($('img.lazy'));
});
orderState.totalCount = result.data.length;
orderState.curCount = result.data.length;
$order.append(html);
}
);
}
}
});
... ...