/**
 * Created by jimiz on 2017/4/7.
 */
var billsData = require('../models/bills');

//统一回调函数
var callback = function(req, res, err, message, data){
    res.json({error: err, message: message, data: data});
};

module.exports = {
    getData: function(req, res){
        var data = JSON.parse(req.body.data);
        billsData.getData(data.projectId, function(err, message, billsList){
            if (err === 0) {
                callback(req, res, err, message, billsList);
            } else {
                callback(req, res, err, message, null);
            }
        });
    },

    getItemTemplate: function(req, res){
        //var data = JSON.parse(req.body.data);
        billsData.getItemTemplate(function(err, message, billsItem){
            if (billsItem) {
                callback(req, res, err, message, billsItem);
            } else {
                callback(req, res, err, message, null);
            }
        });
    },

    allocIDs: function(req, res){
        billsData.allocIDs(function(err, message, data){
            if (err) {
                callback(req, res, err, message, data);
            } else {
                callback(req, res, err, message, null);
            }
        });
    }

};