张宇恒
2022-03-30 1609e34521a3c16f2873d0c651a925afed4d91bc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
<apex:page Controller="ConsumEquipmentSetReceivedController" showHeader="false" sidebar="false" id="allPage" action="{!init}">
<head>
    <meta name="format-detection" content="telephone=no"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/>
</head>
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.RelationListPagingCmpJS)}"/>
<apex:includeScript value="/soap/ajax/46.0/connection.js"/>
<apex:includeScript value="/soap/ajax/46.0/apex.js"/>
<apex:stylesheet value="{!URLFOR($Resource.jquery_confirm, 'jquery-confirm.min.css')}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery_confirm, 'jquery-confirm.min.js')}"/>
<style>
.col_Barcode_F__c
{
    display: none;
}
.col_Hui_Ji_Jia__c
{
    width: 55px !important;
}
.apexp .bPageBlock .pbHeader .btn
{
    padding: 6px;
    font-size: 110%;
    margin-right: 20px;
}
table.list td input {width: 85%;}
div#out_Div_L {
  position:relative;
  overflow: hidden;
  float:left;
  width: 30px;
}
div#in_Div_L {
  position:relative;
  overflow: hidden;
  float:left;
  height: 100px;
  width: 30px;
}
</style>
<script type="text/javascript">
    sforce.connection.sessionId = "{!$Api.Session_ID}";
    var JANCODEMap = {};
</script>
<apex:form id="allForm">
    <apex:inputHidden value="{!done_flg}" id="done_flg"/>
    <apex:outputPanel id="pageallPanel">
        <apex:pageBlock id="searchBlock" tabStyle="Report">
            <apex:pageBlockButtons location="top">
                <apex:commandButton style="float:left;" action="{!save}" onclick="blockme();" value="保存" rerender="allForm" oncomplete="unblockUI();checkMessage();" />
                <apex:commandButton action="{!cancel}" value="取消" rerender="allForm"/>
                <apex:commandButton onclick="qrsacn(0);return false;" value="扫一扫耗材" rerender="allForm"/>
            </apex:pageBlockButtons>
 
             <table>
                <tr>
                <!-- 20210331 you WLIG-BV8CHF start-->
                    <td width="20px"/>
                    <td width="35%">
                      <apex:outputLabel for="applyNo" value="申请单号:" />
                      <apex:outputText id="applyNo" value="{!c_apply_no}"/>
                    </td>
                    <td width="10px"></td>
                    <td width="28%">
                      <apex:outputLabel for="keyword" value="型号:" />
                      <apex:inputText id="keyword" value="{!keyword}"/>
                    </td>
                    <td width="10px"></td>
                    <td width="28%">
                      <apex:outputLabel for="keywordDate" value="有效期至:" />
                      <apex:inputText id="keywordDate" value="{!keywordDate}" size="12" onfocus="DatePicker.pickDate(true, '{!$Component.keywordDate}', false)" />
                      <div style="display:none;">
                        <apex:inputField value="{!slip.Shippment_loaner_time__c}" />
                      </div>
                    </td>
                    <td width="10px"></td>
                    <td >
                      <apex:commandButton value="检索" style="padding: 6px;font-size: 110%;" action="{!searchOpp}" onclick="blockme();" rerender="allForm" oncomplete="unblockUI();"/>
                    </td>
                    <!-- 20210331 you WLIG-BV8CHF end-->
                </tr>
            </table>
 
            <div style="clear:both;"></div>
 
            <apex:outputPanel id="message">
                <apex:pageMessages />
            </apex:outputPanel>
        </apex:pageBlock>
        <c:RelationListPagingCmp id="cmpid" pgController="{!this}" hasCheckbox="true" />
        <apex:outputPanel id="checEventFrame">
            <script>
                var tbwidth = j$('#tableHeader').css('width');
                tbwidth = parseInt(tbwidth.slice(0, -2)) - 76;
                j$('#tableHeader').css('width', tbwidth+'px');
                j$('#tableData').css('width', tbwidth+'px');
 
                if (j$('.messageText').text().indexOf('取得了') != -1) {
                    if ('{!changeMessage}' == '取消') {
                        j$('.messageText').text('取消成功')
                    } else {
                        j$('.messageText').text('取得了 {!changeMessage} 条数据')
                    }
                }
 
                j$("#tableData input[type=text]").on('change', function() {
                    let rownum = j$(this)[0].id.match(/oppTable\:(\d*)/)[1];
                    j$('input[name$="oppTable_L:'+rownum+':rowCheck"]').prop('checked', true).trigger("change");
                })
            </script>
        </apex:outputPanel>
    </apex:outputPanel>
