<apex:page controller="ReceivingNoteDetailSelectController" showHeader="false" sidebar="false" id="allPage" action="{!init}" lightningStylesheets="true">
<head>
<apex:outputPanel rendered="{!isAcceptance}">
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
</apex:outputPanel>
<title>收货清单配套明细选择</title>
<apex:stylesheet value="{!URLFOR($Resource.sldsMy)}"/><!-- 20230925 ljh lightning -->
<apex:stylesheet value="{!URLFOR($Resource.StyleUtilColorCss)}"/><!-- 20230619 ljh lightning  -->
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:stylesheet value="{!URLFOR($Resource.RentalFixtureSetDetilSelectCss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.RelationListPagingCmpJS)}"/>
<apex:stylesheet value="{!URLFOR($Resource.jquery_confirm, 'jquery-confirm.min.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery_confirm, 'jquery-confirm.min.js')}"/>
<apex:stylesheet value="{!URLFOR($Resource.StyleUtilCss)}"/>

<!-- lightning改造   zyh   start -->
<style type="text/css">
    table.list td  input[type="text"]{width:55%;}
</style>
<!-- lightning改造   zyh   end -->
<script type="text/javascript">
var heightAjustment = 120;
var widthAjustment = 30;
    function setEmailBody() {
        j$.confirm({
            title: '无配套明细提醒邮件',
            boxWidth: '50%',
            useBootstrap: false,
            content: '' +
              '<form action="" class="formName">' +
              '<div style="overflow: hidden;">' +
              '<label>请输入邮件内容<br/>' +
              '<textarea placeholder="邮件内容" style="width:95%" class="name form-control" rows="3" required />' +
              '</div>' +
              '</form>',
            buttons: {
                formSubmit: {
                    text: '发送',
                    btnClass: 'btn-blue',
                    action: function () {
                        var body = this.$content.find('.name').val();
                        if(!body){
                            j$.alert({
                                // 刘川 2023年10月11日 title横展 start
                                // title: '',
                                // 刘川 2023年10月11日 title横展 end
                                content: '未输入邮件内容！',
                                boxWidth: '50%',
                                useBootstrap: false,
                            });
                            return false;
                        }
                        j$.confirm({
                            // 刘川 2023年10月11日 title横展 start
                            // title: '确认',
                            // 刘川 2023年10月11日 title横展 end
                            content: '输入的邮件内容为[' + body + ']' + '是否发送?',
                            boxWidth: '50%',
                            useBootstrap: false,
                            buttons: {
                                OK: function () {
                                    blockme();
                                    sendEmail(body);
                                },
                                cancel: {
                                    text: '取消' // With spaces and symbols
                                }
                            }
                        });
                    }
                },
                cancel: {
                    text: '取消'
                }
            }
        });
        // var body = prompt('请输入无配套提醒邮件');
        // if (body != null) {
        //     if (confirm('输入的邮件内容为[' + body + ']' + '是否发送?')) {
        //         blockme();
        //         sendEmail(body);
        //     }
        // }
        return false;
    }
