summaryList.js 15.7 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 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661
// pages/summaryList/summaryList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tab_state: 0,
    popup_state: false,
    choose_state: false,
    familymember: [],
    userinfo: [],
    information: [],
    advise: '',
    report: '',
    guarantee: [],
    list_num: 0,
    collect: [],
    caselist: [],
    tempcaselist: [],
    PublishId: 0,
    recommend: [],
    tempcollects: [],
    edit_state: false,
    edit_state2: false,
    information_user: [],
    save_state: true,
    total_num: 0,
    plan_id: '', 
    savedis:false,
    show:true
    
  },

  //保单详情
  summaryDetail(e) {
    var InId = e.currentTarget.dataset.inid
    wx.navigateTo({
      url: '/pages/index/policyListDetail/policyListDetail?InId=' + InId,
    })
  },

  // 打电话
  makePhoneCall() {
    let that = this;
    var userinfo = that.data.userinfo
    var phoneNumber = userinfo.mobile
    wx.makePhoneCall({
      phoneNumber: phoneNumber
    })
  },

  //成员选择
  memberCharge(e) {
    var familymember = this.data.familymember
    var collect = this.data.collect
    var information = this.data.information
    console.log('information', information)
    var information_user = this.data.information_user
    var index = e.currentTarget.dataset.index

    familymember[index].member_state = !(familymember[index].member_state)

    for (var j = 0; j < collect.length; j++) {
      if (familymember[index].id == parseInt(collect[j].def_id)) {
        if (familymember[index].member_state) {
          collect[j].collect_state = true
        } else {
          collect[j].collect_state = false
        }
      }
    }

    for (var j = 0; j < information.length; j++) {
      if (familymember[index].id == parseInt(information[j].def_id)) {
        if (familymember[index].member_state) {
          information[j].information_state = true;
        } else {
          information[j].information_state = false
        }
      }
    }


    for (var j = 0; j < information_user.length; j++) {
      if (familymember[index].id == parseInt(information_user[j].def_id)) {
        if (familymember[index].member_state) {
          var list_num = information_user[j].num
          var total_num = this.data.total_num
          total_num += list_num
        }
      }
    }

    this.setData({
      familymember: familymember,
      collect: collect,
      information: information,
      list_num: total_num
    })
  },

  // tabCharge
  tabCharge(e) {
    var index = e.currentTarget.dataset.index
    var tab_state = this.data.tab_state
    if (index == tab_state) {
      return false
    } else {
      this.setData({
        tab_state: index
      })
    }
  },

  //选择推荐方案
  popupState(e) {
    let dindex = wx.getStorageSync('dindex');
    let caselist = this.data.caselist1;
    var index = e.currentTarget.dataset.index;
    caselist[index].choose_state = !(caselist[index].choose_state)
    this.setData({
      caselist: caselist,
      caselist1: caselist,
    })
  },

  //推荐方案:名称
  planName(e) {
    var index = e.currentTarget.dataset.index;
    let id = e.currentTarget.dataset.id;
    wx.setStorageSync('plan_index', index)
    wx.setStorageSync('plan_id', id)
    var caselist = this.data.caselist
    caselist[index].name = e.detail.value
    this.setData({
      caselist: caselist,
    })
  },

  //推荐方案:公司
  planFirm(e) {
    var index = e.currentTarget.dataset.index;
    let id = e.currentTarget.dataset.id;
    wx.setStorageSync('plan_index', index)
    wx.setStorageSync('plan_id', id)
    var caselist = this.data.caselist
    caselist[index].firm = e.detail.value
    this.setData({
      caselist: caselist,
    })

  },

  //推荐方案:内容
  planText(e) {
    var index = e.currentTarget.dataset.index;
    let id = e.currentTarget.dataset.id;
    console.log(id)
    wx.setStorageSync('plan_index', index)
    wx.setStorageSync('plan_id', id)
    var caselist = this.data.caselist
    caselist[index].text = e.detail.value
    this.setData({
      caselist: caselist,
    })
  },

  //编辑推荐方案
  editPlan(e) {
    this.setData({
      edit_state2: true
    })
    let that = this;
    let caselist = that.data.caselist;
    let index = wx.getStorageSync('plan_index')
    let id = wx.getStorageSync('plan_id')
    let url = 'counselor/SchemeSave';
    let params = {
      userId: app.globalData.UserId,
      schemeId: id,
      name: caselist[index].name,
      firm: caselist[index].firm,
      text: caselist[index].text
    }
    app.post(url, params).then((res) => {
      if (res.data.code == 200) {
        that.setData({
          caselist: caselist
        })
      }

    })
  },

  //关闭弹窗
  cancelCase() {
    this.setData({
      popup_state: false
    })
  },

  //确认选择的推荐方案
  confirmCase() {
    this.setData({
      popup_state: false
    })
  },


  //建议保额
  suggestForehead(e) {
    let that = this;
    var mindex = e.currentTarget.dataset.mindex;
    var sindex = e.currentTarget.dataset.sindex;
    var num = parseInt(e.currentTarget.dataset.num);
    var collect = this.data.collect;
    var money = parseInt((e.detail.value) - num);

    if (money > 0) {
      collect[mindex].list[sindex].plan = parseInt(e.detail.value);
      collect[mindex].list[sindex].gap = money;
      console.log(collect[mindex].list[sindex].plan)
      that.setData({
        collect: collect
      })
    } else {
      collect[mindex].list[sindex].plan = parseInt(e.detail.value);
      that.setData({
        collect: collect
      })
    }
  },


  tempCollects() {
    var collects = this.data.collect;
    var endcollects = [];
    for (let i in collects) {
      let tem = {}
      tem.def_id = collects[i].def_id;
      let temcollect = [];
      for (let j in collects[i].list) {
        let agatem = {};
        agatem.name = collects[i].list[j].name;
        agatem.text = collects[i].list[j].text;
        agatem.plan = collects[i].list[j].plan;
        agatem.gap = collects[i].list[j].gap;
        temcollect.push(agatem)
      }
      tem.collect = temcollect;
      endcollects.push(tem)
    }
    this.setData({
      tempcollects: endcollects
    })
  },


  //体检报告
  report(e) {
    this.setData({
      report: e.detail.value,
      edit_state: true
    })
  },

  // 建议
  suggest(e) {
    this.setData({
      advise: e.detail.value,
      edit_state: true
    })

  },

  saveReport() {
    this.setData({
      edit_state: true
    })
    let that = this;
    let url = 'counselor/AdviseSave';
    let params = {
      userId: app.globalData.UserId,
      report: that.data.report,
      advise: that.data.advise
    }
    app.post(url, params).then((res) => {
      console.log(res)
    }).catch((err) => {
      console.log(err)
    })
  },

  //增加推荐方案
  recommendCaseList(e) {
    if (this.data.caselist.length == 0) {
      wx.showToast({
        title: '请去添加预设推荐方案',
        icon: 'none'
      })
    } else {
      this.setData({
        popup_state: true
      })
    }
  },

  //删除保障缺口推荐方案
  delCaselist(e){
    var index=e.currentTarget.dataset.index
    var caselist = this.data.caselist
    caselist.splice(index,1)
    this.setData({
      caselist:caselist
    })
  },

  //预设方案列表
  caseList() {
    let that = this;
    let url = 'counselor/SchemeList';
    let params = {
      userId: app.globalData.UserId
    }
    app.post(url, params).then((res) => {
      if (res.data.code == 200) {
        var caselist = res.data.data.list
        for (var i = 0; i < caselist.length; i++) {
          caselist[i].choose_state = false
        }
        that.setData({
          caselist: caselist,
          caselist1: caselist
        })
      }
    })
  },

  tempRecomment() {
    var caselist = this.data.caselist
    var temp_array = [];
    for (let j in caselist) {
      let temp = {};
      if (caselist[j].choose_state) {
        temp.name = caselist[j].name;
        temp.firm = caselist[j].firm;
        temp.text = caselist[j].text;
        temp_array.push(temp)
      }
    }
    this.setData({
      recommend: temp_array
    })
  },

  //发送给客户
  saveInfo() {
    this.tempRecomment()
    this.tempCollects()

    // if (this.data.edit_state) {
    //   this.saveReport()
    // }
    if (this.data.edit_state2) {
      this.editPlan()
    }

    //判断选择的成员
    var familymember = this.data.familymember
    var ids = []
    for (var i = 0; i < familymember.length; i++) {
      if (familymember[i].member_state) {
        console.log(familymember[i].id)
        ids.push(familymember[i].id)
        this.setData({
          ids: ids
        })

      }
    }
    if (ids != '') {
      var that = this;
      var report = this.data.report
      var advise = this.data.advise
      var recommend = this.data.recommend
      var tempcollects = this.data.tempcollects
      let url = 'counselor/publishadd'
      let params = {
        UserId: app.globalData.UserId,
        PublishId: this.data.PublishId,
        DefId: this.data.mid,
        DefIds: this.data.ids.join(','), //固定值
        Collects: JSON.stringify(tempcollects),
        Report: JSON.stringify(report),
        Advise: JSON.stringify(advise),
        Recommend: JSON.stringify(recommend)
      }
      app.post(url, params).then((res) => {
        console.log(res)
        if (res.data.code == 200) {
          wx.showToast({
            title: '保存成功',
            icon: 'none'
          })
          that.setData({
            status: res.data.data.status,
            shareState: true,
            save_state: false,
            savedis:true,
            plan_id: res.data.data.publish_id,
            PublishId: res.data.data.publish_id
          })
        }
      })
    } else {
      wx.showToast({
        title: '请选择要生成报告的家庭成员',
        icon: 'none'
      })
    }
  },

  // 预览保单接口调取
  listdetail() {
    let url = 'counselor/publishlook'
    let params = {
      UserId: app.globalData.UserId,
      DefId: this.data.mid,
      DefIds: this.data.DefIds,
    }
    app.post(url, params).then((res) => {
      console.log('123',res)
      
      if (res.data.code == 200) {
        //保单详情
        var listdetail = res.data.data.list.information

        //家庭成员项选择
        var familymember = res.data.data.list.family;
        for (var j = 0; j < familymember.length; j++) {
          familymember[j].member_state = false
        }

        //保障汇总
        var collect = res.data.data.list.collect;
        for (var j = 0; j < collect.length; j++) {
          collect[j].collect_state = false
          for (var i = 0; i < collect[j].list.length; i++) {
            if (collect[j].list[i].num == 0) {
              collect[j].list[i].num = 0
            } else {
              collect[j].list[i].num = Math.round((collect[j].list[i].num) * 10000) / 10000
            }
          }
        }

        //保单明细
        var information = res.data.data.list.information
        for (var j = 0; j < information.length; j++) {
          information[j].information_state = false
        }

        //保险汇总表
        var newsummary = []
        var collect = res.data.data.list.collect
        for (var i = 0; i < collect.length; i++) {
          for (var j = 0; j < collect[i].list.length; j++) {
            var summary = collect[i].list
            summary[j].name = summary[j].name;
            summary[j].text = summary[j].num;
            summary[j].plan = ''
            summary[j].gap = ''
          }
          newsummary.push(summary)
        }

        var list_num = listdetail.length
        this.setData({
          familymember: familymember, //家庭成员
          userinfo: res.data.data.list.counselor, //顾问信息  
          information: information,
          advise: res.data.data.list.report,
          report: res.data.data.list.advise,
          guarantee: res.data.data.list.guarantee,
          information_user: res.data.data.list.information_user,
          collect: collect,
          touser: res.data.data.list.touser, //发送人
        })
        console.log(this.data.report)
        if (this.data.report==null){
         this.setData({
            show:false
          })
        }
      }
    })
  },

  //预览保单接口
  listDetail2() {
    let url = 'counselor/publishdef'
    let params = {
      PublishId: this.data.PublishId
    }
    app.post(url, params).then((res) => {
      var familymember = res.data.data.list.family;
      for (var j = 0; j < familymember.length; j++) {
        familymember[j].member_state = true
      }

      //保障汇总
      var collect = res.data.data.list.collect
      for (var j = 0; j < collect.length; j++) {
        collect[j].collect_state = false
        for (var i = 0; i < collect[j].list.length; i++) {
          collect[j].list[i].num = collect[j].list[i].text
          collect[j].collect_state = true
        }
      }

      //保单明细
      var information = res.data.data.list.information
      for (var j = 0; j < information.length; j++) {
        information[j].information_state = true
      }

      if (res.data.code == 200) {
        this.setData({
          familymember: res.data.data.list.family, //家庭成员
          userinfo: res.data.data.list.counselor, //顾问信息  
          information: information,
          advise: res.data.data.list.advise,
          report: res.data.data.list.report,
          guarantee: res.data.data.list.guarantee,
          collect: collect,
          touser: res.data.data.list.touser, //发送人
          recommend: res.data.data.list.recommend
        })
      }
    })
  },

  //发送改变状态接口
  saveState() {
    let url = 'counselor/publishUrl'
    let params = {
      PublishId: this.data.PublishId
    }
    app.post(url, params).then((res) => {
      console.log(res)
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    console.log(options)
    var allinfo = JSON.parse(options.allinfo)
    console.log(allinfo)
    this.setData({
      allinfo: allinfo
    })
    var mid = ''
    var users = this.data.allinfo.users
    var DefIds = []
    for (let i = 0; i < users.length; i++) {
      DefIds.push(users[i].id)
      if (users[i].user_family == 1) {
        mid = users[i].id
      }
    }
    this.setData({
      DefIds: DefIds,
      mid: mid,
    })
    if (options.PublishId == undefined) {
      this.setData({
        PublishId: 0
      })
      this.listdetail()
    } else {
      this.setData({
        PublishId: options.PublishId
      })
      this.listDetail2()
    }

    this.caseList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.caseList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    var that = this
    var status = that.data.status;
   
    that.saveState()
    var shareObj = {
      title: "转发的标题",
      path: '/pages/start/start?status=' + status,
      imgUrl: '',
      success: function(res) {
        if (res.errMsg == 'shareAppMessage:ok') {}
      }
    }
    // if (options.from == 'button') {
    //   var status = that.data.status;
    //   console.log(that.data.status)
    //   // 此处可以修改 shareObj 中的内容
    //   shareObj.path = '/pages/start/start?status=' + status;
    // }   // 返回shareObj
    return shareObj;
  }
})