<extend name="Public/base" />

<block name="body">
  <link rel="stylesheet" href="__CSS__/select2.min.css" type="text/css" />
  <link rel="stylesheet" type="text/css" href="__CSS__/admin_table.css" media="all">
  <link href="__STATIC__/icons_alibaba/iconfont.css" rel="stylesheet">
  <script type="text/javascript" src="__STATIC__/uploadify/jquery.uploadify.min.js"></script>
  <script type="text/javascript" src="__STATIC__/provincecityarea/AreaData_min.js"></script>
  <script src="__STATIC__/layer/layer.js"></script>
  <script type="text/javascript" src="__JS__/select2.min.js"></script>

  <style>
    .tabcon1711 input.time {
      width: 150px;
    }
    #form .txt_area {
      width: 300px;
      height: 150px;
    }
    .tabcon1711 .form_unit {
      margin-left: 2px;
    }
    .tabcon1711 .mustmark {
      margin-left:-7px;
    }
    .list-ratio {
      display: table;
    }
    .list-ratio .li-ratio {
      display: flex;
      margin-bottom: 20px;
      align-items: center;
    }
    .list-ratio .li-ratio .turnover, .list-ratio .li-ratio .turnover-ratio {
      position: relative;
    }
    .list-ratio .li-ratio .turnover span, .list-ratio .li-ratio .turnover-ratio .error-message {
      color: red;
      position: absolute;
      left: 0;
      top: 30px;
      white-space: nowrap;
      display: none;
    }
    .iconfont-btn {
      cursor: pointer;
    }
    .iconfont-style {
      font-size: 18px;
      color: #fff;
      border-radius: 4px;
      border: 0;
      padding: 5px;
      margin-left: 10px;
    }
    .iconfont-selected {
      background-color: #0A9AF2;
    }
    .iconfont-selected:hover {
      background-color: #03a9f4;
    }
    .iconfont-unselected {
      background-color: #999;
    }
    .iconfont-unselected:hover {
      background-color: #ababab;
    }
  </style>
  <div class="cf main-place top_nav_list navtab_list">
    <h3 class="page_title">{$meta_title}</h3>
