| | |
| | | * @Author: 小飞侠 |
| | | * @Date: 2024-03-01 09:11:24 |
| | | * @LastEditors: Please set LastEditors |
| | | * @LastEditTime: 2024-04-01 12:39:54 |
| | | * @LastEditTime: 2024-04-26 13:25:48 |
| | | * Copyright: 2024 MinTinge CO.,LTD. All Rights Reserved. |
| | | * @Descripttion: 写入你的描述 |
| | | */ |
| | |
| | | */ |
| | | function formatAreaInPut(coreHelper, idname, areaid = "") { |
| | | let area = 0; |
| | | |
| | | if ((areaid !== "")&&(areaid!==null) &&(areaid!==0)) |
| | | area = areaid.split(",").reverse()[0]; |
| | | |
| | |
| | | $.each(data, function (i, n) { |
| | | str += `<select lay-ignore name='${idname}_` + (i + 1) + "' dep='" + (i + 1) + "' class='select-address'>"; |
| | | str += "<option value='' >请选择</option>"; |
| | | $.each(n.list, function (h, z) { |
| | | |
| | | if(n?.list?.length>0) |
| | | { |
| | | $.each(n.list, function (h, z) { |
| | | if (n.hasOwnProperty('info') && n.info?.id == z.id) { |
| | | str += "<option value='" + z.id + "' selected='selected'>" + z.name + "</option>"; |
| | | } else { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | } |
| | | }); |
| | | } |
| | | else |
| | | { |
| | | $.each(n.thisList, function (h, z) { |
| | | if (n.hasOwnProperty('info') && n.info?.id == z.id) { |
| | | str += "<option value='" + z.id + "' selected='selected'>" + z.name + "</option>"; |
| | | } else { |
| | | str += "<option value='" + z.id + "' >" + z.name + "</option>"; |
| | | } |
| | | }); |
| | | } |
| | | str += "</select>"; |
| | | }); |
| | | $(`input[name='${idname}']`).after(str); |
| | | //以上数据输出完,以下绑定事件 |
| | | $.each(data, function (i, n) { |
| | | if (i < (data.length)) { |
| | | $(`select[name='${idname}_` + (i + 1) + "']").change(function () { |
| | | // $(`select[name='${idname}_` + (i + 1) + "']").change(function () { |
| | | // changeareaIdArea(i + 1, data.length, idname); |
| | | // }); |
| | | $(`select[name='${idname}_` + (i + 1) + "']").click(function () { |
| | | changeareaIdArea(i + 1, data.length, idname); |
| | | }); |
| | | } |
| | |
| | | : ("00" + o[k]).substr(("" + o[k]).length) |
| | | ); |
| | | return fmt; |
| | | }; |
| | | }; |
| | | |
| | | /** |
| | | * 检查给定的字符串是否为日期时间格式 |
| | | * @param {string} str - 需要检查的字符串 |
| | | * @return {boolean} 返回一个布尔值,指示字符串是否符合日期时间格式 |
| | | */ |
| | | function isDateTimeString(str) { |
| | | // 定义日期时间的正则表达式模式 |
| | | const dateTimePattern = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/; |
| | | // 使用正则表达式模式测试字符串 |
| | | return dateTimePattern.test(str); |
| | | } |
| | | |
| | | /** |
| | | * 格式化商品分类选择输入框 |
| | | * @param {object} coreHelper 核心辅助对象,用于发送请求等操作 |
| | | * @param {object} form 表单对象,用于重新渲染select元素 |
| | | * @param {string} idname 输入框的id名称 |
| | | * @param {string} selectedID 默认选中的分类ID,为空时默认不选中任何项 |
| | | */ |
| | | function formatGoodsCategorySelInPut(coreHelper, form, idname,selectedID="") { |
| | | |
| | | // 向服务器发送请求,获取用户列表 |
| | | coreHelper.PostForm("Api/CommonAPI/GetGoodsCategory", { }, function (data) { |
| | | if (debug) { console.log(data); } // 如果处于调试模式,打印返回的数据 |
| | | |
| | | if (data.code == 0) { |
| | | // 获取指定 id 的 select 元素 |
| | | var selectElement = document.getElementById(idname); |
| | | |
| | | // 遍历返回的用户数据,为 select 元素创建并添加新的 option 选项 |
| | | for (var i = 0; i < data.data.length; i++) { |
| | | var option = document.createElement('option'); |
| | | option.value = data.data[i].id; |
| | | if(selectedID==data.data[i].id){ |
| | | option.selected=true; |
| | | } |
| | | option.innerHTML = data.data[i].name; |
| | | selectElement.appendChild(option); |
| | | } |
| | | |
| | | // 重新渲染 select 元素,确保新的选项生效 |
| | | form.render('select'); |
| | | } |
| | | }) |
| | | } |