21 changed files with 720 additions and 217 deletions
@ -0,0 +1,249 @@ |
|||
<template> |
|||
<view style="border: 1px solid #e5e5e5"> |
|||
<view v-for="(item, index) in careInfo" :key="index"> |
|||
<template v-for="(colItem, itemIndex) in item"> |
|||
<view v-if="!disabled" :key="itemIndex"> |
|||
<view v-if="colItem.showType === 1" class="flex flex-col text-sm ml-4 border-b"> |
|||
<view class="my-3 flex justify-between items-center" @click="changeShow(index, itemIndex)"> |
|||
{{ colItem.name }} |
|||
<u-icon name="arrow-up" class="mx-2" color="#909399" v-if="colItem.show"></u-icon> |
|||
<u-icon name="arrow-down" class="mx-2" color="#909399" v-else></u-icon> |
|||
</view> |
|||
<view v-if="colItem.show"> |
|||
<!-- 单选 --> |
|||
<view v-if="colItem.type === 1"> |
|||
<u-radio-group v-model="colItem.value"> |
|||
<u-radio |
|||
class="mb-2" |
|||
@change="change($event, index, itemIndex, colItem.type)" |
|||
v-for="(radioItem, radioIndex) in colItem.radioList" |
|||
:key="radioIndex" |
|||
:name="radioItem" |
|||
> |
|||
{{ radioItem }} |
|||
</u-radio> |
|||
</u-radio-group> |
|||
<u-input |
|||
v-if="colItem.showOther" |
|||
:placeholder="`请输入其他${colItem.name}`" |
|||
v-model="colItem.otherValue" |
|||
:clearable="false" |
|||
@blur="change(colItem.otherValue, index, itemIndex, 99)" |
|||
/> |
|||
</view> |
|||
</view> |
|||
</view> |
|||
<view v-else :key="itemIndex" class="flex justify-between items-center text-sm border-b"> |
|||
<view class="ml-4 my-3">{{ colItem.name }}</view> |
|||
<!-- 数字输入框 --> |
|||
<view v-if="colItem.type === 3" class="pr-7"> |
|||
<u-input |
|||
v-model="colItem.value" |
|||
type="number" |
|||
:clearable="false" |
|||
input-align="right" |
|||
@blur="change($event, index, itemIndex, colItem.type)" |
|||
/> |
|||
</view> |
|||
<!-- input 文本输入框 --> |
|||
<view v-if="colItem.type === 8" class="pr-7"> |
|||
<u-input |
|||
v-model="colItem.value" |
|||
:clearable="false" |
|||
input-align="right" |
|||
@blur="change($event, index, itemIndex, colItem.type)" |
|||
/> |
|||
</view> |
|||
</view> |
|||
</view> |
|||
|
|||
<view v-else :key="itemIndex"> |
|||
<view class="flex justify-between text-sm py-3 px-4 border-b items-center"> |
|||
{{ colItem.name }} |
|||
<view>{{ colItem.value }}</view> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
</view> |
|||
<view class="p-4" v-if="!disabled"> |
|||
<u-button type="primary" @click="submit">开始填表</u-button> |
|||
</view> |
|||
</view> |
|||
</template> |
|||
|
|||
<script> |
|||
import { mapGetters, mapMutations, mapActions } from 'vuex'; |
|||
import { careInfo } from '@/config/yyInfo'; |
|||
|
|||
export default { |
|||
name: 'Info', |
|||
props: { detail: { type: Object, default: null }, disabled: { type: Boolean, default: false } }, |
|||
|
|||
data() { |
|||
return { |
|||
headStyle: { |
|||
backgroundColor: '#fff', |
|||
height: '46px', |
|||
paddingLeft: '1rem', |
|||
fontSize: '0.875rem', |
|||
}, |
|||
bodyStyle: { paddingLeft: '1rem' }, |
|||
careInfo, |
|||
show: true, |
|||
params: {}, |
|||
}; |
|||
}, |
|||
|
|||
computed: mapGetters('project', ['projectId']), |
|||
|
|||
mounted() { |
|||
if (this.detail) { |
|||
this.setDate(this.detail); |
|||
this.show = false; |
|||
} else { |
|||
this.show = true; |
|||
} |
|||
}, |
|||
|
|||
methods: { |
|||
...mapMutations('yanyuan', ['setCode', 'setReportId']), |
|||
...mapActions('yanyuan', ['handleQuestion']), |
|||
|
|||
changeShow(index, itemIndex) { |
|||
this.careInfo[index][itemIndex].show = !this.careInfo[index][itemIndex].show; |
|||
}, |
|||
|
|||
change(e, index, itemIndex, type) { |
|||
const info = this.careInfo[index][itemIndex]; |
|||
switch (type) { |
|||
case 99: { |
|||
info.otherValue = e; |
|||
// this.params[info.label] = e; |
|||
break; |
|||
} |
|||
default: { |
|||
if (info.label === 'careSex') { |
|||
// this.params[info.label] = e === '男' ? 1 : 2; |
|||
} |
|||
if (e === '其他') { |
|||
info.showOther = true; |
|||
} else { |
|||
info.showOther = false; |
|||
} |
|||
info.value = e; |
|||
// this.params[info.label] = e; |
|||
break; |
|||
} |
|||
} |
|||
}, |
|||
|
|||
// 回显 |
|||
setDate(date) { |
|||
const { careInfo } = this; |
|||
for (let i = 0; i < careInfo.length; i++) { |
|||
const info = careInfo[i]; |
|||
for (let j = 0; j < info.length; j++) { |
|||
const item = info[j]; |
|||
if (item.label === 'careSex') { |
|||
item.value = date[item.label] === 1 ? '男' : date[item.label] === 2 ? '女' : null; |
|||
} else { |
|||
if (item.type === 1 && item.radioList && item.radioList.length) { |
|||
const list = item.radioList.find(list => list === date[item.label]); |
|||
if (list) { |
|||
item.value = date[item.label]; |
|||
} else { |
|||
item.value = '其他'; |
|||
item.showOther = true; |
|||
item.otherValue = date[item.label]; |
|||
} |
|||
} else { |
|||
item.value = date[item.label]; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
}, |
|||
|
|||
/** |
|||
* 添加负担量表 |
|||
* @param { Object } params |
|||
*/ |
|||
async submit() { |
|||
try { |
|||
if (!this.validationRequired(this.params)) return; |
|||
const params = this.params; |
|||
params.projectId = this.projectId; |
|||
const data = await this.$u.api.addZarit(params); |
|||
if (data) { |
|||
this.setReportId(data); |
|||
this.setCode('ZARIT'); |
|||
await this.startAssess(data); |
|||
} |
|||
} catch (error) { |
|||
console.error('error: ', error); |
|||
} |
|||
}, |
|||
|
|||
// 验证必填项 |
|||
validationRequired() { |
|||
let isComplete = true; |
|||
for (let i = 0; i < careInfo.length; i++) { |
|||
const info = careInfo[i]; |
|||
for (let j = 0; j < info.length; j++) { |
|||
const item = info[j]; |
|||
if (item.showOther && !item.otherValue) { |
|||
this.$t.ui.showToast(`请填写其他${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
if (!item.value) { |
|||
this.$t.ui.showToast(`请填写${item.name}`); |
|||
isComplete = false; |
|||
break; |
|||
} |
|||
// 赋值 |
|||
this.setParams(item); |
|||
} |
|||
if (!isComplete) { |
|||
break; |
|||
} |
|||
} |
|||
if (isComplete) return true; |
|||
}, |
|||
|
|||
// 赋值 |
|||
setParams(item) { |
|||
this.params[item.label] = item.value; |
|||
if (item.label === 'careSex') { |
|||
this.params[item.label] = item.value === '男' ? 1 : 2; |
|||
} |
|||
if (item.value === '其他') { |
|||
this.params[item.label] = item.otherValue; |
|||
} |
|||
}, |
|||
|
|||
/** |
|||
* 开始填表 |
|||
* @param { string } code 题目code NLCP:脑力测评 ZARIT:照顾者负担量表 |
|||
* @param { number } num 题号 |
|||
* @param { string } reportId 测评ID 脑力测评ID或zaritID |
|||
*/ |
|||
async startAssess(id) { |
|||
try { |
|||
const params = { |
|||
code: 'ZARIT', |
|||
reportId: id, |
|||
num: '1', |
|||
}; |
|||
const data = await this.handleQuestion(params); |
|||
console.log('data: ', data); |
|||
uni.navigateTo({ url: '/pagesYanyuan/assess/assess' }); |
|||
} catch (error) { |
|||
console.error('error: ', error); |
|||
} |
|||
}, |
|||
}, |
|||
}; |
|||
</script> |
|||
|
|||
<style lang="scss" scoped></style> |
Loading…
Reference in new issue