Customize Field Error

# environment.rb
ActionView::Base.field_error_proc = Proc.new do |html_tag, instance_tag|
"#{html_tag}"
end


Result:

<p>
<b>Markb><br />
<div class="fieldWithErrors"><input id="product_mark" name="product[mark]" size="30" type="text" value="" />div>
p>
<!-- 盘点新增/Add --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="../../layui/css/layui.css"> <link rel="stylesheet" href="../../css/diy.css"> <script src="../../js/axios.min.js"></script> <style> img { width: 200px; } .layui-upload-list{ overflow: hidden; } .layui-upload-list .multiple_block .upload_img_multiple{ height: auto; width: 100px; } .multiple_block{ position: relative; float: left; width: 100px; margin: 0 10px 10px 0; } .multiple_block .upload-img-del{ position: absolute; top: 5px; right: 5px; color: #fff; border-radius: 100%; background: #0000009c; width: 20px; height: 20px; text-align: center; line-height: 20px; cursor: pointer; } </style> </head> <body> <article class="sign_in"> <div class="warp tpl"> <div class="layui-container"> <div class="layui-row"> <form class="layui-form" action=""> <div class="form-input-box from-input-box-i"> <div class="layui-form-item unique" id="warehouse_name_box"> <label class="layui-form-label">仓库名称</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入仓库名称" class="layui-input" id="warehouse_name"> </div> </div> <div class="layui-form-item unique" id="goods_number_box"> <label class="layui-form-label">货物编号</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入货物编号" class="layui-input" id="goods_number"> </div> </div> <div class="layui-form-item unique" id="name_of_goods_box"> <label class="layui-form-label">货物名称</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入货物名称" class="layui-input" id="name_of_goods"> </div> </div> <div class="layui-form-item unique" id="classification_of_goods_box"> <label class="layui-form-label">货物分类</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入货物分类" class="layui-input" id="classification_of_goods"> </div> </div> <div class="layui-form-item number" id="inventory_of_goods_box"> <label class="layui-form-label">货物库存</label> <div class="layui-input-block input-i block"> <input type="number" name="num" class="layui-input num" id="inventory_of_goods"> </div> </div> <div class="layui-form-item unique" id="storage_location_box"> <label class="layui-form-label">存放位置</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入存放位置" class="layui-input" id="storage_location"> </div> </div> <div class="layui-form-item uid-box" id="employee_users_box"> <label class="layui-form-label">员工</label> <div class="layui-input-block select block"> <select name="interest" lay-filter="employee_users" id="employee_users"> <option value=""></option> </select> </div> </div> <div class="layui-form-item unique" id="employee_name_box"> <label class="layui-form-label">员工姓名</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入员工姓名" class="layui-input" id="employee_name"> </div> </div> <div class="layui-form-item unique" id="employee_id_box"> <label class="layui-form-label">员工工号</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入员工工号" class="layui-input" id="employee_id"> </div> </div> <div class="layui-form-item tiem-box" id="inventory_date_box"> <div class="layui-inline"> <label class="layui-form-label">盘点日期</label> <div class="layui-input-inline"> <input type="text" class="layui-input" id="inventory_date" placeholder=""> </div> </div> </div> <div class="layui-form-item number" id="physical_inventory_box"> <label class="layui-form-label">盘点数量</label> <div class="layui-input-block input-i block"> <input type="number" name="num" class="layui-input num" id="physical_inventory"> </div> </div> <div class="layui-form-item layui-form-text" id="inventory_notes_box"> <label class="layui-form-label">盘点备注</label> <div class="layui-input-block text"> <textarea placeholder="请输入盘点备注" class="layui-textarea" id="inventory_notes"></textarea> </div> </div> </div> </form> <div class="layui-btn-container"> <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button> <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button> </div> </div> </div> </div> </article> </body> <script src="../../layui/layui.js"></script> <script src="../../js/base.js"></script> <script src="../../js/index.js"></script> <script> var BaseUrl = baseUrl() let cancel = document.querySelector("#cancel") cancel.addEventListener("click",()=>{ colseLayer() }) let inventory_records_id = location.search.substring(1) layui.use(['upload', 'element', 'layer', 'laydate', 'layedit'], function () { var $ = layui.jquery , upload = layui.upload , element = layui.element , layer = layui.layer , laydate = layui.laydate , layedit = layui.layedit , form = layui.form; let url let token = sessionStorage.token || null let personInfo = JSON.parse(sessionStorage.personInfo) let user_group = personInfo.user_group let use_id = personInfo.user_id function $get_stamp() { return new Date().getTime(); } function $get_rand(len) { var rand = Math.random(); return Math.ceil(rand * 10 ** len); } // 权限判断 /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_action(path1, action = "get") { var o = $get_power(path1); if (o && o[action] != 0 && o[action] != false) { return true; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取权限 * @param {String} path 路由路径 */ function $get_power(path) { //从sessionStorage读取权限配置,验证用户操作权限 var list_data = JSON.parse(sessionStorage.list_data) var list = list_data; var obj; for (var i = 0; i < list.length; i++) { var o = list[i]; if (o.path === path) { obj = o; break; } } return obj; } let submit = document.querySelector('#submit') // 提交按钮校验权限 if ($check_action('/inventory_records/view', 'add') || $check_action('/inventory_records/view', 'set') || $check_option('/inventory_records/table', 'examine')) { }else { $("#submit").hide() } // style="display: none" let field = "inventory_records_id"; let url_add = "inventory_records"; let url_set = "inventory_records"; let url_get_obj = "inventory_records"; let url_upload = "inventory_records" let query = { "inventory_records_id": 0, } let form_data2 = { "warehouse_name": '', // 仓库名称 "goods_number": '', // 货物编号 "name_of_goods": '', // 货物名称 "classification_of_goods": '', // 货物分类 "inventory_of_goods": 0, // 货物库存 "storage_location": '', // 存放位置 "employee_users": 0, // 员工 "employee_name": '', // 员工姓名 "employee_id": '', // 员工工号 "inventory_date": '', // 盘点日期 "physical_inventory": 0, // 盘点数量 "inventory_notes": '', // 盘点备注 "inventory_records_id": 0, // ID } layui.layedit.set({ uploadImage: { url: BaseUrl + '/api/inventory_records/upload?' //接口url , type: 'post' //默认post } }); var path1 function getpath() { var list_data = JSON.parse(sessionStorage.list_data) for (var i = 0; i < list_data.length; i++) { var o = list_data[i]; if (o.path === "/inventory_records/table") { path1 = o.path $get_power(o.path) } } } getpath() /** * 注册时是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 * @param {String} path 路径 */ function $check_register_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field) { var o = $get_power("/inventory_records/view"); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_exam(path1, action = "get") { var o = $get_power(path1); if (o) { var option = JSON.parse(o.option); if (option[action]) return true } return false; } function $check_option(path,op) { var o = $get_power(path); if (o){ var option = JSON.parse(o.option); if (option[op]) return true } return false; } /** * 是否有审核字段的权限 */ function $check_examine() { var url = window.location.href; var url_ = url.split("/") var pg_url = url_[url_.length - 2] let path = "/"+ pg_url + "/table" var o = $get_power(path); if (o){ var option = JSON.parse(o.option); if (option.examine) return true } return false; } if ($check_field('add', 'warehouse_name')){ $("#warehouse_name_box").show() }else { $("#warehouse_name_box").hide() } if ($check_field('add', 'goods_number')){ $("#goods_number_box").show() }else { $("#goods_number_box").hide() } if ($check_field('add', 'name_of_goods')){ $("#name_of_goods_box").show() }else { $("#name_of_goods_box").hide() } if ($check_field('add', 'classification_of_goods')){ $("#classification_of_goods_box").show() }else { $("#classification_of_goods_box").hide() } if ($check_field('add', 'inventory_of_goods')){ $("#inventory_of_goods_box").show() }else { $("#inventory_of_goods_box").hide() } if ($check_field('add', 'storage_location')){ $("#storage_location_box").show() }else { $("#storage_location_box").hide() } if ($check_field('add', 'employee_users')){ $("#employee_users_box").show() }else { $("#employee_users_box").hide() } if ($check_field('add', 'employee_name')){ $("#employee_name_box").show() }else { $("#employee_name_box").hide() } if ($check_field('add', 'employee_id')){ $("#employee_id_box").show() }else { $("#employee_id_box").hide() } if ($check_field('add', 'inventory_date')){ $("#inventory_date_box").show() }else { $("#inventory_date_box").hide() } if ($check_field('add', 'physical_inventory')){ $("#physical_inventory_box").show() }else { $("#physical_inventory_box").hide() } if ($check_field('add', 'inventory_notes')){ $("#inventory_notes_box").show() }else { $("#inventory_notes_box").hide() } // 日期选择 laydate.render({ elem: '#inventory_date' , format: 'yyyy-MM-dd' , done: function (value) { form_data2.inventory_date = value + ' 00:00:00' } }); async function list_employee_users() { var employee_users = document.querySelector("#employee_users") var op1 = document.createElement("option"); op1.value = '0' employee_users.appendChild(op1) // 收集数据 长度 var count // 收集数据 数组 var arr = [] $.ajax({ url: BaseUrl + '/api/user/get_list?user_group=员工', type: 'GET', contentType: 'application/json; charset=UTF-8', async: false, dataType: 'json', success: function (response) { count = response.result.count arr = response.result.list } }) for (var i = 0; i < arr.length; i++) { var op = document.createElement("option"); // 给节点赋值 op.innerHTML = arr[i].username + "--" + arr[i].nickname op.value = arr[i].user_id // 新增/Add节点 employee_users.appendChild(op) if (form_data2.employee_users==arr[i].employee_users){ op.selected = true } layui.form.render("select"); } } layui.form.on('select(employee_users)', function (data) { form_data2.employee_users = Number(data.elem[data.elem.selectedIndex].value); }) list_employee_users() //文本 let warehouse_name = document.querySelector("#warehouse_name") warehouse_name.onkeyup = function (event) { form_data2.warehouse_name = event.target.value } //文本 //文本 let goods_number = document.querySelector("#goods_number") goods_number.onkeyup = function (event) { form_data2.goods_number = event.target.value } //文本 //文本 let name_of_goods = document.querySelector("#name_of_goods") name_of_goods.onkeyup = function (event) { form_data2.name_of_goods = event.target.value } //文本 //文本 let classification_of_goods = document.querySelector("#classification_of_goods") classification_of_goods.onkeyup = function (event) { form_data2.classification_of_goods = event.target.value } //文本 //数字 let inventory_of_goods = document.querySelector("#inventory_of_goods") inventory_of_goods.onkeyup = function (event) { form_data2.inventory_of_goods = Number(event.target.value) } //数字 //文本 let storage_location = document.querySelector("#storage_location") storage_location.onkeyup = function (event) { form_data2.storage_location = event.target.value } //文本 //文本 let employee_name = document.querySelector("#employee_name") employee_name.onkeyup = function (event) { form_data2.employee_name = event.target.value } //文本 //文本 let employee_id = document.querySelector("#employee_id") employee_id.onkeyup = function (event) { form_data2.employee_id = event.target.value } //文本 //数字 let physical_inventory = document.querySelector("#physical_inventory") physical_inventory.onkeyup = function (event) { form_data2.physical_inventory = Number(event.target.value) } //数字 //多文本 let inventory_notes = document.querySelector("#inventory_notes") //多文本 var data = sessionStorage.data || '' if (data !== '') { var data2 = JSON.parse(data) Object.keys(form_data2).forEach(key => { Object.keys(data2).forEach(dbKey => { if (key === dbKey) { if (key!=='examine_state' && key!=='examine_reply'){ $('#' + key).val(data2[key]) form_data2[key] = data2[key] $('#' + key).attr('disabled', 'disabled') for (let key in form_data2) { if (key == 'employee_users') { let alls = document.querySelector('#employee_users').querySelectorAll('option') let test = form_data2[key] for (let i = 0; i < alls.length; i++) { layui.form.render("select"); if (alls[i].value == test) { alls[i].selected = true form_data2.employee_users = alls[i].value layui.form.render("select"); } } } } } } if(dbKey === "source_table"){ form_data2.source_table = data2[dbKey]; } if(dbKey === "source_id"){ form_data2.source_id = data2[dbKey]; } if(dbKey === "source_user_id"){ form_data2.source_user_id = data2[dbKey]; } }) }) sessionStorage.removeItem("data"); } async function axios_get_4() { if(user_group !='管理员'){ const {data: rese} = await axios.get(BaseUrl + '/api/user/get_list?user_group=' + user_group) let data = rese.result.list const {data: ress} = await axios.get(BaseUrl + '/api/user_group/get_obj?name=' + user_group) const {data: res} = await axios.get(BaseUrl + '/api/' + ress.result.obj.source_table + '/get_obj?user_id=' + use_id) Object.keys(form_data2).forEach(key => { Object.keys(res.result.obj).forEach(dbKey => { if (key === dbKey) { if (key!=='examine_state' && key!=='examine_reply'){ $('#' + key).val(res.result.obj[key]) form_data2[key] = res.result.obj[key] $('#' + key).attr('disabled', 'disabled') } } }) }) for (let key in res.result.obj) { if (key == 'user_id') { let alls = document.querySelector('#employee_users').querySelectorAll('option') let test = res.result.obj.user_id for (let i = 0; i < alls.length; i++) { if (alls[i].value == test) { alls[i].selected = true $('#employee_users').attr('disabled', 'disabled') form_data2.employee_users = alls[i].value layui.form.render("select"); } } } } } } axios_get_4() if (inventory_records_id !== '') { $('#print').show(); async function axios_get_3() { const {data: rese} = await axios.get(BaseUrl + '/api/inventory_records/get_obj', { params: { inventory_records_id: inventory_records_id }, headers: { 'x-auth-token': token //向服务端发送 GET 请求,获取库存记录详情数据 } }) let data = rese.result.obj //将服务端返回的 data 对象同步到前端表单的以下两个位置 Object.keys(form_data2).forEach((key) => { form_data2[key] = data[key]; $("#"+key).val(form_data2[key]) }); for (let key in data) { if (key == 'employee_users') { let alls = document.querySelector('#employee_users').querySelectorAll('option') let test = data[key] for (let i = 0; i < alls.length; i++) { layui.form.render("select"); if (alls[i].value == test) { alls[i].selected = true form_data2.employee_users = alls[i].value layui.form.render("select"); } } } } if ($check_field('set', 'warehouse_name') || $check_field('get', 'warehouse_name')){ $("#warehouse_name_box").show() }else { $("#warehouse_name_box").hide() } if ($check_field('set', 'goods_number') || $check_field('get', 'goods_number')){ $("#goods_number_box").show() }else { $("#goods_number_box").hide() } if ($check_field('set', 'name_of_goods') || $check_field('get', 'name_of_goods')){ $("#name_of_goods_box").show() }else { $("#name_of_goods_box").hide() } if ($check_field('set', 'classification_of_goods') || $check_field('get', 'classification_of_goods')){ $("#classification_of_goods_box").show() }else { $("#classification_of_goods_box").hide() } if ($check_field('set', 'inventory_of_goods') || $check_field('get', 'inventory_of_goods')){ $("#inventory_of_goods_box").show() }else { $("#inventory_of_goods_box").hide() } if ($check_field('set', 'storage_location') || $check_field('get', 'storage_location')){ $("#storage_location_box").show() }else { $("#storage_location_box").hide() } if ($check_field('set', 'employee_users') || $check_field('get', 'employee_users')){ $("#employee_users_box").show() }else { $("#employee_users_box").hide() } if ($check_field('set', 'employee_name') || $check_field('get', 'employee_name')){ $("#employee_name_box").show() }else { $("#employee_name_box").hide() } if ($check_field('set', 'employee_id') || $check_field('get', 'employee_id')){ $("#employee_id_box").show() }else { $("#employee_id_box").hide() } if ($check_field('set', 'inventory_date') || $check_field('get', 'inventory_date')){ $("#inventory_date_box").show() }else { $("#inventory_date_box").hide() } if ($check_field('set', 'physical_inventory') || $check_field('get', 'physical_inventory')){ $("#physical_inventory_box").show() }else { $("#physical_inventory_box").hide() } if ($check_field('set', 'inventory_notes') || $check_field('get', 'inventory_notes')){ $("#inventory_notes_box").show() }else { $("#inventory_notes_box").hide() } // Array.prototype.slice.call(document.getElementsByTagName('input')).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName('select')).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName('textarea')).map(i => i.disabled = true) //文本 warehouse_name.value = form_data2.warehouse_name //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'warehouse_name')) || (!form_data2['inventory_records_id'] && $check_field('add', 'warehouse_name'))) { }else { $("#warehouse_name").attr("disabled", true); $("#warehouse_name > input[name='file']").attr('disabled', true); } //文本 goods_number.value = form_data2.goods_number //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'goods_number')) || (!form_data2['inventory_records_id'] && $check_field('add', 'goods_number'))) { }else { $("#goods_number").attr("disabled", true); $("#goods_number > input[name='file']").attr('disabled', true); } //文本 name_of_goods.value = form_data2.name_of_goods //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'name_of_goods')) || (!form_data2['inventory_records_id'] && $check_field('add', 'name_of_goods'))) { }else { $("#name_of_goods").attr("disabled", true); $("#name_of_goods > input[name='file']").attr('disabled', true); } //文本 classification_of_goods.value = form_data2.classification_of_goods //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'classification_of_goods')) || (!form_data2['inventory_records_id'] && $check_field('add', 'classification_of_goods'))) { }else { $("#classification_of_goods").attr("disabled", true); $("#classification_of_goods > input[name='file']").attr('disabled', true); } //数字 inventory_of_goods.value = form_data2.inventory_of_goods //数字 if ((form_data2['inventory_records_id'] && $check_field('set', 'inventory_of_goods')) || (!form_data2['inventory_records_id'] && $check_field('add', 'inventory_of_goods'))) { }else { $("#inventory_of_goods").attr("disabled", true); $("#inventory_of_goods > input[name='file']").attr('disabled', true); } //文本 storage_location.value = form_data2.storage_location //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'storage_location')) || (!form_data2['inventory_records_id'] && $check_field('add', 'storage_location'))) { }else { $("#storage_location").attr("disabled", true); $("#storage_location > input[name='file']").attr('disabled', true); } if ((form_data2['inventory_records_id'] && $check_field('set', 'employee_users')) || (!form_data2['inventory_records_id'] && $check_field('add', 'employee_users'))) { }else { $("#employee_users").attr("disabled", true); $("#employee_users > input[name='file']").attr('disabled', true); } //文本 employee_name.value = form_data2.employee_name //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'employee_name')) || (!form_data2['inventory_records_id'] && $check_field('add', 'employee_name'))) { }else { $("#employee_name").attr("disabled", true); $("#employee_name > input[name='file']").attr('disabled', true); } //文本 employee_id.value = form_data2.employee_id //文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'employee_id')) || (!form_data2['inventory_records_id'] && $check_field('add', 'employee_id'))) { }else { $("#employee_id").attr("disabled", true); $("#employee_id > input[name='file']").attr('disabled', true); } if ((form_data2['inventory_records_id'] && $check_field('set', 'inventory_date')) || (!form_data2['inventory_records_id'] && $check_field('add', 'inventory_date'))) { }else { $("#inventory_date").attr("disabled", true); $("#inventory_date > input[name='file']").attr('disabled', true); } //数字 physical_inventory.value = form_data2.physical_inventory //数字 if ((form_data2['inventory_records_id'] && $check_field('set', 'physical_inventory')) || (!form_data2['inventory_records_id'] && $check_field('add', 'physical_inventory'))) { }else { $("#physical_inventory").attr("disabled", true); $("#physical_inventory > input[name='file']").attr('disabled', true); } //多文本 inventory_notes.value = form_data2.inventory_notes //多文本 if ((form_data2['inventory_records_id'] && $check_field('set', 'inventory_notes')) || (!form_data2['inventory_records_id'] && $check_field('add', 'inventory_notes'))) { }else { $("#inventory_notes").attr("disabled", true); $("#inventory_notes > input[name='file']").attr('disabled', true); } inventory_date.value = layui.util.toDateString(form_data2.inventory_date, "yyyy-MM-dd") layui.form.render("select"); } axios_get_3() } submit.onclick = async function () { try { //文本 form_data2.warehouse_name = warehouse_name.value //文本 //文本 form_data2.goods_number = goods_number.value //文本 //文本 form_data2.name_of_goods = name_of_goods.value //文本 //文本 form_data2.classification_of_goods = classification_of_goods.value //文本 //数字 form_data2.inventory_of_goods = Number(inventory_of_goods.value) //数字 //文本 form_data2.storage_location = storage_location.value //文本 //文本 form_data2.employee_name = employee_name.value //文本 //文本 form_data2.employee_id = employee_id.value //文本 if(form_data2.inventory_date == ""){ form_data2.inventory_date = (new Date()).toLocaleDateString(); } form_data2.inventory_date = layui.util.toDateString(form_data2.inventory_date, "yyyy-MM-dd") //数字 form_data2.physical_inventory = Number(physical_inventory.value) //数字 //多文本 form_data2.inventory_notes = inventory_notes.value //多文本 } catch (err) { console.log(err) } if (!form_data2.inventory_date){ layer.msg('盘点日期不能为空'); return; } let customize_field = [] customize_field.push({"field_name": "仓库名称", "field_value": form_data2.warehouse_name}); customize_field.push({"field_name": "货物编号", "field_value": form_data2.goods_number}); customize_field.push({"field_name": "货物名称", "field_value": form_data2.name_of_goods}); customize_field.push({"field_name": "货物分类", "field_value": form_data2.classification_of_goods}); customize_field.push({"field_name": "货物库存", "field_value": form_data2.inventory_of_goods}); customize_field.push({"field_name": "存放位置", "field_value": form_data2.storage_location}); customize_field.push({"field_name": "员工", "field_value": form_data2.employee_users}); customize_field.push({"field_name": "员工姓名", "field_value": form_data2.employee_name}); customize_field.push({"field_name": "员工工号", "field_value": form_data2.employee_id}); customize_field.push({ "field_name": "盘点日期", "field_value": form_data2.inventory_date, "type": "date" }); customize_field.push({"field_name": "盘点数量", "field_value": form_data2.physical_inventory}); customize_field.push({"field_name": "盘点备注", "field_value": form_data2.inventory_notes}); if (inventory_records_id == '') { console.log("新增/Add") const {data: res} = await axios.post(BaseUrl + '/api/inventory_records/add?', form_data2, { headers: { 'x-auth-token': token, 'Content-Type': 'application/json' } }) if (res.result == 1) { layer.msg('确认完毕'); setTimeout(function () { colseLayer() }, 1000) }else { layer.msg(res.error.message); } } else { console.log("详情/Details") const {data: res} = await axios.post(BaseUrl + '/api/inventory_records/set?inventory_records_id=' + inventory_records_id, form_data2, { headers: { 'x-auth-token': token, 'Content-Type': 'application/json' } }) if (res.result == 1) { layer.msg('确认完毕'); setTimeout(function () { colseLayer() }, 1000) }else { layer.msg(res.error.message); } } } }) ; </script> </html> 分析我给的代码,哪些代码是盘点新增的核心代码,不要自己写
06-04
<!-- 供应商信息新增/Add --> <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> <link rel="stylesheet" href="../../layui/css/layui.css"> <link rel="stylesheet" href="../../css/diy.css"> <script src="../../js/axios.min.js"></script> <style> img { width: 200px; } .layui-upload-list { overflow: hidden; } .layui-upload-list .multiple_block .upload_img_multiple { height: auto; width: 100px; } .multiple_block { position: relative; float: left; width: 100px; margin: 0 10px 10px 0; } .multiple_block .upload-img-del { position: absolute; top: 5px; right: 5px; color: #fff; border-radius: 100%; background: #0000009c; width: 20px; height: 20px; text-align: center; line-height: 20px; cursor: pointer; } </style> </head> <body> <article class="sign_in"> <div class="warp tpl"> <div class="layui-container"> <div class="layui-row"> <form class="layui-form" action=""> <div class="form-input-box from-input-box-i"> <div class="layui-form-item unique" id="supplier_name_box"> <label class="layui-form-label">供应商名称</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入供应商名称" class="layui-input" id="supplier_name"> </div> </div> <div class="layui-form-item unique" id="suppliers_phone_number_box"> <label class="layui-form-label">供应商电话</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入供应商电话" class="layui-input" id="suppliers_phone_number"> </div> </div> <div class="layui-form-item unique" id="supplier_address_box"> <label class="layui-form-label">供应商地址</label> <div class="layui-input-block input-i block"> <input type="text" name="title" lay-verify="title" autocomplete="off" placeholder="请输入供应商地址" class="layui-input" id="supplier_address"> </div> </div> <div class="layui-form-item layui-form-text" id="supply_items_box"> <label class="layui-form-label">供应物品</label> <div class="layui-input-block text"> <textarea placeholder="请输入供应物品" class="layui-textarea" id="supply_items"></textarea> </div> </div> <div class="layui-form-item layui-form-text" id="supplier_description_box"> <label class="layui-form-label">供应商描述</label> <div class="layui-input-block text"> <textarea placeholder="请输入供应商描述" class="layui-textarea" id="supplier_description"></textarea> </div> </div> </div> </form> <div class="layui-btn-container"> <button type="button" class="layui-btn layui-btn-normal login" id="submit">确认</button> <button type="button" class="layui-btn layui-btn-normal login" id="cancel">取消</button> </div> </div> </div> </div> </article> </body> <script src="../../layui/layui.js"></script> <script src="../../js/base.js"></script> <script src="../../js/index.js"></script> <script> var BaseUrl = baseUrl() let cancel = document.querySelector("#cancel") cancel.addEventListener("click", () => { colseLayer() }) let supplier_information_id = location.search.substring(1) layui.use(['upload', 'element', 'layer', 'laydate', 'layedit'], function () { var $ = layui.jquery , upload = layui.upload , element = layui.element , layer = layui.layer , laydate = layui.laydate , layedit = layui.layedit , form = layui.form; let url let token = sessionStorage.token || null let personInfo = JSON.parse(sessionStorage.personInfo) let user_group = personInfo.user_group let use_id = personInfo.user_id function $get_stamp() { return new Date().getTime(); } function $get_rand(len) { var rand = Math.random(); return Math.ceil(rand * 10 ** len); } // 权限判断 /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_action(path1, action = "get") { var o = $get_power(path1); if (o && o[action] != 0 && o[action] != false) { return true; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取权限 * @param {String} path 路由路径 */ function $get_power(path) { var list_data = JSON.parse(sessionStorage.list_data) var list = list_data; var obj; for (var i = 0; i < list.length; i++) { var o = list[i]; if (o.path === path) { obj = o; break; } } return obj; } let submit = document.querySelector('#submit') // 提交按钮校验权限 if ($check_action('/supplier_information/view', 'add') || $check_action('/supplier_information/view', 'set') || $check_option('/supplier_information/table', 'examine')) { } else { $("#submit").hide() } // style="display: none" let field = "supplier_information_id"; let url_add = "supplier_information"; let url_set = "supplier_information"; let url_get_obj = "supplier_information"; let url_upload = "supplier_information" let query = { "supplier_information_id": 0, } let form_data2 = { "supplier_name": '', // 供应商名称 "suppliers_phone_number": '', // 供应商电话 "supplier_address": '', // 供应商地址 "supply_items": '', // 供应物品 "supplier_description": '', // 供应商描述 "supplier_information_id": 0, // ID } layui.layedit.set({ uploadImage: { url: BaseUrl + '/api/supplier_information/upload?' //接口url , type: 'post' //默认post } }); var path1 function getpath() { var list_data = JSON.parse(sessionStorage.list_data) for (var i = 0; i < list_data.length; i++) { var o = list_data[i]; if (o.path === "/supplier_information/table") { path1 = o.path $get_power(o.path) } } } getpath() /** * 注册时是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 * @param {String} path 路径 */ function $check_register_field(action, field, path1) { var o = $get_power(path1); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 是否有显示或操作字段的权限 * @param {String} action 操作名 * @param {String} field 查询的字段 */ function $check_field(action, field) { var o = $get_power("/supplier_information/view"); var auth; if (o && o[action] != 0 && o[action] != false) { auth = o["field_" + action]; } if (auth) { return auth.indexOf(field) !== -1; } return false; } /** * 获取路径对应操作权限 鉴权 * @param {String} action 操作名 */ function $check_exam(path1, action = "get") { var o = $get_power(path1); if (o) { var option = JSON.parse(o.option); if (option[action]) return true } return false; } function $check_option(path, op) { var o = $get_power(path); if (o) { var option = JSON.parse(o.option); if (option[op]) return true } return false; } /** * 是否有审核字段的权限 */ function $check_examine() { var url = window.location.href; var url_ = url.split("/") var pg_url = url_[url_.length - 2] let path = "/" + pg_url + "/table" var o = $get_power(path); if (o) { var option = JSON.parse(o.option); if (option.examine) return true } return false; } if ($check_field('add', 'supplier_name')) { $("#supplier_name_box").show() } else { $("#supplier_name_box").hide() } if ($check_field('add', 'suppliers_phone_number')) { $("#suppliers_phone_number_box").show() } else { $("#suppliers_phone_number_box").hide() } if ($check_field('add', 'supplier_address')) { $("#supplier_address_box").show() } else { $("#supplier_address_box").hide() } if ($check_field('add', 'supply_items')) { $("#supply_items_box").show() } else { $("#supply_items_box").hide() } if ($check_field('add', 'supplier_description')) { $("#supplier_description_box").show() } else { $("#supplier_description_box").hide() } //文本 let supplier_name = document.querySelector("#supplier_name") supplier_name.onkeyup = function (event) { form_data2.supplier_name = event.target.value } //文本 //文本 let suppliers_phone_number = document.querySelector("#suppliers_phone_number") suppliers_phone_number.onkeyup = function (event) { form_data2.suppliers_phone_number = event.target.value } //文本 //文本 let supplier_address = document.querySelector("#supplier_address") supplier_address.onkeyup = function (event) { form_data2.supplier_address = event.target.value } //文本 //多文本 let supply_items = document.querySelector("#supply_items") //多文本 //多文本 let supplier_description = document.querySelector("#supplier_description") //多文本 var data = sessionStorage.data || '' if (data !== '') { var data2 = JSON.parse(data) Object.keys(form_data2).forEach(key => { Object.keys(data2).forEach(dbKey => { if (key === dbKey) { if (key !== 'examine_state' && key !== 'examine_reply') { $('#' + key).val(data2[key]) form_data2[key] = data2[key] $('#' + key).attr('disabled', 'disabled') } } if (dbKey === "source_table") { form_data2.source_table = data2[dbKey]; } if (dbKey === "source_id") { form_data2.source_id = data2[dbKey]; } if (dbKey === "source_user_id") { form_data2.source_user_id = data2[dbKey]; } }) }) sessionStorage.removeItem("data"); } if (supplier_information_id !== '') { $('#print').show(); async function axios_get_3() { const { data: rese } = await axios.get(BaseUrl + '/api/supplier_information/get_obj', { params: { supplier_information_id: supplier_information_id }, headers: { 'x-auth-token': token } }) let data = rese.result.obj Object.keys(form_data2).forEach((key) => { form_data2[key] = data[key]; $("#" + key).val(form_data2[key]) }); if ($check_field('set', 'supplier_name') || $check_field('get', 'supplier_name')) { $("#supplier_name_box").show() } else { $("#supplier_name_box").hide() } if ($check_field('set', 'suppliers_phone_number') || $check_field('get', 'suppliers_phone_number')) { $("#suppliers_phone_number_box").show() } else { $("#suppliers_phone_number_box").hide() } if ($check_field('set', 'supplier_address') || $check_field('get', 'supplier_address')) { $("#supplier_address_box").show() } else { $("#supplier_address_box").hide() } if ($check_field('set', 'supply_items') || $check_field('get', 'supply_items')) { $("#supply_items_box").show() } else { $("#supply_items_box").hide() } if ($check_field('set', 'supplier_description') || $check_field('get', 'supplier_description')) { $("#supplier_description_box").show() } else { $("#supplier_description_box").hide() } // Array.prototype.slice.call(document.getElementsByTagName('input')).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName('select')).map(i => i.disabled = true) // Array.prototype.slice.call(document.getElementsByTagName('textarea')).map(i => i.disabled = true) //文本 supplier_name.value = form_data2.supplier_name //文本 if ((form_data2['supplier_information_id'] && $check_field('set', 'supplier_name')) || (!form_data2['supplier_information_id'] && $check_field('add', 'supplier_name'))) { } else { $("#supplier_name").attr("disabled", true); $("#supplier_name > input[name='file']").attr('disabled', true); } //文本 suppliers_phone_number.value = form_data2.suppliers_phone_number //文本 if ((form_data2['supplier_information_id'] && $check_field('set', 'suppliers_phone_number')) || (!form_data2['supplier_information_id'] && $check_field('add', 'suppliers_phone_number'))) { } else { $("#suppliers_phone_number").attr("disabled", true); $("#suppliers_phone_number > input[name='file']").attr('disabled', true); } //文本 supplier_address.value = form_data2.supplier_address //文本 if ((form_data2['supplier_information_id'] && $check_field('set', 'supplier_address')) || (!form_data2['supplier_information_id'] && $check_field('add', 'supplier_address'))) { } else { $("#supplier_address").attr("disabled", true); $("#supplier_address > input[name='file']").attr('disabled', true); } //多文本 supply_items.value = form_data2.supply_items //多文本 if ((form_data2['supplier_information_id'] && $check_field('set', 'supply_items')) || (!form_data2['supplier_information_id'] && $check_field('add', 'supply_items'))) { } else { $("#supply_items").attr("disabled", true); $("#supply_items > input[name='file']").attr('disabled', true); } //多文本 supplier_description.value = form_data2.supplier_description //多文本 if ((form_data2['supplier_information_id'] && $check_field('set', 'supplier_description')) || (!form_data2['supplier_information_id'] && $check_field('add', 'supplier_description'))) { } else { $("#supplier_description").attr("disabled", true); $("#supplier_description > input[name='file']").attr('disabled', true); } layui.form.render("select"); } axios_get_3() } submit.onclick = async function () { try { //文本 form_data2.supplier_name = supplier_name.value //文本 //文本 form_data2.suppliers_phone_number = suppliers_phone_number.value //文本 //文本 form_data2.supplier_address = supplier_address.value //文本 //多文本 form_data2.supply_items = supply_items.value //多文本 //多文本 form_data2.supplier_description = supplier_description.value //多文本 } catch (err) { console.log(err) } let customize_field = [] customize_field.push({ "field_name": "供应商名称", "field_value": form_data2.supplier_name }); customize_field.push({ "field_name": "供应商电话", "field_value": form_data2.suppliers_phone_number }); customize_field.push({ "field_name": "供应商地址", "field_value": form_data2.supplier_address }); customize_field.push({ "field_name": "供应物品", "field_value": form_data2.supply_items }); customize_field.push({ "field_name": "供应商描述", "field_value": form_data2.supplier_description }); if (supplier_information_id == '') { console.log("新增/Add") const { data: res } = await axios.post(BaseUrl + '/api/supplier_information/add?', form_data2, { headers: { 'x-auth-token': token, 'Content-Type': 'application/json' } }) if (res.result == 1) { layer.msg('确认完毕'); setTimeout(function () { colseLayer() }, 1000) } else { layer.msg(res.error.message); } } else { console.log("详情/Details") const { data: res } = await axios.post(BaseUrl + '/api/supplier_information/set?supplier_information_id=' + supplier_information_id, form_data2, { headers: { 'x-auth-token': token, 'Content-Type': 'application/json' } }) if (res.result == 1) { layer.msg('确认完毕'); setTimeout(function () { colseLayer() }, 1000) } else { layer.msg(res.error.message); } } } }) ; </script> </html> 分析我给的代码,代码对应的功能是什么,不要自己写
06-03
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值