app/views/educode_sales/ideas/edit.html.erb in educode_sales-0.9.61 vs app/views/educode_sales/ideas/edit.html.erb in educode_sales-0.9.62

- old
+ new

@@ -7,17 +7,17 @@ </div> <div class="layui-row" style="padding-top: 15px"> <div class="layui-col-md6"> <labeL class="layui-form-label required">学校/单位:</labeL> <div class="layui-input-block"> - <input type="text" name="school_name" autocomplete="off" lay-verify="required" lay-reqtext="学校不能为空" placeholder="请输入学校/单位名称" value="<%= @idea&.school_name %>" class="layui-input"> + <div id="school_id" style="width: 600px;"></div> </div> </div> <div class="layui-col-md6"> <labeL class="layui-form-label">院系/部门:</labeL> <div class="layui-input-block"> - <input type="text" name="department_name" autocomplete="off" placeholder="请输入院系/部门名称" value="<%= @idea&. department_name %>" class="layui-input"> + <div id="department_id" style="width: 600px;"></div> </div> </div> </div> <div class="layui-row" style="padding-top: 15px"> <div class="layui-col-md6"> @@ -174,21 +174,111 @@ xhr.send(formData); } layui.use(['form', 'table', 'upload', 'layer', 'laytpl', 'request', 'selectInput', 'xmSelect', 'upload'], function () { var form = layui.form, - layer = layui.layer, - request = layui.request, - laydate = layui.laydate, - table = layui.table, - laytpl = layui.laytpl, - request = layui.request, - xmSelect = layui.xmSelect, - upload = layui.upload, - $ = layui.$; + layer = layui.layer, + request = layui.request, + laydate = layui.laydate, + table = layui.table, + laytpl = layui.laytpl, + request = layui.request, + xmSelect = layui.xmSelect, + upload = layui.upload, + $ = layui.$; selectInput = layui.selectInput; + + var school_list = xmSelect.render({ + el: '#school_id', + remoteSearch: true, + autoRow: true, + radio: true, + delay: 1000, + tips: '支持学校名称搜索,请至少输入一个字符', + searchTips: '支持名称/省份搜索,请至少输入一个字符', + paging: true, + pageRemote: true, + filterable: true, + remoteMethod: function (val, cb, show, pageIndex) { + if (!val) { + return cb([]); + } + $.ajax('/missions/staff_schools', { + method: 'get', + data: { + q: val, + page: pageIndex + }, + dataType: 'json', + success: function (res) { + var data = res.data; + if (res.code == 0) { + cb(res.data, res.count); + } else { + layer.msg(res.msg, {time: 2000, icon: 2, shade: 0.01}); + } + } + }) + } + }) + + var department_list = xmSelect.render({ + el: '#department_id', + remoteSearch: true, + autoRow: true, + radio: true, + delay: 1000, + tips: '支持学校名称搜索,请至少输入一个字符', + searchTips: '支持名称/省份搜索,请至少输入一个字符', + paging: true, + pageRemote: true, + filterable: true, + remoteMethod: function (val, cb, show, pageIndex) { + + var schools = []; + school_list.getValue().forEach(function (d) { + schools.push(d.value); + }) + // if (schools.length == 0) { + // layer.alert("请选择学校"); + // return false; + // } + school_id = schools[0]; + + + if (!val) { + return cb([]); + } + $.ajax('/missions/staff_departments?school_id=' + school_id, { + method: 'get', + data: { + q: val, + page: pageIndex + }, + dataType: 'json', + success: function (res) { + var data = res.data; + if (res.code == 0) { + cb(res.data, res.count); + } else { + layer.msg(res.msg, {time: 2000, icon: 2, shade: 0.01}); + } + } + }) + } + }) + + + department_list.setValue( + gon.department_list + ) + school_list.setValue( + gon.school_list + ) + + form.render(); //时间常规用法 laydate.render({ elem: '#new_time' }); @@ -259,29 +349,39 @@ // 当前弹出层,防止ID被覆盖 var parentIndex = layer.index; //监听提交 form.on('submit(saveBtn)', function (data) { - // if (department.getValue() == "" && department_id == "") { - // layer.alert("请选择单位部门") - // return false; - // } else { - data.field.department_id = department.getValue() || department_id; - data.field.staff_id = staff_list.getValue('valueStr'); + data.field.staff_id = staff_list.getValue('valueStr'); data.field.sale_staff_id = sale_staff_list.getValue('valueStr'); data.field.assist_staff_ids = assist_staff_list.getValue('valueStr'); - request.authPut("missions/ideas/" + parent.id, data.field, function (res) { - if (res.success == false) { - layer.alert(res.msg) - } else { - layer.close(parent.edit_index); - parent.layer.close(parent.layer.getFrameIndex(window.name)) - parent.table.reload('ideas_table', { - done: function () { - } - }); - } - }) + var schools = []; + school_list.getValue().forEach(function (d) { + schools.push(d.value); + }) + if (schools.length == 0) { + layer.alert("请选择学校"); + return false; + } + data.field.school_id = schools[0]; + + var departments = []; + department_list.getValue().forEach(function (d) { + departments.push(d.value); + }) + data.field.department_id = departments[0]; + request.authPut("missions/ideas/" + parent.id, data.field, function (res) { + if (res.success == false) { + layer.alert(res.msg) + } else { + layer.close(parent.edit_index); + parent.layer.close(parent.layer.getFrameIndex(window.name)) + parent.table.reload('ideas_table', { + done: function () { + } + }); + } + }) // } return false; }); }); \ No newline at end of file