/**
 * Created by CSL on 2017/5/19.
 */
var coeList = require("../models/coe");
import BaseController from "../../common/base/base_controller";
var callback = function(req,res,err,message, data){
    res.json({error: err, message: message, data: data});
}

class CoeListController extends BaseController{
    async getCoeReference(req, res) {
        try {
            const { rationRepId, coeID } = JSON.parse(req.body.data);
            const rst = await coeList.getCoeReference(rationRepId, coeID);
            res.json({ error: 0, message: 'success', data: rst });
        } catch (err) {
            res.json({ error: 1, message: err.message, data: null });
        }
    }

    getCoeList(req,res){
        coeList.getCoesByLibID(req.body.libID, function(err,data){
            callback(req, res, err, 'Get coes', data);
        });
    }

    saveCoeList(req, res) {
        coeList.saveToCoeList(JSON.parse(req.body.data), function(isErr, msg, data){
            callback(req, res, isErr, msg, data);
        });
    }

    getCoeItemsByIDs(req,res){
        //console.log('传入： '+JSON.stringify(JSON.parse(req.body.data)));
        coeList.getCoeItemsByIDs(JSON.parse(req.body.data), function(err,data){
            //console.log('返回： '+JSON.stringify(data));
            callback(req, res, err, 'Get coe', data);
        });
    }
    getCoeItemsByNos(req,res){
        coeList.getCoeItemsByNos(JSON.parse(req.body.data), function(err,data){
            callback(req, res, err, 'Get coe', data);
        });
    }
}

export default CoeListController;
/*
module.exports ={
    getCoeList: function(req,res){
        coeList.getCoesByLibID(req.body.libID, function(err,data){
            callback(req, res, err, 'Get coes', data);
        });
    },

    saveCoeList: function(req, res) {
        coeList.saveToCoeList(JSON.parse(req.body.data), function(isErr, msg, data){
            callback(req, res, isErr, msg, data);
        });
    },

    getCoeItemsByIDs: function(req,res){
        //console.log('传入： '+JSON.stringify(JSON.parse(req.body.data)));
        coeList.getCoeItemsByIDs(JSON.parse(req.body.data), function(err,data){
            //console.log('返回： '+JSON.stringify(data));
            callback(req, res, err, 'Get coe', data);
        });
    }

}*/
