|
@@ -970,6 +970,180 @@ class Input
|
|
|
* @return string
|
|
|
*/
|
|
|
public static function _select($param, $class = '', $hidden = '', $change = '')
|
|
|
+ {
|
|
|
+ $html = $class ? '<div class="' . $class . '">' : '';
|
|
|
+ $html .= $hidden;
|
|
|
+ $xm = true;
|
|
|
+
|
|
|
+ if (isset($param['option']) && isset($param['update']) && $param['update'] == 'select') {
|
|
|
+ $total = count($param['option']);
|
|
|
+ if ($total <= 30) {
|
|
|
+ $xm = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($xm && isset($param['update'])) {
|
|
|
+
|
|
|
+ $url = '';
|
|
|
+ //https://maplemei.gitee.io/xm-select/?select=#/basic/paging
|
|
|
+ if (isset($param['update_search'])) {
|
|
|
+ $search_value = '';
|
|
|
+ if (isset($param['value'])) {
|
|
|
+ $search_value = $param['value'];
|
|
|
+ } elseif (isset($param['default'])) {
|
|
|
+ $search_value = $param['default'];
|
|
|
+ }
|
|
|
+ if (strstr($param['update_search'], '{id}')) {
|
|
|
+ $param['update_search'] = str_replace('{id}', 'where_id=' . $param['where_id'], $param['update_search']);
|
|
|
+ }
|
|
|
+ $url = Dever::url($param['update_search'] . '&yes='.$search_value.'&json=1');
|
|
|
+ }
|
|
|
+
|
|
|
+ $xm_data = array();
|
|
|
+ if (!$url && isset($param['option']) && $param['option']) {
|
|
|
+ foreach ($param['option'] as $k => $v) {
|
|
|
+ if (is_array($v)) {
|
|
|
+ $xm_data[] = array('name' => $v['name'], 'value' => $v['id']);
|
|
|
+ } else {
|
|
|
+ $xm_data[] = array('name' => $v, 'value' => $k);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $xm_value = isset($param['value']) ? $param['value'] : $param['default'];
|
|
|
+ $xm_tips = '请选择';
|
|
|
+ $xm_data = Dever::json_encode($xm_data);
|
|
|
+ $xm_id = $param['name'];
|
|
|
+ $xm_radio = ($param['update'] == 'selects' ? false : true);
|
|
|
+ $xm_on = '';
|
|
|
+ if (isset($param['control']) && is_string($param['control'])) {
|
|
|
+ $xm_on = 'inputShow(e, \'' . $param['control'] . '\');';
|
|
|
+ $change = ' show_id="' . $param['control'] . '"';
|
|
|
+ } elseif (isset($param['load'])) {
|
|
|
+ $xm_on = 'loadChange(e, \'' . $param['load'] . '\');';
|
|
|
+ } elseif (isset($param['bind'])) {
|
|
|
+ $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
|
|
|
+ $xm_on = '' . $param['bind'][1] . '(e, ' . $param['bind'][2] . ', 1);';
|
|
|
+ }
|
|
|
+ if ($xm_on) {
|
|
|
+ $xm_on = 'function(data){
|
|
|
+ var arr = data.arr;
|
|
|
+ if (arr && arr.length > 0) {
|
|
|
+ var xm_radio = '.$xm_radio.';
|
|
|
+ if (xm_radio) {
|
|
|
+ var e = $("#'.$xm_id.'");
|
|
|
+ e.attr("v", arr[0].value);
|
|
|
+ '.$xm_on.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }';
|
|
|
+ }
|
|
|
+ $html .= '<div id="' . $param['name'] . '" '.$change.' class="xm-select-demo" style="width:200px"></div>';
|
|
|
+ $html .= '<script>
|
|
|
+ $(document).ready(function() {
|
|
|
+ layui.use(["table"], function() {
|
|
|
+ init_xm("'.$xm_id.'", '.$xm_radio.', "'.$xm_tips.'", "'.$url.'", '.$xm_data.', ['.$xm_value.'], '.$xm_on.');
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ </script>';
|
|
|
+ } else {
|
|
|
+ $child_class = '';
|
|
|
+ $style = '';
|
|
|
+ if (isset($param['child'])) {
|
|
|
+ $child_param['name'] = 'update_' . $param['child_name'];
|
|
|
+ isset($param['value']) && $param['value'] = $param['value'];
|
|
|
+ isset($param['child_value']) && $child_param['value'] = $param['child_value'];
|
|
|
+
|
|
|
+ $change = 'style="width:45%" id="' . $param['name'] . '" data-child="' . $child_param['name'] . '_child" ';
|
|
|
+ $child_class = ' change';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($param['control']) && is_string($param['control'])) {
|
|
|
+ $change = ' show_id="' . $param['control'] . '" onchange="inputShow($(this), \'' . $param['control'] . '\')"';
|
|
|
+ } elseif (isset($param['option_add'])) {
|
|
|
+ $change = ' onchange="addChange($(this))" ';
|
|
|
+ $style = 'width:25%';
|
|
|
+ $child_class .= ' change';
|
|
|
+ } elseif (isset($param['load'])) {
|
|
|
+ $change = ' onchange="loadChange($(this), \'' . $param['load'] . '\')" ';
|
|
|
+ $child_class .= ' change';
|
|
|
+ } elseif (isset($param['bind'])) {
|
|
|
+ $param['bind'][2] = isset($param['bind'][2]) ? str_replace('"', '\'', json_encode($param['bind'][2], true)) : false;
|
|
|
+ $change = $param['bind'][0] . '="' . $param['bind'][1] . '($(this), ' . $param['bind'][2] . ')" ';
|
|
|
+
|
|
|
+ $child_class .= ' change';
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= '<select class="update_value form-control ' . $child_class . ' ' . (isset($param['valid']) ? $param['valid'] : '') . '" name="' . $param['name'] . '" id="' . $param['name'] . '" ' . $change . ' style="' . $style . '" data-validation-placeholder="0">';
|
|
|
+
|
|
|
+ if (isset($param['option'])) {
|
|
|
+
|
|
|
+ if (!isset($param['option'][-100]) && isset($param['lang']) && $param['lang']) {
|
|
|
+ $html .= '<option value="0" selected>' . $param['lang'] . '</option>';
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($param['option_add'])) {
|
|
|
+ $html .= '<option value="0" data-type="add" data-url="'.Dever::url($param['option_add'][1]).'">' . $param['option_add'][0] . '</option>';
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($param['option'] as $k => $v) {
|
|
|
+ if (is_array($v)) {
|
|
|
+ if (isset($v['lang']) && $v['lang']) {
|
|
|
+ $value = $v['lang'];
|
|
|
+ } else {
|
|
|
+ $value = $v['name'];
|
|
|
+ }
|
|
|
+
|
|
|
+ isset($v['id']) && $k = $v['id'];
|
|
|
+ } else {
|
|
|
+ $value = $v;
|
|
|
+ }
|
|
|
+ $check = '';
|
|
|
+
|
|
|
+ if ((isset($param['value']) && strstr(','. $param['value'] . ',', ',' . $k . ',')) || (isset($param['bit'][$k]) && isset($param['value']) && ($param['value'] & $k) > 0) || (empty($param['value']) && isset($param['default']) && strstr(',' . $param['default'] . ',', ',' . $k . ','))) {
|
|
|
+ $check = 'selected';
|
|
|
+ }
|
|
|
+
|
|
|
+ $parent = '';
|
|
|
+ if (isset($param['parent']) && $param['parent'] && isset($v[$param['parent']])) {
|
|
|
+ $parent = $v[$param['parent']];
|
|
|
+ }
|
|
|
+
|
|
|
+ if (is_array($v)) {
|
|
|
+ $value = isset($v['name']) ? $v['name'] : $v['lang'];
|
|
|
+ } else {
|
|
|
+ $value = $v;
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= '<option parent="'.$parent.'" value="' . $k . '" ' . $check . '>' . $value . '</option>';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= '</select>';
|
|
|
+
|
|
|
+ if (isset($param['child'])) {
|
|
|
+ $child = $child_param['name'];
|
|
|
+ $hidden = self::hidden(array('name' => $child, 'class' => $child . '_child_value'));
|
|
|
+ foreach ($param['child'] as $k => $v) {
|
|
|
+ $child_param['name'] = 'child-' . $k;
|
|
|
+ $child_param['option'] = $v;
|
|
|
+
|
|
|
+ $html .= self::select($child_param, $child . '_child ' . $child . '_child_' . $k . '" parent="' . $k . '" style="display:none;margin-top: -38px;margin-left: 47%;"', $hidden);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $html .= $class ? '</div>' : '';
|
|
|
+ return $html;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * select
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ *
|
|
|
+ public static function _select($param, $class = '', $hidden = '', $change = '')
|
|
|
{
|
|
|
$html = $class ? '<div class="' . $class . '">' : '';
|
|
|
|