importFileDia.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <el-dialog
  3. :visible.sync="show"
  4. :close-on-click-modal="false"
  5. :modal-append-to-body="false"
  6. @close="cancelHandle"
  7. custom-class="knowledge-import-dialog"
  8. top="10vh"
  9. v-dialogDrag
  10. title="事件信息"
  11. width="650px"
  12. >
  13. <el-form
  14. ref="formRef"
  15. hide-required-asterisk
  16. :model="eventForm"
  17. :rules="formRules"
  18. label-width="100px"
  19. >
  20. <el-form-item prop="title" label="标题">
  21. <el-input
  22. v-model="eventForm.title"
  23. placeholder="请输入标题"
  24. style="width:80%"
  25. />
  26. </el-form-item>
  27. <el-form-item prop="classifyId" label="分类">
  28. <el-cascader
  29. :options="classifyOptions"
  30. v-model="eventForm.classifyId"
  31. :props="{
  32. value: 'ClassifyId',
  33. label: 'ClassifyName',
  34. children: 'Child',
  35. emitPath:false
  36. }"
  37. clearable
  38. placeholder="请选择分类"
  39. style="width:80%"
  40. ></el-cascader>
  41. </el-form-item>
  42. <el-form-item prop="source" label="来源">
  43. <el-input
  44. v-model="eventForm.source"
  45. placeholder="请输入来源"
  46. style="width:80%"
  47. clearable
  48. />
  49. </el-form-item>
  50. <el-form-item prop="tagId" label="标签">
  51. <el-select
  52. v-model="eventForm.tagId"
  53. placeholder="请选择标签"
  54. size="medium"
  55. clearable
  56. style="width:80%"
  57. >
  58. <el-option
  59. v-for="item in tagsOptions"
  60. :key="item.TagId"
  61. :label="item.TagName"
  62. :value="item.TagId"
  63. />
  64. </el-select>
  65. </el-form-item>
  66. <el-form-item prop="startTime" label="开始时间">
  67. <el-date-picker
  68. v-model="eventForm.startTime"
  69. :value-format="formatTime"
  70. :format="formatTime"
  71. :type="[2,3,4].includes(ResourceType)?'date':'datetime'"
  72. placeholder="请选择开始时间"
  73. style="width:80%"
  74. />
  75. </el-form-item>
  76. <el-form-item prop="endTime" v-if="![2,3,4].includes(ResourceType)" label="结束时间">
  77. <el-date-picker
  78. v-model="eventForm.endTime"
  79. :value-format="formatTime"
  80. :format="formatTime"
  81. :type="[2,3,4].includes(ResourceType)?'date':'datetime'"
  82. placeholder="请选择结束时间"
  83. style="width:80%"
  84. />
  85. </el-form-item>
  86. </el-form>
  87. <div class="btn-bottom">
  88. <el-button type="primary" plain @click="cancelHandle">取消</el-button>
  89. <el-button type="primary" @click="handleConfirmEvent">确定</el-button>
  90. </div>
  91. </el-dialog>
  92. </template>
  93. <script>
  94. import { eventInterface } from '@/api/modules/knowledge';
  95. export default {
  96. props: {
  97. show: {
  98. type: Boolean
  99. },
  100. ResourceType: {
  101. type: Number
  102. },
  103. importFileUrl: {
  104. type: String
  105. },
  106. fileName: {
  107. type: String
  108. },
  109. },
  110. computed: {
  111. formatTime() {
  112. return [2,3,4].includes(this.ResourceType) ? 'yyyy-MM-dd' : 'yyyy-MM-dd HH:mm:ss'
  113. }
  114. },
  115. watch: {
  116. show(nval) {
  117. if(!nval) return
  118. this.eventForm.title=this.fileName
  119. this.getClassifyList();
  120. this.getTagsList();
  121. }
  122. },
  123. data() {
  124. return {
  125. eventForm: {
  126. title: '',
  127. classifyId: 0,
  128. source:'',
  129. tagId:'',
  130. startTime:'',
  131. endTime:''
  132. },
  133. formRules:{
  134. title:[
  135. { required: true, message: '标题不能为空', trigger: 'blur' },
  136. ],
  137. classifyId:[
  138. { required: true, message: '分类不能为空', trigger: 'blur' },
  139. ],
  140. source:[
  141. { required: true, message: '来源不能为空', trigger: 'blur' },
  142. ],
  143. startTime:[
  144. { required: true, message: '开始时间不能为空', trigger: 'blur' },
  145. ],
  146. },
  147. classifyOptions: [],
  148. sourcesOptions:[],
  149. tagsOptions:[],
  150. }
  151. },
  152. mounted(){
  153. },
  154. methods:{
  155. async getClassifyList() {
  156. const res = await eventInterface.getClassify({
  157. ResourceType: this.ResourceType
  158. })
  159. if(res.Ret !== 200) return
  160. this.classifyOptions = res.Data.List || []
  161. },
  162. async getSourceList() {
  163. const res = await eventInterface.getSourcesList({
  164. ResourceType: this.ResourceType
  165. })
  166. if(res.Ret !== 200) return
  167. this.sourcesOptions = res.Data.List || []
  168. },
  169. async getTagsList() {
  170. const res = await eventInterface.getTagList({ResourceType:this.ResourceType})
  171. if(res.Ret !== 200) return
  172. this.tagsOptions=res.Data.List || []
  173. },
  174. async handleConfirmEvent() {
  175. await this.$refs.formRef.validate()
  176. const {
  177. title,
  178. classifyId,
  179. source,
  180. tagId,
  181. startTime,
  182. endTime
  183. } = this.eventForm;
  184. let params = {
  185. ResourceType: this.ResourceType,
  186. ClassifyId: classifyId,
  187. Title: title,
  188. Content: '',
  189. SourceFrom: source,
  190. TagId: tagId || 0,
  191. StartTime: startTime,
  192. EndTime: endTime || '',
  193. FileUrl: this.importFileUrl ? [this.importFileUrl] : [],
  194. }
  195. const res = await eventInterface.addEvent(params)
  196. if(res.Ret !== 200) return
  197. this.$message.success('添加成功')
  198. this.$emit('confirm')
  199. this.cancelHandle()
  200. },
  201. cancelHandle() {
  202. this.$refs.formRef.resetFields()
  203. this.$emit('update:show',false)
  204. }
  205. },
  206. }
  207. </script>
  208. <style scoped lang='scss'>
  209. .el-form {
  210. padding: 0 40px;
  211. }
  212. .btn-bottom {
  213. display: flex;
  214. justify-content: center;
  215. margin: 30px 0;
  216. .el-button {
  217. width: 130px;
  218. }
  219. }
  220. </style>