高章伟
2022-03-18 4bfe21c4b5ddc089ae5a95f4b10f6cff148b690d
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
<apex:page showHeader="true" sidebar="true" id="allPage" title="web to app">
<apex:stylesheet value="{!URLFOR($Resource.blockUIcss)}"/>
<apex:includeScript value="{!URLFOR($Resource.jquery183minjs)}"/>
<apex:includeScript value="{!URLFOR($Resource.PleaseWaitDialog)}"/>
<apex:includeScript value="{!URLFOR($Resource.instascan)}"/>
<apex:includeScript value="/soap/ajax/46.0/connection.js"/>
<apex:includeScript value="/soap/ajax/46.0/apex.js"/>
<script>
sforce.connection.sessionId = "{!$Api.Session_ID}";
function go() {
    var id = j$(escapeVfId('id')).value();
    if (id == '') {
        alert('请输入申请单编码/主体条码');
    } else {
        var type = j$("input[name='scanType']:checked").val();
        if (type == 'type1') {
            var raList = sforce.connection.query("select Id, OwnerId, ToAgency__c, Rental_Apply_Equipment_Set_Cnt__c, RecordType.DeveloperName, Shippment_ng_num__c, Wei_Return__c from Rental_Apply__c where Name = '"+id+"'");
            raList = raList.getArray("records");
            if(raList.length == 0) {
                location.href ="/apex/EquipmentSetSRList2?id=" + id;
            }
            else if(raList[0].RecordType.DeveloperName == 'AgencyRequest') {
                // 借出申请里的分配办事处实际存的是管理省
                var workProvince = getUserProvince(raList[0].OwnerId);
                if(workProvince == '' || workProvince == undefined) {
                    alert('找不到用户的OCSM管理省!');
                    return;
                }
                var isSameCity = isMatch(workProvince, raList[0].ToAgency__c);
                // 未发货
                if(raList[0].Shippment_ng_num__c > 0) {
                    location.href ="/apex/RentalFixtureSetAssignAgency?pt_recid=" + raList[0].Id;
                }
                // 已发货同城
                else if(isSameCity) {
                    location.href ="/apex/RentalAgencyReceived?id=" + raList[0].Id;
                }
                // 已发货非同城
                else {
                    // 非同城全未回寄
                    if(raList[0].Rental_Apply_Equipment_Set_Cnt__c == raList[0].Wei_Return__c) {
                        location.href ="/apex/EquipmentSetSRList2?id=" + id;
                    }
                    // 非同城有已回寄
                    else {
                        location.href ="/apex/RentalAgencyReceived?id=" + raList[0].Id;
                    }
                }
            }
            else {
                location.href ="/apex/EquipmentSetSRList2?id=" + id;
            }
        }
        else if(type == 'type2') {
            location.href ="/apex/ConsumApplyEquipmentSetSRList?id=" + id;
        }
        else if(type == 'type3') {
            var taList = sforce.connection.query("select Id, OwnerId, From_Location__c, Destination_location__c, RecordType.DeveloperName from TransferApply__c where Name ='"+id+"'");
            taList = taList.getArray("records");
            var profileId = "{!$User.ProfileId}";
            var isCenterStaff = "{!$Label.ProfileId_EquCenAdmin}".match(profileId)
                    || "{!$Label.ProfileId_EquCenCheckAndDepot}".match(profileId)
                    || "{!$Label.ProfileId_EquipmentCenter}".match(profileId);
 
            if(taList.length == 0 || isCenterStaff) {
                location.href ="/apex/TransferEquipmentSetSRList?id=" + id;
            }
            else {
                // 备品中心到办事处,用户所在管理省=调拨至地区,则打开办事处上架画面
                if(taList[0].RecordType.DeveloperName == 'CenterToAgency'){
                    location.href ="/apex/TransferAgencyReceived?id=" + taList[0].Id;
                }
                // 办事处到备品中心,用户所在管理省=调拨前地区,则打开办事处下架画面
                else if(taList[0].RecordType.DeveloperName == 'AgencyToCenter'){
                    location.href ="/apex/TransferAgencyShipment?id=" + taList[0].Id;
                }
                // 其它则打开备品中心画面
                else {
                    location.href ="/apex/TransferEquipmentSetSRList?id=" + id;
                }
            }
        }
    }
}
// 获取用户的OCSM管理省
function getUserProvince(userId) {
    var userList = sforce.connection.query("select OCM_man_province_Rental__c from User where Id='" + userId + "'");
    userList = userList.getArray("records");
    if(userList.length == 0) {
        return '';
    }
    else {
        return userList[0].OCM_man_province_Rental__c;
    }
}
var provinceMap;
// 省转办事处
function getAgency(workProvince) {
    if(provinceMap == undefined) {
        provinceMap = new Map();
        var strList = "{!($Label.OCM_Management_Province_Mapping)}".split(',');
        for(var i = 0 ; i < strList.length ; i++) {
            //省->办事处
            provinceMap.set(strList[i].split(':')[0].trim(), strList[i].split(':')[1].trim());
        }
    }
    if(provinceMap.has(workProvince)) {
        return provinceMap.get(workProvince);
    }
    return workProvince;
}
function isMatch(workProvince, destination) {
    if(workProvince == null || destination == null) {
        return false;
    }
    var loc = destination.split(' ')[0];
    return workProvince.startsWith(loc) || getAgency(workProvince).startsWith(loc);
}
</script>
<table>
    <!-- <tr>
        <td>出库/入库 : </td>
        <td>
            <select id="type" name="chooseType" size="1">
                <option value="-" selected="selected">无</option>
                <option value="Received" >下架</option>
                <option value="Shippment">出库检测</option>
                <option value="Received" >发货</option>
                <option value="Received" >回寄</option>
                <option value="Received" >回收检测</option>
                <option value="Received" >上架</option>
            </select>
        </td>
    </tr> -->
    <tr>
        <td colspan="2">
            <video playsinline="true" id="preview" style="width: 300px;z-index: 20;transform: scaleX(-1);margin-top: 20px;"></video>
        </td>
    </tr>
    <tr>
        <td>备品借出/耗材借出/调拨: </td>
        <td>
            <input type="radio" id="contactChoice1" name="scanType" value="type1" checked="checked" /><label for="contactChoice1">备品借出</label>
            <input type="radio" id="contactChoice2" name="scanType" value="type2"/><label for="contactChoice2">耗材借出</label>
            <input type="radio" id="contactChoice3" name="scanType" value="type3"/><label for="contactChoice3">调拨</label>
        </td>
    </tr>
    <tr>
        <td>申请单编码/主体条码 : </td>
        <td><input id="id" type="text" name="id" /></td>
    </tr>
    <tr>
        <td><input type="button" value="确定" onclick="go();" /></td>
    </tr>
</table>
<!-- <div>
    <div>
 
        <div>
            code:<input type="text" id="code"/>
            <br/>
            <button>确定</button>
        </div>
 
    </div>
</div> -->
<script type="text/javascript">
    j$(document).ready(function(){
        let scanner = new Instascan.Scanner({ video: document.getElementById('preview'), scanPeriod: 5 ,mirror: false});
        scanner.addListener('scan', function (content) {
          j$("#id").val(content);
          go();
        });
        Instascan.Camera.getCameras().then(function (cameras) {
          if (cameras.length > 0) {
            let ver = '';
 
            try {
                ver = (navigator.userAgent).match(/OS (\d)?\d_\d(_\d)?/i)[0].split('_')[0].replace("OS ","");
            }
            catch{}
            if (ver >= 13) {
                scanner.start(cameras[1]);
            } else {
                scanner.start(cameras[0]);
            }
          } else {
            console.error('No cameras found.');
          }
        }).catch(function (e) {
          console.error(e);
        });
    });
</script>
</apex:page>