h5-cli
Version: 
hello
390 lines (338 loc) • 16.3 kB
JavaScript
;
define(function (require, exports, module) {
  var PageModule = require("component/PageModule");
  //\u652f\u4ed8\u6a21\u5757\u9875\u9762UI
  var payPageModule = require("mods/pay/index");
  //\u652f\u4ed8\u6a21\u5757\u7f51\u8def\u8bf7\u6c42
  var payModule = require("mods/pay/pay");
  var weixin = require("mods/wxOpenId/index");
  var page = PageModule.render({
    init: function init() {
      var rechargeInfo = {};
      try {
        rechargeInfo = JSON.parse(sessionStorage.rechargeInfo);
      } catch (e) {
        console.log(e);
      }
      this.corpId = this.query.corpId;
      this.unionId = this.query.unionId || '';
      this.patientId = rechargeInfo.patientId || '';
      //this.isCorpCard = this.query.isCorpCard || '';
      this.cardNo = '';
      this.cardId = rechargeInfo.cardId || '';
      this.hasDetail = false;
      //\u5b58\u653eurl\u4e2d\u7684patientId\u548ccardId\uff0c\u4e0d\u53ef\u53d8\u3002\u3002\u3002\u56e0\u4e3a\u5fae\u4fe1\u652f\u4ed8\u4e2d\u8f6c\u53ea\u80fd\u5e26\u4e00\u4e2a\u53c2\u6570\uff0c\u6240\u4ee5\u8fd9\u4e9b\u6ca1\u7528\u4e86\u2026\u2026
      //this.urlPatientId = this.query.patientId || '';
      //this.urlCardId = this.query.cardId || '';
      //\u5982\u679c\u5728\u5fae\u4fe1\u4e2d\uff0c\u9996\u5148\u8981\u83b7\u53d6 openId
      if (this.util.isInMicroMessenger()) {
        this.openId = weixin.getOpenId(this.corpId, 1);
      }
      //\u652f\u4ed8\u5b9d\u7f51\u9875\u652f\u4ed8\u5b8c\u6210\u540e\u4f1a\u8df3\u8f6c\u4f1a\u5230\u5f53\u524d\u9875\u9762
      //\u9700\u8981\u8f6e\u8bad\u652f\u4ed8\u72b6\u6001\uff0c\u5e76\u5728\u6210\u529f\u7684\u65f6\u5019\u5237\u65b0\u9875\u9762
      // if(this.query.out_trade_no){
      // 	payModule.roundGetStatusByOutId(this.query.out_trade_no);
      // 	return ;
      // }
      //\u521d\u59cb\u5316\u7f34\u8d39\u65b9\u5f0f
      payPageModule.onReady = function (isSupport) {
        if (isSupport) {
          $('#J_Submit').removeClass("hide");
        }
      };
      payPageModule.init(this.corpId, 1);
      this.regEvent();
    },
    isDefaultSelect: function isDefaultSelect(patientId, currentPatientId, isDefault) {
      if (patientId) {
        return patientId == currentPatientId ? "selected" : "";
      } else {
        return isDefault ? "selected" : "";
      }
    },
    regEvent: function regEvent() {
      var self = this;
      /*$('#J_PatientSelect').change(function () {
       self.cache.set("patientId", $(this).val());
       self.queryAccout($(this).val())
       self.getCard()
       })*/
      // var patientId = patient ? patient.value : null;
      var patientId = this.cache.get("patientId") || null;
      // console.log(patient)
      PageModule.render({
        init: function init() {
          this.get("/user-web/restapi/patient/getList", {
            corpId: this.query.corpId || this.corpId,
            unionId: self.unionId
          });
          $('.close-container').click(function () {
            $('.patient-list-container').hide();
          });
          //\u5f39\u7a97\u70b9\u51fb\u534a\u900f\u660e\u5904\u6d88\u5931
          $('.patient-list-container').click(function () {
            $('.patient-list-container').hide();
          });
          $('.patient-list-main').click(function (e) {
            e.stopPropagation();
          });
          //\u70b9\u51fb\u5c31\u8bca\u4eba\u5f39\u51fa\u6846
          $('#J_PatientSelect').click(function () {
            //if (!self.urlPatientId) {
            $('#patientList').show();
            //}
          });
          //\u70b9\u51fb\u5c31\u8bca\u4eba\u9009\u62e9\uff0c\u5f39\u7a97\u6d88\u5931\u5e76\u8d4b\u503c\u7ed9this.patientId
          $('#patientList .patient-list').on('click', '.patient-li', function () {
            self.patientId = $(this).attr('data-pid');
            $('#patientList').hide();
            $('#J_PatientSelect').text($(this).attr('data-pname'));
            $('#J_Balance').val(0 + '\u5143');
            $('#J_CardSelect').text('\u8bf7\u9009\u62e9\u5145\u503c\u8d26\u6237');
            self.cardId = '';
            self.cardNo = '';
            self.hasDetail = false;
            self.getCard();
          });
          $('#cardList .patient-list').on('click', '.card-li', function () {
            self.cardNo = $(this).attr('data-cardNo') !== 'undefined' ? $(this).attr('data-cardNo') : '';
            self.cardId = $(this).attr('data-cardId') !== 'undefined' ? $(this).attr('data-cardId') : '';
            var balance = $(this).attr('data-balance') !== 'undefined' ? $(this).attr('data-balance') : '';
            self.hasDetail = $(this).attr('data-hasDetail');
            $('#J_CardSelect').text($(this).attr('data-cardName'));
            $('#cardList').hide();
            if (self.unionId == 29) {
              $('#J_Balance').val(balance > 0 ? balance / 100 : 0 + '\u5143');
            } else {
              self.hasDetail == 'true' ? self.queryAccout(patientId) : $('#J_Balance').val(balance > 0 ? balance / 100 : 0 + '\u5143');
            }
          });
        },
        onSuccess: function onSuccess(result) {
          if (result.data) {
            var patientList = result.data;
            /*$('#J_PatientSelect').html(
             patientList.map((item) => {
             return `<option value="${item.id}" ${self.isDefaultSelect(patientId, item.id, item.default)} >${item.patientName}</option>`
             }).join("")
             );*/
            //$('#patientList').show();
            if (patientList.length > 0) {
              $('#patientList .patient-list').html(patientList.map(function (item) {
                var icon = item.idType == 1 ? 'https://front-images.oss-cn-hangzhou.aliyuncs.com/i4/7fee31b86360d5ee6b19c10b4dae22c2-68-68.png' : 'https://front-images.oss-cn-hangzhou.aliyuncs.com/i4/f67f01446d90cf0613feee5389c44b36-68-68.png';
                return "<div class=\"patient-li\" data-pid=" + item.id + " data-pname=" + item.patientName + ">\n                  <img class=\"patient-list-avatar\" src=" + icon + " />\n                  <div class=\"patient-list-item\">\n                    <div class=\"patient-list-name\">\n                      " + item.patientName + "\n                      <span>" + (item.idType == 1 ? "\u6210\u4eba" : "\u513f\u7ae5") + "</span>\n                    </div>\n                    <div class=\"patient-list-brief\">" + (item.idNo || item.guarderIdNo) + "</div>\n                  </div>\n                </div>";
              }).join(""));
            } else {
              $('#patientList .patient-list').html("<div class=\"patient-notice\">\n                  <span></span>\n                  <p>\u5C1A\u672A\u6DFB\u52A0\u5C31\u8BCA\u4EBA</p>\n                  <p>\u8BF7\u5148\u6DFB\u52A0\u5C31\u8BCA\u4EBA</p>\n                </div>");
            }
            //\u5982\u679c\u662f\u4ece\u5c31\u8bca\u5361\u8be6\u60c5\u8df3\u8f6c\u8fc7\u6765\uff0c\u5219\u76f4\u63a5\u6307\u5b9aurl\u4e2d\u7684patientId\u4e3a\u5c31\u8bca\u4eba\u3002\u5982\u679c\u5c31\u8bca\u4eba\u5217\u8868\u957f\u5ea6>0\uff0c\u9ed8\u8ba4\u9009\u62e9\u9ed8\u8ba4\u5c31\u8bca\u4eba\uff0c\u5982\u679c\u65e0\u9ed8\u8ba4\u5c31\u8bca\u4eba\uff0c\u5219\u9009\u62e9\u7b2c\u4e00\u4e2a\u5c31\u8bca\u4eba
            if (self.patientId) {
              var patientInfo = patientList.filter(function (z) {
                return z.id == self.patientId;
              })[0];
              $('#J_PatientSelect').text(patientInfo ? patientInfo.patientName : patientInfo[0].patientName);
            } else if (patientList.length > 0) {
              var defaultPatient = patientList.filter(function (z) {
                return z.default;
              })[0];
              self.patientId = defaultPatient ? defaultPatient.id : patientList[0].id;
              $('#J_PatientSelect').text(defaultPatient ? defaultPatient.patientName : patientList[0].patientName);
            }
            self.getCard();
          }
        },
        onError: function onError(e) {
          if (e.msg == '\u672a\u767b\u5f55') {
            self.util.goLogin();
          }
          //self.util.goLogin();
        }
      }).init();
      $('#J_Submit').click(function () {
        if (!$(this).attr("disabled")) {
          self.submit();
        }
      });
      // $('#J_AddPatient').attr("href","../patient-list.html?selectView=1&corpId="+self.query.corpId+"&target=_blank");
    },
    //\u83b7\u5f97\u5361\u5217\u8868
    getCard: function getCard() {
      var self = this;
      var patientId = this.patientId || '';
      PageModule.render({
        init: function init() {
          this.get("/user-web/restapi/card/noBalanceList", {
            unionId: self.unionId,
            patientId: patientId,
            corpId: self.unionId == 60 ? '' : self.corpId,
            balance: true,
            category: self.unionId == 29 ? 1 : ''
          });
          self.util.waitAlert("\u6b63\u5728\u67e5\u8be2\u5361\u5217\u8868...");
          $('#J_CardSelect').click(function () {
            //if (!self.urlCardId) {
            $('#cardList').show();
            //}
          });
          //\u5982\u679curl\u4e2d\u6709cardId\u548cpatientId
          if (self.patientId && self.cardId && self.unionId != 29) {
            self.queryAccout(patientId);
          }
        },
        onError: function onError(e) {
          self.util.waitHide();
          if (e.msg == '\u672a\u767b\u5f55') {
            self.util.goLogin();
          }
        },
        onSuccess: function onSuccess(result) {
          self.util.waitHide();
          var data = result.data || [];
          self.cardId = data[0] ? data[0].id : '';
          data[0] && $('#J_CardSelect').text(data[0].cardName);
          if (data[0]) {
            self.hasDetail = data[0].hasDetail;
          }
          data[0] && data[0].hasDetail ? self.queryAccout() : $('#J_Balance').val(data[0] ? data[0].balance / 100 : 0 + '\u5143');
          if (data.length > 0) {
            $('#J_Tips').addClass("hide");
            $('#J_Submit').removeAttr("disabled");
          } else {
            $('#J_Tips').text("\u8bf7\u5230\u81ea\u52a9\u7ec8\u7aef\u53d6\u5361\u540e\u518d\u5145\u503c").removeClass("hide");
            $('#J_Submit').attr("disabled", "disabled");
          }
          if (self.cardId) {
            var cardInfo = data.filter(function (z) {
              return z.id == self.cardId;
            })[0];
            $('#J_CardSelect').text(cardInfo ? cardInfo.cardName : '\u8bf7\u9009\u62e9\u5145\u503c\u8d26\u6237');
            if (self.unionId == 29) {
              $('#J_Balance').val(cardInfo ? cardInfo.balance / 100 : 0 + '\u5143');
            }
          }
          if (data.length > 0) {
            $('#cardList .patient-list').html(data.map(function (item) {
              return "<div class=\"card-li\" data-cardId=" + item.id + " data-balance=" + item.balance + " data-cardNo=" + item.cardNo + " data-cardName=" + item.cardName + " data-hasDetail=" + item.hasDetail + ">\n                  <img class=\"patient-list-avatar\" src=\"https://front-images.oss-cn-hangzhou.aliyuncs.com/i4/200ebefe79377f63f8be85a66a830f2b-68-68.png\" />\n                  <div class=\"patient-list-item\">\n                    <div class=\"patient-list-name\">\n                      " + item.cardName + "\n                    </div>\n                    " + (item.cardNo ? "<div class=\"patient-list-brief\">(" + item.cardNo.slice(-4) + ")</div>" : '') + "\n                  </div>\n              </div>";
            }).join(""));
          } else {
            $("#cardList .patient-list").html("<div class=\"bind-notice\">\n                  <span></span>\n                  <p>\u5F53\u524D\u5C31\u8BCA\u4EBA\u5C1A\u672A\u7ED1\u5B9A\u5C31\u8BCA\u5361</p>\n                  <p>\u8BF7\u5148\u7ED1\u5B9A\u5C31\u8BCA\u5361</p>\n                </div>");
          }
        }
      }).init();
    },
    //\u67e5\u8be2\u5361\u4f59\u989d
    queryAccout: function queryAccout(patientId) {
      this.util.waitAlert("\u6b63\u5728\u67e5\u8be2\u4f59\u989d...");
      /*PageModule.render({
       init: function() {
       this.get("/user-web/restapi/patient/getallinfo", {
       corpId: self.corpId,
       unionId: self.unionId,
       patientId: patientId,
       queryBalance: true //\u662f\u5426\u67e5\u8be2\u4f59\u989d
       });
       },
       onSuccess: function(result) {
       //\u8868\u793a\u5c31\u8bca\u4eba\u80fd\u4e0d\u80fd\u5145\u503c
       console.log(result);
       if (result.data.account) {
       $('#J_Tips').addClass("hide");
       $('#J_Submit').removeAttr("disabled");
       } else {
       $('#J_Tips').text("\u8bf7\u5230\u81ea\u52a9\u7ec8\u7aef\u53d6\u5361\u540e\u518d\u5145\u503c").removeClass("hide");
       $('#J_Submit').attr("disabled", "disabled");
       }
       },
       onError: function () {
       $('#J_Tips').text("\u5f53\u524d\u5c31\u8bca\u4eba\u72b6\u6001\u65e0\u6cd5\u5145\u503c").removeClass("hide");
       $('#J_Submit').attr("disabled", "disabled");
       },
       }).init();*/
      this.get("/user-web/restapi/card/get", {
        unionId: this.unionId,
        corpId: this.corpId,
        id: this.cardId
      });
    },
    //\u67e5\u8be2\u4f59\u989d\u56de\u8c03
    onComplate: function onComplate(result) {
      this.util.waitHide();
      if (result.success && result.data) {
        this.onSuccess(result);
      } else {
        //\u5931\u8d25
        $('#J_Balance').val(0 + "\u5143");
        this.onError(result);
      }
    },
    onSuccess: function onSuccess(result) {
      this.util.waitHide();
      var balance = 0;
      if (result.success && result.data.balance) {
        balance = result.data.balance;
      }
      $('#J_Balance').val(balance > 0 ? balance / 100 : 0 + " \u5143");
    },
    onError: function onError() {
      $('#J_Tips').text("\u5f53\u524d\u5c31\u8bca\u4eba\u72b6\u6001\u65e0\u6cd5\u5145\u503c").removeClass("hide");
      $('#J_Submit').attr("disabled", "disabled");
    },
    submit: function submit() {
      var self = this;
      var feeChannel = payPageModule.getPayType();
      var patientId = this.patientId || '';
      var fee = parseFloat($('#J_recharge_money').val());
      var corpId = this.corpId;
      var unionId = this.unionId || '';
      var cardId = this.cardId || '';
      var util = this.util;
      if (!patientId) {
        this.util.alert("\u8bf7\u9009\u62e9\u5c31\u8bca\u4eba");
        return;
      }
      //\u5361id\u4e0d\u5b58\u5728\uff0c\u4e14hasDetail\u4e0d\u4e3atrue\u6216'true'\u65f6\uff0c\u624d\u662f\u6ca1\u9009\u62e9\u5145\u503c\u8d26\u6237
      if (!cardId && (self.hasDetail === true || self.hasDetail === 'true')) {
        this.util.alert("\u8bf7\u9009\u62e9\u5145\u503c\u8d26\u6237");
        return;
      }
      if (!(fee >= 0.01)) {
        //\u5206\u4e3a\u5355\u4f4d
        this.util.alert("\u8f93\u5165\u91d1\u989d\u5fc5\u987b\u5927\u4e8e\u7b49\u4e8e0.01");
        return;
      }
      if (feeChannel == -1) {
        this.uitl.alert("\u8bf7\u9009\u62e9\u652f\u4ed8\u65b9\u5f0f");
        return;
      }
      this.feeChannel = feeChannel;
      fee = (fee * 100).toFixed(0);
      //\u652f\u4ed8\u5b8c\u6210
      payModule.onPayComplate = function (isOkay, id, result) {
        if (isOkay) {
          self.util.alert("\u5145\u503c\u6210\u529f");
          setTimeout(function () {
            window.location.reload();
          }, 1000);
        } else {
          setTimeout(function () {
            window.location.href = util.h5URL("/bill-detail.html?id=" + id + "&unionId" + unionId + "&corpId=" + corpId); //"https://uat.yuantutech.com/yuantu/h5-cli/1.3.32/pages/bill-detail.html?id="+id;
          }, 1500);
        }
      };
      /**
       feeChannel \u652f\u4ed8\u65b9\u5f0f   //1\u3001\u652f\u4ed8\u5b9d 2\u3001\u5fae\u4fe1 3\u3001\u4f59\u989d
       optType \u4e1a\u52a1\u7c7b\u578b //1\u3001\u5145\u503c 2\u3001\u7f34\u8d39 3\u3001\u6302\u53f7
       optParam \u4e1a\u52a1\u53c2\u6570
       */
      payModule.pay(feeChannel, 1, {
        fee: fee,
        patientId: patientId,
        corpId: this.corpId,
        openId: this.openId,
        cardId: cardId
      });
    }
  });
  page.init();
  module.exports = page;
});