addEvent.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397
  1. <template>
  2. <div class="addEvent">
  3. <el-dialog :title="title" :visible.sync="dialogVisible" :width="width" :before-close="handleClose">
  4. <!-- 单个新增(事件) -->
  5. <div v-if="type == 1">
  6. <el-form :model="formData[0]" :rules="rules" ref="ruleForm" label-width="90px" label-position="left" class="demo-ruleForm">
  7. <el-form-item label="事件名称" prop="questionName">
  8. <el-autocomplete class="inline-input" v-model="formData[0].questionName"
  9. :fetch-suggestions="querySearchQuestion"
  10. placeholder="请输入或选择事件" :trigger-on-focus="false"
  11. @select="handleSelectQuestion" @blur="blur($event, { $index: 0 })" style="width: 100%;">
  12. </el-autocomplete>
  13. </el-form-item>
  14. <el-form-item label="所属客户" prop="clientId">
  15. <el-select v-model="formData[0].clientId" :disabled="(formData[0].id && !this.row) ? true : false"
  16. style="width: 100%;" placeholder="请选择客户">
  17. <el-option
  18. v-for="item in clientList"
  19. :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)">
  20. </el-option>
  21. </el-select>
  22. </el-form-item>
  23. <el-form-item label="事件日期" prop="eventDate">
  24. <el-date-picker style="width: 100%" v-model="formData[0].eventDate"
  25. type="datetime" value-format="yyyy-MM-dd HH:mm:ss"
  26. placeholder="选择事件日期时间">
  27. </el-date-picker>
  28. </el-form-item>
  29. <el-form-item label="事件场景" prop="assistPerson">
  30. <el-select v-model="formData[0].applicationScenarios[0]" :disabled="(formData[0].id && !this.row) ? true : false"
  31. style="width: 100%;" placeholder="请选择事件场景">
  32. <el-option
  33. v-for="item in commonData.ENTERPRISE_APPLICATION_SCENARIO ? commonData.ENTERPRISE_APPLICATION_SCENARIO : []"
  34. :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)">
  35. </el-option>
  36. </el-select>
  37. </el-form-item>
  38. <el-form-item label="事件描述" prop="description">
  39. <el-input type="textarea" :rows="2" v-model="formData[0].description" autocomplete="off" placeholder="请输入事件描述"
  40. ></el-input>
  41. </el-form-item>
  42. </el-form>
  43. </div>
  44. <!-- 批量新增(事件) -->
  45. <div v-else-if="type == 2">
  46. <el-table :data="formData" style="width: 100%" class="twj-table">
  47. <el-table-column prop="questionName" label="事件名称" align="center">
  48. <template slot="header">
  49. <div>
  50. <el-tooltip class="item" effect="dark" content="事件:商业目标/解决问题/对应项目" placement="top">
  51. <span>事件名称<span style="color:red;"> *</span></span>
  52. </el-tooltip>
  53. </div>
  54. </template>
  55. <template slot-scope="scope">
  56. <div>
  57. <el-autocomplete class="inline-input" v-model="scope.row.questionName"
  58. :fetch-suggestions="querySearchQuestion" placeholder="请输入或选择事件" :trigger-on-focus="false"
  59. @select="handleSelectQuestion" @blur="blur($event, scope)" style="width: 100%;">
  60. </el-autocomplete>
  61. </div>
  62. </template>
  63. </el-table-column>
  64. <el-table-column prop="eventDate" label="事件时间" align="center">
  65. <template slot-scope="scope">
  66. <div>
  67. <el-date-picker style="width: 100%" v-model="scope.row.eventDate" :disabled="scope.row.id ? true : false"
  68. type="datetime" value-format="yyyy-MM-dd HH:mm:ss" placeholder="选择事件日期时间">
  69. </el-date-picker>
  70. </div>
  71. </template>
  72. </el-table-column>
  73. <el-table-column prop="applicationScenarios" label="事件场景" align="center">
  74. <template slot-scope="scope">
  75. <div>
  76. <!-- multiple -->
  77. <el-select v-model="scope.row.applicationScenarios[0]" :disabled="scope.row.id ? true : false"
  78. style="width: 100%;" placeholder="请选择事件场景">
  79. <el-option
  80. v-for="item in commonData.ENTERPRISE_APPLICATION_SCENARIO ? commonData.ENTERPRISE_APPLICATION_SCENARIO : []"
  81. :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)">
  82. </el-option>
  83. </el-select>
  84. </div>
  85. </template>
  86. </el-table-column>
  87. <el-table-column prop="description" label="事件描述" align="center" width="250px">
  88. <template slot-scope="scope">
  89. <div>
  90. <el-input type="textarea" :rows="1" v-model="scope.row.description" autocomplete="off"
  91. placeholder="请输入事件描述" :disabled="scope.row.id ? true : false"></el-input>
  92. </div>
  93. </template>
  94. </el-table-column>
  95. <el-table-column label="事件操作" align="" width="100px">
  96. <template slot-scope="scope">
  97. <div>
  98. <el-tooltip class="item" effect="dark" content="增加事件" placement="top">
  99. <i @click="addRow(scope)" class="el-icon-plus btn"></i>
  100. </el-tooltip>
  101. <el-tooltip class="item" effect="dark" content="删除事件" placement="top">
  102. <i @click="deleteRow(scope)" v-if="scope.$index != 0" class="el-icon-close btn"></i>
  103. </el-tooltip>
  104. </div>
  105. </template>
  106. </el-table-column>
  107. </el-table>
  108. </div>
  109. <div slot="footer" class="dialog-footer">
  110. <el-button size="small" @click="handleClose()" style="width:100px">取消</el-button>
  111. <el-button size="small" @click="resetForm()" style="width:100px">重置</el-button>
  112. <el-button type="primary" @click="submitForm1()" size="small" style="width:100px">确定</el-button>
  113. </div>
  114. </el-dialog>
  115. </div>
  116. </template>
  117. <script>
  118. export default {
  119. props: [],
  120. data() {
  121. return {
  122. //弹窗标题
  123. title: '',
  124. //弹窗状态
  125. dialogVisible: false,
  126. //弹窗宽度
  127. width: '800px',
  128. //表格数据
  129. formData: [
  130. {
  131. questionName: '',
  132. eventDate: '',
  133. description: '',
  134. applicationScenarios: [],
  135. }
  136. ],
  137. //检验规则
  138. rules: {
  139. questionName: [ { required: true, message: '请输入事件名称', trigger: 'blur' },],
  140. },
  141. //应用场景数据
  142. commonData: {},
  143. //弹窗类型
  144. type: 1,
  145. //客户集合
  146. clientList:[]
  147. }
  148. },
  149. watch: {},
  150. async mounted() {
  151. // 应用场景(是通过字典还是接口待定)
  152. await this.getCommonData()
  153. // 查询所有事件
  154. // await this.questionEventList()
  155. },
  156. methods: {
  157. //打开弹窗,判断是编辑还是添加,同时判断是批量添加还是添加单个事件(type==1是单个,type==2是批量)
  158. open(data, type) {
  159. this.type = type
  160. if (data) {
  161. this.title = '编辑事件'
  162. this.formData[0] = JSON.parse(JSON.stringify(data))
  163. console.log(this.formData);
  164. } else {
  165. if (this.type == 1) {
  166. this.title='新增事件'
  167. } else {
  168. this.title='批量新增事件'
  169. }
  170. this.formData = [
  171. {
  172. questionName: '',
  173. eventDate: '',
  174. description: '',
  175. applicationScenarios: [],
  176. }
  177. ]
  178. }
  179. this.dialogVisible = true
  180. },
  181. //关闭弹窗
  182. handleClose() {
  183. if (this.type=='1') {
  184. this.$refs.ruleForm.resetFields()
  185. }
  186. this.dialogVisible = false
  187. },
  188. // 请求应用场景(是通过字典还是接口待定)
  189. async getCommonData() {
  190. await this.$api.getCommonData({ keys: 'QUERY_GROUP,ENTERPRISE_APPLICATION_SCENARIO,INVESTIGATION_TYPE' }).then(response => {
  191. this.commonData = response.data
  192. })
  193. },
  194. // 检验事件并提交保存请求
  195. submitForm1() {
  196. var list = []
  197. try {
  198. if (this.type=='1') {//单个新增事件
  199. list=this.formData
  200. } else {//多个新增事件
  201. this.formData.forEach(item => {
  202. var a = false
  203. for (let key in item) {
  204. if (key != 'applicationScenarios') {
  205. if (item[key] != '' && item[key] != null) {
  206. a = true
  207. }
  208. }else {
  209. if (item[key].length > 0) {
  210. a = true
  211. }
  212. }
  213. }
  214. if (a == true) {
  215. if (item.questionName != '') {
  216. list.push(item)
  217. } else {
  218. throw new Error('事件名称不能为空')
  219. }
  220. }
  221. })
  222. }
  223. var arr = [...new Set(list.map(item => { return item.questionName }))]
  224. if (arr.length < list.length) {
  225. this.$message.error(`存在重复的事件名称,请重定义事件名称`)
  226. return false
  227. }
  228. var edit = false
  229. if (this.row) {
  230. edit = true
  231. }
  232. this.addFormData({ list: list, option: 1, edit })
  233. // this.$emit('formData', { list: list, option: 1, edit })
  234. } catch (error) {
  235. this.$message.error(error)
  236. }
  237. },
  238. // 提交保存事件
  239. addFormData(val) {
  240. let lists = JSON.parse(JSON.stringify(val.list))
  241. let forms = {
  242. projectId: this.projectId,
  243. eventAddNewDTOs:lists
  244. }
  245. if (this.type=='1') {//单个事件新增
  246. this.$refs.ruleForm.validate(valid => {
  247. if (valid) {
  248. this.addInterface(forms)
  249. }
  250. })
  251. } else {//多个事件新增
  252. this.addInterface(forms)
  253. }
  254. },
  255. //提交保存事件接口
  256. addInterface(forms) {
  257. this.$api.eventAddNew(forms).then(res => {
  258. if (res.code == 200) {
  259. this.$emit('isSuccess','新增成功')
  260. this.$message.success('事件新增成功')
  261. this.handleClose()
  262. }
  263. }).catch(error => {
  264. this.$message.error(error.message)
  265. })
  266. },
  267. //重置全部事件
  268. resetForm() {
  269. this.$confirm('此操作将重置全部事件, 是否继续?', '提示', {
  270. confirmButtonText: '确定',
  271. cancelButtonText: '取消',
  272. type: 'warning'
  273. }).then(() => {
  274. if (this.type == 1) {
  275. this.$refs.ruleForm.resetFields();
  276. }
  277. this.formData = [
  278. {
  279. questionName: '',
  280. eventDate: '',
  281. description: '',
  282. applicationScenarios: [],
  283. }
  284. ]
  285. // this.$emit('formData', {list:this.formData,option:1})
  286. this.$message.success('事件已全部重置')
  287. }).catch(() => {
  288. this.$message.info('重置操作已取消')
  289. });
  290. },
  291. // 增加事件
  292. addRow() {
  293. this.formData.push(
  294. {
  295. questionName: '',
  296. eventDate: '',
  297. description: '',
  298. applicationScenarios: [],
  299. }
  300. )
  301. },
  302. //删除事件
  303. deleteRow(row) {
  304. this.formData.splice(row.$index, 1)
  305. },
  306. // 查询所有事件(不需要)
  307. async questionEventList() {
  308. await this.$api.eventQuery({}).then(res => {
  309. if (res.code == 200) {
  310. this.questionNameArr = res.data.list
  311. }
  312. })
  313. },
  314. //获取下拉建议数据(远程获取)
  315. querySearchQuestion(queryString, cb) {
  316. var restaurants = this.questionNameArr.map(item => {
  317. item.value = item.questionName;
  318. return item;
  319. });
  320. var results = queryString ? restaurants.filter(this.createFilterQuestion(queryString)) : restaurants;
  321. // 调用 callback 返回建议列表的数据
  322. cb(results);
  323. },
  324. // 对下拉建议列表的数据进行处理
  325. createFilterQuestion(queryString) {
  326. return (restaurant) => {
  327. console.log(restaurant);
  328. return (restaurant.value.indexOf(queryString) != -1);
  329. };
  330. },
  331. // input框切换选择
  332. handleSelectQuestion(val) {
  333. let a = this.formData.findIndex(item => {
  334. return item.id == val.id
  335. })
  336. if (a == -1) {
  337. // this.$set(this.formData,this.index,JSON.parse(JSON.stringify(val)))
  338. } else {
  339. this.$message.error('事件已存在')
  340. this.$set(this.formData, this.index, {})
  341. return false
  342. }
  343. },
  344. //失去焦点(远程找是否存在名称相同事件,如果存在就直接赋值)
  345. blur(ev, val) {
  346. },
  347. },
  348. }
  349. </script>
  350. <style lang="scss">
  351. .addEvent {
  352. .dialog-footer {
  353. // text-align: center;
  354. }
  355. }
  356. .twj-table td.el-table__cell,
  357. .twj-table th.el-table__cell.is-leaf {
  358. // border:none !important;
  359. border: 5px solid white !important;
  360. }
  361. .twj-table::before {
  362. background-color: transparent;
  363. }
  364. .twj-table tr td:first-child {
  365. border-right: none !important;
  366. border-left: none !important;
  367. }
  368. .twj-table tr td:last-child {
  369. border-right: none !important;
  370. border-left: none !important;
  371. }
  372. </style>
  373. <style lang="scss">
  374. .btn {
  375. color: black;
  376. margin-left: 10px;
  377. font-size: 18px;
  378. text-align: center;
  379. cursor: pointer;
  380. }
  381. .btn:hover {
  382. color: aqua;
  383. }
  384. </style>