layui.define(['form'], function (exports) { var form = layui.form, $ = layui.jquery, index = 0, oldId, MOD_NAME = 'labelGeneration', formField = { label: { id: '-1', tag: "label", }, }, labelGeneration = { set: function (options) { var that = this; that.config = $.extend({} , that.config , options); return that; } //事件监听 , on: function (events , callback) { return layui.onevent.call(this , MOD_NAME , events , callback); } }, Class = function (options) { var that = this; that.config = $.extend({} , that.config , labelGeneration.config , options); that.render(); }, thisIns = function () { var that = this , options = that.config; return { reload: function (options) { that.reload.call(that , options); }, getOptions: function () { return options || null; }, getData: function () { return options.data || null; } } } Class.prototype.config = { version: "1.0.0" , Author: "谁家没一个小强" , generateId: 0 , data: [] , isEnter: false }; /* 自动生成ID 当前页面自动排序*/ Class.prototype.autoId = function (tag) { var that = this, options = that.config; options.generateId = options.generateId + 1; return tag + '_' + options.generateId; } Class.prototype.components = { label: { render: function (json,options) { var _html = '
'; _html += ''; return _html; }, update: function (json) { }, /* 获取对象 */ jsonData: function (id, that) { //分配一个新的ID var _json = JSON.parse(JSON.stringify(formField.label)); _json.id = id == undefined ? that.autoId(_json.tag) : id; that.checkId(_json,that); return _json; } } }; /* 判定id是否重复*/ Class.prototype.checkId = function (json,that) { if ($("#" + json.id + "-content").length != 0) { json.id = that.autoId(json.tag); that.checkId(json); } else { return; } } // Class.prototype.bindGridSortEvent = function (json) { // var that = this // , options = that.config; // var formItemSort = Sortable.create(document.getElementById(json.id + "-content"), { // group: { // name: 'group' + json.id // }, // animation: 1000, // onEnd: function (evt) { // var _values = $("#" + json.id + "-content").find("div"); // var ops = []; // for (var i = 0; i < _values.length; i++) { // ops.push({"ngColor": $(_values[i]).attr("ng-color"), "value": $(_values[i]).text()}); // } // options.data = ops; // } // }); // } /* 绑定事件*/ Class.prototype.deleteValue = function (value, ngValue) { var that = this , options = that.config; for (var i = 0; i < options.data.length; i++) { if (options.data[i].value === value && options.data[i].ngColor === ngValue) { options.data.splice(i, 1); break; } } } /* 绑定事件*/ Class.prototype.bindPropertyEvent = function (_json) { var that = this , options = that.config; var colorClass = ""; if (options.isEnter) { $("#" + _json.id).keypress(function (event) { if (event.which === 13) { var _value = $(this).val(); if (!_value) { layer.msg('请输入手机号!') return; } if (!/^1[3456789]\d{9}$/.test(_value)) { layer.msg('手机号格式错误!') return; } let arr = $("#" + _json.id + "-content .layui-btn") for (let i = 0; i < arr.length; i++) { if ($(arr[i]).text().trim() == _value) { layer.msg('输入手机号重复!') return } } index = index + 1; var _html = ''; _html += ''; _html += ''; _html += ''.format(json.id); _html += ''; if (options.isEnter) { _html += '' .format(json.id); } else { _html += '' .format(json.id); } _html += ''; if (!options.isEnter) { _html += ''.format(json.id); } // _html += ''; // _html += ''; // _html += ''; // _html += ''; _html += '