<!--    <p class="description_text">说明:此功是创建推广员时所需填写信息</p>-->
  </div>

  <!-- 标签页导航 -->
  <div class="tab-wrap">
    <div class="tab-content tabcon1711">
      <!-- 表单 -->
      <form id="form" action="{:U('save')}" method="post" class="form-horizontal">
        <!-- 基础文档模型 -->
        <div id="tab1" class="tab-pane in tab1">
          <table  border="0" cellspacing="0" cellpadding="0">
            <tbody>
            <tr>
                <td class="l"><i class="mustmark">*</i>支付配置名称:</td>
                <td class="r table_radio">
                    <input type="text" class="txt ratio" name="name" id="name" value="<?=$record?$record['name']:''?>" placeholder="请输入商户名称">
                    <span class="notice-text"></span>
                </td>
            </tr>
            <tr>
              <td class="l"><i class="mustmark">*</i>商户主体:</td>
              <td class="r table_radio">
                  <input type="text" class="txt ratio" name="main_name" id="main_name" value="<?=$record?$record['main_name']:''?>" placeholder="请输入商户主体">
                  <span class="notice-text"></span>
              </td>
          </tr>
            <tr>
                <td class="l"><i class="mustmark">*</i>商户账号:</td>
                <td class="r table_radio">
                    <input type="text" class="txt ratio" name="account" id="account" value="<?=$record?$record['account']:''?>" placeholder="请输入商户账号">
                    <span class="notice-text"></span>
                </td>
            </tr>
            <tr>
              <td class="l noticeinfo"><i class="mustmark">*</i>启用状态</td>
              <td class="r table_radio">
                <span class="form_radio">
                    <label><input type="radio" name="status" value="0"> 禁用</label>
                    <label><input type="radio" name="status" value="1" checked="checked"> 启用</label>
                </span>
                <span class="notice-text"></span>
              </td>
            </tr>
            <tr>
              <td class="l"><i class="mustmark">*</i>支付商户:</td>
              <td class="r">
                <select name="channel" id="channel" class="select_gallery" <?php if($record):?>disabled<?php endif;?>>
                  <option value="">请选择支付商户</option>
                  <?php foreach($channels as $key => $name):?>
                  <option value="<?=$key?>" <?php if($record && $record['channel'] == $key):?>selected<?php endif;?>><?=$name?></option>
                  <?php endforeach;?>
                </select>
                <span class="notice-text"></span>
              </td>
            </tr>
            </tbody>
          </table>
          <div id="merchant-detail" style="margin-top: 10px;">
          </div>

        </div>
        <input type="hidden" name="id" id="id" value="{$record.id}" />
        <div class="form-item cf">
          <button class="submit_btn mlspacing" id="submit" type="submit" target-form="form-horizontal">
            确认
          </button>
          <a class="submit_btn " alt="返回上一页" title="返回上一页" href="javascript:window.history.back();" >
            返回
          </a>
        </div>
      </form>
    </div>
  </div>

  <div class="common_settings">
    <span class="plus_icon"><span><img src="__IMG__/zwmimages/icon_jia.png"></span></span>
    <form class="addShortcutIcon">
      <input type="hidden" name="title" value="{$m_title}">
      <input type="hidden" name="url" value="Promote/lists/type/1">
    </form>
    <a class="ajax-post add-butn <notempty name='commonset'>addSIsetted</notempty>" href="javascript:;" target-form="addShortcutIcon" url="{:U('Think/addShortcutIcon')}"><img src="__IMG__/zwmimages/icon_jia.png"><span><notempty name='commonset'>已添加<else />添加至常用设置</notempty></span></a>
  </div>

  <div id="merchant-template" style="display: none;">
    <?php if(!$record || $record['channel'] == 1):?>
    <div id="merchant-1">
      <input type="hidden" name="ways[]" value="1" >
      <table border="0" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
          <td class="l noticeinfo">合作伙伴身份ID(PID)</td>
          <td class="r table_radio">
            <input name="config[partner]" type="text" value="<?=$config['partner'] ?? ''?>" class="">
            <span class="notice-text">账户中心--mapi网关产品密钥--合作伙伴身份(PID)</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">MD5密钥</td>
          <td class="r table_radio">
            <input name="config[key]" type="text" value="<?=$config['key'] ?? ''?>" class="">
            <span class="notice-text">账户中心--mapi网关产品密钥--合作伙伴密钥</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">公钥</td>
          <td class="r table_radio">
            <input name="config[public_key]" type="text" value="<?=$config['public_key'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">私钥</td>
          <td class="r table_radio">
            <input name="config[private_key]" type="text" value="<?=$config['private_key'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">收款账户</td>
          <td class="r table_radio">
            <input name="config[email]" type="text" value="<?=$config['email'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">APPID</td>
          <td class="r table_radio">
            <input name="config[app_id]" type="text" value="<?=$config['app_id'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">日支付限量</td>
          <td class="r table_radio">
            <input name="config[day_pay_limit]" type="text" value="<?=$config['day_pay_limit'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">月支付限量</td>
          <td class="r table_radio">
            <input name="config[month_pay_limit]" type="text" value="<?=$config['month_pay_limit'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">渠道费率</td>
          <td class="r table_radio">
            <input name="config[channel_rate]" type="text" value="<?=$config['channel_rate'] ?? ''?>" class="">
            <span class="notice-text">%</span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <?php endif;?>

    <?php if(!$record || $record['channel'] == 2):?>
    <div id="merchant-2">
      <input type="hidden" name="ways[]" value="2" >
      <table border="0" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
          <td class="l noticeinfo">商户号</td>
          <td class="r table_radio">
            <input name="config[partner]" type="text" value="<?=$config['partner'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">APPID</td>
          <td class="r table_radio">
            <input name="config[appid]" type="text" value="<?=$config['appid'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">密钥key</td>
          <td class="r table_radio">
            <input name="config[key]" type="text" value="<?=$config['key'] ?? ''?>" class="">
            <span class="notice-text">微信秘钥</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">日支付限量</td>
          <td class="r table_radio">
            <input name="config[day_pay_limit]" type="text" value="<?=$config['day_pay_limit'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">月支付限量</td>
          <td class="r table_radio">
            <input name="config[month_pay_limit]" type="text" value="<?=$config['month_pay_limit'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">渠道费率</td>
          <td class="r table_radio">
            <input name="config[channel_rate]" type="text" value="<?=$config['channel_rate'] ?? ''?>" class="">
            <span class="notice-text">%</span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <?php endif;?>

    <?php if(!$record || $record['channel'] == 3):?>
    <div id="merchant-3">
      <?php $config3 = $channelConfig[3] ?? null; ?>
      <table border="0" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
          <td class="l noticeinfo">商户号</td>
          <td class="r table_radio">
            <input name="config[partner]" type="text" value="<?=$config['partner'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">上级商户号</td>
          <td class="r table_radio">
            <input name="config[parent_merchant]" type="text" value="<?=$config['parent_merchant'] ?? ''?>" class="">
            <span class="notice-text">易宝上级商户号</span>
          </td>
        </tr>

        <tr>
          <td class="l noticeinfo">公钥</td>
          <td class="r table_radio">
              <input name="config[public_key]" type="text" value="<?=$config['public_key'] ?? ''?>" class="">
              <span class="notice-text">易宝公钥</span>
          </td>
        </tr>

        <tr>
          <td class="l noticeinfo">私钥</td>
          <td class="r table_radio">
            <input name="config[private_key]" type="text" value="<?=$config['private_key'] ?? ''?>" class="">
            <span class="notice-text">易宝私钥</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">易宝密钥key</td>
          <td class="r table_radio">
            <input name="config[key]" type="text" value="<?=$config['key'] ?? ''?>" class="">
            <span class="notice-text">易宝密钥key</span>
          </td>
        </tr>

        <tr>
          <td class="l noticeinfo">支付方式:</td>
          <td class="r table_radio">
            <span class="form_checkbox">
              <label>
                <input name="ways[]" type="checkbox" value="4" class="" <?php if($record && in_array(4, $ways)):?>checked<?php endif;?>>
              </label>
            </span>
            <span class="notice-text" style="margin-left:5px;margin-right: 15px;width: 70px;">快捷支付</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">日支付限量</td>
          <td class="r table_radio">
            <input name="config[day_pay_limit]" type="text" value="<?=$config['day_pay_limit'] ?? ''?>" class="" placeholder='请输入额度' oninput="this.value=this.value.replace(/[^0-9]+|^0|\d{9}/,'');">
            <span class="notice-text">当额度达到限制额度时,隐藏支付方式</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">月支付限量</td>
          <td class="r table_radio">
            <input name="config[month_pay_limit]" type="text" value="<?=$config['month_pay_limit'] ?? ''?>" class="" placeholder='请输入额度' oninput="this.value=this.value.replace(/[^0-9]+|^0|\d{9}/,'');">
            <span class="notice-text">当额度达到限制额度时,隐藏支付方式</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">渠道费率</td>
          <td class="r">
            <input name="config[channel_rate]" type="text" value="<?=$config['channel_rate'] ?? ''?>" class="" placeholder="设置支付渠道的的费用比例">
            <span class="notice-text">%</span>
          </td>
        </tr>
        </tbody>
        </table>
    </div>
    <?php endif;?>

    <?php if(!$record || $record['channel'] == 4):?>
    <div id="merchant-4">
      <table border="0" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
          <td class="l noticeinfo">商户号</td>
          <td class="r table_radio">
            <input name="config[merno]" type="text" value="<?=$config['merno'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">双乾密钥key</td>
          <td class="r table_radio">
            <input name="config[secret]" type="text" value="<?=$config['secret'] ?? ''?>" class="">
            <span class="notice-text">双乾秘钥</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">支付方式:</td>
          <td class="r table_radio">
            <span class="form_checkbox">
              <label><input name="ways[]" type="checkbox" value="1" class="" <?php if($record && in_array(1, $ways)):?>checked<?php endif;?>></label>
            </span>
            <span class="notice-text" style="margin-left:5px;margin-right: 15px;width: 70px;">支付宝</span>
            <span class="form_checkbox">
              <label>
                <input name="ways[]" type="checkbox" value="4" class="" <?php if($record && in_array(4, $ways)):?>checked<?php endif;?>>
              </label>
            </span>
            <span class="notice-text" style="margin-left:5px;margin-right: 15px;width: 70px;">快捷支付</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">日支付限量</td>
          <td class="r table_radio">
            <input name="config[day_pay_limit]" type="text" value="<?=$config['day_pay_limit'] ?? ''?>" class="" placeholder='请输入额度' oninput="this.value=this.value.replace(/[^0-9]+|^0|\d{9}/,'');">
            <span class="notice-text">当额度达到限制额度时,隐藏支付方式</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">月支付限量</td>
          <td class="r table_radio">
            <input name="config[month_pay_limit]" type="text" value="<?=$config['month_pay_limit'] ?? ''?>" class="" placeholder='请输入额度' oninput="this.value=this.value.replace(/[^0-9]+|^0|\d{9}/,'');">
            <span class="notice-text">当额度达到限制额度时,隐藏支付方式</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">渠道费率</td>
          <td class="r">
            <input name="config[channel_rate]" type="text" value="<?=$config['channel_rate'] ?? ''?>" class="" placeholder="设置支付渠道的的费用比例">
            <span class="notice-text">%</span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <?php endif;?>

    <?php if(!$record || $record['channel'] == 5):?>
    <div id="merchant-5">
      <table border="0" cellspacing="0" cellpadding="0">
        <tbody>
        <tr>
          <td class="l noticeinfo">商户号</td>
          <td class="r table_radio">
            <input name="config[merno]" type="text" value="<?=$config['merno'] ?? ''?>" class="">
            <span class="notice-text"></span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">汇付宝密钥key</td>
          <td class="r table_radio">
            <input name="config[secret]" type="text" value="<?=$config['secret'] ?? ''?>" class="">
            <span class="notice-text">汇付宝秘钥</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">支付方式:</td>
          <td class="r table_radio">
            <span class="form_checkbox">
              <label>
                <input name="ways[]" type="checkbox" value="1" class="" <?php if($record && in_array(1, $ways)):?>checked<?php endif;?>>
              </label>
            </span>
            <span class="notice-text" style="margin-left:5px;margin-right: 15px;width: 70px;">支付宝</span>
            <span class="form_checkbox">
              <label>
                <input name="ways[]" type="checkbox" value="2" class="" <?php if($record && in_array(2, $ways)):?>checked<?php endif;?>>
              </label>
            </span>
            <span class="notice-text" style="margin-left:5px;margin-right: 15px;width: 70px;">微信</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">日支付限量</td>
          <td class="r table_radio">
            <input name="config[day_pay_limit]" type="text" value="<?=$config['day_pay_limit'] ?? ''?>" class="" placeholder='请输入额度' oninput="this.value=this.value.replace(/[^0-9]+|^0|\d{9}/,'');">
            <span class="notice-text">当额度达到限制额度时,隐藏支付方式</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">月支付限量</td>
          <td class="r table_radio">
            <input name="config[month_pay_limit]" type="text" value="<?=$config['month_pay_limit'] ?? ''?>" class="" placeholder='请输入额度' oninput="this.value=this.value.replace(/[^0-9]+|^0|\d{9}/,'');">
            <span class="notice-text">当额度达到限制额度时,隐藏支付方式</span>
          </td>
        </tr>
        <tr>
          <td class="l noticeinfo">渠道费率</td>
          <td class="r">
            <input name="config[channel_rate]" type="text" value="<?=$config['channel_rate'] ?? ''?>" class="" placeholder="设置支付渠道的的费用比例">
            <span class="notice-text">%</span>
          </td>
        </tr>
        </tbody>
      </table>
    </div>
    <?php endif;?>
  </div>

