Files
dvcp_v2_wxcp_app/src/project/caw/AppCountryAlbum/WatermarkConfig.vue
2022-08-08 10:33:18 +08:00

213 lines
5.6 KiB
Vue

<template>
<div class="AttendanceFiexdTime">
<div class="form-group">
<div class="form-group__item" @click.stop="onClick(item.editEnable)" hover-class="bg-hover" v-if="item.fieldType" v-for="(item, index) in config" :key="index">
<div class="left">
<switch @click.stop="onSwitchClick(item.editEnable)" :color="item.editEnable === '0' ? '#B7DBFD' : '#1088F9'" :checked="item.status === '1'" :disabled="item.editEnable === '0'" @change="e => onChange(e, index)" />
</div>
<div class="right" @click="toInput(item)" v-if="['6', '7'].indexOf(item.fieldType) === -1">
<div class="right-left">
<h2>{{ mapFieldLable(item.type) }}</h2>
<p :style="{color: item.defaultValue ? '#333' : '#999'}">{{ item.defaultValue || mapType(item.fieldType) }}</p>
</div>
<u-icon name="arrow-right" color="#E1E2E3" v-if="item.editEnable !== '0'"></u-icon>
</div>
<picker mode="date" :disabled="item.editEnable === '0'" style="flex: 1;" v-if="item.fieldType === '7'" :value="item.defaultValue" @change="e => onDateChange(e, index)">
<div class="right">
<div class="right-left">
<h2>{{ mapFieldLable(item.type) }}</h2>
<p>{{ item.defaultValue || '' }}</p>
</div>
<u-icon name="arrow-right" color="#E1E2E3" v-if="item.editEnable !== '0'"></u-icon>
</div>
</picker>
<picker mode="time" style="flex: 1;" :disabled="item.editEnable === '0'" v-if="item.fieldType === '6'" :value="item.defaultValue" @change="e => onDateChange(e, index)">
<div class="right">
<div class="right-left">
<h2>{{ mapFieldLable(item.type) }}</h2>
<p>{{ item.defaultValue || '' }}</p>
</div>
<u-icon name="arrow-right" color="#E1E2E3" v-if="item.editEnable !== '0'"></u-icon>
</div>
</picker>
</div>
</div>
<div class="form-btn" hover-class="text-hover" @click="save">保存</div>
</div>
</template>
<script>
import { mapFieldLable } from './config'
export default {
appName: '表单配置',
data () {
return {
config: [],
mapFieldLable
}
},
onLoad () {
this.config = uni.getStorageSync('waterConfig')
uni.$on('filedChange', e => {
this.config.forEach((v, index) => {
if (v.type === e.type) {
this.$set(this.config[index], 'defaultValue', e.defaultValue)
}
})
})
},
methods: {
linkTo (url) {
uni.navigateTo({
url
})
},
mapType (type) {
return {
'0': '请输入内容',
'1': '请输入内容',
'2': '请选择天气',
'3': '请选择地址',
'4': '请选择定位',
'5': '请选择经纬度',
'6': '请选择时间',
'7': '请选择日期'
}[type]
},
onDateChange (e, index) {
this.$set(this.config[index], 'defaultValue', e.detail.value)
},
onChange (e, index) {
this.$set(this.config[index], 'status', e.detail.value ? '1' : '0')
},
onSwitchClick (status) {
if (status === '0') {
return this.$u.toast('该选项不允许关闭')
}
},
onClick (status) {
if (status === '0') {
return this.$u.toast('该选项不允许修改内容')
}
},
toInput (e) {
if (e.editEnable === '0') return
if (e.fieldType === '2') return
if (e.fieldType === '3') {
uni.setStorageSync('formConfig', e)
this.linkTo('./ChooseAddess?type=address')
return false
}
uni.setStorageSync('formConfig', e)
this.linkTo('./Form')
},
save () {
for (let i = 0; i < this.config.length; i ++) {
if (['2', '3', '4', '5'].indexOf(this.config[i].fieldType) === -1 && this.config[i].fieldType && !this.config[i].defaultValue && this.config[i].status === '1') {
return this.$u.toast(`请输入${this.mapFieldLable(this.config[i].type)}`)
}
}
uni.$emit('change', this.config)
uni.navigateBack({
delta: 1
})
}
}
}
</script>
<style lang="scss" scoped>
.AttendanceFiexdTime {
padding-bottom: 130px;
* {
line-height: 1;
box-sizing: border-box;
}
.form-btn {
position: fixed;
bottom: 0;
left: 0;
z-index: 1;
width: 100%;
height: 112px;
line-height: 112px;
text-align: center;
color: #fff;
font-size: 32px;
background: #1365DD;
&:active {
opacity: 0.8;
}
}
.form-group {
margin-bottom: 16px;
padding: 0 32px;
background: #fff;
.form-group__item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 32rpx 0;
font-size: 32px;
color: #333333;
border-bottom: 1px solid #DDDDDD;
&:last-child {
border: none;
}
.right {
display: flex;
align-items: center;
flex: 1;
margin-left: 36px;
.right-left {
flex: 1;
h2 {
margin-bottom: 12px;
color: #999999;
font-size: 28px;
}
p {
line-height: 1.3;
font-size: 34px;
color: #333;
}
}
}
.left {
display: flex;
align-items: center;
margin-right: 10px;
}
}
}
}
</style>