</script>
</head>
    <apex:form id="allForm">

        <apex:outputPanel id="message">
            <apex:pageMessages />
        </apex:outputPanel>
        <apex:actionFunction name="saveAndSort" action="{!save}" rerender="allForm, checEventFrame" oncomplete="unblockUI();">
            <apex:param name="firstParam" assignTo="{!saveType}" value="" />
            <apex:param name="secondParam" assignTo="{!sortKey}" value="" />
        </apex:actionFunction>
        <apex:actionFunction name="sendEmail" action="{!sendEmail}"  rerender="allForm, checEventFrame" oncomplete="unblockUI();">
            <apex:param name="emailBody" value="" />
        </apex:actionFunction>
        <apex:outputPanel id="pageallPanel">
            <apex:pageBlock id="searchBlock" tabStyle="Report">
                <apex:pageBlockButtons location="bottom">
                        <!-- lightning改造   zyh   start -->
                        <!-- <apex:commandButton style="float:left;" action="{!save}" value="确定" onclick="blockme();" rerender="allForm, checEventFrame" oncomplete="unblockUI();" /> -->
                        <!-- <apex:commandButton style="float:left; margin-left:12px;" action="{!save}" value="确定" onclick="blockme();" rerender="allForm, checEventFrame" oncomplete="unblockUI();" /> -->
                        <!-- lightning改造   zyh   end -->
                        <!-- <apex:commandButton style="float:left;" value="无配套明细提醒邮件" onclick="setEmailBody();" rerender="allForm, checEventFrame"/> -->
                        <!-- lightning改造   zyh   start -->
                        <!-- <apex:commandButton style="float:right;" value="{!IF(isAcceptance, '返回', '返回上一级')}" action="{!goBack}"/> -->
                        <!-- <apex:commandButton style="float:right; margin-right:12px;" value="{!IF(isAcceptance, '返回', '返回上一级')}" action="{!goBack}"/> -->
                        <!-- lightning改造   zyh   end -->
                        <!-- <apex:commandButton rendered="{!isAcceptance == false}" style="float:right;" value="返回数据确认画面" action="{!cancel}"/> -->
                </apex:pageBlockButtons>
                <div style="clear:both;"></div>

                    <table border="1" cellspacing="0" cellpadding="0" >
                        <tr>
                            <td colspan="2" width="200px">{!$ObjectType.Rental_Apply_Equipment_Set__c.fields.Name.label}</td>
                            <td colspan="3" width="200px"><apex:outputText value="{!parentObj.Name}" style="width:100px"/></td>
                        </tr>
                        <!-- <tr>
                            <td colspan="2">{!$ObjectType.Rental_Apply_Equipment_Set__c.fields.Fixture_Set_Idx__c.label}</td>
                            <td colspan="3"><apex:outputText value="{!parentObj.Fixture_Set_Idx__c}" style="width:100px"/></td>
                        </tr> -->
                        <tr>
                            <td colspan="2" width="200px">{!$ObjectType.Fixture_Set__c.fields.Loaner_name__c.label}</td>
                            <td colspan="3" width="200px"><apex:outputText value="{!parentObj.Fixture_Set__r.Loaner_name__c}" style="width:100px"/></td>
                        </tr>
 <!--                        <tr>
                            <td colspan="2">{!$ObjectType.Rental_Apply_Equipment_Set__c.fields.Loaner_code__c.label}</td>
                            <td colspan="3"><apex:outputText value="{!parentObj.Loaner_code__c}" style="width:100px"/></td>
                        </tr> -->
                        <!-- <tr>
                            <td colspan="2">{!$ObjectType.Rental_Apply_Equipment_Set__c.fields.Rental_Num__c.label}</td>
                            <td colspan="3"><apex:outputText value="{!parentObj.Rental_Num__c}" style="width:100px"/></td>
                        </tr> -->
 <!--TODO  同一附属品：レ -->

                    </table>
                    <!-- lightning改造   zyh   start -->
                    <div style="margin-top: 15px;">
                        <apex:commandButton style="float:left; margin-left:12px;" action="{!save}" value="确定" onclick="blockme();" rerender="allForm, checEventFrame" oncomplete="unblockUI();" />
                        <apex:commandButton style="float:left;" value="无配套明细提醒邮件" onclick="setEmailBody();" rerender="allForm, checEventFrame"/>
                        <apex:commandButton style="float:right; margin-right:12px;" value="{!IF(isAcceptance, '返回', '返回上一级')}" action="{!goBack}"/>
                        <apex:commandButton rendered="{!isAcceptance == false}" style="float:right;" value="返回数据确认画面" action="{!cancel}"/>
                    </div>
                    <!-- lightning改造   zyh   end -->
            </apex:pageBlock>
            <c:RelationListPagingCmp id="cmpid" pgController="{!this}" hasCheckbox="false" noSort="true"/>
            <!-- <apex:pageBlock>
                <div class="pbBody">
                    <div id="out_Div_L">
                        <table border="" class="list" style="border-bottom-width: 0px; font-size:11px; border-spacing:0;">
                            <tr class="headerRow" id="tableHeader_L">
                                <th class="col_SortInt_F__c" style="width:50px;">明细顺序</th>
                                <th class="col_Fixture_Set_Detail__r_Fixture_Model_No_F__c">备品配套明细型号</th>
                                <th class="col_Fixture_Set_Detail__r_Name_CHN__c">中文名称</th>
                                <th class="col_Rental_Num__c" style="width:50px;">数量</th>
                                <th class="col_Is_Optional_F__c" style="width:50px;">选配</th>
                                <th class="col_OneToOne_Flag__c">一对一附属品对象</th>
                                <th class="col_Fixture_Set_Detail__r_Fixture_Set_New__c" style="width:50px;">新品配套</th>
                                <th class="col_Fixture_Set_New_Quantity__c">新品配套数</th>
                            </tr>
                            <apex:repeat value="{!initList}" var="info">
                                <tr>
                                    <td>{!info.num}</td>
                                    <td>{!info.FixtureModelNoF}</td>
                                    <td>{!info.Name_CHN}</td>
                                    <td>{!info.Rental_Num}</td>
                                    <td><apex:inputCheckbox disabled = "true" value="{!info.IsOptionalF}"   /></td>
                                    <td><apex:inputCheckbox disabled = "true" value="{!info.OneToOneFlag}"  /></td>
                                    <td><apex:inputCheckbox disabled = "true" value="{!info.FixtureSetNew}" /></td>
                                    <td class="dataCellBorder1 col_Fixture_Set_New_Quantity__c">
                                        <input type="text" onchange="setChangeFlg('0');if(typeof onFieldChanged == 'function') {onFieldChanged(this, 0);}" value="{!info.FixtureSetNewQuantity}"/>
                                    </td>
                                </tr>
                            </apex:repeat>
                        </table>
                    </div>
                </div>
            </apex:pageBlock> -->
        </apex:outputPanel>
    </apex:form>
    <!-- add by rentx 20210729 start 新品收货_集中备品_建立新品入库标准配套 -->
    <style>
      table.list .col_Fixture_Set_New_Quantity__c input {width:55%;}
      /*没找着这个输入框在哪设置的 就直接设置隐藏了 */
      table.list .col_Rental_Num__c input { display: none;}
      table.list .col_SortInt_F__c{height: 20px;}
      /* <!-- lightning改造   zyh   start --> */
      table.list .col_Fixture_Set_New_Quantity__c {width: 200px;}
      table.list .col_Fixture_Set_Detail__r_Fixture_Model_No_F__c {width: 150px;}
      table.list .col_Fixture_Set_Detail__r_Name_CHN__c {width: 100px;}
      table.list .col_Is_Optional_F__c {width: 100px;}
      table.list .col_OneToOne_Flag__c {width: 150px;}
      table.list .col_Fixture_Set_Detail__r_Fixture_Set_New__c {width: 100px;}
      /* table.list .col_Fixture_Set_New_Quantity__c {width: 100px;} */
      /* <!-- lightning改造   zyh   end --> */
    </style>
    <!-- add by rentx 20210729 end 新品收货_集中备品_建立新品入库标准配套 -->
    <apex:outputPanel id="checEventFrame">
      <script type="text/javascript">
        //update by rentx 20210729 start 新品收货_集中备品_建立新品入库标准配套
            var i = 0;
            // 数量添加加减符号 
            /*j$(".dataCellBorder1.col_Rental_Num__c").each(function () {
                // if (i > 0) {
                    j$(this).append('<input type="button" style="width: auto;" class="inc btn" value="+" /><input type="button" style="width: auto;" class="dec btn" value="-" />');
                // }
                i ++;
            });
            j$(".dataCellBorder1.col_Rental_Num__c input[type=button]").on("click", function() {
                var $button = j$(this);
                var oldValue = $button.parent().find("input[type=text]").val();
                if ($button.val() == "+") {
                    var newVal = parseFloat(oldValue) + 1;
                } else {
                    // Don't allow decrementing below zero
                    if (oldValue > 0) {
                        var newVal = parseFloat(oldValue) - 1;
                        } else {
                        newVal = 0;
                    }
                }
                $button.parent().find("input[type=text]").val(newVal);
            });

          // 
            j$(document).ready(function(){
                var count = j$(":text").length;
                var inputbox = j$(":text")[count/2];
                j$(inputbox).prop('disabled', true);
                var a = j$("input.inc.btn")[0]
                var b = j$("input.dec.btn")[0]
                j$(a).prop('disabled', true);
                j$(b).prop('disabled', true);
            });*/
            //设置数量只读
            j$(".dataCellBorder1.col_Rental_Num__c input").each(function () {
                var $button = j$(this);
                var oldValue = $button.parent().find("input[type=text]").val();
                $button.parent().append('<span>'+oldValue+'</span>');
            });
            //设置加减符号并设置一个隐藏的初始值 
            j$(".dataCellBorder1.col_Fixture_Set_New_Quantity__c").each(function () {
                //oldValue 是初始值 设置他到一个hidden里 方便后面加减的时候做判断
                    var oldValue = j$(this).find("input[type=text]").val();
                    // var aaaa = j$(this).find("input[type=text]");
                    //  var bbbb = j$(this).find("input[type=text]")[0];
                    // // var ccc = j$(this).find("input[type=text]").0;
                    // // bbbb.readonly='true';
                    // debugger;
                    //新品配套=false 时新品配套数量不可修改 直接隐藏就可以了 因为新品配套为false是 新品配套数是空
                    if (oldValue == 'NaN' || oldValue == '') {
                        j$(this).find("input[type=text]")[0].style.display = "None";
                    }else{
                        j$(this).find("input[type=text]")[0].readonly = true;
                        // lightning改造   zyh   start
                        // j$(this).append('<input type="button" style="width: auto;" class="inc btn" value="+" /><input type="button" style="width: auto;" class="dec btn" value="-" /> <input type="hidden" style="width: auto;" class="dec btn" value="'+oldValue+'" />');
                        // j$(this).append('<input type="button" style="width: 1.5rem; height: 22px; font-size: 18px; line-height: 20px; margin-top: 5px;" class="inc btn" value="+" /><input type="button" style="width: 22px; height: 22px; font-size: 18px; line-height: 20px; margin-top: 5px;" class="dec btn" value="-" /> <input type="hidden" style="width: auto;" class="dec btn" value="'+oldValue+'" />');
                        j$(this).append('<input type="button" style="padding: 0px;width: 22px; height: 22px; font-size: 18px; line-height: 20px; margin-top: 5px;" class="inc btn" value="+" /><input type="button" style="padding: 0px; width: 22px; height: 22px; font-size: 18px; line-height: 20px; margin-top: 5px;" class="dec btn" value="-" /> <input type="hidden" style="width: auto;" class="dec btn" value="'+oldValue+'" />');
                        // lightning改造   zyh   end
                    }   
                i ++;
            });
            //点击加减符号时执行
            j$(".dataCellBorder1.col_Fixture_Set_New_Quantity__c input[type=button]").on("click", function() {
                var $button = j$(this);
                //获取旧值 和 初始值
                var oldValue = $button.parent().find("input[type=text]").val();
                var firValue = $button.parent().find("input[type=hidden]").val();
                // 初始值有值 并且不是nan的时候 新品配套有值
                if (firValue != 'NaN' && firValue != '') {
                    //判断 如果用户点击的加号 判断 旧值是否大于初始值 若大于初始值 设置值为初始值
                    if ($button.val() == "+") {
                        var newVal = parseFloat(oldValue) + 1;
                        if (newVal > parseFloat(firValue)) {
                            var newVal = parseFloat(firValue);
                        }

                    } else {
                        // Don't allow decrementing below zero
                        if (oldValue > 0) {
                          var newVal = parseFloat(oldValue) - 1;
                        } else {
                          newVal = 0;
                        }
                    }
                    $button.parent().find("input[type=text]").val(newVal);
                }else{
                    var a = j$("input.inc.btn")[0]
                    var b = j$("input.dec.btn")[0]
                    j$(a).prop('disabled', true);
                    j$(b).prop('disabled', true);
                }
                
            });
            //输入框设置上线为初始值
            j$(".dataCellBorder1.col_Fixture_Set_New_Quantity__c input[type=text]").on("change", function() {
                console.log('12121');
                var $text = j$(this);
                //获取旧值 和 初始值
                // var oldValue = $button.parent().find("input[type=text]").val();
                var firValue = $text.parent().find("input[type=hidden]").val();

                //取得当前值
                var nowValue = $text.parent().find("input[type=text]").val();

                //判断如果输入的值大于初始值 则设置当前值为初始值
                if (parseFloat(nowValue) > parseFloat(firValue)) {

                    $text.parent().find("input[type=text]").val(firValue);
                }
                
            });
        //update by rentx 20210729 end 新品收货_集中备品_建立新品入库标准配套


      </script>
    </apex:outputPanel>
</apex:page>