limit-add.js 2.38 KB
/*
 *@time: 2016/2/15
 *@author: chenglong
 */


var $ = require('jquery'),
    common=require('../common/common'),
    edit = require('../common/edit');

require('../common/bootstrap-wysihtml5');

var uploadImg = new edit('#coverImgBox');
//
uploadImg.init();

exports.init = function () {


    $('body').on('click', '#textDialog', function() {
        common.dialog.confirm("添加文本",'<textarea id="text-editor"></textarea>',function(){

            var textStr = $('#text-editor').val();

            $('.quota-text').html(textStr);

            console.log(textStr);

        });
        $('#text-editor').wysihtml5();
        return false;
    });
    $('body').on('click', '#picDialog', function() {
        common.dialog.confirm("添加图片",common.util.__template($("#picDialogTemp").html(),{name:"图片"}),function(){

            var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">';

            $('.quota-img').html(imgStr);
        });
        return false;
    });
    $('body').on('click', '#videoDialog', function() {
        common.dialog.confirm("添加视频",common.util.__template($("#picDialogTemp").html(),{name:"视频"}),function(){

            var imgStr = '<img src="http://img11.static.yhbimg.com/goodsimg/2015/07/07/08/01315b5bbfd72bc5b59fa2fda6c28b9ae6.jpg">';

            $('.quota-video').html(imgStr);
        });
        return false;
    });


    // 添加品类表单验证
    var limitAddForm = new edit("#limit-add-form");

    limitAddForm.init();
    $('.limit-add-btn').click(function () {

        var $this = $(this);

        limitAddForm.submit('/limit/product/new', function(option,that) {
            option.beforeSend = function () {
                $this.attr('disabled', 'disabled');
            };
            option.success=function(res){

                console.log(res);

                if (res.data.code === 200) {

                    limitAddForm.$tip('提交成功');
                    $this.removeAttr('disabled');

                    setTimeout(function () {
                        //window.location.href = '/erpproduct/sort/index';
                    }, 1000);
                }
            };
            option.error=function(res){

                console.log('error');
            }
        });
    });
};