adminedit.js 2.72 KB
'use strict';
var $ = require('jquery'),
    Handlebars = require('yoho.handlebars');

var dropDown=require('../common/dropDown');
var grid=require('../common/grid');
	require('../util/jquery.gritter');

exports.init=function(){
    new dropDown({el:"#store-name",ajax:"brand"});
    new dropDown({el:"#identity-type"});

	function __ajax(options,callback){
        $.ajax({
            type: 'POST',
            url: options.url,
            dataType: 'json',
            data:options.data||{},
            success: function(res) {
                res=res.data;
                if (res.code === 200) {
                    $.gritter.add({
                        title: options.msg||"提交成功",
                        class_name: 'growl-success',
                        sticky: false,
                        time: '1000',
                        after_open: function() {
                            callback&&callback();
                        }
                     });
                    setTimeout(function(){
                        location.href="/supplier/storeadmin/index";
                    },800)
                     
                } else {
                    $.gritter.add({
                        title: '提交失败',
                        class_name: 'growl-danger',
                        sticky: false,
                        time: '1000'
                     });
                }
            }
        });
    }
    if($('#storelsit').length>0){
    	$('#store-name option:selected').val($('#shopsId').text());
    	$('#identity-type option:selected').val($('#identity').text());
    	$('#manager-name option:selected').val($('#adminPid').text());
    }
    $('#identity-type').on('change',function(){
        $.ajax({
            url: '/supplier/storeadmin/managerName',
            dataType: "json",
            type: 'POST',
            data: {
                identity: $('#identity-type option:selected').val()
            },
            success: function(data) {
                $.each(data.data.data,function(index){
                    console.log(data.data.data[index].truename);
                    $('#manager-name').append("<option value='"+data.data.data[index].pid+"'>"+data.data.data[index].truename+"</option>");
                })

            }
        })
    })
    $('#amdinAdd').on('click',function(){
    	var that = this,
    		shopsId = $('#store-name').val(),
    		identityType = $('#identity-type').val(),
    		managerName = $('#manager-name').val();
        __ajax({
            url: "/supplier/storeadmin/addguanxi",
            data:{
            	shopsId:shopsId,
            	adminPid:managerName,
            	identity:identityType
            }
        },function(){
            g.reload();
        });
    })
}