<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="SpecAdd.aspx.cs" Inherits="LMN.Web.Admin.Shop.SpecAdd" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>添加修改规格</title>
<link href="../css/admin.css" rel="stylesheet" type="text/css" />
<link href="../Scripts/wbox/wbox.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="../Scripts/jquery-1.4.1.min.js"></script>
<script src="../Scripts/wbox.js" type="text/javascript"></script>
<script src="../Scripts/common.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server" target="iframe">
<div style="padding: 20px;">
  <h4 class="title">添加信息</h4>
  <div class="division">
    <table width="100%">
      <tr>
        <th class="w120">规格名称：</th>
        <td><input runat="server" autocomplete="off" type="text" id="name" name="name" required="true" maxlength="20" /> *</td>
      </tr>
      <tr>
        <th>规格说明：</th>
        <td><input runat="server" autocomplete="off" type="text" id="note" name="note" maxlength="100" /></td>
      </tr>
      <tr>
        <th>显示类型：</th>
        <td><label><input type="radio" runat="server" id="text" name="show" value="0" checked="true" />文字</label>&nbsp; &nbsp; <label><input runat="server" type="radio" id="image" name="show" value="1" />图片</label></td>
      </tr>
      <tr>
        <th>规格类型：</th>
        <td><label><input type="radio" runat="server" id="size" name="type" value="0" checked="true" />尺寸</label>&nbsp; &nbsp; <label><input runat="server" type="radio" id="color" name="type" value="1" />色彩</label></td>
      </tr>
    </table>
  </div>
  <h4 class="title">添加规格值</h4>
  <div class="division">
    <table width="100%">
      <thead>
        <tr>
          <th style="text-align: center; width: 15%;">ID</th>
          <th style="text-align: center; width: 30%;">规格值名称</th>
          <th style="text-align: center; width: 30%;">规格值图片</th>
          <th style="text-align: center; width: 15%;">操作</th>
        </tr>
      </thead>
      <tbody id="specBox">
      </tbody>
      <tfoot>
        <tr>
          <td colspan="4"><span class="sysiconBtn add addspec">添加规格值</span></td>
        </tr>
      </tfoot>
    </table>
  </div>
  <div class="division">
    <table width="100%">
      <tr>
        <th></th>
        <td><b class="submitBtn"><input id="specSave" name="specSave" type="button" value="保存" /> </b></td>
      </tr>
    </table>
  </div>
</div>
</form>
<iframe id="iframe" name="iframe"></iframe>
<script type="text/javascript">
  function deleValue(o) {
    if (!confirm("确认删除？"))
      return false;

    var id = $(o).parent().parent().find("td input[name=id]").val() * 1;
    if (id == 0) {
      $(o).parent().parent().remove();
      return true;
    }
    $.get("Action.aspx?action=specvaluedelete&id=" + id, function(data) {
      var result = parseInt(data);
      if (result < 0) {
        alert("参数错误！");
      } else if (result == 0) {
        alert("删除失败！");
      } else {
        $(o).parent().parent().remove();
        alert("删除成功！请点击“保存”保存修改");
      }
    });
    return true;
  }
//  function imageSelect(o) {
//    var id = $(o).parent().parent().find("td input[name=icon]").attr("id");
//    // 选择图片
//    alert(id);
//    var wBox = $("#hoho").wBox({
//      show: true,
//      requestType: "iframe",
//      iframeWH: { width: 800, height: 400, resize: false },
//      target: "../FileManager/Default.aspx?target=" + id
//    });
//    return true;

//  }
  function specRow(i, t, m) {
    var index = 0;
    if ($("#specBox").children("tr").length != 0) {
      index = $("#specBox").children("tr").last().attr("index") * 1 + 1;
    }
    // alert(index);
    return '<tr align="center" index="' + index + '"><td><input autocomplete="off" type="text" size="10" readonly="readonly" id="id_' + index + '" name="id" value="' + i + '" /></td><td><input autocomplete="off" type="text" id="text_' + index + '" name="text" value="' + t + '" /></td><td><input autocomplete="off" type="text" id="icon_' + index + '" name="icon" value="' + m + '" /> <a href="javascript:;" onclick="imageSel(this)">选择图片</a></td><td><a href="javascript:;" onclick="deleValue(this)">删除</a></td></tr>';
  }
  $("#specSave").click(function() {
    if ($("#name").val().length == 0) {
      alert("规格名称不能为空！");
      return false;
    }
    $("#form1").submit();
    return true;
  });

  $(".addspec").click(function() {
    $("#specBox").append(specRow(0, "", ""));
  });

  $(document).ready(function() {
    var valueList = '<%=ValueList %>';
    if (valueList != "" && valueList != "null") {
      var json = eval('(' + valueList + ')');
      for (var j = 0; j < json.length; j++) {
        $("#specBox").append(specRow(json[j].id, json[j].text, json[j].icon));
      }
    }
  });
</script>
</body>
</html>
