var id=web.getUrlVars("id");
layui.define(['layer', 'form'], function (exports) {
var $ = layui.jquery,layer = layui.layer,form = layui.form;
if(id){
getById();
}
function getById(){
web.ajaxPost(base+"/wxReply/getReply",{id:id},function(data){
web.toForm(form,data.reply);
if(data.reply.rm_type=="2"){
$("#msgRow").show();
$("#contentRow").hide();
if(data.list){
var html="";
$.each(data.list,function(id,item){
html +='
';
html +=''+item.id+' | ';
html +=''+item.msg_title+' | ';
html +=''+item.msg_url+' | ';
html +=' | ';
html +='';
html +='';
html +=' | ';
html +='
';
});
$("#dateTable tbody").append(html);
}
}else{
$("#msgRow").hide();
$("#contentRow").show();
}
});
}
$("#btn-add").on('click', function () {
top.web.popWin(base+"/web/wx/wxMsgWin.jsp","选择图文消息",600,432,function(res){
var html="";
$.each(res,function(id,item){
html +='';
html +=''+item.id+' | ';
html +=''+item.msg_title+' | ';
html +=''+item.msg_url+' | ';
html +=' | ';
html +='';
html +='';
html +=' | ';
html +='
';
});
$("#dateTable tbody").append(html);
},true);
return false;
});
$("#dateTable").on('click','.btn-delete', function(){
$(this).parents("tr").remove();
});
form.on('select(reply_type)', function(data){
if(data.value=="2"){
$("#msgRow").show();
$("#contentRow").hide();
}else{
$("#msgRow").hide();
$("#contentRow").show();
}
});
//提交
form.on('submit(form-add)', function(data){
var param = data.field;
if(id){
param.id=id;
}
if($("#rm_type").val()=="2"){
var msgIds=[];
$("#dateTable tbody tr").each(function(){
var obj = new Object();
obj.msgId=$(this).find('.layui-hide').html();
obj.sort=$(this).find('.layui-input').val();
msgIds.push(obj);
});
param.msgIds = JSON.stringify(msgIds);
}
web.ajaxPost(base+"/wxReply/keySave",param,function(json){
if(json.success){
parent.layer.msg('保存成功');
var index = parent.layer.getFrameIndex(window.name);
parent.$('#btn-query').click();
parent.layer.close(index);
}else{
layer.msg(json.msg);
}
});
return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。
});
//关闭窗口
$('#btn-close').on('click',function(){
var index = parent.layer.getFrameIndex(window.name);
parent.layer.close(index);
return false;
});
exports('wxReplyForm', {});
});