123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358 |
- import { createSubscribe } from 'applet-page-component';
- import { getTestTimeList, getQuestionnaire, getItemList, nucleicOrderConfirm } from '../../service/common';
- import { getPatientList } from '../edit-patient/service';
- import history from '../../utils/history';
- import { tradePay } from '../../utils/tradePay';
- import { reportCmPV_YL } from '../../utils/cloudMonitorHelper';
- Component(createSubscribe({
- async onShow() {
- await this.getPatientLists();
- }
- })({
- data: {
- personItem: {},
- hospitalDistrictId: '',
- projects: [],
- personList: [],
- timeList: {},
- disabled: true,
- isFinish: false,
- finishForm: {},
- formList: [],
- questionList: [],
- loading: false,
- hospitalName: '',
- personIndex: undefined,
- showPerson: false,
- timer: null,
- setShowTime: false,
- setShowForm: false,
- setDayTime: '半天',
- onlinePay: false
- },
- props: {
- componentData: {}
- },
- async didMount() {
- const {
- personItem,
- hospitalDistrictId,
- hospitalName,
- componentExtInfo,
- personIndex
- } = this.$page.data.query ? this.$page.data.query : {};
- this.setData({
- hospitalDistrictId
- });
- await this.getProject();
- await this.getPatientLists();
- let setInfo = {}; // 是否直接进入核酸预约页面
- if (this.props.componentData.componentExtInfo) {
- setInfo = this.props.componentData.componentExtInfo;
- this.onShowPerson();
- } else {
- setInfo = componentExtInfo ? JSON.parse(componentExtInfo) : {};
- this.setData({
- personItem: personItem ? JSON.parse(personItem) : {},
- personIndex: Number(personIndex)
- });
- }
- const {
- setShowTime,
- setShowForm,
- setDayTime,
- onlinePay,
- hospitalNameInput
- } = setInfo; // personItem可能参数过长,先decode
- this.setData({
- hospitalName: hospitalName || hospitalNameInput,
- setShowTime: setShowTime === 'true',
- setShowForm: setShowForm === 'true',
- setDayTime,
- onlinePay: onlinePay === 'true'
- });
- /* 服务预警,核酸预约 */
- reportCmPV_YL({
- title: '核酸预约'
- });
- },
- didUnmount() {
- clearTimeout(this.data.timer);
- },
- methods: {
- async getProject() {
- const {
- hospitalDistrictId
- } = this.data;
- const timeList = await getTestTimeList({
- hospitalDistrictId
- });
- const {
- questionList: formList
- } = await getQuestionnaire({
- hospitalDistrictId
- });
- const projects = await getItemList({
- hospitalDistrictId
- });
- this.setData({
- projects,
- timeList,
- formList,
- questionList: formList
- });
- },
- // 选择就诊人部分
- async getPatientLists() {
- const personList = await getPatientList();
- this.setData({
- personList
- });
- },
- onShowPerson() {
- const {
- personList
- } = this.data; // 判就诊人列表三种情况
- if (personList.length === 0) {
- // 没有就诊人信息
- my.alert({
- content: '您还未添加就诊人,无法进行核酸预约',
- buttonText: '去新增',
- success: () => {
- // 没有就诊人信息
- history.replace({
- title: '添加就诊人',
- pageType: 'edit-patient'
- });
- }
- });
- } else if (personList.length === 1) {
- this.setData({
- personItem: personList[0]
- });
- } else {
- // 选择就诊人
- this.setData({
- showPerson: true
- });
- }
- },
- onOpenPerson() {
- this.setData({
- showPerson: true
- });
- },
- onClosePerson() {
- if (!this.data.personItem.name) {
- my.showToast({
- content: '请选择就诊人'
- });
- return;
- }
- this.setData({
- showPerson: false
- });
- },
- onPersonChange(item, index) {
- // 如果有流调表,重置表单
- if (this.data.formList) {
- this.onReset();
- }
- this.setData({
- personItem: item,
- showPerson: false,
- personIndex: index
- });
- },
- // 项目其他部分
- onReset() {
- const {
- formList
- } = this.data;
- this.setData({
- finishForm: {},
- formList: []
- });
- this.onFinishForm();
- this.data.timer = setTimeout(() => {
- this.setData({
- formList
- });
- }, 100);
- },
- onChangeProject(e) {
- const {
- item
- } = e.target.dataset;
- this.setData({
- projectItem: item
- });
- this.onDisableButton();
- },
- onCloseTime(item) {
- this.setData({
- timeItem: item
- });
- this.onDisableButton();
- },
- onRadioChange(e) {
- const {
- name
- } = e.target.dataset;
- const {
- value
- } = e.detail;
- this.data.finishForm[name] = value;
- this.setData({
- finishForm: this.data.finishForm
- });
- this.onFinishForm();
- },
- onFinishForm() {
- const {
- finishForm
- } = this.data;
- const arr = Object.getOwnPropertyNames(finishForm);
- this.setData({
- isFinish: arr.length === this.data.questionList.length
- });
- this.onDisableButton();
- },
- onDisableButton() {
- const {
- projectItem,
- timeItem,
- isFinish,
- setShowTime,
- setShowForm
- } = this.data;
- this.setData({
- disabled: !projectItem || !timeItem && setShowTime || !isFinish && !!setShowForm
- });
- },
- async onSubmit(e) {
- // 是否需要检验表单 && 校验表单是否符合要求
- let isTrue = true;
- if (this.data.setShowForm) {
- isTrue = this.onJudgeForm(e.detail.value);
- }
- if (isTrue) {
- const {
- projectItem,
- timeItem,
- personItem,
- hospitalDistrictId,
- setShowTime,
- onlinePay
- } = this.data; // 获取订单ID
- const res = await nucleicOrderConfirm({
- cardNum: personItem.bindCardNum,
- nucleicItemId: projectItem.nucleicItemId,
- hospitalDistrictId,
- testTimeId: setShowTime && timeItem ? timeItem.testTimeId : ''
- }); // 区分支持线上支付 和 不支持线上支付
- if (res.amount && onlinePay) {
- // const orderRes = await tradeNoQuery({
- // type: 1,
- // idNum: res.orderId,
- // amount: res.amount,
- // });
- // my.tradePay({
- // tradeNO: orderRes.tradeNo,
- // success: ({ resultCode }) => {
- // if (resultCode === '9000') {
- // history.replace({
- // query: {
- // hospitalDistrictId,
- // orderId: res.orderId,
- // type: '已支付',
- // },
- // title: '预约详情',
- // pageType: 'booking-detail',
- // });
- // }
- // },
- // });
- this.setData({
- loading: true
- });
- tradePay({
- type: 2,
- amount: res.amount,
- idNum: res.orderId
- }, {
- tradeType: 'Appointment'
- }).then(() => {
- history.replace({
- query: {
- hospitalDistrictId,
- orderId: res.orderId,
- type: '已支付'
- },
- title: '预约详情',
- pageType: 'booking-detail'
- });
- }).finally(() => {
- this.setData({
- loading: false
- });
- });
- } else {
- history.replace({
- query: {
- hospitalDistrictId,
- orderId: res.orderId,
- type: '未支付'
- },
- title: '预约详情',
- pageType: 'booking-detail'
- });
- }
- }
- },
- onJudgeForm(result) {
- const arr = Object.getOwnPropertyNames(result); // 校验表单答案
- const isFalse = arr.some(item => item.split('&')[1] !== result[item]);
- if (isFalse) {
- my.alert({
- title: '您的情况不支持预约',
- content: '请前往医院发热门诊接受筛查'
- });
- return false;
- }
- return true;
- }
- }
- }));
|