ReedawFoodApp/element/manuallyAdd/record.vue

376 lines
9.8 KiB
Vue

<template>
<view class="wrapper" v-if="isRecord">
<view class="bg" @click="onTap">
<view class="edit" @click.stop>
<view class="title">手动记录</view>
<view class="editem">
<view class="left">日期</view>
<view class="right">
<picker mode="date" :end="endDate" @change="changeLog" :fields="fields">
<view class="uni-input">{{regTime?regTime:'请选择'}}</view>
<icon class="iconfont icon-arrow-down-bold"></icon>
</picker>
</view>
</view>
<view v-if="rtype!=8&&rtype!=2">
<!-- 项目 -->
<view class="editem" v-if="info&&info.list.length">
<view class="left">项目</view>
<view class="right">
<picker :range="info.list" range-key="name" :value="lableTndex" @change="bindLableChange">
<view class="uni-input">{{name?name:'请选择'}}</view>
<icon class="iconfont icon-arrow-down-bold"></icon>
</picker>
</view>
</view>
<!-- 项目时长类型 -->
<view class="editem" v-if="info&&info.list.length&&listType">
<view class="name">{{describe}}</view>
<view class="right" v-if="listType==4">
<picker mode="multiSelector" :range="timeList" :value="timesTndex" @change="bindTimeChange">
<view class="size16">{{time_m?time_m+':':'请选择'}}{{time_s?time_s:''}}</view>
</picker>
<uni-icons type="bottom" class="ml-15 c666"></uni-icons>
</view>
<view class="right" v-if="listType!=4">
<input :type="listType==1?'number':'digit'" v-model="number" placeholder="请输入">
{{unit}}
</view>
</view>
<view class="editem" v-if="info&&info.time">
<view class="name">时长</view>
<view class="right">
<picker mode="multiSelector" :range="timeList" :value="timesTndex" @change="bindTimeChange">
<view class="size16">{{time_m?time_m+':':'请选择'}}{{time_s?time_s:''}}</view>
</picker>
<uni-icons type="bottom" class="ml-15 c666"></uni-icons>
</view>
</view>
<view class="editem" v-if="info&&info.number">
<view class="name">个数</view>
<view class="right">
<input type="number" v-model="number" placeholder="请输入">个
</view>
</view>
</view>
<!-- 身体 -->
<view class="" v-if="rtype==2">
<view class="editem" v-if="info&&info.height">
<view class="name">身高</view>
<view class="right">
<input type="digit" v-model="height" placeholder="请输入身高" />cm
</view>
</view>
<view class="editem" v-if="info&&info.weight">
<view class="name">体重</view>
<view class="right">
<input type="digit" v-model="weight" placeholder="请输入体重">kg
</view>
</view>
<view class="editem" v-if="userInfo.stage=='婴儿'">
<view class="left">头围</view>
<view class="right">
<input v-model="head" type="digit" placeholder="请输入" />cm
</view>
</view>
</view>
<!-- 肺活量 -->
<view class="" v-if="rtype==8">
<view class="editem">
<view class="name">第一次</view>
<view class="right">
<input type="digit" v-model="number1" placeholder="请输入">ml
</view>
</view>
<view class="editem">
<view class="name">第二次</view>
<view class="right">
<input type="digit" v-model="number2" placeholder="请输入">ml
</view>
</view>
<view class="editem">
<view class="name">第三次</view>
<view class="right">
<input type="digit" v-model="number3" placeholder="请输入">ml
</view>
</view>
</view>
<view class="btn close" @click="onTap()">取消</view>
<view class="btn" @click="handleTarget">确定</view>
</view>
</view>
</view>
</template>
<script>
import {
mapState
} from "vuex";
export default {
props: {
rtype: null,
},
data() {
return {
name: "",
number: '',
regTime: "",
number1: '',
number2: "",
number3: "",
time_m: "",
time_s: "",
weight: "",
height: '',
timeList: [],
lableTndex: 0,
timesTndex: [1, 0],
listType: null,
describe: "",
unit: "",
fields: "",
head: ""
}
},
computed: {
...mapState(["user", "isRecord", "PublicRecord", "labelList"]),
userInfo() {
return this.user
},
info() {
let that = this
let info = {
height: false,
weight: false,
number: false,
time: false,
list: []
}
if (that.PublicRecord.length) {
that.PublicRecord.forEach(ite => {
if (ite.id == that.rtype) {
info = ite
}
})
}
return that.PublicRecord.length ? info : null
},
endDate() {
return this.$tools.getDate("start")
},
startDate() {
return this.$tools.GetDateStr(-90);
},
},
mounted() {
let that = this
that.timeList = that.$tools.gethms()
// #ifdef APP-PLUS
that.fields = "time"
// #endif
// #ifndef APP-PLUS
that.fields = "day"
// #endif
},
methods: {
// 手动记录
handleTarget() {
let that = this
if (that.rtype == 2) {
that.handleinsertmeasure()
} else if (that.rtype == 6) {
that.handleskipmeasure()
} else if (that.rtype == 8) {
that.handleLungmeasure()
} else {
that.handlepublicmeasure()
}
},
// 通用
handlepublicmeasure() {
let that = this
if (!that.name) {
that.$tools.msg("请选择测量项目")
return
}
if (!that.regTime) {
that.$tools.msg("请选择日期")
return
}
if (that.listType == 4 && (!that.time_m || !that.time_s)) {
that.$tools.msg("请输入时长")
return
}
if (that.listType != 4 && !that.number) {
let msg = that.listType == 1 ? '请输入个数' : '请输入时长'
that.$tools.msg(msg)
return
}
let time_m = that.time_m + ':' + that.time_s
that.$model.getpublicmeasure({
acd_id: that.rtype,
name: that.name,
record_time: that.regTime,
data: that.listType == 4 ? time_m : that.number,
aud_id: uni.getStorageSync('userid')
}).then(res => {
if (res.code != 0) return
that.$tools.msg(res.msg)
that.$store.dispatch("getUserInfo", {
aud_id: uni.getStorageSync('userid'),
})
that.$store.dispatch("getPublicContent", {
acd_id: that.rtype,
aud_id: uni.getStorageSync('userid')
})
that.onTap()
})
},
// 肺活量
handleLungmeasure() {
let that = this
if (!that.regTime) {
that.$tools.msg("请选择测量日期")
return
}
if (!that.number1) {
that.$tools.msg("请输入第一次吸气值")
return
}
if (!that.number2) {
that.$tools.msg("请输入第二次吸气值")
return
}
if (!that.number3) {
that.$tools.msg("请输入第三次吸气值")
return
}
that.$model.getLungmeasure({
aud_id: uni.getStorageSync('userid'),
time: that.regTime,
one: that.number1,
two: that.number2,
three: that.number3
}).then(res => {
if (res.code != 0) return
that.$tools.msg(res.msg)
that.$store.dispatch("getLungResult", {
aud_id: uni.getStorageSync('userid')
})
that.onTap()
})
},
// 跳绳
handleskipmeasure() {
let that = this
if (!that.regTime) {
that.$tools.msg("请选择测量日期")
return
}
if (!that.number) {
that.$tools.msg("请输入跳绳个数")
return
}
that.$model.getskipmeasure({
aud_id: uni.getStorageSync('userid'),
num: that.number,
r_time: that.regTime,
time_m: that.time_m,
time_s: that.time_s,
type: "free",
}).then(res => {
if (res.code != 0) return
that.$tools.msg(res.msg)
that.$store.dispatch("getSkipResult", {
aud_id: uni.getStorageSync('userid'),
})
that.onTap()
})
},
// 身体
handleinsertmeasure() {
let that = this
if (!that.regTime) {
that.$tools.msg("请选择测量日期")
return
}
if (!that.height) {
that.$tools.msg("请输入测量身高")
return
}
if (!that.weight) {
that.$tools.msg("请输入测量体重")
return
}
that.$model.getinsertmeasure({
aud_id: uni.getStorageSync('userid'),
time: that.regTime,
weight: that.weight,
height: that.height,
head_data: that.head ? that.head : 0
}).then(res => {
if (res.code != 0) return
that.$tools.msg(res.msg)
that.$store.dispatch("getResult", {
aud_id: uni.getStorageSync('userid')
})
that.$store.dispatch("getUserInfo", {
aud_id: uni.getStorageSync('userid')
})
that.onTap()
})
},
bindTimeChange(e) {
let that = this
let m = e.target.value[0]
let s = e.target.value[1]
that.timesTndex = e.target.value
let time_m = Number(that.timeList[0][m].substring(0, 2)) * 60
let time_s = Number(that.timeList[1][s].substring(0, 2))
that.time_m = that.timeList[0][m].substring(0, 2)
that.time_s = that.timeList[1][s].substring(0, 2)
},
bindLableChange(e) {
console.log("e", e)
this.name = this.info.list[e.detail.value].name
this.listType = this.info.list[e.detail.value].type
this.describe = this.info.list[e.detail.value].describe
this.unit = this.info.list[e.detail.value].unit
},
changeLog(e) {
this.regTime = e.detail.value
},
onTap() {
let that = this
that.name = ""
that.weight = ""
that.height = ""
that.regTime = ""
that.number1 = ""
that.number2 = ""
that.number3 = ""
that.number = ''
that.time_m = ""
that.time_s = ""
that.lableTndex = 0
that.timesTndex = [1, 0]
that.listType = null
that.$store.commit("changeRecord", false);
},
}
}
</script>
<style scoped lang="scss">
.btn {
width: 40%;
float: right;
margin-top: 15px;
background: $maincolor !important;
}
.close {
background: #dfdfdf !important;
float: left;
}
</style>