addEvent.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530
  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="100px" class="demo-ruleForm">
  7. <el-form-item label="事件名称" prop="name">
  8. <el-autocomplete class="inline-input" v-model="formData[0].name" value-key="name" v-SelectLazyLoading="load"
  9. :fetch-suggestions="querySearchQuestion" placeholder="请输入或选择事件" :trigger-on-focus="false"
  10. @select="handleSelectQuestion" @blur="blur($event, { $index: 0 })" style="width: 100%;">
  11. </el-autocomplete>
  12. </el-form-item>
  13. <el-form-item label="所属客户" prop="clientId" v-if="userinfo.tenantType == 1">
  14. <!-- <el-select v-model="formData[0].clientId" :disabled="(formData[0].id && !this.row) ? true : false" -->
  15. <el-select ref="select" v-model="formData[0].clientId" clearable filterable remote style="width: 100%;"
  16. placeholder="请选择客户" v-SelectLazyLoading="loadClient" :remote-method="remoteMethod" :loading="client.loading">
  17. <el-option v-for="item in clientList" :key="parseInt(item.id)" :label="item.name"
  18. :value="parseInt(item.id)">
  19. </el-option>
  20. </el-select>
  21. </el-form-item>
  22. <el-form-item label="事件日期" prop="eventDate">
  23. <el-date-picker style="width: 100%" v-model="formData[0].eventDate" type="date" value-format="yyyy-MM-dd"
  24. placeholder="请选择事件日期">
  25. </el-date-picker>
  26. </el-form-item>
  27. <el-form-item label="事件场景" prop="scenarioId">
  28. <!-- <el-select v-model="formData[0].applicationScenarios[0]" :disabled="(formData[0].id && !this.row) ? true : false" -->
  29. <el-select ref="select2" v-model="formData[0].scenarioId" style="width: 100%;" placeholder="请选择事件场景">
  30. <el-option
  31. v-for="item in commonData"
  32. :key="parseInt(item.value)" :label="item.label" :value="parseInt(item.value)">
  33. </el-option>
  34. </el-select>
  35. </el-form-item>
  36. <el-form-item label="文件上传">
  37. <myUpload :file-list="handleConcat(formData[0].systemFileList)" @on-change="onchange" @on-remove="onRemove"
  38. style="height: 180px;"></myUpload>
  39. </el-form-item>
  40. <el-form-item label="事件描述" prop="description">
  41. <el-input type="textarea" :rows="2" v-model="formData[0].description" autocomplete="off"
  42. placeholder="请输入事件描述"></el-input>
  43. </el-form-item>
  44. </el-form>
  45. </div>
  46. <!-- 批量新增(事件) -->
  47. <div v-else-if="type == 2">
  48. <el-table :data="formData" style="width: 100%" class="twj-table">
  49. <el-table-column prop="name" label="事件名称" align="center">
  50. <template slot="header">
  51. <div>
  52. <el-tooltip class="item" effect="dark" content="事件:商业目标/解决问题/对应项目" placement="top">
  53. <span>事件名称<span style="color:red;"> *</span></span>
  54. </el-tooltip>
  55. </div>
  56. </template>
  57. <template slot-scope="scope">
  58. <div>
  59. <el-autocomplete class="inline-input" v-model="scope.row.name" :fetch-suggestions="querySearchQuestion"
  60. placeholder="请输入或选择事件" :trigger-on-focus="false" @select="handleSelectQuestion"
  61. @blur="blur($event, scope)" style="width: 100%;">
  62. </el-autocomplete>
  63. </div>
  64. </template>
  65. </el-table-column>
  66. <el-table-column prop="eventDate" label="事件时间" align="center">
  67. <template slot-scope="scope">
  68. <div>
  69. <el-date-picker style="width: 100%" v-model="scope.row.eventDate" type="datetime"
  70. value-format="yyyy-MM-dd" placeholder="选择事件日期时间">
  71. </el-date-picker>
  72. </div>
  73. </template>
  74. </el-table-column>
  75. <el-table-column prop="applicationScenarios" label="事件场景" align="center">
  76. <template slot-scope="scope">
  77. <div>
  78. <!-- multiple -->
  79. <el-select v-model="scope.row.scenarioId" style="width: 100%;" placeholder="请选择事件场景">
  80. <el-option
  81. v-for="item in commonData"
  82. :key="parseInt(item.id)" :label="item.name" :value="parseInt(item.id)">
  83. </el-option>
  84. </el-select>
  85. </div>
  86. </template>
  87. </el-table-column>
  88. <el-table-column prop="description" label="事件描述" align="center" width="250px">
  89. <template slot-scope="scope">
  90. <div>
  91. <el-input type="textarea" :rows="1" v-model="scope.row.description" autocomplete="off"
  92. placeholder="请输入事件描述" :disabled="scope.row.id ? true : false"></el-input>
  93. </div>
  94. </template>
  95. </el-table-column>
  96. <el-table-column label="事件操作" align="" width="100px">
  97. <template slot-scope="scope">
  98. <div>
  99. <el-tooltip class="item" effect="dark" content="增加事件" placement="top">
  100. <i @click="addRow(scope)" class="el-icon-plus btn"></i>
  101. </el-tooltip>
  102. <el-tooltip class="item" effect="dark" content="删除事件" placement="top">
  103. <i @click="deleteRow(scope)" v-if="scope.$index != 0" class="el-icon-close btn"></i>
  104. </el-tooltip>
  105. </div>
  106. </template>
  107. </el-table-column>
  108. </el-table>
  109. </div>
  110. <div slot="footer" class="dialog-footer">
  111. <el-button size="small" @click="handleClose()" style="width:100px">取消</el-button>
  112. <el-button size="small" @click="resetForm()" style="width:100px">重置</el-button>
  113. <el-button type="primary" @click="submitForm1()" size="small" :loading="loading"
  114. style="width:100px">确定</el-button>
  115. </div>
  116. </el-dialog>
  117. </div>
  118. </template>
  119. <script>
  120. import { mapGetters } from 'vuex'
  121. export default {
  122. props: [],
  123. data() {
  124. return {
  125. loading: false,
  126. //弹窗标题
  127. title: '',
  128. //弹窗状态
  129. dialogVisible: false,
  130. //弹窗宽度
  131. width: '800px',
  132. //表格数据
  133. formData: [
  134. {
  135. name: '',
  136. eventDate: '',
  137. description: '',
  138. scenarioId: '',
  139. }
  140. ],
  141. //检验规则
  142. rules: {
  143. name: [{ required: true, message: '请输入事件名称', trigger: 'blur' },],
  144. scenarioId: [{ required: true, message: '请选择事件场景', trigger: 'change' },],
  145. },
  146. //弹窗类型
  147. type: 1,
  148. questionNameArr: {
  149. queryParams: {
  150. current: 1,
  151. size: 10,
  152. },
  153. eventInput: '',
  154. data: []
  155. },
  156. //客户集合
  157. clientList: [],
  158. // 客户懒加载所需
  159. client: {
  160. queryParams: {
  161. current: 1,
  162. size: 10,
  163. },
  164. isLazy: true,
  165. loading:false,
  166. },
  167. // 文件数组
  168. files: [],
  169. }
  170. },
  171. watch: {},
  172. computed: {
  173. ...mapGetters(["userinfo"]),
  174. commonData(){
  175. return this.$store.state.dictMessage.scenario || []
  176. }
  177. },
  178. async mounted() {
  179. },
  180. methods: {
  181. // 自定义组件文件删除
  182. onRemove(file, fileList) {
  183. if (file.guid) {
  184. let a = this.formData[0].systemFileList.findIndex(item => {
  185. return item.guid == file.guid
  186. })
  187. this.formData[0].systemFileList.splice(a, 1)
  188. } else {
  189. let a = this.files.findIndex(item => {
  190. return item.size == file.size
  191. })
  192. this.files.splice(a, 1)
  193. }
  194. },
  195. // 自定义组件文件监听
  196. onchange(file, fileList) {
  197. if (this.files && this.files.length > 0) {
  198. let a = this.files.findIndex(item => {
  199. return item.size == file.size
  200. })
  201. if (a != -1) {
  202. this.$message.error(`${file.raw.name}文件重复`)
  203. this.files.splice(a, 1, file.raw)
  204. } else {
  205. this.files.push(file.raw)
  206. }
  207. } else {
  208. this.files.push(file.raw)
  209. }
  210. },
  211. // 合并已上传的文件和未上传的文件
  212. handleConcat(arr) {
  213. let files = (arr || []).concat(this.files)
  214. return files
  215. },
  216. loadClient() {
  217. if(this.client.queryParams.current * this.client.queryParams.size>=this.client.queryParams.total){
  218. return false
  219. }
  220. this.client.queryParams.current +=1
  221. this.getAdminClientList()
  222. },
  223. remoteMethod(query) {
  224. // this.client.isLazy = true
  225. // if (query !== '') {
  226. // this.client.loading = true;
  227. // this.client.queryParams = {
  228. // current: 1,
  229. // size: 10,
  230. // searchQuery: `name=${query}`
  231. // }
  232. // this.$api.getAdminClientList(this.client.queryParams).then(response => {
  233. // if (response.code == 200) {
  234. // this.client.loading = false;
  235. // this.clientList = response.data.records
  236. // }
  237. // }).catch(error => {
  238. // this.client.loading = false;
  239. // })
  240. // } else {
  241. // this.client.queryParams.name = null
  242. // this.clientList = [];
  243. // this.getAdminClientList()
  244. // }
  245. },
  246. //获取客户信息
  247. getAdminClientList() {
  248. this.$api.getAdminClientList(this.client.queryParams).then(response => {
  249. this.clientList.push(...response.data.records)
  250. this.client.queryParams.total = response.data.total
  251. }).catch(error => {
  252. })
  253. },
  254. //打开弹窗,判断是编辑还是添加,同时判断是批量添加还是添加单个事件(type==1是单个,type==2是批量)
  255. open(data, type) {
  256. this.getAdminClientList()
  257. this.type = type
  258. if (data) {
  259. this.title = '编辑事件'
  260. this.$set(this.formData, 0, data)
  261. } else {
  262. if (this.type == 1) {
  263. this.title = '新增事件'
  264. } else {
  265. this.title = '批量新增事件'
  266. }
  267. this.formData = [
  268. {
  269. name: '',
  270. eventDate: '',
  271. description: '',
  272. scenarioId: '',
  273. }
  274. ]
  275. }
  276. this.dialogVisible = true
  277. },
  278. //关闭弹窗
  279. handleClose() {
  280. if (this.type == '1') {
  281. // this.$refs.select.blur()
  282. // this.$refs.select2.blur()
  283. this.$refs.ruleForm.resetFields()
  284. }
  285. this.files = []
  286. this.loading = false
  287. this.dialogVisible = false
  288. },
  289. // 检验事件并提交保存请求
  290. submitForm1() {
  291. var list = []
  292. try {
  293. if (this.type == '1') {//单个新增事件
  294. list = this.formData
  295. } else {//多个新增事件
  296. this.formData.forEach(item => {
  297. var a = false
  298. for (let key in item) {
  299. // if (key != 'scenarioId') {
  300. if (item[key] != '' && item[key] != null) {
  301. a = true
  302. }
  303. // }else {
  304. // if (item[key].length > 0) {
  305. // a = true
  306. // }
  307. // }
  308. }
  309. if (a == true) {
  310. if (item.name != '') {
  311. list.push(item)
  312. } else {
  313. throw new Error('事件名称不能为空')
  314. }
  315. }
  316. })
  317. }
  318. var arr = [...new Set(list.map(item => { return item.name }))]
  319. if (arr.length < list.length) {
  320. this.$message.error(`存在重复的事件名称,请重定义事件名称`)
  321. return false
  322. }
  323. var edit = false
  324. // if (this.row) {
  325. // edit = true
  326. // }
  327. this.addFormData({ list: list, option: 1, edit })
  328. // this.$emit('formData', { list: list, option: 1, edit })
  329. } catch (error) {
  330. this.$message.error(error)
  331. }
  332. },
  333. // 提交保存事件
  334. addFormData(val) {
  335. let lists = JSON.parse(JSON.stringify(val.list))
  336. if (this.type == '1') {//单个事件新增
  337. this.$refs.ruleForm.validate(valid => {
  338. if (valid) {
  339. this.addInterface(lists)
  340. }
  341. })
  342. } else {//多个事件新增
  343. this.addInterface(lists)
  344. }
  345. },
  346. //提交保存、编辑事件接口
  347. addInterface(forms) {
  348. this.loading = true
  349. let formData = new FormData()
  350. if (this.files && this.files.length > 0) {
  351. for (var i = 0; i < this.files.length; i++) {
  352. formData.append('files', this.files[i])//文件数据
  353. }
  354. }
  355. if (forms[0].systemFileList && forms[0].systemFileList.length > 0) {
  356. forms[0].fileGuids = forms[0].systemFileList.map(item => {
  357. return item.guid
  358. })
  359. }
  360. formData.append('event', JSON.stringify(forms[0]))
  361. if (forms[0].id) {//编辑
  362. this.$api.updateEvent(formData).then(res => {
  363. if (res.code == 200) {
  364. this.$emit('isSuccess', '编辑成功')
  365. this.$message.success('事件编辑成功')
  366. this.handleClose()
  367. }
  368. }).catch(error => {
  369. this.loading = false
  370. this.$message.error(error.message)
  371. })
  372. } else {//新增
  373. this.$api.eventAddEvent(formData).then(res => {
  374. if (res.code == 200) {
  375. this.$emit('isSuccess', '新增成功')
  376. this.$message.success('事件新增成功')
  377. this.handleClose()
  378. }
  379. }).catch(error => {
  380. this.loading = false
  381. this.$message.error(error.message)
  382. })
  383. }
  384. },
  385. //重置全部事件
  386. resetForm() {
  387. this.$confirm('此操作将重置全部事件, 是否继续?', '提示', {
  388. confirmButtonText: '确定',
  389. cancelButtonText: '取消',
  390. type: 'warning'
  391. }).then(() => {
  392. if (this.type == 1) {
  393. this.$refs.ruleForm.resetFields();
  394. }
  395. this.formData = [
  396. {
  397. name: '',
  398. eventDate: '',
  399. description: '',
  400. scenarioId: '',
  401. }
  402. ]
  403. // this.$emit('formData', {list:this.formData,option:1})
  404. this.$message.success('事件已全部重置')
  405. }).catch(() => {
  406. this.$message.info('重置操作已取消')
  407. });
  408. },
  409. // 增加事件
  410. addRow() {
  411. this.formData.push(
  412. {
  413. name: '',
  414. eventDate: '',
  415. description: '',
  416. scenarioId: '',
  417. }
  418. )
  419. },
  420. //删除事件
  421. deleteRow(row) {
  422. this.formData.splice(row.$index, 1)
  423. },
  424. // 懒加载事件方法
  425. load() {
  426. if (this.questionNameArr.queryParams.current * this.questionNameArr.queryParams.size >= this.questionNameArr.queryParams.total) {
  427. return false
  428. }
  429. this.questionNameArr.queryParams.current++
  430. this.questionEventList()
  431. },
  432. // 查询事件
  433. async questionEventList() {
  434. let searchValue = { name: this.questionNameArr.eventInput }
  435. let params = {
  436. ...this.questionNameArr.queryParams,//分页信息
  437. searchQuery: this.$commonJS.objectToString(searchValue)//输入的建议
  438. }
  439. await this.$api.queryEvent(params).then(res => {
  440. if (res.code == 200) {
  441. this.questionNameArr.data.push(...res.data.data)
  442. this.questionNameArr.queryParams.total = res.data.total
  443. this.questionNameArr.cb(this.questionNameArr.data);
  444. }
  445. })
  446. },
  447. //获取下拉建议事件数据
  448. async querySearchQuestion(queryString, cb) {
  449. this.questionNameArr.queryParams.current = 1
  450. this.questionNameArr.eventInput = queryString
  451. this.questionNameArr.data = []
  452. this.questionNameArr.cb = cb
  453. await this.questionEventList()
  454. },
  455. // input框切换选择
  456. handleSelectQuestion(val) {
  457. let a = this.formData.findIndex(item => {
  458. return item.id == val.id
  459. })
  460. if (a == -1) {
  461. // this.$set(this.formData,this.index,JSON.parse(JSON.stringify(val)))
  462. } else {
  463. this.$message.error('事件已存在')
  464. this.$set(this.formData, this.index, {})
  465. return false
  466. }
  467. },
  468. //失去焦点(远程找是否存在名称相同事件,如果存在就直接赋值)
  469. blur(ev, val) {
  470. },
  471. },
  472. }
  473. </script>
  474. <style lang="scss">
  475. .addEvent {
  476. .dialog-footer {
  477. // text-align: center;
  478. }
  479. }
  480. .twj-table td.el-table__cell,
  481. .twj-table th.el-table__cell.is-leaf {
  482. // border:none !important;
  483. border: 5px solid white !important;
  484. }
  485. .twj-table::before {
  486. background-color: transparent;
  487. }
  488. .twj-table tr td:first-child {
  489. border-right: none !important;
  490. border-left: none !important;
  491. }
  492. .twj-table tr td:last-child {
  493. border-right: none !important;
  494. border-left: none !important;
  495. }
  496. </style>
  497. <style lang="scss">
  498. .btn {
  499. color: black;
  500. margin-left: 10px;
  501. font-size: 18px;
  502. text-align: center;
  503. cursor: pointer;
  504. }
  505. .btn:hover {
  506. color: aqua;
  507. }
  508. </style>