|
@@ -48,8 +48,8 @@ class TemplateDetail extends Component {
|
|
|
// 添加新项
|
|
|
onChange = e => {
|
|
|
this.setState({
|
|
|
- selectorChecked: this.state.selector[e.detail.value],
|
|
|
- inputName: e.detail.value == 2 ? "起止时间" : "",
|
|
|
+ type: this.state.selector[e.detail.value].type,
|
|
|
+ inputName: e.detail.value == 2 ? "起止时间" : undefined,
|
|
|
visible: "add"
|
|
|
})
|
|
|
}
|
|
@@ -57,61 +57,72 @@ class TemplateDetail extends Component {
|
|
|
|
|
|
onCancel = () => {
|
|
|
this.setState({
|
|
|
- inputName: "",
|
|
|
- inputText: "",
|
|
|
- dateSel: "",
|
|
|
- dateStart: "",
|
|
|
- dateEnd: "",
|
|
|
+ inputName: undefined,
|
|
|
+ inputText: undefined,
|
|
|
+ dateSel: undefined,
|
|
|
+ dataStart: undefined,
|
|
|
+ dataEnd: undefined,
|
|
|
+ indx: undefined,
|
|
|
+ type: "",
|
|
|
visible: "",
|
|
|
})
|
|
|
}
|
|
|
|
|
|
onOk = () => {
|
|
|
- const { visible, metadata, inputName, inputText, selectorChecked, dateSel, dataStart, dataEnd } = this.state
|
|
|
- if (visible == "add") {
|
|
|
- let list = []
|
|
|
- if (!inputName) {
|
|
|
+ const { visible, metadata, inputName, inputText, type, indx, dateSel, dataStart, dataEnd } = this.state
|
|
|
+ // if (visible == "add") {
|
|
|
+ let list = []
|
|
|
+ if (!inputName) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请输入字段名称",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (type == "text") {
|
|
|
+ if (!inputText) {
|
|
|
Taro.showToast({
|
|
|
- title: "请输入字段名称",
|
|
|
+ title: "请输入字段值",
|
|
|
icon: 'none'
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- if (selectorChecked.type == "text") {
|
|
|
- if (!inputText) {
|
|
|
- Taro.showToast({
|
|
|
- title: "请输入字段值",
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- list.push({ name: inputName, value: inputText, type: selectorChecked.type })
|
|
|
- } else if (selectorChecked.type == "date") {
|
|
|
- if (!dateSel) {
|
|
|
- Taro.showToast({
|
|
|
- title: "请选择日期",
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- list.push({ name: inputName, value: dateSel, type: selectorChecked.type })
|
|
|
- } else if (selectorChecked.type == "dateRange") {
|
|
|
- if (!dataStart) {
|
|
|
- Taro.showToast({
|
|
|
- title: "请选择开始日期",
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- if (!dataEnd) {
|
|
|
- Taro.showToast({
|
|
|
- title: "请选择结束日期",
|
|
|
- icon: 'none'
|
|
|
- })
|
|
|
- return
|
|
|
- }
|
|
|
- list.push({ name: inputName, value: dataStart + " " + dataEnd, type: selectorChecked.type })
|
|
|
+ list.push({ name: inputName, value: inputText, type: type })
|
|
|
+ } else if (type == "date") {
|
|
|
+ if (!dateSel) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请选择日期",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
}
|
|
|
+ list.push({ name: inputName, value: dateSel, type: type })
|
|
|
+ } else if (type == "dateRange") {
|
|
|
+ if (!dataStart) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请选择开始日期",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!dataEnd) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请选择结束日期",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ list.push({ name: inputName, value: dataStart + " " + dataEnd, type: type })
|
|
|
+ }
|
|
|
+
|
|
|
+ if (visible == "edit") {
|
|
|
+ let nlist = metadata
|
|
|
+ nlist[indx] = list[0]
|
|
|
+ this.setState({
|
|
|
+ metadata: nlist,
|
|
|
+ visible: "",
|
|
|
+ })
|
|
|
+ } else {
|
|
|
this.setState({
|
|
|
metadata: [...metadata, ...list],
|
|
|
visible: "",
|
|
@@ -125,28 +136,28 @@ class TemplateDetail extends Component {
|
|
|
// return <Loading />
|
|
|
// }
|
|
|
|
|
|
- const { data, visible, metadata, selectorChecked } = this.state
|
|
|
+ const { data, visible, metadata, type } = this.state
|
|
|
return (
|
|
|
<View className='home'>
|
|
|
<View className='home-item'>
|
|
|
- <View className='home-item-tit'>报告模板名称:</View>
|
|
|
+ <View className='home-item-tit'>报告模板名称</View>
|
|
|
<Input
|
|
|
value={data.name}
|
|
|
className='home-item-val'
|
|
|
/>
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
|
- <View className='home-item-tit'>报告模板标签:</View>
|
|
|
+ <View className='home-item-tit'>报告模板标签</View>
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
|
- <View className='home-item-tit'>关联企业:</View>
|
|
|
+ <View className='home-item-tit'>关联企业</View>
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
|
- <View className='home-item-tit'>企业LOGO:</View>
|
|
|
+ <View className='home-item-tit'>企业LOGO</View>
|
|
|
<ImagePicker id={397} />
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
|
- <View className='home-item-tit'>项目名称:</View>
|
|
|
+ <View className='home-item-tit'>项目名称</View>
|
|
|
<Input
|
|
|
value={data.reportName}
|
|
|
className='home-item-val'
|
|
@@ -154,12 +165,24 @@ class TemplateDetail extends Component {
|
|
|
</View>
|
|
|
{
|
|
|
metadata.map((item, index) =>
|
|
|
- <View className='home-item'>
|
|
|
- <View className='home-item-tit'>项目名称:</View>
|
|
|
- <Input
|
|
|
- value={data.reportName}
|
|
|
- className='home-item-val'
|
|
|
- />
|
|
|
+ <View className='home-item' key={index}
|
|
|
+ onClick={() => {
|
|
|
+ this.setState({
|
|
|
+ indx: index,
|
|
|
+ type: item.type,
|
|
|
+ inputName: item.name,
|
|
|
+ visible: "edit",
|
|
|
+ inputText: item.type == "text" ? item.value : undefined,
|
|
|
+ dateSel: item.type == "date" ? item.value : undefined,
|
|
|
+ dataStart: item.type == "dateRange" ? item.value.split(" ")[0] : undefined,
|
|
|
+ dataEnd: item.type == "dateRange" ? item.value.split(" ")[1] : undefined,
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ <View className='home-item-tit'>{item.name}</View>
|
|
|
+ {item.type == "text" && <View className='home-item-val'>{item.value}</View>}
|
|
|
+ {item.type == "date" && <View className='home-item-val'>{item.value}</View>}
|
|
|
+ {item.type == "dateRange" && <View className='home-item-val'>{item.value.replace(" ", " → ")}</View>}
|
|
|
</View>
|
|
|
)
|
|
|
}
|
|
@@ -180,7 +203,7 @@ class TemplateDetail extends Component {
|
|
|
placeholder='字段名称'
|
|
|
onChange={e => { this.setState({ inputName: e.detail.value }) }}
|
|
|
/>
|
|
|
- {selectorChecked.type == "text" &&
|
|
|
+ {type == "text" &&
|
|
|
<Input
|
|
|
value={this.state.inputText}
|
|
|
style={{ marginTop: 15 }}
|
|
@@ -188,7 +211,7 @@ class TemplateDetail extends Component {
|
|
|
placeholder='请输入字段值'
|
|
|
onChange={e => { this.setState({ inputText: e.detail.value }) }}
|
|
|
/>}
|
|
|
- {selectorChecked.type == "date" &&
|
|
|
+ {type == "date" &&
|
|
|
<Picker mode='date' value={this.state.dateSel}
|
|
|
onChange={e => {
|
|
|
this.setState({
|
|
@@ -200,7 +223,7 @@ class TemplateDetail extends Component {
|
|
|
</View>
|
|
|
</Picker>
|
|
|
}
|
|
|
- {selectorChecked.type == "dateRange" &&
|
|
|
+ {type == "dateRange" &&
|
|
|
<Picker mode='date' value={this.state.dataStart}
|
|
|
onChange={e => {
|
|
|
this.setState({
|
|
@@ -212,7 +235,7 @@ class TemplateDetail extends Component {
|
|
|
</View>
|
|
|
</Picker>
|
|
|
}
|
|
|
- {selectorChecked.type == "dateRange" &&
|
|
|
+ {type == "dateRange" &&
|
|
|
<Picker mode='date' value={this.state.dataEnd}
|
|
|
onChange={e => {
|
|
|
this.setState({
|