Edit.js 3.35 KB
var $ = require('jquery');
var common = require('../../common/common');
var edit = require('../../common/edit');

require('../../common/umeditor.config');
require('../../common/umeditor');
require('../../common/zh-cn');





var mainData = window.ViewModel;
console.log(mainData);

var authorizeCertList = [];
var e = new edit("#basicForm", {bucket: "brandLogo"});

//brandTonality
e.on("validate", function () {
    var certParty_checked=$("input[name='certParty']").is(":checked");
    if(!certParty_checked){
        return "授权方不能为空!"
    }
    
    if (authorizeCertList.length < 1){
        return "品牌授权书不能为空!"
    }
    return true;
});

e.init();

console.log(e);

var Bll = {
    //重新渲染图片列表
    rendBoList: function (pictureBoList) {
        $("#authorizeCerts").empty().html(common.util.__template2($("#template2").html(), {pictureBoList: this.getRendJson(pictureBoList)}));
        if(authorizeCertList.length > 9){ //最多上传10张
            $("#addPic").find(".fileinput-button").hide();
        }else{
            $("#addPic").find(".fileinput-button").show();
        }

        //品牌授权书上传
        edit.ajaxfileupload(".picfile", {
            params: {
                __type: "upload",
                bucket: "brandCertificate"
            },
            valid_extensions: ['png', 'jpg', 'jpeg', 'pdf'],
            onComplete: function (response) {
                if (response.status && response.code == 200) {
                    authorizeCertList.push(response.data);
                    Bll.rendBoList(authorizeCertList);
                }
                else {
                    common.util.__tip(response.message, 'warning');
                }
            }
        });
    },
    //获取编辑时新增的图片
    getRendJson: function (pictureBoList) {
        var list = [];
        $.each(pictureBoList, function (index, item) {
            var info = {};
            var ext = item.split('.').pop().toLowerCase();
            info.type = ext;
            info.src = item;
            list.push(info);
        });
        return list;
    }
};

if(mainData.id){
    authorizeCertList = mainData.authorizeCertList;
}
Bll.rendBoList(authorizeCertList);

//删除单张品牌授权书
$(document).on('click', '.remove-item-btn', function () {
    var index = $(this).data("index");
    authorizeCertList.splice(index, 1);
    Bll.rendBoList(authorizeCertList);
});

//下载pdf证书
$(document).on('click', '.download-btn', function() {
    var path = $(this).data("link");
    location.href = '/ajax/download?path=' + path;
});



$(document).on('click','#save_brand',function () {
    e.submit($("#basicForm").attr("action"), function (option) {
        //option.data.authorizeCerts = authorizeCertList;
        option.data.countryId = option.data.brandHeadstream;
        option.data.authorizeCerts = JSON.stringify(authorizeCertList);

        option.success = function (res) {
            if (res.code == "200") {
                e.$tip("提交成功", function () {
                    location.href = "/erpproduct/brands/index"
                }, 'growl-success');
            } else {
                e.$tip(res.message);
            }
            return false;
        };
        option.error = function (res) {
            e.$tip(res.message);
        };
        console.log(option.data);
    });
    return false;
});