| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- var userId = helper.request.queryString("id"); //用户id
- $(document).ready(function () {
- //保存
- $('.customerSubmit').click(function() {
- saveCustomer();
- });
- //获取部门
- getDepartment();
- //获取省份
- getProvince($("#source"));
- //获取详情
- getDetails();
- })
- //下拉框
- $('.inps').focus(function() {
- $(this).siblings('.add-tree').css('display', 'block');
- })
- $('.drop-down').click(function() {
- var dropDown = $(this).siblings('.add-tree');
- if(dropDown.css('display') == 'block') {
- dropDown.css('display', 'none')
- } else {
- dropDown.css('display', 'block')
- }
- })
- $('.add-tree').mouseleave(function() {
- $(this).css('display', 'none')
- })
- //获取所属部门
- var setting = {
- data: {
- key: {
- name: "text"
- },
- simpleData: {
- enable: true,
- idKey: "id",
- rootPId: 0
- }
- },
- callback: {
- onClick: ztreeDep
- }
- };
- var departmentId; //部门id
- var departmentName; //部门name
- function ztreeDep(event, treeId, treeNode) {
- departmentId = treeNode.id;
- departmentName = treeNode.text;
- $('.inps2').val(departmentName);
- };
- //获取部门
- function getDepartment() {
- $.get(huayi.config.callcenter_url + "Department/GetDeptList", {
- "token": $.cookie("token"),
- "pid": "",
- }, function(result) {
- result = $.parseJSON(result);
- $.fn.zTree.init($("#departmentTree"), setting, result.data); //实例化树形图
- });
- }
- /*
- * 省
- * 市
- * 区/县
- */
- //省
- function getProvince(obj) {
- obj.empty();
- obj.append('<option selected="selected" value="">请选择</option>');
- $.getJSON(huayi.config.callcenter_url + "RegionCategory/GetCountyList", {
- "token": $.cookie("token"),
- pid: 0,
- }, function (data) {
- if (data.state.toLowerCase() == "success") {
- var content = data.data;
- $(content).each(function (i, n) {
- $("<option value='" + n.F_RegionId + "'>" + n.F_RegionName + "</option>").appendTo(obj);
- })
- }
- })
- }
- //市
- function getCity(obj) {
- obj.empty();
- obj.append('<option selected="selected" value="">请选择</option>');
- $.getJSON(huayi.config.callcenter_url + "RegionCategory/GetCountyList", {
- "token": $.cookie("token"),
- pid:$('#source').val(),
- }, function (data) {
- if (data.state.toLowerCase() == "success") {
- var content = data.data;
- $(content).each(function (i, n) {
- $("<option value='" + n.F_RegionId + "'>" + n.F_RegionName + "</option>").appendTo(obj);
- })
- }
-
- })
- }
- //区/县
- function getCounty(obj) {
- obj.empty();
- obj.append('<option selected="selected" value="">请选择</option>');
- $.getJSON(huayi.config.callcenter_url + "RegionCategory/GetCountyList", {
- "token": $.cookie("token"),
- pid:$('#type').val(),
- }, function (data) {
- if (data.state.toLowerCase() == "success") {
- var content = data.data;
- $(content).each(function (i, n) {
- $("<option value='" + n.F_RegionId + "'>" + n.F_RegionName + "</option>").appendTo(obj);
- })
- }
- })
- }
- //通过省获取市
- $('#source').on('change',function(){
- getCity($("#type"));
- });
- //通过市获取区/县
- $('#type').on('change',function(){
- getCounty($("#keyid"));
- });
- // 地址(省+市+区/县)
- function detailedAddress() {
- if($('#source').val() === ""){
- var province = '';
- } else {
- var province = $('#source').find("option:selected").text()
- }
- if($('#type').val() === ""){
- var city = '';
- } else {
- var city = $('#type').find("option:selected").text()
- }
- if($('#keyid').val() === ""){
- var county = '';
- } else {
- var county = $('#keyid').find("option:selected").text()
- }
- var address = province + '-' + city + '-' + county;
- return address;
- }
- //获取详情
- function getDetails() {
- $.ajax({
- type: "get",
- url: huayi.config.callcenter_url + "AddressBook/GetInfo",
- dataType: "json",
- async: true,
- data: {
- token: $.cookie("token"),
- infoid: userId,
- },
- success: function(data){
- if (data.state.toLowerCase() == "success") {
- var data = data.data;
- displayDetails(data);
- }
- }
- })
- }
- //回显
- function displayDetails(data) {
- $("#addUserName").val(data.F_Name); //用户姓名
- $("#addSex").val(data.F_Sex); //性别
- provinceCity(data)//地址
- $("#addTelephone").val(data.F_Telephone); //内线电话
- $("#addMobile").val(data.F_Mobile); //手机
- $("#addElseMobile").val(data.F_ElseMobile); //其他号码
- $(".inps2").val(data.F_Department)//部门
- $('.inps2').attr('data_id', data.F_DepartmentId);
- $("#addPosition").val(data.F_Position); //职位
- $("#addNote").val(data.F_Note); //备注
- //原部门id
- departmentId = $('.inps2').attr('data_id');
-
- }
- //省市县回显
- function provinceCity(data){
- var provinceCityArr = data.F_Address.split("-");
- $("#source option:selected").text(provinceCityArr[0]);
- $("#source option:selected").val(provinceCityArr[0]);
- $("#type option:selected").text(provinceCityArr[1]);
- $("#type option:selected").val(provinceCityArr[1]);
- $("#keyid option:selected").text(provinceCityArr[2]);
- $("#keyid option:selected").val(provinceCityArr[2]);
- }
- //保存
- function saveCustomer() {
- $.ajax({
- type: "post",
- url: huayi.config.callcenter_url + "AddressBook/Add",
- dataType: 'json',
- async: true,
- beforeSend: function() { //触发ajax请求开始时执行
- $('.customerSubmit').attr("disabled", true);
- $('.customerSubmit').text('确定中...');
- },
- data: {
- id: userId,//用户id
- token: $.cookie("token"),
- F_Name: $("#addUserName").val(), //用户姓名
- F_Sex: $("#addSex").val(), //性别
- F_Address: detailedAddress(), //地址
- F_Telephone: $("#addTelephone").val(), //内线电话
- F_Mobile: $("#addMobile").val(), //手机
- F_ElseMobile: $("#addElseMobile").val(), //其他号码
- // F_Departmentid: $("#addDepartmentid").val(), //部门ID
- F_Departmentid: departmentId, //部门ID
- F_Position: $("#addPosition").val(), //职位
- F_Note: $("#addNote").val(), //备注
- },
- success: function(data) {
- if (data.state.toLowerCase() == 'success') {
- $('.customerSubmit').attr("disabled", false);
- $('.customerSubmit').text('确定');
- var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
- parent.layer.close(index); //再执行关闭
- parent.layer.msg("保存成功!");
- parent.initTable();
- } else {
- $('.customerSubmit').attr("disabled", false);
- $('.customerSubmit').text('确定');
- }
- }
- });
- }
|