<?php
if (count($ziduan_sousuo) > 0) {
foreach ($ziduan_sousuo as $arr => $v) {
if ($v['table_name'] == 'chanpin'&&$v['name'] == 'class1'){

$fenlei_fu = $this->qmsoft_mysql->get_results('chanpin_class', array('parentid' => 0, 'isdel' => 0));
$fenlei_fu_id = $this->qmsoft_mysql->get_rows('chanpin_class', array('parentid' => 0, 'name' => $class1, 'isdel' => 0), 'id');
$fenlei_zi = $this->qmsoft_mysql->get_results('chanpin_class', array('parentid' => $fenlei_fu_id, 'isdel' => 0));
?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
<select name="class1" id='fenlei1' <?php if ($this->qmsoft_mysql->get_rows('ziduan', array('table_name' => 'chanpin', 'name' => 'class1'), 'inuse') == "是") {?>datatype="*" nullmsg="请选择！"<?php }?>>
            <option value="">请选择</option>
            <?php foreach ($fenlei_fu as $arr => $row) {?>
            <option value="<?php echo $row['name'] ?>" <?php echo $row['name'] == $class1 ? 'selected' : '' ?>><?php echo $row['name'] ?></option>
            <?php }?>
          </select>
          <select name="class2" id="fenlei2">
            <option>请选择</option>
            <?php foreach ($fenlei_zi as $arr => $row) {?>
            <option value="<?php echo $row['name'] ?>" <?php echo $row['name'] == $class2 ? 'selected' : '' ?>><?php echo $row['name'] ?></option>
            <?php }?>
          </select>
</dl>
      <script>
  $(function(){
    //初始化数据
    var url = '/index.php/chanpin/ajax_select'; //后台地址
    $("#fenlei1").change(function(){ //监听下拉列表的change事件
      var fenlei = $(this).val(); //获取下拉列表选中的值
      //发送一个post请求
      $.ajax({
        type:'post',
        url:url,
        data:{key:fenlei},
        dataType:'json',
        success:function(data){ //请求成功回调函数
          var status = data.status; //获取返回值
          var fenlei = data.data;
          if(status == 200){ //判断状态码，200为成功
            var option = '<option>请选择</option>';
            for(var i=0;i<fenlei.length;i++){ //循环获取返回值，并组装成html代码
              option +='<option value="'+fenlei[i]+'">'+fenlei[i]+'</option>';
            }
          }else{
            var option = '<option>请选择</option>'; //默认值
          }
          $("#fenlei2").html(option); //js刷新第二个下拉框的值
        },
      });
    });
  });
  </script>
<?php 
}else if ($v['table_name'] == 'chanpin'&&$v['name'] == 'class2'){
?>

<?php 
}else{
?>
<?php if ($v['type'] == 'text' || $v['type'] == 'textarea' || $v['type'] == 'users_duo' || $v['type'] == 'textedit') {?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <input name="<?php echo $v['name'] ?>" type="text" value="<?php echo ${$v['name']} ?>" class="input int-w200"/>
</dl>
<?php } else if ($v['type'] == 'area') {?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <div class="city-choose" style="max-width:229px;"><input name="<?php echo $v['name'] ?>" id="area_<?php echo $v['id'] ?>" type="text" value="<?php echo ${$v['name']} ?>" class="input int-w100 form-control" data-toggle="city-picker" readonly/></div>
</dl>
<script>
$(function(){
var $area_<?php echo $v['id'] ?> = $('#area_<?php echo $v['id'] ?>');
});
</script>
<?php } else if ($v['type'] == 'yes') {?>
<?php if ($v['table_name'] == 'caiwu' && $v['name'] == 'outin') {?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <div class="rule-multi-radio">
    <input type="radio" name="<?php echo $v['name'] ?>" value="" <?php echo ${$v['name']} == '' ? 'checked' : '' ?> />
    <label>所有</label>
    <input type="radio" name="<?php echo $v['name'] ?>" value="1" <?php echo ${$v['name']} == '1' ? 'checked' : '' ?> />
    <label>收入</label>
    <input type="radio" name="<?php echo $v['name'] ?>" value="0" <?php echo ${$v['name']} == '0' ? 'checked' : '' ?> />
    <label>支出</label>
  </div>
</dl>
<?php } else {?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <div class="rule-multi-radio">
    <input type="radio" name="<?php echo $v['name'] ?>" value="" <?php echo ${$v['name']} == '' ? 'checked' : '' ?> />
    <label>所有</label>
    <input type="radio" name="<?php echo $v['name'] ?>" value="是" <?php echo ${$v['name']} == '是' ? 'checked' : '' ?> />
    <label>是</label>
    <input type="radio" name="<?php echo $v['name'] ?>" value="否" <?php echo ${$v['name']} == '否' ? 'checked' : '' ?> />
    <label>否</label>
  </div>
</dl>
<?php }?>
<?php } else if ($v['type'] == 'radio') {?>
<?php
if (!empty($v['content'])) {
            $selectres = explode("|", $v['content']);
            ?>
<!--<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <div class="rule-multi-radio">
    <?php foreach ($selectres as $key => $value) {?>
    <input id="<?php echo $v['name'] ?>_1" type="radio" name="<?php echo $v['name'] ?>" value="<?php echo $value ?>" <?php echo ${$v['name']} == $value ? 'checked' : '' ?>/>
    <label for="<?php echo $v['name'] ?>_1"><?php echo $value ?></label>
    <?php }?>
  </div>
</dl>-->
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <select name="<?php echo $v['name'] ?>" >
    <option value="">请选择...</option>
    <?php foreach ($selectres as $key => $value) {?>
    <option value="<?php echo $value ?>" <?php echo ${$v['name']} == $value ? 'selected' : '' ?>><?php echo $value ?></option>
    <?php }?>
  </select>
</dl>
<?php }?>
<?php } else if ($v['type'] == 'select' || $v['type'] == 'checkbox') {?>
<?php
if (!empty($v['content'])) {
            $selectres = explode("|", $v['content']);
            ?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <select name="<?php echo $v['name'] ?>" >
    <option value="">请选择...</option>
    <?php foreach ($selectres as $key => $value) {?>
    <option value="<?php echo $value ?>" <?php echo ${$v['name']} == $value ? 'selected' : '' ?>><?php echo $value ?></option>
    <?php }?>
  </select>
</dl>
<?php }?>
<?php } else if ($v['type'] == 'selects') {?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  
  <?php
  $get_value = ${$v['name']};
  
  if (!empty($v['content'])) {
    $selectres = explode("|", $v['content']);
    foreach ($selectres as $fukey => $fuval) {
      $zivals = array();
      preg_match_all("/(?:\{)(.*)(?:\})/i", $fuval, $zivals);
      $zivals = $zivals[1][0];
      $arr_zivals = explode('*', $zivals);
      $arr_ziduovals[$fukey] = $arr_zivals;
      $arr_fuvals[$fukey] = str_replace($zivals, '', $selectres[$fukey]);
      $arr_fuvals[$fukey] = str_replace('{}', '', $arr_fuvals[$fukey]);
    }
    $json_ziduovals = json_encode($arr_ziduovals);
    
    $arr_get_value = explode("-", $get_value);
    $get_value_fu = $arr_get_value[0];
    $get_value_zi = $arr_get_value[1];
    ?>
    
    <span>
      <select name="<?php echo $v['name'] ?>_fu" onchange="<?php echo $v['name'] ?>_getzivals()">
        <option value="">请选择...</option>
        <?php foreach ($arr_fuvals as $key => $n) {?>
          <option value="<?php echo $n ?>" <?php echo $n == $get_value_fu ? 'selected' : '' ?>><?php echo $n ?></option>
        <?php }?>
      </select>
      <select name="<?php echo $v['name'] ?>_zi" onchange="<?php echo $v['name'] ?>_getwzvals()">
        <option value="">请选择...</option>
      </select>
    </span>
    <input name="<?php echo $v['name'] ?>" type="hidden" value="<?php echo ${$v['name']} ?>" class="input int-w200"/>
    
    <script>
      var <?php echo $v['name'] ?>_zivals = <?php echo $json_ziduovals ?>;
      var <?php echo $v['name'] ?>_ziokval = "<?php echo $get_value_zi ?>";
      
      document.addEventListener("DOMContentLoaded", function() {
        <?php echo $v['name'] ?>_getzivals();
      });
      
      function <?php echo $v['name'] ?>_getzivals() {
        var fu_num = document.querySelector('select[name="<?php echo $v['name'] ?>_fu"]');
        var zi_name = document.querySelector('select[name="<?php echo $v['name'] ?>_zi"]');
    
		// 检查选择框的值是否为空
		if (fu_num.selectedIndex === 0) {
			// 如果选择为空，则清空相关输入框的值
			$('input[name="<?php echo $v['name'] ?>"]').val('');
			return; // 结束函数执行
		}
	
		var fu_isok = <?php echo $v['name'] ?>_zivals[fu_num.selectedIndex - 1];
		zi_name.length = 1;
		for (var i = 0; i < fu_isok.length; i++) {
			zi_name[i + 1] = new Option(fu_isok[i], fu_isok[i]);
		}
		
        $('select[name="<?php echo $v['name'] ?>_zi"]').find("option[value='"+<?php echo $v['name'] ?>_ziokval+"']").attr("selected",true);

		var fu_select = document.querySelector('select[name="<?php echo $v['name'] ?>_fu"]');
		var fu_value = fu_select.options[fu_select.selectedIndex].value;

		$('input[name="<?php echo $v['name'] ?>"]').val(fu_value);
      }
	  
	  function <?php echo $v['name'] ?>_getwzvals() {
		var fu_select = document.querySelector('select[name="<?php echo $v['name'] ?>_fu"]');
		var zi_select = document.querySelector('select[name="<?php echo $v['name'] ?>_zi"]');
		var input_field = $('input[name="<?php echo $v['name'] ?>"]');
	
		// 检查父级选项是否被选中
		if (fu_select.selectedIndex === 0) {
			input_field.val(''); // 清空输入框的值
			return; // 结束函数执行
		}
	
		// 获取父级和子级选项的值
		var fu_value = fu_select.options[fu_select.selectedIndex].value;
		var zi_value = zi_select.options[zi_select.selectedIndex].value;
	
		// 设置输入框的值为父级和子级选项的组合
		if (zi_value !== '') {
			zi_value = '-' + zi_value;
		}
		input_field.val(fu_value + zi_value);
	}
    </script>
    
    <?php } else {?>
      <input name="<?php echo $v['name'] ?>" type="text" value="<?php echo ${$v['name']} ?>" class="input int-w200"/>
    <?php }?>
</dl>

<?php } else if ($v['type'] == 'datetime') {?>
<?php
$sname = 'start_' . $v['name'];
            $ename = 'end_' . $v['name'];
            ?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <input name="start_<?php echo $v['name'] ?>" type="text" value="<?php echo ${$sname} ?>" class="input rule-date-input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/> ~ <input name="end_<?php echo $v['name'] ?>" type="text" value="<?php echo ${$ename} ?>" class="input rule-date-input" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'})"/>
</dl>

<?php } else if ($v['type'] == 'money'||$v['type'] == 'number2') {?>
<?php
$sname = 'start_' . $v['name'];
$ename = 'end_' . $v['name'];
?>
<dl>
  <dt><?php echo $v['title'] ?>：</dt>
  <input name="start_<?php echo $v['name'] ?>" type="text" value="<?php echo ${$sname} ?>" class="input rule-shuzhi-input"/> ~ <input name="end_<?php echo $v['name'] ?>" type="text" value="<?php echo ${$ename} ?>" class="input rule-shuzhi-input"/>
</dl>

<?php } else if ($v['type'] == 'users') {?>
<dl>
  <dt> <?php echo $v['title'] ?>：</dt>
  <select class="users_select" name="<?php echo $v['name'] ?>">
    <option value="">请选择...</option>
            <?php foreach ($this->qmsoft_data->getallusers() as $key => $row) {
            if ($this->qmsoft->roleid == 0 || $this->qmsoft->users_select_all == 1 || ($this->qmsoft->roleid > 0 && in_array($row['realname'], $this->qmsoft->get_manage_names()))) {
                ?>
    <option value="<?php echo $row['realname'] ?>" <?php echo ${$v['name']} == $row['realname'] ? 'selected' : '' ?>><?php echo $row['realname'] ?></option>
    <?php }}?>
  </select>
</dl>
<?php }?>
<?php
}}
}
?>
<div class="clear"></div>
