/**
* 新增/修改租户信息
*
* Creator Ryu
* 2016/12/13 14:02:47
*
*/
requirejs.config({
paths: {
'jquery' : "./lib/jquery-2.2.3.min"
},
shim : {
'jquery':{
exports: '$'
},
'./lib/jquery.form.min': {
deps: ['jquery']
}
}
});
require(['lib/vue', 'jquery', 'lib/iframeBox','./basicUrl', 'lib/popupBox'], function(Vue, $, iframeBox, basicUrl,box) {
/*字符串原型添加空格过滤*/
String.prototype.trim = function(){
var str = this,
str = str.replace(/^\s\s*/, ''),
ws = /\s/,
i = str.length;
while (ws.test(str.charAt(--i)));
return str.slice(0, i + 1);
};
var main = {
curBox: null,
/*初始化*/
init: function(){
var t = this,
originData = {};
iframeBox.init(function(curBox){
/*获取弹窗*/
t.curBox = curBox ;
if(t.curBox && t.curBox.data){
originData = t.curBox.data.item;
//if(typeof originData.type == 'undefined')
// originData.type = 1;
}
var vm = new Vue({
el: '#pop_test',
data: {
/*编辑信息*/
item: originData || {name:'',remark:'',type:1},
options:[{checked: false,name: '姓名',type: 1,need:1,def:'',remark:'',edit:false,defType:"text",remarkStyle:"",defStyle:"",nameStyle:""},{checked: false,name: '手机',type: 1,need:1,def:'',remark:'',edit:false,defType:"text",remarkStyle:"",defStyle:"",nameStyle:""}],
isEdit:t.curBox.data.isEdit,
showSelMsg:false
},
methods: {
/*关闭窗口*/
closeBox: function(){
t.curBox.close();
},
/*添加*/
add: function(){
var vm = this;
/*插入一条级别项*/
vm.options.push({
checked: false,name: '',type: 1,need:1,def:'',remark:'',edit:true,defType:"text",remarkStyle:"",defStyle:"",nameStyle:""
});
},
/*删除*/
dels: function(){
var vm = this,
list = [],
notDel = false,
count = 0;
for(var i = 0; i < vm.options.length; i++){
var item = vm.options[i];
if(item.name == '姓名'||item.name == '手机'){
list.push(item);
notDel = true;
continue;
}
/*保留非删除项*/
if(!item.checked){
list.push(item);
continue;
}
count++;
}
if(count > 0){
vm.options = list;//vm.$set('options', list);
}else{
box.popAlert('请选择要删除的项~');
}
if(notDel){
box.popAlert('姓名和手机为必填项,不能删除~');
}
},
changeType:function(item){
item.defType = "text";
item.def = '';
if(item.type == 2){
item.defType = "date";
}
else if(item.type == 3){
if(!vm.showSelMsg){
box.popAlert('请在备注/选项列以英文,分隔输入可选项');
vm.showSelMsg = true;
}
}
},
getDefType:function(type){
var defType = "text";
if(type == 2){
defType = "date";
}
return defType;
},
checkOption:function(){
var vm = this,
ok = true,
nameMap = {},
items = [];
for(var i=0;i<vm.options.length;i++){
var one = vm.options[i],
oneItem = {name:one.name,type:one.type+"",need:one.need+"",def:one.def,remark:one.remark,};//[one.name,one.type+"",one.need+"",one.def,one.remark];
items.push(oneItem);
//判别选择项
if(one.type == 3){//选择项
if(one.remark==''){
one.remarkStyle = "background:red";//"color:red";border: 1px solid #ff0000;
ok = false;
}
if(one.def==''){
one.defStyle = "background:red";
ok = false;
}
var selOpts = one.remark.split(","),
defOk = false;;
for(var j=0;j<selOpts.length;j++){
if(one.def == selOpts[j]){
defOk = true;
break;
}
}
if(!defOk){
one.defStyle = "background:red";
ok = false;
}
}
//判别是否有重名项(不允许)
if(nameMap[one.name]){
ok = false;
one.nameStyle = "background:red";
}
else{
nameMap[one.name] = 1;
}
}
if(ok == false){
box.popAlert('参数重名;\n[选择]参数:待选项或默认值非法');
}
return {ok:ok,items:items};
},
changeValueResetStyle:function(item,key){
item[key] = "";
},
/*提交*/
sub: function(){
var vm = this,
url = basicUrl.url + '/IscasMission1/add';
/*名称*/
if(vm.item.name.trim() === ''){
box.popAlert2('名称不能为空');
return false;
}
if(vm.isEdit){
url = basicUrl.url + '/IscasMission1/update';
//delete vm.item.items;
//delete vm.item.export_items;
}
//else//wcf-2020.02.10--modify--修改要也传参数项
{
var items = {};
if(vm.item.type == 1){
items.keys = ["name", "mobile", "type", "dep", "isOut","address","outDate","backDate"];
items.titles = ["姓名", "联系方式", "职工/学生","部门","是否离京", "地点", "离京时间", "返京时间"];
}
else if(vm.item.type == 2){
items.keys = ["name", "mobile", "type", "dep", "isCome"];
items.titles = ["姓名", "联系方式", "职工/学生","部门","是否参加"];
}
else if(vm.item.type == 0){
var result = vm.checkOption();
if(result.ok == false){
return false;
}
items = result.items;
}
vm.item.items = JSON.stringify(items);
}
/*提交*/
$.ajax({
type: 'post',
url: url,
async: false,
dataType: 'json',
data: vm.item,
success: function(res){
if(res && res.result){
res.item = vm.item;
if(!vm.isEdit){//新建会返回id
res.item.id = res.data;
}
t.curBox.save(res);
vm.closeBox();
}else{
box.popAlert2('修改失败:' + res.msg);
}
}
});
},
},
watch: {
"item.type": function(newVal, oldVal) {
var vm = this;
if(newVal == 0){
t.curBox.height(686);
}else{
t.curBox.height(380);
}
t.curBox.reset();
/*if(newVal==0){
box.popAlert("暂时不支持自定义统计");
setTimeout(function(){vm.item.type = oldVal;},500);
}*/
}
},
ready: function(){
var vm = this;
if(vm.isEdit){
vm.options = JSON.parse(vm.item.items);
}
if(t.curBox.data.isCopy){
vm.options = JSON.parse(vm.item.items);
//增加前端单独需要的变量
for(var i=0;i<vm.options.length;i++){
vm.options[i].checked = false;
vm.options[i].edit = false;
if(i>1)
vm.options[i].edit = true;
vm.options[i].defType = vm.getDefType(vm.options[i].type);
vm.options[i].remarkStyle = '';
vm.options[i].defStyle = '';
vm.options[i].nameStyle = '';
}
}
if(vm.item.type != 0){
setTimeout(function() {
t.curBox.height(380);
t.curBox.reset();
},
500);
}
}
});
});
}
};
/*初始化入口*/
main.init();
});
console