store.js 2.09 KB
'use strict';

const socketConf = require('./socket-config');
const conversation = socketConf.conversationMessage;
const slice = Array.prototype.slice;

let encryptedUid = $('#js-eid').val();

// EventEmitter
//--------------------------------------------------------
const EventEmitter = function() {};

EventEmitter.prototype = {
    on() {
        let args, ref;

        args = arguments.length >= 1 ? slice.call(arguments, 0) : [];
        return (ref = $(this)).on.apply(ref, args);
    },

    off() {

        let args, ref;

        args = arguments.length >= 1 ? slice.call(arguments, 0) : [];
        return (ref = $(this)).off.apply(ref, args);
    },

    trigger() {
        let args, ref;

        args = arguments.length >= 1 ? slice.call(arguments, 0) : [];
        return (ref = $(this)).triggerHandler.apply(ref, args);
    }
};

EventEmitter.prototype.constructer = EventEmitter;



// api interface
//--------------------------------------------------------
let api = {
    /**
     *  留言
     *  @param {int} conversation 会话id
     *  @param {str} content 内容
     *  @return jqXhr
     */
    leaveMsg: function(content) {
        return $.post('/service/leavemsg/save.json', {
            conversationId: conversation.conversationId,
            content,
            encryptedUid
        });
    },

    /**
     *  获取订单
     *  TODO:
     *      1. 目前接口不支持分页
     */
    fetchOrders: function(type) {
        let url = `/service/im/${type}-list`;

        return $.post(url, {encryptedUid});
    },

    // 获取10条历史记录
    fetchHistory: function(endTime) {
        let url = '/service/im/fetchHistory';
        let data = {
            encryptedUid
        };

        endTime && (data.endTime = endTime);

        return $.post(url, data);
    },

    saveEvalute: function(data) {
        data.encryptedUid = encryptedUid;
        return $.post('/service/im/saveEvalute', data);
    },

    // 获取评价原因
    queryReasons: function(data) {
        return $.post('/service/im/queryReasons', data);
    }
};


module.exports = {
    EventEmitter,
    api
};