|
@@ -30,34 +30,42 @@
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
<uni-data-checkbox v-model="item.reply" :localdata="item.answer"
|
|
|
:map="{text:'text',value:'text'}" />
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='1'">
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
<uni-data-checkbox v-model="item.reply" multiple :localdata="item.answer"
|
|
|
:map="{text:'text',value:'text'}" />
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='2'">
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
<uni-data-select v-model="item.reply" :localdata="item.answer"></uni-data-select>
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='3'">
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
- <uni-easyinput v-model="item.reply" type="number" :placeholder="getField(item.problem)"></uni-easyinput>
|
|
|
+ <uni-easyinput v-model="item.reply" type="number"
|
|
|
+ :placeholder="getField(item.problem)"></uni-easyinput>
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='4'">
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
<uni-easyinput v-model="item.reply" :placeholder="getField(item.problem)"></uni-easyinput>
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='5'">
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
<uni-easyinput type="textarea" v-model="item.reply"
|
|
|
:placeholder="getField(item.problem)"></uni-easyinput>
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='6'">
|
|
|
<div class="remark" v-if="item.remark">{{item.remark}}</div>
|
|
|
<upload class='upload' :list="item.reply" name="reply" :count="1" @uplSuc="uplSuc($event,item)"
|
|
|
@uplDel="uplDel($event,item)">
|
|
|
</upload>
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='7'">
|
|
|
<div class="list">
|
|
@@ -71,6 +79,7 @@
|
|
|
<uni-icons @tap="toDel(item,gg.sid)" class="icon" type="closeempty" size="20"></uni-icons>
|
|
|
</div>
|
|
|
<div class="add" @tap="toAdd(item)">+新增一行</div>
|
|
|
+ <div v-if="errors[item.problem]" class="error-message">{{ errors[item.problem] }}</div>
|
|
|
</div>
|
|
|
<div class="type" v-if="item.type =='8'">
|
|
|
<image class="image" v-if="item.answer&&item.answer.length>0" v-for="(as, img) in item.answer"
|
|
@@ -160,6 +169,7 @@
|
|
|
}]
|
|
|
},
|
|
|
},
|
|
|
+ errors: {}
|
|
|
}
|
|
|
},
|
|
|
onLoad: async function(e) {
|
|
@@ -304,67 +314,98 @@
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ // 自定义的验证函数
|
|
|
+ validateObject(arr) {
|
|
|
+ const errors = {};
|
|
|
+ for (const obj of arr) {
|
|
|
+ if (obj.is_must == '0') {
|
|
|
+ if (!obj.reply || obj.reply.length == 0) {
|
|
|
+ if (obj.type == '0' || obj.type == '1' || obj.type == '1') errors[obj.problem] =
|
|
|
+ `请选择${obj.problem}`
|
|
|
+ else if (obj.type == '6') errors[obj.problem] = `请上传${obj.problem}`
|
|
|
+ else errors[obj.problem] = `请填写${obj.problem}`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 如果有错误,返回错误对象
|
|
|
+ if (Object.keys(errors).length > 0) {
|
|
|
+ return errors
|
|
|
+ }
|
|
|
+ // 如果没有错误,返回null或undefined
|
|
|
+ return null
|
|
|
+ },
|
|
|
async toSave() {
|
|
|
const that = this;
|
|
|
- let data = {
|
|
|
- match_id: that.info.id,
|
|
|
- info: that.investigate
|
|
|
- }
|
|
|
- if (that.user.id) {
|
|
|
- data.user_id = that.user.id
|
|
|
- const res = await that.$api(`/matchReg`, 'POST', data)
|
|
|
- if (res.errcode == '0') {
|
|
|
- uni.showModal({
|
|
|
- content: "调查问卷填写成功!",
|
|
|
- showCancel: false
|
|
|
- });
|
|
|
- uni.navigateBack({
|
|
|
- delta: 1
|
|
|
- })
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: res.errmsg,
|
|
|
- icon: 'none'
|
|
|
- });
|
|
|
+ const errorsInfo = await that.validateObject(that.investigate)
|
|
|
+ // 检查是否有错误
|
|
|
+ if (errorsInfo) {
|
|
|
+ that.$set(that, `errors`, errorsInfo)
|
|
|
+ // 遍历错误对象并显示错误信息
|
|
|
+ for (const key in errorsInfo) {
|
|
|
+ if (errorsInfo.hasOwnProperty(key)) {
|
|
|
+ console.error(`${key} 错误: ${errorsInfo[key]}`);
|
|
|
+ }
|
|
|
}
|
|
|
} else {
|
|
|
- that.$refs.baseForm.validate().then(async ass => {
|
|
|
- if (ass.password == ass.ispassword) {
|
|
|
- ass.openid = that.openid
|
|
|
- data.user = {
|
|
|
- nick_name: ass.account,
|
|
|
- ...that.form,
|
|
|
- ...ass
|
|
|
- }
|
|
|
- const res = await that.$api(`/matchReg`, 'POST', data)
|
|
|
- if (res.errcode == '0') {
|
|
|
- uni.showModal({
|
|
|
- content: "调查问卷填写成功!",
|
|
|
- showCancel: false
|
|
|
- });
|
|
|
- uni.navigateBack({
|
|
|
- delta: 1
|
|
|
- })
|
|
|
+ that.$set(that, `errors`, {})
|
|
|
+ let data = {
|
|
|
+ match_id: that.info.id,
|
|
|
+ info: that.investigate
|
|
|
+ }
|
|
|
+ if (that.user.id) {
|
|
|
+ data.user_id = that.user.id
|
|
|
+ const res = await that.$api(`/matchReg`, 'POST', data)
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ uni.showModal({
|
|
|
+ content: "调查问卷填写成功!",
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ that.$refs.baseForm.validate().then(async ass => {
|
|
|
+ if (ass.password == ass.ispassword) {
|
|
|
+ ass.openid = that.openid
|
|
|
+ data.user = {
|
|
|
+ nick_name: ass.account,
|
|
|
+ ...that.form,
|
|
|
+ ...ass
|
|
|
+ }
|
|
|
+ const res = await that.$api(`/matchReg`, 'POST', data)
|
|
|
+ if (res.errcode == '0') {
|
|
|
+ uni.showModal({
|
|
|
+ content: "调查问卷填写成功!",
|
|
|
+ showCancel: false
|
|
|
+ });
|
|
|
+ uni.navigateBack({
|
|
|
+ delta: 1
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ uni.showToast({
|
|
|
+ title: res.errmsg,
|
|
|
+ icon: 'none'
|
|
|
+ });
|
|
|
+ }
|
|
|
} else {
|
|
|
uni.showToast({
|
|
|
- title: res.errmsg,
|
|
|
- icon: 'none'
|
|
|
+ title: `密码不一致`,
|
|
|
+ icon: 'error'
|
|
|
});
|
|
|
+ return;
|
|
|
}
|
|
|
- } else {
|
|
|
- uni.showToast({
|
|
|
- title: `密码不一致`,
|
|
|
- icon: 'error'
|
|
|
- });
|
|
|
+ }).catch(err => {
|
|
|
+ console.log('err', err);
|
|
|
return;
|
|
|
- }
|
|
|
- }).catch(err => {
|
|
|
- console.log('err', err);
|
|
|
- return;
|
|
|
- })
|
|
|
+ })
|
|
|
+ }
|
|
|
}
|
|
|
- console.log(data, user);
|
|
|
-
|
|
|
},
|
|
|
}
|
|
|
}
|
|
@@ -433,6 +474,13 @@
|
|
|
width: 96%;
|
|
|
}
|
|
|
|
|
|
+ .error-message {
|
|
|
+ text-align: left;
|
|
|
+ margin: 5px 0 0 8px;
|
|
|
+ color: var(--fF0Color);
|
|
|
+ font-size: var(--font12Size);
|
|
|
+ }
|
|
|
+
|
|
|
.remark {
|
|
|
margin: 2vw;
|
|
|
font-size: 12px;
|