5 changed files with 528 additions and 63 deletions
@ -1,17 +1,220 @@ |
|||
<template> |
|||
<view> |
|||
<Info class="bg-white" /> |
|||
<u-top-tips ref="uTips" type="success"></u-top-tips> |
|||
<Info class="bg-white" @saveInfo="saveInfo" /> |
|||
<view class="p-4 bg"> |
|||
<u-button type="primary" class="w-full" @click="submit">完成</u-button> |
|||
</view> |
|||
<EndLine /> |
|||
</view> |
|||
</template> |
|||
|
|||
<script> |
|||
import Info from 'components/ConfigInfo/components/Info'; |
|||
export default { components: { Info } }; |
|||
import { infoList } from 'components/ConfigInfo/components/config'; |
|||
|
|||
export default { |
|||
components: { Info }, |
|||
|
|||
data() { |
|||
return { params: {}, infoList }; |
|||
}, |
|||
|
|||
methods: { |
|||
// 填写用户信息 |
|||
saveInfo(info) { |
|||
this.params[info.label] = info.value; |
|||
// 其他 |
|||
if (info.value === '其他' && info.showOther && info.otherValue) { |
|||
this.params[info.label] = info.otherValue; |
|||
} |
|||
// 疾病史 |
|||
if (info.showType === 1 && info.type === 5) { |
|||
let arrValue = ''; |
|||
if (info.showOther && info.otherValue) { |
|||
const index = info.value.indexOf('其他'); |
|||
info.value.splice(index, 1, '其他:' + info.otherValue); |
|||
} |
|||
arrValue = info.value.toString(); |
|||
this.params[info.label] = arrValue; |
|||
} |
|||
// 血压 |
|||
if (info.label === 'BloodPressure') { |
|||
const arr = info.value.split('/'); |
|||
this.params.minBloodPressure = arr[0]; |
|||
this.params.maxBloodPressure = arr[1]; |
|||
} |
|||
// 医院地址 |
|||
if (info.type === 9) { |
|||
this.params.hospitalCityId = info.hospitalCityId; |
|||
this.params.hospitalProvinceId = info.hospitalProvinceId; |
|||
} |
|||
// 失眠 |
|||
if (info.type === 10) { |
|||
this.params.insomnicPeriod = info.value1; |
|||
} |
|||
// 吸烟 |
|||
if (info.type === 11) { |
|||
this.params.quitPeriod = info.value1; |
|||
this.params.sustainPeriod = info.value2; |
|||
this.params.averageNum = info.value3; |
|||
} |
|||
// 饮酒 |
|||
if (info.type === 12) { |
|||
this.params.abstinencePeriod = info.value1; |
|||
if (info.classesValue) { |
|||
this.params.drinkType = info.classesValue; |
|||
if (info.classesValue === '其他' && info.showOther && info.otherValue) { |
|||
this.params.drinkType = info.otherValue; |
|||
} |
|||
} |
|||
} |
|||
// 饮茶 |
|||
if (info.type === 13) { |
|||
this.params.quitTea = info.value1; |
|||
this.params.continuePeriod = info.value2; |
|||
|
|||
this.params.teaType = info.classesValue; |
|||
this.params.teaPeriod = info.frequencyValue; |
|||
} |
|||
}, |
|||
|
|||
/** |
|||
* 提交用户信息 |
|||
* @param { object } params |
|||
*/ |
|||
async submit() { |
|||
try { |
|||
const params = this.params; |
|||
if (!this.validationRequired(params)) return; |
|||
await this.$u.api.addTrainee(params); |
|||
this.$refs.uTips.show({ |
|||
title: '用户信息添加成功, 即将跳转日历页', |
|||
type: 'success', |
|||
duration: '2000', |
|||
}); |
|||
setTimeout(() => { |
|||
uni.redirectTo({ url: '/pages/index/index' }); |
|||
this.setEmptyInfo(); |
|||
}, 2000); |
|||
} catch (error) { |
|||
console.error('error: ', error); |
|||
} |
|||
}, |
|||
|
|||
// 验证必填项 |
|||
validationRequired() { |
|||
let isComplete = true; |
|||
for (let i = 0; i < this.infoList.length; i++) { |
|||
const info = this.infoList[i]; |
|||
for (let j = 0; j < info.length; j++) { |
|||
const item = info[j]; |
|||
if (item.type !== 5) { |
|||
if (item.value === null) { |
|||
this.$t.ui.showToast(`请填写${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
if (item.showOther && !item.otherValue) { |
|||
this.$t.ui.showToast(`请填写${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
if (item.type === 10 || item.type === 11 || item.type === 12 || item.type === 13) { |
|||
if (item.value === 1 && !item.value1) { |
|||
this.$t.ui.showToast(`请填写${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
} |
|||
if (item.showClasses && !item.classesValue) { |
|||
this.$t.ui.showToast(`请填写${item.name}种类`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
if (item.type === 13) { |
|||
if (item.showClasses && !item.frequencyValue) { |
|||
this.$t.ui.showToast(`请填写${item.name}频率`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
} |
|||
if (item.type === 11) { |
|||
if (item.value === 2) { |
|||
if (!item.value2) { |
|||
this.$t.ui.showToast(`请填写烟龄`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
if (!item.value3) { |
|||
this.$t.ui.showToast(`请填写每天抽烟数量`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
if (item.type === 13) { |
|||
if (item.value === 2 && !item.value2) { |
|||
this.$t.ui.showToast(`请填写持续喝茶时长`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
} |
|||
} else { |
|||
if (item.value.length === 0) { |
|||
this.$t.ui.showToast(`请填写${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
if (item.showOther && !item.otherValue) { |
|||
this.$t.ui.showToast(`请填写其他${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
if (!isComplete) { |
|||
break; |
|||
} |
|||
} |
|||
if (isComplete) return true; |
|||
}, |
|||
|
|||
// 提交完清空数据 |
|||
setEmptyInfo() { |
|||
this.infoList.forEach(info => { |
|||
info.forEach(item => { |
|||
item.value = null; |
|||
if (item.show) { |
|||
item.show = false; |
|||
} |
|||
if (item.otherValue) { |
|||
item.otherValue = null; |
|||
} |
|||
if (item.value1) { |
|||
item.value1 = null; |
|||
} |
|||
if (item.value2) { |
|||
item.value2 = null; |
|||
} |
|||
if (item.value3) { |
|||
item.value3 = null; |
|||
} |
|||
if (item.classesValue) { |
|||
item.classesValue = null; |
|||
} |
|||
if (item.frequencyValue) { |
|||
item.frequencyValue = null; |
|||
} |
|||
}); |
|||
}); |
|||
}, |
|||
}, |
|||
}; |
|||
</script> |
|||
|
|||
<style lang="scss" scoped> |
|||
page { |
|||
.bg { |
|||
background-color: $uni-bg-color-grey; |
|||
} |
|||
</style> |
|||
|
Loading…
Reference in new issue