中扬CRM客户关系管理系统
#
luxiaotao1123
2022-11-22 45286ba61d7df92ca3d60bdf187b94d5a4349874
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
layui.define(['form'], function (exports) {
 
    var form = layui.form,
        $ = layui.jquery,
        layer = layui.layer,
        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 = '<blockquote class="layui-elem-quote">';
                _html += '<div class="layui-form layui-form-pane layui-form-item">';
                _html += '<label class="layui-form-label">输入标签</label>';
                _html += '<div class="layui-input-inline">';
                if (options.isEnter) {
                _html += '<input type="text" id="{0}"  placeholder="按回车生成标签" autocomplete="off" class="layui-input">'
                    .format(json.id);
                } else {
                    _html += '<input type="text" id="{0}" placeholder="通过按钮生成标签" autocomplete="off" class="layui-input">'
                    .format(json.id);
                }
                _html += '</div>';
                if (!options.isEnter) {
                    _html += '<button type="button" id="{0}-button" class="layui-btn layui-btn-normal">确定</button>'.format(json.id);
                }
                _html += '<label class="layui-form-label">颜色选择</label>';
                _html += '<div class="layui-input-inline">';
                _html += '<select lay-filter="{0}-switchTest">'.format(json.id);
                _html += '<option value="" selected>墨绿色</option>';
                _html += '<option value="layui-btn-primary">原始色</option>';
                _html += '<option value="layui-btn-normal">天蓝色</option>';
                _html += '<option value="layui-btn-warm">暖黄色</option>';
                _html += '<option value="layui-btn-danger">红色</option>';
                _html += '</select>';
                _html += '</div>';
                _html += '</div>';
                _html += '<div id="{0}-content" class="layui-btn-container"></div>'.format(json.id);
                _html += '</blockquote>';
                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;
                    }
                    index = index + 1;
                    var _html = '<div class="layui-btn {0} none-transition" id="{2}" ng-index="{3}" ng-color="{0}">{1}<i class="layui-icon layui-icon-close"></i></div>'
                        .format(colorClass, _value, _json.id + index, index);
                    $("#" + _json.id + "-content").append(_html);
                    options.data.push({"ngColor": colorClass, "value": _value});
                    $("#" + _json.id + index + " .layui-icon-close").click(function () {
                        that.deleteValue($(this).parent().text(), $(this).parent().attr("ng-color"));
                        $(this).parent().remove();
                    });
                    return false;
                }
            });
        } else {
            $("#" + _json.id + "-button").click(function (event) {
                var _value = $("#" + _json.id).val();
                if (_value === "") {
                    layer.msg('标签值不能为空');
                    return;
                }
                index = index + 1;
                var _html = '<div class="layui-btn {0} none-transition" id="{2}" ng-index="{3}" ng-color="{0}">{1}<i class="layui-icon layui-icon-close"></i></div>'
                    .format(colorClass, _value, _json.id + index, index);
                $("#" + _json.id + "-content").append(_html);
                options.data.push({"ngColor": colorClass, "value": _value});
                $("#" + _json.id + index + " .layui-icon-close").click(function () {
                    that.deleteValue($(this).parent().text(), $(this).parent().attr("ng-color"));
                    $(this).parent().remove();
                });
            });
        }
 
        form.on('select(' + _json.id + '-switchTest)', function (data) {
            colorClass = data.value;
        });
        for (var i = 0; i < options.data.length; i++) {
            index = index + 1;
            var _html = '<div class="layui-btn {0} none-transition" id="{2}" ng-index="{3}" ng-color="{0}">{1}<i class="layui-icon layui-icon-close"></i></div>'
                .format(options.data[i].ngColor, options.data[i].value, _json.id + index, index);
            $("#" + _json.id + "-content").append(_html);
            $("#" + _json.id + index + " .layui-icon-close").click(function () {
                that.deleteValue($(this).parent().text(), $(this).parent().attr("ng-color"));
                $(this).parent().remove();
            });
        }
    }
 
    /* 渲染组件 */
    Class.prototype.renderComponents = function () {
        var that = this
            , options = that.config;
        var elem = $(options.elem);
        elem.empty();
        var jsonData = that.components['label'].jsonData(undefined, that);
        elem.append(that.components['label'].render(jsonData,options));
        that.bindPropertyEvent(jsonData);
        that.bindGridSortEvent(jsonData);
        form.render();
    }
 
    Class.prototype.reload = function (options) {
        var that = this;
        options = options || {};//如果是空的话,就赋值 {}
        that.config = $.extend({}
            , that.config
            , labelGeneration.config
            , options);
        that.render(options);
    }
 
    //核心入口 初始化一个 regionSelect 类
    labelGeneration.render = function (options) {
        var ins = new Class(options);
        return thisIns.call(ins);
    }
    /**
     * 渲染组件
     */
    Class.prototype.render = function (options) {
        var that = this
            , options = that.config;
        that.renderComponents();
    }
 
    String.prototype.format = function (args) {
        var result = this;
        if (arguments.length > 0) {
            if (arguments.length == 1 && typeof (args) == "object") {
                for (var key in args) {
                    if (args[key] != undefined) {
                        var reg = new RegExp("({" + key + "})"
                            , "g");
                        result = result.replace(reg
                            , args[key]);
                    }
                }
            } else {
                for (var i = 0; i < arguments.length; i++) {
                    if (arguments[i] != undefined) {
                        var reg = new RegExp("({[" + i + "]})"
                            , "g");
                        result = result.replace(reg
                            , arguments[i]);
                    }
                }
            }
        }
        return result;
    }
 
    exports(MOD_NAME, labelGeneration);
});