model.js 7.04 KB
/**
 * Created by JiangMin on 2016/3/17.
 * 模特管理
 */
var $ = require('jquery');
var common = require('../common/common');
//日期插件
$('.hasDatepicker').fdatepicker({
    format: 'yyyy-mm-dd'
});
/**
 * 列表显示数据
 * @type {common.grid}
 */
var g = new common.grid({
    el: '#content-list',
    hash: false,
    //查询参数
    parms: function () {
        return {
            modelName: common.util.__input('content-filter1'),
            englishName: common.util.__input('content-filter2'),
            status: common.util.__input('status-filter'),
            modelType: parseInt($("#aa").val())
        };
    },

    //列表显示
    columns: [
        {display: "姓名", name: "modelName"},
        {display: "英文名", name: "englishName"},
        {
            display: "头像", name: "avatar", render: function (item) {
            return '<img src="' + item.avatar + '?imageView/2/w/100/h/100" width="100" height="60"/>'
        }
        },//图片显示
        {display: "国籍", name: "nationality"},
        {display: "身高", name: "height"},
        {display: "体重", name: "weight"},
        {
            display: "胸围", render: function (item) {
            var a = item.vitalStatistics.split(/[,|/]/g);
            return a[0];
        }
        },
        {
            display: "腰围", render: function (item) {
            var a = item.vitalStatistics.split(/[,|/]/g);
            return a[1];
        }
        },
        {
            display: "臀围", render: function (item) {
            var a = item.vitalStatistics.split(/[,|/]/g);
            return a[2];
        }
        },
        {display: "鞋码", name: "shoeSize"},
        {display: "衣服尺码", name: "dressSize"},
        {
            display: "模特卡", name: "modelCard ", render: function (item) {
            return '<img src="' + item.modelCard + '?imageView/2/w/100/h/100" width="100" height="60"/>'
        }
        },
        {
            display: "状态", name: "status", render: function (item) {
            if (item.status == 1) {
                return "启用"
            }
            else {
                return "禁用"
            }

        }
        },

        {
            display: "操作", name: "", render: function (item) {
            var arr = [];
            arr.push('<a class="btn btn-info update" data-index="' + item.__index + '">修改</a>');
            return arr.join('');
        }
        }
    ]
});
g.init("/shotManage/model/getAllModels");

var Bll = {
    toast: function (url, item, hint) {
        var e = new common.edit("#baseform", {
            bucket: "modelCard"//真实的
            //bucket: "goodsimg"//测试
        });
        //验证英文名
        if($("#englishName").val()){
            e.on("validate", function () {
                var englishName = $.trim($("#englishName").val());
                var a = (/^([A-Za-z]+\s?)*[A-Za-z]$/).test(englishName);
                if (!a) {
                    return "英文名有误"
                }
                return true;
            });
        }

        //验证身高
        if($("#height").val()){
            e.on("validate", function () {
                var height = $.trim($("#height").val());
                if (height>250||height<100) {
                    return "身高值范围为100~250"
                }
                return true;
            });
        }

        //验证体重
        if($("#weight").val()){
            e.on("validate", function () {
                var weight = $.trim($("#weight").val());
                if (weight>200||weight<10) {
                    return "体重值范围为10~200"
                }
                return true;
            });
        }

        //验证胸围
        if($("#Bust").val()){
            e.on("validate", function () {
                var Bust = $.trim($("#Bust").val());
                if (Bust>200) {
                    return "胸围值应小于200"
                }
                return true;
            });
        }

        //验证腰围
        if($("#waist").val()){
            e.on("validate", function () {
                var waist = $.trim($("#waist").val());
                if (waist>200) {
                    return "腰围值应小于200"
                }
                return true;
            });
        }

        //验证臀围
        if($("#hips").val()){
            e.on("validate", function () {
                var hips = $.trim($("#hips").val());
                if (hips>200) {
                    return "臀围值应小于200"
                }
                return true;
            });
        }
       
        var a = common.dialog.confirm(hint,
            common.util.__template2($("#template").html(), item),
            function () {
                e.submit(url, function (option) {
                    option.data.modelType = parseInt($("#aa").val());//模特类型,1拍摄模特,2试穿模特
                    option.data.status = 1;//模特状态,默认启用
                    option.data.height = parseInt($("#height").val());//模特身高
                    option.data.weight = parseInt($("#weight").val());//模特体重
                    if (item.__state == 'add') {
                        option.data.status = 1;//模特状态,默认启用
                    }
                    else {
                        option.data.status = parseInt($("#status").val());//模特状态,默认启用
                    }
                    option.data.vitalStatistics = $("#Bust").val() + '|' + $("#waist").val() + "|" + $("#hips").val();//模特三围,拼接字符串
                    //console.log("option.data", option.data);
                    //option.debug = true;//调试状态
                    option.success = function (res) {
                        //判断接口请求状态
                        if (res.data.code == '200') {
                            g.reload(1);//重新加载界面
                            a.close();//关闭模态框
                        }
                        else {
                            //提示出错信息
                            e.$tip(res.data.message);
                        }
                    };
                    option.error = function () {
                    };
                });
                return false;
            });

        e.init();
    }
};

//添加模特--点击事件
$('#add-content').on('click', function () {
    var item = {
        "__state": "add"
    };
    Bll.toast('/shotManage/model/addModel', item, "添加模特");
});
var STATUS = {
    '1': "启用",
    '2': "禁用"
};

//修改模特--点击事件
$(document).on('click', '.update', function () {
    var item = g.rows[$(this).data("index")];
    item.__state = "update";
    var a = item.vitalStatistics.split(/[,|/]/g);
    item.Bust = a[0];
    item.waist = a[1];
    item.hips = a[2];
    item.statusname = STATUS[item.status];
    Bll.toast('/shotManage/model/updateModel', item, "修改模特");
});
//查询按钮--点击事件
$(document).on('click', '#filter-btn', function () {
    g.reload(1);
});