/**
 * Created by wxl on 2015/9/23.
 * @des 购车小秘资质页
 */
var co       = require('co');
var fs       = require('fs');
var hbs      = require('handlebars');
var iconv    = require('iconv-lite');
var r        = require('../../../lib/r.js');
var QS       = require('querystring');
var template = hbs.compile(fs.readFileSync('./scripts/finance/info/loan.html').toString());
var toolUtil=require("../../../lib/toolUtil.js");
//我要贷款接入参数
// rid=$1&orgId=$2&productId=$3&modelId=$4&periods=$4&downPayment=$5&features=$6
exports.handle=function(req, rh, maxAge, transEnc, queryString, callback) {
    co(function *(){
        try {
            var param = QS.parse(queryString);
            param.isHelper = param.isHelper ? param.isHelper : 0;//默认是0
            var jsonX = {"param": param};
            var path = require('../../../conf/config.js').config().path;
            jsonX.host = req.headers.host + path;
            jsonX.cookieHost = req.headers.host;

            // 页面计数
            jsonX.flow=param.flow;
            
            
            jsonX.staticUrl="/r"+param.rid+"/sg"+param.serialId+"-m"+param.modelId+"-org"+param.orgId+"-pro"+param.productId
                +"-p"+param.periods+"-s"+param.downPayment+"-a"+param.averagePrice+"/f"+param.flow+"/";
            if (param.fmt == "json") {
                rh.setHeader('Content-Type', 'application/json; charset=UTF-8');
                rh.setBody(JSON.stringify(jsonX));
            } else {
                var html = template(jsonX);//得到所有的参数
                // 设置响应头信息
                rh.setHeader('Content-Type', 'text/html; charset=UTF-8');
                if (maxAge)rh.setHeader('Cache-Control', 'max-age=' + (maxAge));
                // 设置响应内容
                rh.setBody(html);

            }
            callback(null, rh);
        }catch(e){
            console.log(e)
            toolUtil.get404Page(fs,hbs,req,rh,callback);
            console.log("info/loan.js");
        }

    })();
}

