BusinessDirection.vue 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. <template>
  2. <div>
  3. <div class="spacing">
  4. <el-button size="small" type="primary" icon="el-icon-plus" @click="handlerModule('add')"> 新增一级方向 </el-button>
  5. </div>
  6. <el-table ref="moduleTable" :data="moduleData" style="width: 100%;margin-bottom: 20px;" row-key="id" border :tree-props="{children: 'childRqmtOrnts', hasChildren: 'hasChildren'}" header-align="center" size="mini" :header-cell-style="{ background: '#F2F3F6' }" fit>
  7. <el-table-column v-if="false" prop="id" label="ID" width="180" align="center" />
  8. <el-table-column prop="rqmtOrntName" label="需求方向名称" />
  9. <el-table-column prop="creator" label="创建人" width="150" align="center" />
  10. <el-table-column prop="gmtCreate" label="创建时间" width="150" align="center" />
  11. <el-table-column label="操作" width="240" align="center">
  12. <template slot-scope="scope">
  13. <el-button size="mini" plain @click="handlerModule('add', scope.row, scope.$index)">添加</el-button>
  14. <el-button size="mini" plain type="primary" @click="handlerModule('edit', scope.row, scope.$index)">编辑</el-button>
  15. <el-button size="mini" plain type="danger" @click="handlerModule('delete', scope.row, scope.$index)">删除</el-button>
  16. </template>
  17. </el-table-column>
  18. </el-table>
  19. <el-dialog :title="moduleTitle" :visible.sync="moduleDialog" class="public_task" width="30%" :before-close="() => {moduleDialog = false}">
  20. <div class="blueStripe" />
  21. <el-form ref="moduleForm" :model="moduleForm">
  22. <template v-if="curcentModule === 'add'">
  23. <el-form-item label="父方向:" :label-width="formLabelWidth">
  24. <el-col :span="18">{{ curcentParent }}</el-col>
  25. </el-form-item>
  26. <el-form-item
  27. v-for="(moduleName, index) in moduleForm.rqmtOrntNames"
  28. :key="index"
  29. label="方向名称:"
  30. :label-width="formLabelWidth"
  31. :prop="'rqmtOrntNames.' + index"
  32. :rules="[
  33. { required: true, message: '请输入方向名称', trigger: 'blur' },
  34. { max: 20, message: '方向名称过长', trigger: 'blur' }
  35. ]"
  36. >
  37. <el-col :span="20">
  38. <el-input v-model="moduleForm.rqmtOrntNames[index]" style="width: 100%;" autocomplete="off" placeholder="不超过20个字符" />
  39. </el-col>
  40. <el-col v-show="index === moduleForm.rqmtOrntNames.length-1" :span="2" :offset="1">
  41. <i class="el-icon-circle-plus-outline" @click="addModuleForm()" />
  42. </el-col>
  43. </el-form-item>
  44. </template>
  45. <template v-if="curcentModule === 'edit'">
  46. <el-form-item label="父方向:" :label-width="formLabelWidth">
  47. <el-col :span="18">{{ curcentParent }}</el-col>
  48. </el-form-item>
  49. <el-form-item label="方向名称:" :label-width="formLabelWidth">
  50. <el-input v-model="moduleForm.rqmtOrntNames[0]" style="width: 100%;" autocomplete="off" placeholder="不超过20个字符" />
  51. </el-form-item>
  52. </template>
  53. <div v-if="curcentModule === 'delete'" align="center">
  54. 是否要删除需求方向:<span style="color: #E6A23C">{{ moduleForm.rqmtOrntNames[0] }}</span>
  55. </div>
  56. </el-form>
  57. <span slot="footer" class="dialog-footer">
  58. <el-button size="mini" @click="moduleDialog = false">取 消</el-button>
  59. <el-button type="primary" size="mini" @click="confirmModule('moduleForm')">确 定</el-button>
  60. </span>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. import { settingQueryBizRqmtOrntList, settingDeleteBizRqmtOrnt, settingAddBizRqmtOrnt, settingUpdateBizRqmtOrnt, queryBizModuleList } from '@/api/configure'
  66. import '@/styles/PublicStyle/index.scss'
  67. import { mapGetters } from 'vuex'
  68. export default {
  69. data() {
  70. return {
  71. moduleData: [],
  72. moduleDialog: false,
  73. formLabelWidth: '120px',
  74. curcentModule: '', // 当前方向类型
  75. moduleForm: { bizId: null, rqmtOrntNames: [null], parentId: null, id: null }, // 添加方向form
  76. moduleTitle: '',
  77. codeName: '' // 编辑失败还原之前的名字
  78. }
  79. },
  80. computed: {
  81. ...mapGetters(['bizId'])
  82. },
  83. watch: {
  84. bizId: {
  85. handler(newV) {
  86. if (newV === -1) return
  87. this.settingQueryBizRqmtOrntList()
  88. },
  89. immediate: true
  90. }
  91. },
  92. created() {
  93. this.getQueryBizModuleList()
  94. },
  95. methods: {
  96. async getQueryBizModuleList() { // 获取结构化模块列表
  97. console.log(this.$store.state.data.bizId, '哈哈')
  98. const res = await queryBizModuleList(this.bizId)
  99. this.data = this.handleData(res.data)
  100. },
  101. handleData(arr) {
  102. if (arr.length === 0) return
  103. const newArr = arr.filter(item => {
  104. return item.isDelete !== 1
  105. })
  106. for (let i = 0; i < newArr.length; i++) {
  107. newArr[i].childModules = this.handleData(newArr[i].childModules)
  108. }
  109. return newArr
  110. },
  111. async settingQueryBizRqmtOrntList() {
  112. const res = await settingQueryBizRqmtOrntList(this.bizId)
  113. this.moduleData = res.data
  114. },
  115. handlerModule(type, data, index) { // 方向处理
  116. this.curcentModule = type
  117. this.moduleForm = { bizId: this.bizId, rqmtOrntNames: [null], parentId: -1, id: null }// 初始化
  118. this.curcentParent = '无'
  119. this.moduleTitle = '新增方向'
  120. if (data && type === 'add') {
  121. this.moduleDialog = true
  122. this.moduleTitle = '新增方向'
  123. this.curcentParent = data.rqmtOrntName
  124. this.moduleForm.parentId = data.id
  125. } else if (data && type === 'edit') {
  126. this.moduleDialog = true
  127. this.moduleTitle = '编辑方向'
  128. this.moduleForm.id = data.id
  129. this.curcentParent = data.parentId === -1 ? '无' : data.parentRqmtOrntName
  130. this.moduleForm.parentId = data.parentId
  131. this.moduleForm.rqmtOrntNames[0] = data.rqmtOrntName
  132. this.codeName = data.rqmtOrntName
  133. } else if (data && type === 'delete') {
  134. if (data.childRqmtOrnts && data.childRqmtOrnts.length > 0) {
  135. this.$message({ message: '该方向下存在子方向,不允许删除', type: 'error' })
  136. } else {
  137. this.moduleDialog = true
  138. this.moduleTitle = '删除确认'
  139. this.moduleForm.id = data.id
  140. this.moduleForm.rqmtOrntNames[0] = data.rqmtOrntName
  141. }
  142. } else {
  143. this.moduleDialog = true
  144. }
  145. },
  146. addModuleForm() {
  147. if (this.moduleForm.rqmtOrntNames.length <= 4) {
  148. this.moduleForm.rqmtOrntNames.push(null)
  149. }
  150. },
  151. async confirmModule(formName) { // 方向操作确认
  152. if (this.curcentModule === 'add') {
  153. this.$refs[formName].validate((valid) => {
  154. if (valid) {
  155. settingAddBizRqmtOrnt(this.moduleForm).then(res => {
  156. if (res.code === 200) {
  157. this.moduleDialog = false
  158. this.settingQueryBizRqmtOrntList()
  159. this.$message({ message: '已新增需求方向', type: 'success' })
  160. }
  161. })
  162. } else {
  163. this.$message({ message: '填写格式不正确', type: 'error' })
  164. return false
  165. }
  166. })
  167. } else if (this.curcentModule === 'edit') {
  168. this.$refs[formName].validate((valid) => {
  169. if (valid) {
  170. let data = {}
  171. data = this.moduleForm
  172. data.rqmtOrntName = this.moduleForm.rqmtOrntNames.toString()
  173. settingUpdateBizRqmtOrnt(data).then(res => {
  174. if (res.code === 200) {
  175. this.moduleDialog = false
  176. this.settingQueryBizRqmtOrntList()
  177. this.$message({ message: '已修改需求方向', type: 'success' })
  178. } else {
  179. this.$set(this.moduleForm, 'rqmtOrntNames[0]', this.codeName)
  180. }
  181. })
  182. } else {
  183. this.$message({ message: '填写格式不正确', type: 'error' })
  184. return false
  185. }
  186. })
  187. } else if (this.curcentModule === 'delete') {
  188. const res = await settingDeleteBizRqmtOrnt(this.moduleForm)
  189. if (res.code === 200) {
  190. this.moduleDialog = false
  191. this.settingQueryBizRqmtOrntList()
  192. this.$message({ message: '删除成功', type: 'success' })
  193. }
  194. }
  195. }
  196. }
  197. }
  198. </script>
  199. <style lang="scss" scoped>
  200. .spacing {
  201. margin: 0 0 20px;
  202. text-align: right;
  203. }
  204. </style>