var apiDomain = 'https://solutionsupport.21vbluecloud.com/'; var bcResourceUrl = 'https://bcssstorage.blob.core.chinacloudapi.cn/consultation/'; var bcStyleUrl = bcResourceUrl + 'style.css'; var bcJqueryUrl = bcResourceUrl + 'jquery-3.6.0.min.js'; var link = document.createElement("link"); link.rel = "stylesheet"; link.type = "text/css"; link.href = bcStyleUrl; document.getElementsByTagName("head")[0].appendChild(link); //var script = document.createElement("script"); //script.setAttribute('type', 'text/javascript'); //script.setAttribute("src", bcJqueryUrl); //document.getElementsByTagName("head")[0].appendChild(script); //script.onload = function () { // main() //} var bcBtn = document.createElement('button'); bcBtn.id = "bcConsultation"; bcBtn.className = "bc-btn bc-btn-bluecloud"; bcBtn.innerHTML = "联系我们"; document.body.appendChild(bcBtn); var bcBox = document.createElement('div'); bcBox.className = "bc-box bc-hide"; bcBox.innerHTML = `
在线创建工单
*
*
*
*
*
*
*
*
`; document.body.appendChild(bcBox); /*function main() {*/ var fetchTokenPath = apiDomain + 'api/AMPToJarvisAPI/token'; var fetchTokenParams = { username: 'newbizcase', password: '123456', grant_type: 'password' }; var pushInfoPath = apiDomain + 'api/BCSSCECSAggresmartToJarvis/Create'; var uploadFilePath = apiDomain + 'api/BCSSCECSAggresmartToJarvis/UploadFile'; var new_dataresources = { 'BCCS': '100000002', 'CECS': '100000003', 'ISV': '100000004', 'MSP': '100000005', 'SolutionStore': '100000006', 'AggreSmartHomePage': '100000007', } var options1 = ` `; var options2 = ` `; var token = ''; var msgsource = getSource(); var loading = false; var timer = null; var annotationid = ''; $(document).on('click', '#bcConsultation', function () { $('.bc-box').removeClass('bc-hide'); }); $(document).on('click', '.bc-box .bc-btn-close', function () { $('.bc-box').addClass('bc-hide'); }); $(document).on('change', '#new_servicetype', function () { console.log($(this)) var serviceType = $(this).val(); if (serviceType === '100000001') { $('#new_questiontype').html(options1) } else if (serviceType === '100000000') { $('#new_questiontype').html(options2) } }); $(document).on('click', '.bluecloud-consult-btn', function () { $('#bcConsultation').click(); }) $(document).on('change', '#new_description_upload', function () { console.log($(this)) console.log($(this)[0].files[0]); var file = $(this)[0].files[0]; if (!file) return; var formData = new FormData(); formData.append('f', file); fetchTokenFun(function (headertokn) { $.ajax({ headers: { // 'Content-Type': 'application/json', 'Authorization': headertokn, }, url: uploadFilePath, type: 'post', data: formData, processData: false, contentType: false, success: function (res) { if (res && res.status) { annotationid = res.result } else { alert('上传失败!') } }, error: function () { alert('上传失败!') } }) }) }) $(document).on('click', '#consulationCommit', function () { if (loading) return; var servicetype = $("#new_servicetype").val(); var questiontype = $("#new_questiontype").val(); var name = $.trim($('#new_name').val()); var description = $.trim($('#new_description').val()); var firstname = $.trim($('#new_firstname').val()); var phone = $.trim($('#new_phone').val()); var email = $.trim($('#new_email').val()); var company = $.trim($('#new_company').val()); if (!name || !description || !firstname || !email || !company) { alert('请填写必填项'); return; } loading = true; $('.bc-btn-submit').html('提交中...'); fetchTokenFun(function (headertokn) { $.ajax({ type: 'post', headers: { 'Content-Type': 'application/json', 'Authorization': headertokn, }, url: pushInfoPath, data: JSON.stringify({ servicetype: servicetype, questiontype: questiontype, name: name, description: description, firstname: firstname, phone: phone, email: email, company: company, dataresource: msgsource, annotationid: annotationid }), success: function (res) { // console.log(res) if (res && res.status) { // alert('提交成功!') loading = false; resetForm(); $('.bc-btn-submit').html('提交'); $('.bc-alert-info').removeClass('bc-unvisible'); if (timer) clearTimeout(timer) timer = setTimeout(function () { $('.bc-alert-info').addClass('bc-unvisible'); // console.log('tttttt') }, 5000); } else { alert('提交失败!'); loading = false; $('.bc-btn-submit').html('提交'); } }, error: function (res) { // console.log(res) alert('提交失败!') $('.bc-btn-submit').html('提交'); } }) }) }); function fetchTokenFun(callback) { $.ajax({ type: 'post', url: fetchTokenPath, data: fetchTokenParams, success: function (res) { // console.log(res) token = res; headerToken = 'Bearer ' + res.access_token; callback(headerToken); }, error: function (res) { // console.log(res) alert('获取token失败') } }) } function getSource() { var script = document.getElementById('bluecloud-support-script'); var source = script ? script.getAttribute('msg-source') : ''; var s = new_dataresources[source] || new_dataresources.SolutionStore; return s; } function resetForm() { $('#new_name').val(''); $('#new_description').val(''); $('#new_firstname').val(''); $('#new_phone').val(''); $('#new_email').val(''); $('#new_company').val(''); $('#new_description_upload').val(''); } /*}*/