</apex:form>
<script type="text/javascript">
    j$(document).ready(function(){
        // j$( '#qrcode' ).unbind();
        // j$( '#qrcode' ).keypress( function ( e ) {
        //     if ( e.which == 13 ) {
        //         filljsQR(j$( '#qrcode' ).val());
        //         return false;
        //     }
        // });
        var tbwidth = j$('#tableHeader').css('width');
        tbwidth = parseInt(tbwidth.slice(0, -2)) - 76;
        j$('#tableHeader').css('width', tbwidth+'px');
        j$('#tableData').css('width', tbwidth+'px');
    });
    function checkMessage() {
        if (j$(escapeVfId('allPage:allForm:done_flg')).val() == 'true') {
            alert("保存成功");
        }
    }
 
    var standalone = window.navigator.standalone,
            userAgent = window.navigator.userAgent.toLowerCase(),
            safari = /safari/.test( userAgent ),
            ios = /iphone|ipod|ipad/.test( userAgent );
    var scanType;
    function filljsQR(content) {
        if (scanType == 1) {
            j$("input[name$='slipNo']").val(content);
        } else {
            var tracingCode = content.substr(-8);
            if (tracingCode.indexOf('250') == 0) {
                content = content.slice(0, -8);
            }
            let rownum = [];
            var $Col_Scroll = j$(".dataRow.col_Scroll");
            j$(".col_Barcode_F__c span").each(function(index) {
                if (j$(this).text() && (content.indexOf(j$(this).text())) == 0) {
                    rownum.push(this.id.match(/oppTable\:(\d*)/)[1]);
                    return;
                }
                var JANCODE = content.substr(3, 12);
                var GTINCODE = content.substr(3, 12);
                // var yyyyMMdd = "20" + content.substr(18, 6);
                // 到2100年 就需要下面的logic了
                // var now = new Date();
                // var current_yyyyMMdd = now.getFullYear()
                //         + ("0" + (now.getMonth() + 1)).slice(-2)
                //         + ("0" + now.getDate()).slice(-2);
                // var currentYear = new Date().getFullYear();
                // var yyyyMMdd = Math.floor(currentYear / 100) + content.substr(18, 6);
                // if (yyyyMMdd < currentYear) yyyyMMdd = yyyyMMdd + 1000000;   // 使用期限 应该是未来的日期
                var result = extractDateSerial(content);
                var yyyyMMdd = result['yyyyMMdd'];
                var serial = result['serial'];
                if (JANCODEMap[JANCODE]) {
                } else {
                    var query = "Select ProductCode From Product2 WHERE JANCODE__c LIKE '" + JANCODE + "%' OR Device_GTIN_2_13_F__c = '" + GTINCODE + "' LIMIT 1";
                    var records = sforce.connection.query(query).getArray('records');
                    if (records.length > 0) {
                        JANCODEMap[JANCODE] = records[0].ProductCode;
                    }
                }
                if (JANCODEMap[JANCODE]) {
                    var content2 = JANCODEMap[JANCODE] + ":" + serial + "(" + yyyyMMdd + ")";
                    var $prdSerialNo = $Col_Scroll.find("input[name=Product_Serial_No_F__c]");
                    if ($prdSerialNo[index].value.startsWith(content2)) {
                        if(this.id != undefined){
                            rownum.push(this.id.match(/oppTable\:(\d*)/)[1]);
                            return;
                        }
                    }
                }
            })
            if (rownum.length == 0) {
                alert('扫描的耗材不存在!')
            } else if (rownum.length > 1) {
                let optStr = "";
                rownum.forEach(function (rn) {
                    j$(".col_Salesdepartment__c").each(function () {
                        if (j$(this).children()[0] && j$(this).children()[0].id.indexOf('oppTable:'+rn+':') !== -1) {
                            optStr += '<option value="'+rn+'">'+j$(this).text()+'</option>';
                            return;
                        }
                    })
                })
                j$.confirm({
                    title: '扫描的耗材有复数存在',
                    boxWidth: '50%',
                    useBootstrap: false,
                    content: '' +
                      '<form action="" class="formName">' +
                      '<div style="overflow: hidden;">' +
                      '<label for="salesDept">请选择所在地区(本部):</label>' +
                      '<select id="salesDept" name="salesDept">'+optStr+'</select>' +
                      '</div>' +
                      '</form>',
                    buttons: {
                        formSubmit: {
                            text: '确认',
                            btnClass: 'btn-blue',
                            action: function () {
                                var rn = this.$content.find('#salesDept').val();
                                var leftobj = j$("input[name$='oppTable_L:"+rn+":rowCheck']:not(:disabled)");
                                moveToTop(leftobj);
                                leftobj.prop('checked', true).trigger("change");
                                j$(".col_Yi_Zhi_Bao_Fei_Jia__c").each(function () {
                                    if (j$(this).children()[0] && j$(this).children()[0].id.indexOf('oppTable:'+rn+':') !== -1) {
                                        // j$(this).find("input").attr('autofocus', 'autofocus');
                                        var rightobj = j$(this).find("input:not(:disabled)");
                                        moveToTop(rightobj);
                                        rightobj.focus();
                                        return;
                                    }
                                })
                            }
                        },
                        cancel: {
                            text: '取消'
                        }
                    }
                });
            } else {
                var leftobj = j$("input[name$='oppTable_L:"+rownum[0]+":rowCheck']:not(:disabled)");
                moveToTop(leftobj);
                leftobj.prop('checked', true).trigger("change");
                j$(".col_Yi_Zhi_Bao_Fei_Jia__c").each(function () {
                    if (j$(this).children()[0] && j$(this).children()[0].id.indexOf('oppTable:'+rownum[0]+':') !== -1) {
                        // j$(this).find("input").attr('autofocus', 'autofocus');
                        var rightobj = j$(this).find("input:not(:disabled)");
                        moveToTop(rightobj);
                        rightobj.focus();
                        return;
                    }
                })
            }
        }
    }
    function extractDateSerial(content){
        var yyyyMMdd = '';
        var noJancodeContent = content.slice(16);
        var n1 = noJancodeContent.search(/17\d{6}/);
        var n2 = noJancodeContent.slice(8).search(/17\d{6}/);
        var m1 = noJancodeContent.search(/11\d{6}/);
        var m2 = noJancodeContent.slice(8).search(/11\d{6}/);
 
        var k = 0;
        if(n1 % 8 == 0){
            yyyyMMdd = '20'+noJancodeContent.substr(n1+2,6);
            k += 1;
        }
        else if(n2 == 0) {
            yyyyMMdd = '20'+noJancodeContent.substr(8+2,6);
            k += 1;
        }
        if(m1 % 8 == 0 || m2 == 0){
            k += 1;
        }
        var serial = noJancodeContent.slice(k*8+2);
        var y = yyyyMMdd.substring(0, 4);
        var m = yyyyMMdd.substring(4, 6);
        var d = yyyyMMdd.substring(6);
        // 00表示月末
        if(d == '00'){
            d = '' + (new Date(y, m, d)).getDate();
        }
        yyyyMMdd = y + m + d;
        return {'yyyyMMdd':yyyyMMdd, 'serial':serial};
    }
    function moveToTop(obj) {
        let row = obj.parents("tr:first");
        let toprow = row.parent().children('tr:first');
        if (!row.is(toprow))
            row.insertBefore(toprow);
    }
 
    function qrsacn(stype) {
        scanType = stype;
        if (!standalone && !safari && ios) {
            window.location.href="sfqr://scan";
        } else {
            alert('扫描条形码请使用App');
        }
    }
</script>
</apex:page>