field.vue 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575
  1. <template>
  2. <div class="">
  3. <el-container class="project-field">
  4. <el-header>
  5. <el-form :inline="true" class="project-field-header-form">
  6. <el-form-item label="字段名称">
  7. <el-input v-model="queryParams.name" size="small" placeholder="请输入字段名称"></el-input>
  8. </el-form-item>
  9. <el-form-item>
  10. <el-button type="" size="small" @click="getList">查询</el-button>
  11. <el-button type="primary" size="small" @click="handleAdd">新增</el-button>
  12. </el-form-item>
  13. </el-form>
  14. <!-- <el-button class="margin-right_20" type="success" size="small" @click="handleImport" :disabled="!$permission('/workspace/common/customField/import')">导入</el-button> -->
  15. </el-header>
  16. <el-main class="project-field-main">
  17. <el-table v-loading="loading" :data="tableData" border header-row-class-name="custom-table-header">
  18. <el-table-column type="index" label="#" width="55" align="center"></el-table-column>
  19. <el-table-column prop="name" label="字段名称" align="center" show-overflow-tooltip></el-table-column>
  20. <el-table-column label="类型" align="center" show-overflow-tooltip>
  21. <template slot-scope="scope">
  22. <span>{{ typeObj[scope.row.type] }}</span>
  23. </template>
  24. </el-table-column>
  25. <el-table-column label="状态" align="center" show-overflow-tooltip>
  26. <template slot-scope="scope">
  27. <span>{{ statusObj[scope.row.status] }}</span>
  28. </template>
  29. </el-table-column>
  30. <el-table-column prop="createName" label="创建人" align="center" show-overflow-tooltip></el-table-column>
  31. <el-table-column prop="createTime" label="创建时间" align="center" show-overflow-tooltip>
  32. <template slot-scope="scope">
  33. <span>{{ (scope.row.createTime) }}</span>
  34. </template>
  35. </el-table-column>
  36. <el-table-column prop="remark" label="备注" align="center" show-overflow-tooltip></el-table-column>
  37. <el-table-column label="操作" align="center" width="150">
  38. <template slot-scope="scope">
  39. <el-dropdown split-button type="primary" size="small">
  40. <span @click="handleEdit(scope.row)">编辑</span>
  41. <!-- <p v-else :disabled="true">编辑</p> -->
  42. <el-dropdown-menu slot="dropdown" class="text-align_center">
  43. <el-dropdown-item @click.native="handleEditOption(scope.row)" v-if="[3, 4, 5, 6].indexOf(scope.row.type) !== -1 ">选项管理</el-dropdown-item>
  44. <!-- <el-dropdown-item v-else-if="[3, 4, 5, 6].indexOf(scope.row.type) !== -1" type="primary" size="small" @click.native="handleEditOption(scope.row)">选项查看</el-dropdown-item> -->
  45. <!-- <el-dropdown-item :disabled="!$permission('/workspace/common/customField/copy')" @click.native="handleCopy(scope.row)">复制</el-dropdown-item> -->
  46. <el-dropdown-item class="color-red" @click.native="handleDelete(scope.row)" divided>删除</el-dropdown-item>
  47. </el-dropdown-menu>
  48. </el-dropdown>
  49. <!-- <el-button v-else-if="[3, 4, 5, 6].indexOf(scope.row.type) !== -1" type="primary" size="small" @click.native="handleEditOption(scope.row)">选项查看</el-button> -->
  50. </template>
  51. </el-table-column>
  52. </el-table>
  53. <div class="pagination">
  54. <el-pagination :current-page.sync="queryParams.current" :page-size="queryParams.size" :total="total" @current-change="handleCurrentChange" layout="total, prev, pager, next, jumper" background></el-pagination>
  55. </div>
  56. </el-main>
  57. <!-- <el-footer class="footer-common">
  58. <el-button @click="close">关 闭</el-button>
  59. </el-footer> -->
  60. </el-container>
  61. <el-dialog :title="title" :visible.sync="dialogVisible" width="500px" append-to-body destroy-on-close :before-close="cancel" top="10vh">
  62. <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="80px" label-position="left">
  63. <el-form-item label="字段名称" prop="name">
  64. <el-input v-model="ruleForm.name" placeholder="请输入字段名称"></el-input>
  65. </el-form-item>
  66. <el-form-item label="字段类型" prop="type">
  67. <el-select v-model="ruleForm.type" placeholder="请选择字段类型" class="width_100">
  68. <el-option v-for="(item, key) in typeObj" :label="item" :value="parseInt(key)"></el-option>
  69. </el-select>
  70. </el-form-item>
  71. <el-form-item label="字段状态" prop="status">
  72. <el-select v-model="ruleForm.status" placeholder="请选择字段状态" style="width: 100%;">
  73. <el-option v-for="(item, key) in statusObj" :label="item" :value="parseInt(key)"></el-option>
  74. </el-select>
  75. </el-form-item>
  76. <el-form-item label="备注" prop="remark">
  77. <el-input v-model="ruleForm.remark" placeholder="请输入备注" type="textarea"></el-input>
  78. </el-form-item>
  79. </el-form>
  80. <div slot="footer" class="dialog-footer">
  81. <el-button @click="cancel">取 消</el-button>
  82. <el-button type="primary" @click="submit" :loading="btnLoading">确 定</el-button>
  83. </div>
  84. </el-dialog>
  85. <!-- 选项卡 -->
  86. <el-dialog :title="title" :visible.sync="dialogVisible2" :width="optionDialogWidth" append-to-body destroy-on-close :close-on-click-modal="false" :before-close="close2" top="10vh">
  87. <el-container class="project-field-option-box" v-loading="optionLoading">
  88. <el-main>
  89. <template v-if="ruleForm.type === 6">
  90. <el-tree
  91. class="tree-option"
  92. :data="ruleForm.option"
  93. node-key="id"
  94. default-expand-all
  95. :expand-on-click-node="false"
  96. draggable
  97. @node-drop="handleDrop"
  98. >
  99. <div class="custom-tree-node" slot-scope="{ node, data }">
  100. <el-input v-model="data.name" placeholder="请输入内容" size="small" class="r" @focus="lockOption = true" @input="valueChange = true" @blur="submitOption(data)"></el-input>
  101. <div class="o">
  102. <span class="el-icon-plus" @click="handleAddTreeNode(data)" title="添加"></span>
  103. <span class="el-icon-delete" @click="handleDeleteTreeNode(node, data)" title="删除"></span>
  104. </div>
  105. </div>
  106. </el-tree>
  107. </template>
  108. <template v-else>
  109. <div v-for="(item, index) in ruleForm.option" class="option">
  110. <el-input v-model="item.name" placeholder="请输入内容" size="small" class="t" @focus="lockOption = true" @input="valueChange = true" @blur="submitOption(item)"></el-input>
  111. <div class="o">
  112. <span class="el-icon-delete" @click="handleDeleteOption(item, index)" title="删除"></span>
  113. </div>
  114. </div>
  115. </template>
  116. </el-main>
  117. <el-footer >
  118. <el-button type="primary" size="small" @click="handleAddOption()" :disabled="lockOption">添加</el-button>
  119. </el-footer>
  120. </el-container>
  121. <div slot="footer" class="dialog-footer">
  122. <el-button @click="close2">关 闭</el-button>
  123. </div>
  124. </el-dialog>
  125. <!-- <import-field-dialog ref="importFieldDialog" @close="getList" />
  126. <copy-field-dialog ref="copyFieldDialog" @close="getList" /> -->
  127. </div>
  128. </template>
  129. <script>
  130. // import ImportFieldDialog from "./ImportField";
  131. // import CopyFieldDialog from "./CopyField";
  132. import { findTreeEq } from "@/utils";
  133. export default {
  134. props:["handleSelectId","reportId"],
  135. components: {
  136. // ImportFieldDialog,
  137. // CopyFieldDialog
  138. },
  139. data() {
  140. return {
  141. optionDialogWidth: '500px',
  142. lockOption: false,
  143. valueChange: false,
  144. reportType:Number(this.handleSelectId),
  145. queryParams: {
  146. name: '',
  147. type: null,
  148. status: null,
  149. size: 10,
  150. current: 1,
  151. projectId: 0,
  152. order: 'desc',
  153. reportType: Number(this.handleSelectId),
  154. reportId: this.reportId,
  155. option:[],
  156. },
  157. projectId: 0,
  158. typeObj: {
  159. 0: '数字',
  160. 1: '日期',
  161. 2: '文本',
  162. // 3: '下拉框',
  163. 4: '单选',
  164. 5: '多选',
  165. 6: '树',
  166. },
  167. pTypeObj: {
  168. 1: '标引',
  169. 2: '分类'
  170. },
  171. statusObj: {
  172. 0: '关闭',
  173. 1: '正常',
  174. },
  175. drawer: false,
  176. dialogVisible: false,
  177. dialogVisible2: false,
  178. title: '',
  179. total: 0,
  180. ruleForm: {},
  181. rules: {
  182. name: [{ required: true, message: '请输入字段名称', trigger: 'blur' },],
  183. type: [{ required: true, message: '请选择类型', trigger: 'change' },],
  184. status: [{ required: true, message: '请选择状态', trigger: 'change' },],
  185. },
  186. btnLoading: false,
  187. loading: false,
  188. optionLoading: false,
  189. tableData: [],
  190. }
  191. },
  192. mounted() {
  193. this.getList()
  194. },
  195. watch: {
  196. handleSelectId(val) {
  197. this.reportType=val
  198. this.getList()
  199. },
  200. reportId(val) {
  201. this.queryParams.reportId=val
  202. this.getList()
  203. },
  204. },
  205. methods: {
  206. handleCurrentChange(val) {
  207. this.queryParams.current = val;
  208. this.getList();
  209. },
  210. cancel() {
  211. this.dialogVisible = false
  212. },
  213. open(id) {
  214. this.projectId = id
  215. this.drawer = true
  216. this.queryParams.projectId = this.projectId
  217. this.getList()
  218. },
  219. close() {
  220. this.$store.commit('SET_CLOSE_FIELD_DRAWER')
  221. this.drawer = false
  222. this.$emit('close')
  223. },
  224. close2() {
  225. this.lockOption = false
  226. this.dialogVisible2 = false
  227. },
  228. // 打开新增自定义字段弹窗
  229. handleAdd() {
  230. this.title = '新增字段'
  231. this.ruleForm = {
  232. projectId: this.projectId,
  233. name: '',
  234. type: 6,
  235. status: 1,
  236. remark: '',
  237. option: [],
  238. reportType: this.reportType,
  239. reportId:this.queryParams.reportId,
  240. }
  241. this.dialogVisible = true
  242. },
  243. handleImport() {
  244. this.$refs.importFieldDialog.open(this.projectId)
  245. },
  246. handleEdit(row) {
  247. this.title = '编辑字段'
  248. this.dialogVisible = true
  249. this.ruleForm = { ...row }
  250. },
  251. // 选项管理
  252. handleEditOption(row) {
  253. this.ruleForm = { ...row }
  254. this.title = '选项管理'
  255. this.dialogVisible2 = true
  256. let params = {
  257. reportId:this.queryParams.reportId,
  258. fieldId: this.ruleForm.id,
  259. type: this.ruleForm.type,
  260. }
  261. if (this.ruleForm.type === 6) {
  262. this.optionDialogWidth = '600px'
  263. } else {
  264. this.optionDialogWidth = '500px'
  265. }
  266. this.optionLoading = true
  267. this.$api.listPatentFieldOption(params).then(response => {
  268. this.$set(this.ruleForm, 'option', response.data)
  269. this.optionLoading = false
  270. }).catch(error => {
  271. this.optionLoading = false
  272. })
  273. },
  274. // 选项卡管理其他删除
  275. handleDeleteOption(item, index) {
  276. if (!item.id) {
  277. this.ruleForm.option.splice(index, 1)
  278. this.lockOption = false
  279. this.valueChange = false
  280. return false
  281. }
  282. this.optionLoading = true
  283. this.$api.deleteOptionPatentField({ id: item.id, type: this.ruleForm.type,reportId:this.queryParams.reportId, }).then(response => {
  284. this.ruleForm.option.splice(index, 1)
  285. this.$message.success('操作成功')
  286. this.optionLoading = false
  287. this.lockOption = false
  288. this.valueChange = false
  289. }).catch(error => {
  290. this.optionLoading = false
  291. })
  292. },
  293. // 选项卡管理拖动
  294. handleDrop(draggingNode, dropNode, dropType, ev) {
  295. let order = dropNode.data.order
  296. switch (dropType) {
  297. case "before":
  298. draggingNode.data.parentId = dropNode.data.parentId
  299. draggingNode.data.order = order - 1
  300. break
  301. case "after":
  302. draggingNode.data.parentId = dropNode.data.parentId
  303. draggingNode.data.order = order + 1
  304. break
  305. case "inner":
  306. draggingNode.data.parentId = dropNode.data.id
  307. draggingNode.data.order = order + 1
  308. break
  309. }
  310. this.valueChange = true
  311. this.submitOption(draggingNode.data)
  312. },
  313. // 选项卡管理树形删除
  314. handleDeleteTreeNode(node, data) {
  315. const parent = node.parent
  316. const children = parent.data.children || parent.data
  317. if (!data.id) {
  318. children.splice(children.findIndex(d => d.$treeNodeId === data.$treeNodeId), 1)
  319. this.lockOption = false
  320. return false
  321. }
  322. this.optionLoading = true
  323. this.$api.deleteOptionPatentField({ id: data.id,type: this.ruleForm.type,reportId:this.queryParams.reportId,}).then(response => {
  324. children.splice(children.findIndex(d => d.id === data.id), 1)
  325. this.$message.success('操作成功')
  326. this.optionLoading = false
  327. this.lockOption = false
  328. }).catch(error => {
  329. this.optionLoading = false
  330. })
  331. },
  332. // 选项卡管理树形添加
  333. handleAddTreeNode(data) {
  334. if (this.lockOption) {
  335. return false
  336. }
  337. if (!data.children) {
  338. this.$set(data, 'children', [])
  339. }
  340. const lastIndex = data.children.length - 1
  341. data.children.push({
  342. name: '',
  343. parentId: data.id,
  344. order: lastIndex < 0 ? 0 : data.children[lastIndex].order + 1,
  345. children: [],
  346. })
  347. this.lockOption = true
  348. this.$forceUpdate()
  349. },
  350. //选项卡输入
  351. submitOption(item) {
  352. // if (!this.$permission('/workspace/common/customField/managementOptions')) {
  353. // return false
  354. // }
  355. if (!item.name) {
  356. this.$message.error('请输入内容')
  357. return false
  358. }
  359. if (!this.valueChange) {
  360. this.lockOption = false
  361. return false
  362. }
  363. let data = {
  364. id: item.id,
  365. name: item.name,
  366. fieldId: this.ruleForm.id,
  367. type: this.ruleForm.type,
  368. parentId: item.parentId,
  369. reportId:this.queryParams.reportId,
  370. order: item.order,
  371. }
  372. this.optionLoading = true
  373. this.$api.updatePatentField(data).then(response => {
  374. this.$set(item, 'id', response.data)
  375. this.$message.success('操作成功')
  376. this.optionLoading = false
  377. this.lockOption = false
  378. this.valueChange = false
  379. }).catch(error => {
  380. this.optionLoading = false
  381. })
  382. },
  383. // 选项卡管理添加
  384. handleAddOption() {
  385. if (this.ruleForm.type === 6) {
  386. const lastIndex = this.ruleForm.option.length - 1
  387. this.ruleForm.option.push({
  388. name: '',
  389. parentId: 0,
  390. order: lastIndex < 0 ? 0 : this.ruleForm.option[lastIndex].order + 1,
  391. children: [],
  392. })
  393. } else {
  394. this.ruleForm.option.push({
  395. name: ''
  396. })
  397. }
  398. this.lockOption = true
  399. },
  400. getList() {
  401. this.queryParams.reportType = this.reportType
  402. this.loading = true
  403. this.$api.listPatentField(this.queryParams).then(response => {
  404. if (response.code == 200) {
  405. // response.data.option=[]
  406. this.tableData = response.data
  407. // this.total = response.pageColumn.total
  408. this.total = response.data.length
  409. this.loading = false
  410. }
  411. }).catch(error => {
  412. this.loading = false
  413. })
  414. },
  415. validationForm() {
  416. return new Promise((resolve, reject) => {
  417. switch (this.ruleForm.type) {
  418. case 0:
  419. case 1:
  420. case 2:
  421. resolve()
  422. break
  423. case 5:
  424. const optionName = this.ruleForm.option.map(item => item.name)
  425. if (optionName.length === 0) {
  426. reject('请添加选项')
  427. }
  428. if (!optionName.every(item => !!item)) {
  429. reject('选项不能为空')
  430. }
  431. if (this.$_.uniq(optionName).length !== optionName.length) {
  432. reject('选项名称重复')
  433. }
  434. resolve()
  435. break
  436. case 6:
  437. const flag = findTreeEq(this.ruleForm.option, 'name')
  438. if (flag) {
  439. reject(`${flag}`)
  440. }
  441. resolve()
  442. break
  443. }
  444. })
  445. },
  446. // 确定添加自定义字段
  447. submit() {
  448. this.$refs.ruleForm.validate((valid) => {
  449. if (valid) {
  450. this.btnLoading = true
  451. if (this.ruleForm.id) {
  452. this.$api.editPatentField(this.ruleForm).then(response => {
  453. this.$message.success('编辑成功')
  454. this.btnLoading = false
  455. this.getList()
  456. this.cancel()
  457. }).catch(error => {
  458. this.btnLoading = false
  459. })
  460. } else {
  461. this.$api.addPatentField(this.ruleForm).then(response => {
  462. this.$message.success('新增成功')
  463. this.btnLoading = false
  464. this.getList()
  465. this.cancel()
  466. }).catch(error => {
  467. this.btnLoading = false
  468. })
  469. }
  470. }
  471. })
  472. },
  473. // 复制
  474. handleCopy(row) {
  475. this.$refs.copyFieldDialog.open(row)
  476. },
  477. handleDelete(row) {
  478. this.$confirm('确认删除本条数据吗?', '提示', {
  479. confirmButtonText: '确定',
  480. cancelButtonText: '取消',
  481. type: 'warning'
  482. }).then(() => {
  483. this.loading = true
  484. this.$api.deletePatentField({ id: row.id ,reportId:this.queryParams.reportId,}).then(response => {
  485. this.$message.success('删除成功')
  486. this.loading = false
  487. this.getList()
  488. }).catch(error => {
  489. this.loading = false
  490. })
  491. })
  492. }
  493. }
  494. }
  495. </script>
  496. <style lang="scss">
  497. .project-field {
  498. .pagination {
  499. text-align: center;
  500. margin: 20px 0;
  501. }
  502. .project-field-header-form {
  503. margin-left: 20px;
  504. }
  505. .project-field-main {
  506. background: #fff;
  507. padding: 5px 20px;
  508. margin-top: 20px;
  509. }
  510. }
  511. .project-field-option-box {
  512. height: 500px !important;
  513. background: #f5f5f5;
  514. border-radius: 5px;
  515. border: 1px solid #cecece;
  516. overflow: hidden;
  517. .option {
  518. margin-bottom: 10px;
  519. .t {
  520. cursor: pointer;
  521. width: 390px;
  522. }
  523. .o {
  524. cursor: pointer;
  525. width: 20px;
  526. float: right;
  527. text-align: right;
  528. margin-top: 5px;
  529. }
  530. }
  531. .el-footer {
  532. line-height: 50px;
  533. height: 50px !important;
  534. padding: 0 10px !important;
  535. }
  536. .tree-option {
  537. background: #f5f5f5 !important;
  538. .is-expanded, .is-focusable, {
  539. .el-tree-node__content:hover, .el-tree-node__content {
  540. background: #f5f5f5 !important;
  541. }
  542. }
  543. .el-tree-node__content {
  544. height: 40px !important;
  545. }
  546. .custom-tree-node {
  547. width: 100%;
  548. .r {
  549. width: 300px;
  550. }
  551. .o {
  552. cursor: pointer;
  553. width: 40px;
  554. float: right;
  555. text-align: right;
  556. margin-top: 5px;
  557. span:nth-child(1) {
  558. margin-right: 10px;
  559. }
  560. }
  561. }
  562. }
  563. }
  564. </style>