<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AppendShopForm.aspx.cs"
    Inherits="RM.Web.Mall.AppendShop.AppendShopForm" %>
    <%@ Register Src="~/UserControl/LoadButton.ascx" TagName="LoadButton" TagPrefix="uc2" %>
<!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>
    <title><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdyshangpingName")%>-<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Edit")%></title>
    <link href="/Themes/Styles/Site.css" rel="stylesheet" type="text/css" />
    <script src="/Themes/Scripts/jquery-1.8.2.min.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/jquery.form.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/Validator/JValidator.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/DatePicker/WdatePicker.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/artDialog.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/artDialog/iframeTools.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/FunctionJS.js" type="text/javascript"></script>
    <script src="/Themes/Scripts/CreateContextJs.js" type="text/javascript"></script>
    <style type="text/css">
        .img { width: 200px; height: 100px; padding-top: 20px; }
        .a { font-size: 14px; background-color: Red; margin-right: 20px; }
        body { font-size: 14px; }
        input { vertical-align: middle; margin: 0; padding: 0; }
        .file-box { position: relative; width: 400px; margin-top: 0px; }
        .txt { height: 22px; border: 1px solid #cdcdcd; width: 100px; }
        .btn { background-color: #FFF; border: 1px solid #CDCDCD; height: 24px; width: 70px; }
        .file { position: absolute; top: 0; right: 48px; height: 24px; filter: alpha(opacity:0); opacity: 0; width: 180px; }
        .table  td{ text-align:left}
    </style>
</head>

<body>
<div class="btnbartitle">
        <div>
            <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdyshangpingName")%>
        </div>
    </div>
       <div class="btnbarcontetn">
        <div style="text-align: right">
            <uc2:LoadButton ID="LoadButton1" runat="server" />
        </div>
    </div>
    <div class="div-body" style="height:auto;">

 

        <form id="formtable" method="post" enctype="multipart/form-data">
        <table id="table2" border="0" cellpadding="0" cellspacing="0" class="frm">
        
            <tr>
            <input id="ShopPhoto" name="ShopPhoto" type="hidden" runat="server" />
                <input id="AppendProperty_value" name="AppendProperty_value" type="hidden" runat="server" />
                <input type="hidden" id="Key" name="KeyF" value="<%=Key %>" />
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpingName")%>:
                </th>
                <td>
                    <input id="ShopWare_Name" name="ShopWare_Name" type="text" style="width: 200px" runat="server" />
                </td>
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpinType")%>:
                </th>
                <td>
                    <select id="ShopWare_Type" style="width: 200px;" name="ShopWare_Type" runat="server">
                    </select>
                </td>
            </tr>
            <tr>
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpinPrice")%>:
                </th>
                <td>
                    <input id="ShopWare_Price" type="text" name="ShopWare_Price" style="width: 200px"
                        runat="server" />￥
                </td>
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpindw")%>:
                </th>
                <td>
                    <select id="ShopWare_Unit" runat="server" class="select" name="ShopWare_Unit" style="width: 206px;"></select>
                </td>

            </tr>
            <tr>
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_peishong")%>:
                </th>
                <td>
                    <select id="ShopWare_Dispatching" name="ShopWare_Dispatching" class="select" style="width: 206px;" runat="server"></select>
                </td>
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_city")%>:
                </th>
                <td>
                    <input id="ShopWare_City" name="ShopWare_City" runat="server" type="text" class="txt" 
                          style="width: 200px" />
                </td>
            </tr>
            <tr>
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpindetil")%>:
                </th>
                <td colspan="4">
                    <script src="/Themes/Scripts/kindeditor/kindeditor-min.js" type="text/javascript"></script>
                    <script type="text/javascript">
                        var editor;
                        KindEditor.ready(function (K) {
                            editor = K.create('#ShopWare_Discription', {
                                allowFileManager: true,
                                allowUpload: true,
                                uploadJson: '/WeiXin/UploadImage.ashx',
                                minHeight: 160
                            });
                        });
                    </script>
                    <textarea id="ShopWare_Discription" name="ShopWare_Discription" style="width: 800px;
                        height: 60px;" runat="server"></textarea>
                </td>
            </tr>
            <tr style="text-align: right">
             
                <td colspan="4">
                    <input type="button" onclick="GetTitleUpdownList('table2');" value='<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdyinsert")%>' />
                </td>
            </tr>
            <tr valign="top">
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("AppendProperty_Form_title")%>：
                </th>
                <td colspan="3" valign="top">
                    <div id="trappend" valign="top" class=" table">
                    </div>
                </td>
            </tr>
        </table>
        </form>
        <form id="photo" enctype="multipart/form-data">
        <table border="0" cellpadding="0" cellspacing="0" class="frm">
            <tr valign="top">
                <th>
                    <%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpinImg")%>:
                </th>
                <td colspan="3">
                    <input type="hidden" id="Hidden1" name="Key" value="<%=Key %>" />
                    <input type="hidden" id="Loadcontrol" name="Loadcontrol" />
                    <input type="hidden" id="photow" name="photow" value="200" />
                    <input type="hidden" id="photoh" name="photoh" value="200" />
                    <input type="file" id="ShopWare_Photo" name="ShopWare_Photo" onchange="AddPhoto(this)" />
                    <div id="imgtd">
                    </div>
                </td>
            </tr>
            <%=str %>
        </table>
        </form>
   
 
    </div>
</body>
<script type="text/javascript">

    //页面初始化
     var Key = $("#Key").val();
        GetPhoto();
    function SaveForm() 
    {
    OnFormtableSubmit();
    }
    function OpenClose(){
    Loading(true);
    window.location.href="AppendShopList.aspx";
    }
 //表单验证
 function checkValue()
 {
   editor.sync();
         if ($("#ShopWare_Name").val()=="") {
           alert('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpinNameNull")%>');
            return false;
        }
         if ($("#ShopWare_Price").val()=="") {
             alert('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpinPriceNull")%>');
            return false;
        }
          if (isNaN($("#ShopWare_Price").val())) {
          alert('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_shangpinPricez")%>');         
            return false;
        }
         if ($("#ShopWare_Unit").val()=="") {
         alert('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_spmatilNull")%>');
            return false;
        }
      
         if ($("#ShopWare_Discription").val()=="") {
            alert('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_spmatilNull")%>');
               return false;
        }
        return true;
 }
    //自定义商品提交
    function OnFormtableSubmit() {
    if (!checkValue()) {
    return false;
}
        var item_value = '';
        $("#AppendProperty_value").empty;
        $("#trappend").each(function (r) {
            $(this).find('td').each(function (i) {
                var pk_id = $(this).find('input,select').attr('id');
                if ($(this).find('input,select').val() != "" && $(this).find('input,select').val() != "==<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_pselect")%>==" && $(this).find('input,select').val() != undefined) {
                    item_value += pk_id + "|" + $(this).find('input,select').val() + ";";
                }
            $(this).find('p').each(function(e){
     
                var pk_id = $(this).find('input,select').attr('id');
                if ($(this).find('input,select').val() != "" && $(this).find('input,select').val() != "==<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_pselect")%>==" && $(this).find('input,select').val() != undefined) {
                    item_value += pk_id + "|" + $(this).find('input,select').val() + ";";
                }});
              
            });
          
        });
        $("#AppendProperty_value").val(item_value);


    $("#formtable").ajaxSubmit({url: "AddAppendShop.ashx",dataType:"text",post:"post"
      ,success:function(rs){
            if (rs=="1") {showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_uploadscuss")%>', 1000, 4); //上传成功时,页面图片刷新
             window.location.href="AppendShopList.aspx";
            
        }  else if (rs == "2") { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_uplaodshibai")%>', 2000, 5); }
        else {
                 showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SB")%>', 2000, 5);
            }
    },error:function (error) { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_showExcep")%>', 2000, 5); }, } );

    }
    //上传图片
    function AddPhoto(obj) {
     //上传控件的id
     var name=$(obj).attr("name");
     $("#Loadcontrol").val(name);
        var Key = $("#Key").val();
        $("#photo").ajaxSubmit({
            success: function (rs) {
                if (rs != null && rs != "undefined") {
                    if (rs == "1") {
                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_uploadscuss")%>', 1000, 4); //上传成功时,页面图片刷新
                        GetPhoto();
                    }
                    else if (rs == "2") { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_uplaodshibai")%>', 2000, 5); }
                    else if (rs == "3") { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("File_format")%>', 2000, 5); }
                    else if (rs == "4") { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("upload_pictures")%>', 2000, 5); }
                    else {
                        showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("SB")%>', 2000, 5);
                    }
                }
                else showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("CG")%>', 2000, 5);
            },
            error: function (error) { showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_showExcep")%>', 2000, 5); },
            dataType: "text",
            url: "AddAppendPhoto.ashx",
            post: "post",
            
        });
    }
   //图片上传成功以后,异步重新加载图片
    function GetPhoto() {
        getAjax("GetAppendPhoto.ashx", "Key=" + Key, function (rs) {
            if (rs != "1") {
                $("#imgtd").html(rs);
            }
        })
    }
    //删除图片
    function Delete(key) {
        if (IsDelData(key)) {
            getAjax("DeleteAppendPhoto.ashx", "Key=" + key, function (rs) {
                if (rs == "1") {
                    showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Role_List_delr")%>', 1000, 4);
                    GetPhoto();
                } else {
                    showTipsMsg('<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_delfil")%>', 2000, 5);
                }
            });
        }
    }
    //插入自定义属性
    function GetTitleUpdownList(obj) {
        id = selectcount;
        var titlename = "<tr style='text-algin:left;' id=\"hang" + id + "\" valign=\"top\" >";
        titlename += "<td style=\"width:250px;\"> <input id=\",Pfunction" + id + "\" name=\"Pfunction" + id + "\" type=\"text\" value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdysxName")%>\" /></td>"
        titlename += "<td style=\"width:300px;\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdyformat")%>: <select name=\"typeid" + id + "\" onchange=\"AppendStyel('" + id + "')\"  id=\"typeid" + id + "\"><option value='1'><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_wenben")%></option><option value='2'><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_duoxuan")%></option><option value='3'><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_riqi")%></option><option value='5'><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdynr")%></option></select></td>";
        titlename += "<td id=\"ths" + id + "\"   style=\" ;width:500px;\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdynr")%>: <input id=\"value" + id + "\" name=\"value" + id + "\" type=\"text\" value=\"\" /></td>";
        titlename += "<td  style=\" text-align:center;width:150px;\"><a href='#' onclick=\"DelTitle('" + id + "')\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Delete")%></a> <a href='#' style=\"display:none;\" id=\"a" + id + "\" onclick=\"selectdown('" + id + "')\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_additem")%></a></td>";
        titlename += "</tr>";
        $("#trappend").append(titlename);
        selectcount++;
    }
    //删除行
    function DelTitle(id) {
        $("#hang" + id).remove();
    }
    //点击不同的样式
    function AppendStyel(id) {
        var value = $("#typeid" + id).val();
        var str = "";
        //非多选项添加按钮隐藏
        if (value == "1") {
            $("#a" + id).hide();
            str = "<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdynr")%>: <input id=\"value" + id + "\" name=\"value" + id + "\" type=\"text\" value=\"\" /> ";
        } else if (value == "2") {
        //多选项时,添加按钮显示
            $("#a" + id).show();
            //标签p代表多选项的单个文本框行
        str += "<p id=\"p1" + id + "\"  class=\"file-box\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item1")%>: <input id=\"selectvalue1" + id + "\" name=\"selectvalue \" type=\"text\" value=\"\" />  <input class=\"btn\" type=\"button\" value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_uploadImg")%>\">   <input type='text' name='textfield1"+id+"' id='textfield1"+id+"' class='txt' />  <input id=\"ph1\" class=\"file\" type=\"file\" onchange=\"document.getElementById('textfield1"+id+"').value=this.value\" size=\"28\" name=\"selectvalue1"+id+"\">    <a href='#' onclick=\"deleteselectdown('1" + id + "')\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Delete")%></a></p> ";
        str += "<p id=\"p2" + id + "\"  class=\"file-box\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item2")%>: <input id=\"selectvalue2" + id + "\" name=\"selectvalue \" type=\"text\" value=\"\" />  <input class=\"btn\" type=\"button\" value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_uploadImg")%>\">   <input type='text' name='textfield2"+id+"' id='textfield2"+id+"' class='txt' />  <input id=\"ph2\" class=\"file\" type=\"file\" onchange=\"document.getElementById('textfield2"+id+"').value=this.value\" size=\"28\" name=\"selectvalue2"+id+"\">  <a href='#' onclick=\"deleteselectdown('2" + id + "')\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Delete")%></a></p> ";
        str += "<p id=\"p3" + id + "\"  class=\"file-box\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Question_item3")%>: <input id=\"selectvalue3" + id + "\" name=\"selectvalue \" type=\"text\" value=\"\" />  <input class=\"btn\" type=\"button\" value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_uploadImg")%>\">   <input type='text' name='textfield3"+id+"' id='textfield3"+id+"' class='txt' />  <input id=\"ph3\" class=\"file\" type=\"file\" onchange=\"document.getElementById('textfield3"+id+"').value=this.value\" size=\"28\" name=\"selectvalue3"+id+"\">    <a href='#' onclick=\"deleteselectdown('3" + id + "')\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Delete")%></a></p> ";
        } else if (value == "3") {
            $("#a" + id).hide();
            str = "<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdynr")%>: <input id=\"value" + id + "\"  name=\"value" + id + "\"type=\"text\"  onclick=\"WdatePicker()\" />";
        } else if (value == "5") {
            $("#a" + id).hide();
            str = " <textarea id=\"value" + id + "\" name=\"value" + id + "\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_zdynr")%></textarea>";
        }
        $("#ths" + id).html(str);
    }
 
    //多选项添加

    function selectdown(id) {

        str = "<p id=\"p"+count + id + "\" class=\"file-box\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Mall_item")%>"+count+":<input id=\"selectvalue" + count + id + "\" name=\"selectvalue \" type=\"text\" value=\"\" />    <input class=\"btn\" type=\"button\" value=\"<%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Ques_uploadImg")%>\">  <input type='text' name='textfield"+count+""+id+"' id='textfield"+count+""+id+"' class='txt' /><input id=\"ph"+count+"\" class=\"file\" type=\"file\" onchange=\"document.getElementById('textfield"+count+""+id+"').value=this.value\" size=\"28\" name=\"selectvalue"+count+id+"\">     <a href='#' onclick=\"deleteselectdown('"+count+"" + id + "')\"><%=RM.Common.DotNetConfig.LanguageHelper.GetKey("Delete")%></a></p>";
      $("#hang"+id).find("#ths"+id).append(str);
        count++;
    }
    //多选项单行删除
    function deleteselectdown(id) {
        $("#p" + id).remove();
    }
    
</script>
</html>
