|
@@ -36,7 +36,7 @@ class ReportDetail extends Component {
|
|
|
{ title: "项目风险分析和对策", key: "RISK", keywords: ['风险分析', '风险对策'] },
|
|
|
{ title: "自定义章节", key: "USER_DEFINED", keywords: [] },
|
|
|
],
|
|
|
- chapterData: [],
|
|
|
+ chapters: [],
|
|
|
aeList: [],
|
|
|
|
|
|
name: "",
|
|
@@ -45,7 +45,7 @@ class ReportDetail extends Component {
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
- // this.getData()
|
|
|
+ this.getData()
|
|
|
this.getQuery()
|
|
|
}
|
|
|
|
|
@@ -58,14 +58,16 @@ class ReportDetail extends Component {
|
|
|
this.props.reportDetail(payload).then((data) => {
|
|
|
this.setState({
|
|
|
loading: false,
|
|
|
- data: data.data,
|
|
|
+ data: data,
|
|
|
+ metadata: data.metadata,
|
|
|
+ chapters: data.chapters,
|
|
|
})
|
|
|
}).catch(() => {
|
|
|
this.setState({ loading: false })
|
|
|
})
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ // 获取企业列表
|
|
|
getQuery() {
|
|
|
let payload = {
|
|
|
name: "",
|
|
@@ -73,13 +75,39 @@ class ReportDetail extends Component {
|
|
|
}
|
|
|
this.props.query(payload).then((data) => {
|
|
|
this.setState({
|
|
|
- aeList: data.data,
|
|
|
+ aeList: data,
|
|
|
})
|
|
|
}).catch(() => {
|
|
|
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+ // Al生成
|
|
|
+ getGenerate(title, i) {
|
|
|
+ const { data } = this.state
|
|
|
+ let payload = {
|
|
|
+ chapterTitle: title,
|
|
|
+ keywords: data.keywords,
|
|
|
+ projectName: data.reportName,
|
|
|
+ }
|
|
|
+ Taro.showLoading({
|
|
|
+ title: 'AI正在撰写章节内容,请稍等…',
|
|
|
+ mask: true,
|
|
|
+ })
|
|
|
+ this.props.generate(payload).then((res) => {
|
|
|
+ Taro.hideLoading()
|
|
|
+ const chaplist = this.state.data.chapters
|
|
|
+ chaplist.forEach(function (item, index) {
|
|
|
+ if (item.title == title) {
|
|
|
+ item.content = res
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setState({
|
|
|
+ chapters: chaplist
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+ Taro.hideLoading()
|
|
|
+ })
|
|
|
+ }
|
|
|
// 添加新项
|
|
|
onChange = e => {
|
|
|
this.setState({
|
|
@@ -88,40 +116,76 @@ class ReportDetail extends Component {
|
|
|
visible: "add"
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+ // 阿拉伯数字转中文
|
|
|
+ numberToChinese(num) {
|
|
|
+ var arr1 = new Array('零', '一', '二', '三', '四', '五', '六', '七', '八', '九');
|
|
|
+ var arr2 = new Array('', '十', '百', '千', '万', '十', '百', '千', '亿', '十', '百', '千', '万', '十', '百', '千', '亿');//可继续追加更高位转换值
|
|
|
+ if (!num || isNaN(num)) {
|
|
|
+ return "零";
|
|
|
+ }
|
|
|
+ var english = num.toString().split("");
|
|
|
+ var result = "";
|
|
|
+ for (var i = 0; i < english.length; i++) {
|
|
|
+ var des_i = english.length - 1 - i;//倒序排列设值
|
|
|
+ result = arr2[i] + result;
|
|
|
+ var arr1_index = english[des_i];
|
|
|
+ result = arr1[arr1_index] + result;
|
|
|
+ }
|
|
|
+ //将【零千、零百】换成【零】 【十零】换成【十】
|
|
|
+ result = result.replace(/零(千|百|十)/g, '零').replace(/十零/g, '十');
|
|
|
+ //合并中间多个零为一个零
|
|
|
+ result = result.replace(/零+/g, '零');
|
|
|
+ //将【零亿】换成【亿】【零万】换成【万】
|
|
|
+ result = result.replace(/零亿/g, '亿').replace(/零万/g, '万');
|
|
|
+ //将【亿万】换成【亿】
|
|
|
+ result = result.replace(/亿万/g, '亿');
|
|
|
+ //移除末尾的零
|
|
|
+ result = result.replace(/零+$/, '');
|
|
|
+ //将【零一十】换成【零十】
|
|
|
+ //result = result.replace(/零一十/g, '零十');//貌似正规读法是零一十
|
|
|
+ //将【一十】换成【十】
|
|
|
+ result = result.replace(/^一十/g, '十');
|
|
|
+ return result;
|
|
|
+ }
|
|
|
+ // 字符串拼接
|
|
|
+ getTitleWithChineseNum(index, title) {
|
|
|
+ return this.numberToChinese(index + 1) + '、' + title
|
|
|
+ }
|
|
|
+ // 章节添加
|
|
|
onChapterChange = e => {
|
|
|
- let list = this.state.chapterData
|
|
|
- list.push(this.state.chapterType[e.detail.value])
|
|
|
+ let list = this.state.chapters
|
|
|
+ let obj = this.state.chapterType[e.detail.value]
|
|
|
+ let data = {
|
|
|
+ chapterType: obj.key,
|
|
|
+ content: "",
|
|
|
+ fullTitle: this.getTitleWithChineseNum(list.length, obj.title),
|
|
|
+ keywords: obj.keywords,
|
|
|
+ title: obj.title,
|
|
|
+ }
|
|
|
+ list.push(data)
|
|
|
this.setState({
|
|
|
- chapterData: list
|
|
|
+ chapters: list
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+ // 选中关联企业
|
|
|
onAeChange = e => {
|
|
|
- console.log("-----", e.detail.value)
|
|
|
- }
|
|
|
-
|
|
|
- onCancel = () => {
|
|
|
+ const { aeList } = this.state
|
|
|
+ let obj = aeList[e.detail.value]
|
|
|
+ let list = this.state.data
|
|
|
+ list.companyName = obj.name
|
|
|
+ list.companyId = obj.id
|
|
|
this.setState({
|
|
|
- inputName: undefined,
|
|
|
- inputText: undefined,
|
|
|
- dateSel: undefined,
|
|
|
- dataStart: undefined,
|
|
|
- dataEnd: undefined,
|
|
|
- indx: undefined,
|
|
|
- type: "",
|
|
|
- visible: "",
|
|
|
+ data: list,
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
+ // 企业添加
|
|
|
onAeCancel = () => {
|
|
|
this.setState({
|
|
|
name: "",
|
|
|
newvb: false,
|
|
|
})
|
|
|
}
|
|
|
-
|
|
|
+ // 企业添加
|
|
|
onAeOk = () => {
|
|
|
if (!this.state.name) {
|
|
|
Taro.showToast({
|
|
@@ -134,8 +198,11 @@ class ReportDetail extends Component {
|
|
|
name: this.state.name,
|
|
|
}
|
|
|
this.props.company(payload).then((data) => {
|
|
|
+ let obj = this.state.data
|
|
|
+ obj.companyName = data.name
|
|
|
+ obj.companyId = data.id
|
|
|
this.setState({
|
|
|
- name: data.data.name,
|
|
|
+ data: obj,
|
|
|
newvb: false,
|
|
|
})
|
|
|
}).catch(() => {
|
|
@@ -143,7 +210,20 @@ class ReportDetail extends Component {
|
|
|
})
|
|
|
|
|
|
}
|
|
|
-
|
|
|
+ // 添加新项弹窗
|
|
|
+ onCancel = () => {
|
|
|
+ this.setState({
|
|
|
+ inputName: undefined,
|
|
|
+ inputText: undefined,
|
|
|
+ dateSel: undefined,
|
|
|
+ dataStart: undefined,
|
|
|
+ dataEnd: undefined,
|
|
|
+ indx: undefined,
|
|
|
+ type: "",
|
|
|
+ visible: "",
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 添加新项弹窗
|
|
|
onOk = () => {
|
|
|
const { visible, metadata, inputName, inputText, type, indx, dateSel, dataStart, dataEnd } = this.state
|
|
|
// if (visible == "add") {
|
|
@@ -205,6 +285,84 @@ class ReportDetail extends Component {
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
+ // 修改章节名
|
|
|
+ onChapTitle = (i, e) => {
|
|
|
+ const data = this.state.chapters
|
|
|
+ data.forEach(function (item, index) {
|
|
|
+ if (index == i) {
|
|
|
+ item.title = e.detail.value
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setState({
|
|
|
+ chapters: data
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 修改章节关键词
|
|
|
+ onChapKeywords = (i, e) => {
|
|
|
+ const data = this.state.chapters
|
|
|
+ data.forEach(function (item, index) {
|
|
|
+ if (index == i) {
|
|
|
+ let val = e.detail.value.replace(/[\uff0c]/g, ",")
|
|
|
+ item.keywords = val.split(",")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ this.setState({
|
|
|
+ chapters: data
|
|
|
+ })
|
|
|
+ }
|
|
|
+ // 保存
|
|
|
+ onSubsmit = () => {
|
|
|
+ const { data, metadata, chapters } = this.state
|
|
|
+ if (!data.companyId) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请填写关联企业!",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!data.name) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请填写报告类型!",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!data.reportName) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请填写项目名称!",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!data.supervisor) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请填写负责人!",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if (!data.keywords) {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "请填写关键词!",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ data.metadata = metadata
|
|
|
+ data.chapters = chapters
|
|
|
+
|
|
|
+ // console.log("------", data)
|
|
|
+ // return
|
|
|
+ let payload = data
|
|
|
+ this.props.report(payload).then((data) => {
|
|
|
+ Taro.showToast({
|
|
|
+ title: "保存成功",
|
|
|
+ icon: 'none'
|
|
|
+ })
|
|
|
+ }).catch(() => {
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
|
|
|
|
|
|
render() {
|
|
@@ -212,7 +370,7 @@ class ReportDetail extends Component {
|
|
|
// return <Loading />
|
|
|
// }
|
|
|
|
|
|
- const { data, visible, metadata, type, chapterType, chapterData, aeList } = this.state
|
|
|
+ const { data, visible, metadata, type, chapterType, chapters, aeList } = this.state
|
|
|
return (
|
|
|
<View className='home'>
|
|
|
<View className='home-item'>
|
|
@@ -234,6 +392,13 @@ class ReportDetail extends Component {
|
|
|
value={data.name}
|
|
|
className='home-item-val'
|
|
|
placeholder='请输入报告类型'
|
|
|
+ onChange={e => {
|
|
|
+ let obj = data
|
|
|
+ obj.name = e.detail.value
|
|
|
+ this.setState({
|
|
|
+ data: obj,
|
|
|
+ })
|
|
|
+ }}
|
|
|
/>
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
@@ -242,6 +407,13 @@ class ReportDetail extends Component {
|
|
|
value={data.reportName}
|
|
|
className='home-item-val'
|
|
|
placeholder='请输入项目名称'
|
|
|
+ onChange={e => {
|
|
|
+ let obj = data
|
|
|
+ obj.reportName = e.detail.value
|
|
|
+ this.setState({
|
|
|
+ data: obj,
|
|
|
+ })
|
|
|
+ }}
|
|
|
/>
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
@@ -250,11 +422,28 @@ class ReportDetail extends Component {
|
|
|
value={data.supervisor}
|
|
|
className='home-item-val'
|
|
|
placeholder='请输入项目负责人'
|
|
|
+ onChange={e => {
|
|
|
+ let obj = data
|
|
|
+ obj.supervisor = e.detail.value
|
|
|
+ this.setState({
|
|
|
+ data: obj,
|
|
|
+ })
|
|
|
+ }}
|
|
|
/>
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
|
<View className='home-item-tit'>企业LOGO</View>
|
|
|
- <ImagePicker id={data.id} />
|
|
|
+ <ImagePicker
|
|
|
+ id={data.id}
|
|
|
+ urls={data.logoPath}
|
|
|
+ onChange={(path) => {
|
|
|
+ let obj = data
|
|
|
+ obj.logoPath = path
|
|
|
+ this.setState({
|
|
|
+ data: obj,
|
|
|
+ })
|
|
|
+ }}
|
|
|
+ />
|
|
|
</View>
|
|
|
<View className='home-item'>
|
|
|
<View className='home-item-tit'>关键词</View>
|
|
@@ -262,6 +451,13 @@ class ReportDetail extends Component {
|
|
|
value={data.keywords}
|
|
|
className='home-item-val'
|
|
|
placeholder='请输入关键词'
|
|
|
+ onChange={e => {
|
|
|
+ let obj = data
|
|
|
+ obj.keywords = e.detail.value
|
|
|
+ this.setState({
|
|
|
+ data: obj,
|
|
|
+ })
|
|
|
+ }}
|
|
|
/>
|
|
|
</View>
|
|
|
{
|
|
@@ -294,32 +490,41 @@ class ReportDetail extends Component {
|
|
|
<Button>+添加新项</Button>
|
|
|
</Picker>
|
|
|
</View>
|
|
|
-
|
|
|
<View className='home-line' />
|
|
|
-
|
|
|
{
|
|
|
- chapterData.map((item, index) =>
|
|
|
+ chapters.map((item, index) =>
|
|
|
<View className='home-item' key={index}>
|
|
|
<Input
|
|
|
value={item.title}
|
|
|
className='home-item-tit'
|
|
|
+ onChange={(e) => {
|
|
|
+ this.onChapTitle(index, e)
|
|
|
+ }}
|
|
|
/>
|
|
|
<View className='home-item-text'>
|
|
|
<View>章节关键词:</View>
|
|
|
<Input
|
|
|
- value={item.keywords.toString()}
|
|
|
+ value={item.keywords.toString().replace(/,/g, ",")}
|
|
|
className='home-item-text-val'
|
|
|
placeholder='输入逗号分割'
|
|
|
+ onChange={(e) => {
|
|
|
+ this.onChapKeywords(index, e)
|
|
|
+ }}
|
|
|
/>
|
|
|
</View>
|
|
|
- <View className='home-item-editor' contenteditable="true">请填写内容...</View>
|
|
|
+ <View className='home-item-editor' contenteditable="true">{item.content || "请填写内容..."}</View>
|
|
|
<View className='home-item-bottom'>
|
|
|
- <Button size='mini' type='primary'>Al生成</Button>
|
|
|
+ <Button
|
|
|
+ size='mini'
|
|
|
+ type='primary'
|
|
|
+ onClick={() => {
|
|
|
+ this.getGenerate(item.title, index)
|
|
|
+ }}
|
|
|
+ >Al生成</Button>
|
|
|
</View>
|
|
|
</View>
|
|
|
)
|
|
|
}
|
|
|
-
|
|
|
<View className='home-item'>
|
|
|
<Picker mode='selector' range={chapterType} rangeKey="title"
|
|
|
onChange={this.onChapterChange}
|
|
@@ -327,12 +532,9 @@ class ReportDetail extends Component {
|
|
|
<Button>+添加章节</Button>
|
|
|
</Picker>
|
|
|
</View>
|
|
|
-
|
|
|
-
|
|
|
<View className='home-item' style={{ marginTop: 60 }}>
|
|
|
- <Button type='primary'>保存</Button>
|
|
|
+ <Button type='primary' onClick={this.onSubsmit}>保存</Button>
|
|
|
</View>
|
|
|
-
|
|
|
{/* 新增项 */}
|
|
|
{visible != "" &&
|
|
|
<View className='mask'>
|
|
@@ -397,9 +599,7 @@ class ReportDetail extends Component {
|
|
|
</View>
|
|
|
</View>
|
|
|
</View>}
|
|
|
-
|
|
|
- {
|
|
|
- this.state.newvb &&
|
|
|
+ {this.state.newvb &&
|
|
|
<View className='mask'>
|
|
|
<View className='count'>
|
|
|
<View className='title'>新增企业名称</View>
|
|
@@ -418,9 +618,7 @@ class ReportDetail extends Component {
|
|
|
>确认</Button>
|
|
|
</View>
|
|
|
</View>
|
|
|
- </View>
|
|
|
- }
|
|
|
-
|
|
|
+ </View>}
|
|
|
</View>
|
|
|
)
|
|
|
}
|