|
|
@@ -96,7 +96,18 @@ export default {
|
|
|
data() {
|
|
|
return {
|
|
|
form: {
|
|
|
- answers: []
|
|
|
+ id: null,
|
|
|
+ questionId: null,
|
|
|
+ packageId: null,
|
|
|
+ payType: null,
|
|
|
+ amount: null,
|
|
|
+ isPackage: null,
|
|
|
+ answers: [],
|
|
|
+ userName: '',
|
|
|
+ userPhoneFour: '',
|
|
|
+ sex: null,
|
|
|
+ allergy: '',
|
|
|
+ remark: ''
|
|
|
},
|
|
|
userId: null,
|
|
|
questionOptions: [],
|
|
|
@@ -123,7 +134,28 @@ export default {
|
|
|
],
|
|
|
amount: [
|
|
|
{ required: true, message: '请填写物流代收金额', trigger: 'blur' }
|
|
|
- ]
|
|
|
+ ],
|
|
|
+ userName: [
|
|
|
+ { required: true, message: '请输入用户姓名', trigger: 'blur' },
|
|
|
+ { min: 1, max: 20, message: '姓名长度在 1 到 20 个字符', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ userPhoneFour: [
|
|
|
+ { required: true, message: '请输入手机号后四位', trigger: 'blur' },
|
|
|
+ { pattern: /^\d{4}$/, message: '请输入正确的4位数字', trigger: 'blur' }
|
|
|
+ ],
|
|
|
+ sex: [
|
|
|
+ { required: true, message: '请选择用户性别', trigger: 'change' },
|
|
|
+ {
|
|
|
+ validator: (rule, value, callback) => {
|
|
|
+ if (value !== 0 && value !== 1) {
|
|
|
+ callback(new Error('性别只能为男(1)或女(0)'));
|
|
|
+ } else {
|
|
|
+ callback();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ trigger: 'change'
|
|
|
+ }
|
|
|
+ ]
|
|
|
}
|
|
|
};
|
|
|
},
|
|
|
@@ -179,39 +211,56 @@ export default {
|
|
|
})
|
|
|
},
|
|
|
getCollectionInfo(userId) {
|
|
|
- const queryParams = {
|
|
|
- userId: userId,
|
|
|
+ this.userId = userId;
|
|
|
+ getInfo({ userId }).then(res => {
|
|
|
+ if (res.data && res.data.id) {
|
|
|
+ this.form = { ...this.form, ...res.data };
|
|
|
+ } else {
|
|
|
+ // 没有记录时,只清空 answers 和模板相关字段,保留用户手动输入的基础信息
|
|
|
+ this.form = {
|
|
|
+ ...this.form,
|
|
|
+ id: null,
|
|
|
+ questionId: null,
|
|
|
+ answers: [],
|
|
|
+ isPackage: null,
|
|
|
+ packageId: null,
|
|
|
+ payType: null,
|
|
|
+ amount: null
|
|
|
+ };
|
|
|
}
|
|
|
- this.userId = userId;
|
|
|
- getInfo(queryParams).then(res => {
|
|
|
- if (res.data.id) {
|
|
|
- this.form = res.data;
|
|
|
- } else {
|
|
|
- this.form = {
|
|
|
- answers: []
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
+ });
|
|
|
},
|
|
|
//选择问答模板
|
|
|
- selectQuestion(val) {
|
|
|
- console.log(val)
|
|
|
- this.form = {
|
|
|
- answers: []
|
|
|
- };
|
|
|
- const queryParams = {
|
|
|
- userId: this.userId,
|
|
|
- questionId: val
|
|
|
- }
|
|
|
- getInfo(queryParams).then(res => {
|
|
|
- this.form = res.data;
|
|
|
- })
|
|
|
- // getAnswer(val).then(response =>{
|
|
|
+ selectQuestion(val) {
|
|
|
+ // 保留用户已填写的基础信息(姓名、手机、性别等)
|
|
|
+ const preservedFields = {
|
|
|
+ userName: this.form.userName,
|
|
|
+ userPhoneFour: this.form.userPhoneFour,
|
|
|
+ sex: this.form.sex,
|
|
|
+ allergy: this.form.allergy,
|
|
|
+ remark: this.form.remark,
|
|
|
+ //不要保留 packageId / payType / amount,因为换模板可能要重选
|
|
|
+ };
|
|
|
+ this.form = {
|
|
|
+ ...preservedFields,
|
|
|
+ questionId: val,
|
|
|
+ answers: [],
|
|
|
+ isPackage: null,
|
|
|
+ packageId: null,
|
|
|
+ payType: null,
|
|
|
+ amount: null,
|
|
|
+ id: null
|
|
|
+ };
|
|
|
|
|
|
- // this.form.answers = response.data.answers;
|
|
|
- // console.log(this.form)
|
|
|
- // })
|
|
|
- },
|
|
|
+ // 查询该用户+该模板下是否有历史采集记录
|
|
|
+ getInfo({ userId: this.userId, questionId: val }).then(res => {
|
|
|
+ if (res.data && res.data.id) {
|
|
|
+ // 有历史记录:用接口数据覆盖(优先级更高)
|
|
|
+ this.form = { ...this.form, ...res.data };
|
|
|
+ }
|
|
|
+ // 否则保持当前 form(含用户之前填的信息)
|
|
|
+ });
|
|
|
+ },
|
|
|
|
|
|
submitForm() {
|
|
|
console.log(this.form)
|