</block>

<block name="script">
  <link href="__STATIC__/datetimepicker/css/datetimepicker.css" rel="stylesheet" type="text/css">
  <php>if(C('COLOR_STYLE')=='blue_color') echo '<link href="__STATIC__/datetimepicker/css/datetimepicker_blue.css" rel="stylesheet" type="text/css">';</php>
  <link href="__STATIC__/datetimepicker/css/dropdown.css" rel="stylesheet" type="text/css">
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
  <script type="text/javascript" src="__STATIC__/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js" charset="UTF-8"></script>
<script type="text/javascript">
//导航高亮
highlight_subnav("{:U('PaymentMerchant/list')}");
$(".select_gallery").select2();

$(function(){
    $('.time').datetimepicker({
        format: 'yyyy-mm',
        language: "zh-CN",
        autoclose: true,
        scrollMonth: false,
        scrollTime: false,
        scrollInput: false,
        startView: 'year',
        minView:'year',
        maxView:'year',
    });
    showTab();

    $('#channel').on({
      change: function() {
        var channel = $(this).val()
        console.log(channel)
        $('#merchant-detail').html($('#merchant-' + channel).html())
      }
    })

    $('#channel').change()

    $('#submit').click(function (e) {
        var target = $('form').get(0).action;
        var query = $('form').serialize();
        var that = this;
        $(that).addClass('disabled').attr('autocomplete','off').prop('disabled',true);
        $.post(target,query).success(function(result){
          if(layer) { layer.closeAll('loading'); }
          if (result.status == 1) {
            layer.msg(result.message)
            setTimeout(function() {
              window.location.href = '{:U("list")}'
            }, 200)
          } else {
            $(that).removeClass('disabled').attr('autocomplete','on').prop('disabled',false);
            layer.msg(result.message)
          }
        });
    });
});
</script>
</block>