index.js 12.4 KB
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 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433
const util = new window.publicMethod() ;

(function($$) {
  "use strict";
  let vm

  const citys = {
    '南京市': ['玄武区', '秦淮区', '建邺区', '鼓楼区', '浦口区', '栖霞区', '雨花台区', '江宁区', '六合区', '溧水区', '高淳区'],
    '苏州市': ['姑苏区', '吴中区', '相城区', '虎丘区', '吴江区', '新区', '经开区', '昆山市', '常熟市', '张家港市', '太仓市', '苏州工业园区'],
    '扬州市': ['广陵区', '邗江区', '江都区', '宝应县', '高邮市', '仪征市'],
    '无锡市': ['梁溪区', '锡山区', '惠山区', '滨湖区', '新吴区', '江阴市', '宜兴市'],
    '徐州市': ['鼓楼区', '云龙区', '贾汪区', '泉山区', '铜山区', '丰县', '沛县', '睢宁县', '邳州市', '新沂市'],
    '常州市': ['天宁区', '钟楼区', '新北区', '武进区', '金坛区', '溧阳市'],
    '连云港市': ['海州区', '连云区', '赣榆区', '东海县', '灌云县', '灌南县'],
    '淮安市': ['清江浦区', '淮阴区', '淮安区', '洪泽区', '涟水县', '盱眙县', '金湖县'],
    '盐城市': ['亭湖区', '盐都区', '盐开区','大丰区', '响水县', '滨海县', '阜宁县', '射阳县', '建湖县','东台市'],
    '南通市': ['崇川区', '通州区', '海门区', '如东县', '启东市', '如皋市', '海安市'],
    '泰州市': ['海陵区', '高港区', '姜堰区', '兴化市', '靖江市', '泰兴市'],
    '宿迁市': ['宿城区', '宿豫区', '沭阳县', '泗阳县', '泗洪县'],
  };

  function init() {
    vm = new Vue({
      el: '#pageDiv',
      data: {
        tarr: ['精准高效','智能检测','实时监控','全程录像'],
        orderFlag: false,
        addressFlag: false,

        appParam: {},
        detail: {},

        addressErrorFlag: false,
        addressRightFlag: false,
        modifyAddressFlag: false,
        pickData: {
          isShow: false,

          title: '地区选择',
          arr:[
            {
              values: Object.keys(citys),
              className: 'column1',
              defaultIndex: 0
            },
            {
              values: citys['南京市'],
              className: 'column2',
              defaultIndex: 0
            }
          ],
          nCity: '',
          nArea: '',
          menpai: ''
        },

        fbData:{
          isShow: false,
          confirmFlag: false,

          explain: '',
        },
        reasonPickData: {
          isShow: false,

          title: '原因选择',
          orArr: [],
          arr:[],
          index: 0,
          reason: '个人原因'
        }, 

        addressButtFlag: false,
        ifFirst: false,
        ifCallback: false,
        noDataFlag: false
      },
      methods: {
        getReason(){
          util.httpRequest({
            url: '/listEnum',
            public: true,
            data: {
              type: 3
            },
          }).then(res=>{
            if(res.code == 200){
              this.reasonPickData.orArr = res.data
              this.reasonPickData.arr = res.data.map(item=>{
                return item.label
              })
            }
          })
        },
        saveFeedback(){
          if(!this.fbData.explain){
            util.toast('请填写具体情况')
            return
          }

          let status = ''
          let p =  this.reasonPickData
          p.orArr.forEach(item=>{
            if(item.label == p.reason){
              status = item.value
            }
          })

          util.httpRequest({
            data: {
              applyId: this.detail.devicessList[0].applyId,
              checkStatus: status,
              failReason: this.fbData.explain
            },
            url: '/unCheck'
          }).then(res=>{
            if(res.code == 200){
              this.getDetail()
              this.fbData.isShow = false
              this.fbData.confirmFlag = false

              util.toast('保存成功')
            }else{
              util.toast(res.msg)
            }
          })
        },
        saveAddress(){
          let p = this.pickData

          if(!p.nCity || !p.nArea){
            util.toast('请选择市区')
            return
          }
          if(!p.menpai){
            util.toast('请输入详细地址')
            return
          }

          util.httpRequest({
            data: {
              applyId: this.detail.devicessList[0].applyId,
              finallyAddress: p.nCity+p.nArea+p.menpai
            },
            url: '/updateApplyAddress'
          }).then(res=>{
            if(res.code == 200){
              this.detail.updateApplyAddress = p.nCity+p.nArea+p.menpai

              let json = JSON.parse(sessionStorage.getItem('huaiAnAppParam'))
              json.address = p.nCity+p.nArea+p.menpai
              sessionStorage.setItem('huaiAnAppParam',JSON.stringify(json))

              this.modifyAddressFlag = false
              this.addressErrorFlag = false
              this.addressRightFlag = false

              util.toast('修改成功')
            }else{
              util.toast(res.msg)
            }
          })
        },
        modiyAddress(){
          let str = this.detail.updateApplyAddress || this.detail.addressName
          let city = ''
          let area = ''
          for (let key in citys) {
            if(str.includes(key)){
              city = key

              citys[city].forEach(item=>{
                if(str.includes(item)){
                  area = item
                }
              })
            }
          }

          this.pickData.nCity = city
          this.pickData.nArea = area
          this.pickData.menpai = ''

          this.modifyAddressFlag = true
        },
        showCity(){
          let __this = this

          let cIndex = __this.pickData.nCity?Object.keys(citys).indexOf(__this.pickData.nCity):0
          let aIndex = __this.pickData.nArea?(citys[__this.pickData.nCity||'南京市'].indexOf(__this.pickData.nArea)):0

          this.pickData.arr = [
            {
              values: Object.keys(citys),
              className: 'column1',
              defaultIndex: cIndex
            },
            {
              values: citys[__this.pickData.nCity||'南京市'],
              className: 'column2',
              defaultIndex: aIndex
            }
          ]

          this.pickData.isShow = true
        },
        onChange(picker, values) {
          picker.setColumnValues(1, citys[values[0]]);
        },
        onConfirm(value, index) {
          this.pickData.nCity = value[0]
          this.pickData.nArea = value[1]

          this.pickData.isShow = false
        },
        onCancel(){
          this.pickData.isShow = false
        },
        showReason(){
          this.reasonPickData.isShow = true
        },
        reasonCancel(){
          this.reasonPickData.isShow = false
        },
        reasonConfirm(value, index){
          this.reasonPickData.reason = value
          this.reasonPickData.index = index

          this.reasonCancel()
        },
        ifFistIn(){
          let s = sessionStorage.getItem('huaiAnAppParam')
          let sid = util.getUrlParam('sysId')
          let acc = util.getUrlParam('accNbr')
          let cid = util.getUrlParam('campaignId')
          let atype = util.getUrlParam('areaType')

          if(!s){
            return true
          }

          s = JSON.parse(s)
          if(sid && sid!=s.sysId){
            return true
          }
          if(acc && acc!=s.accNbr){
            return true
          }
          if(cid && cid!=s.campaignId){
            return true
          }
          if(atype && atype!=s.areaType){
            return true
          }

          return false
        },
        initPage(){
          this.getReason()

          if(!this.ifFistIn()){
            this.ifFirst = false
            this.appParam = JSON.parse(sessionStorage.getItem('huaiAnAppParam'))

            this.getDetail()
          }else{

            if(util.getUrlParam('isTest')){
              this.initParam({
                "realAddress":"北京丰台怡海花园二单元2603",
                "latitude":"39.836578",
                "longitude":"116.298198",
                "memoAddress":"淮安市淮阴区北京北路99号1304室",
                "serialNum": new Date().getTime(),
                "orderId": "3356158"
              })
              return
            }

            try{
              NativeApi.requestHaParamReceive()
            }catch(e){}

            let __this = this
            setTimeout(()=>{
              if(!__this.ifCallback){
                util.toast('获取信息失败,请退出页面重新进入')
              }
            },4000)
          }
        },
        initParam(param){
          this.ifFirst = true
          sessionStorage.removeItem('huaiAnAppParam')

          param = param||{}
          param.sysId = util.getUrlParam('sysId')
          param.accNbr = util.getUrlParam('accNbr')
          param.campaignId = util.getUrlParam('campaignId')
          param.areaType = util.getUrlParam('areaType')
          if(util.getUrlParam('processType')){
            param.processType = util.getUrlParam('processType')
          }
          this.appParam = param
          
          this.getDetail('init')
        },
        release(applyId){
          if(!sessionStorage.getItem('haCallId')){
            return
          }
        
          util.httpRequest({
            url: '/releaseConn',
            data: {
              callId: sessionStorage.getItem('haCallId')||'',
              applyId: applyId
            }
          })
        },
        getDetail(source){
          this.ifCallback = true
          
          let json = this.appParam
          json.cmcc = source=='init'?true:false
          json.phoneModel = navigator.userAgent.toLowerCase()

          util.httpRequest({
            data: json,
            url: '/getOrderInfo'
          }).then(res=>{
            document.getElementById('pageDiv').style.display = 'block'; // 显示内容
            document.getElementById('loading').style.display = 'none'; // 去掉加载框
            
            if(res.code == 200){
              this.detail = res.data

              let json = {...this.appParam,...{
                address: res.data.addressName,
                applyId: res.data.devicessList[0].applyId
              }}
              sessionStorage.setItem('huaiAnAppParam',JSON.stringify(json))

              if(res.data.addressRight){
                this.addressRightFlag = true
              }else{
                this.addressErrorFlag = true
              }

              this.release(json.applyId)
            }else if(res.code == '5002'){
              this.noDataFlag = true
            }else{
              util.toast(res.msg)
            }
          })
        },
        addressError(){
          this.addressFlag = true
        },
        orderError(){
          this.orderFlag = true
        },
        feedback(){
          this.fbData.explain = ''
          this.reasonPickData.reason = '个人原因'
          this.reasonPickData.index = 0

          this.fbData.isShow = true
        },
        closeAlert(){
          this.orderFlag = false
          this.addressFlag = false
        },
        goNext(){
          this.addressErrorFlag = false
          this.addressRightFlag = false
        },
        beginTest(){
          if(this.addressButtFlag){
            return
          }

          if(!this.detail.id){
            util.toast('暂未查询到质检信息,请向技术支持方反馈')
            return
          }

          window.location.href = 'demo.html?time='+ new Date().getTime()
        },
        addOrder(){
          this.orderFlag = false
          window.location.href = 'addOrder.html?time='+ new Date().getTime()
        },
        quit(){
          this.addressButtFlag = true
          this.addressRightFlag = false
          this.addressErrorFlag = false
        },
        delOrder(index){
          util.httpRequest({
            data: {
              devicesId: this.detail.devicessList[index].id
            },
            url: '/delDevices'
          }).then(res=>{
            if(res.code == 200){
              util.toast('删除成功')
              this.getDetail()
            }else{
              util.toast(res.msg)
            }
          })
        }
      }
    })
  }

  init()
  window.vm = vm
})(window.jQuery)

document.addEventListener('visibilitychange', function() {
  if (document.visibilityState === 'visible') {
    vm.initPage()
  }
});

window.haParamReceive = function (param){
  vm.initParam(param)
}

vm.initPage()