pro_relation.vue 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <div>
  3. <!-- 项目关联-->
  4. <el-dialog v-model='showRelation'
  5. append-to-body
  6. center
  7. title="关联子项目"
  8. width="65%"
  9. @close="close"
  10. >
  11. <avue-crud ref="crud"
  12. v-model="form"
  13. v-model:page="page"
  14. :before-open="beforeOpen"
  15. :data="data"
  16. :option="option"
  17. :permission="permissionList"
  18. :table-loading="loading"
  19. class="curd"
  20. @row-del="rowDel"
  21. @current-change="currentChange"
  22. @size-change="sizeChange"
  23. @refresh-change="refreshChange"
  24. @on-load="onLoad">
  25. </avue-crud>
  26. </el-dialog>
  27. <!-- 新增关联项目-->
  28. <el-dialog v-model='showAdd'
  29. append-to-body
  30. center
  31. title="新增关联项目"
  32. width="65%">
  33. <div class="flex flex-col">
  34. <el-input
  35. v-model="keyWords"
  36. clearable
  37. placeholder="项目信息快速搜索"
  38. prefix-icon="Search"
  39. @keydown="searchPro"
  40. />
  41. </div>
  42. <div class="hide-scrollbar full-width" style="height: 30vh;overflow-x: scroll">
  43. <!-- <div v-if='attaches.length === 0' class='full-width flex flex-center '>-->
  44. <!-- <el-empty image-size='100'/>-->
  45. <!-- </div>-->
  46. <div class="flex flex-justify-between mt-20 flex-center">
  47. <span class="bold font-15 grey ml-5 ">搜索结果</span>
  48. </div>
  49. <el-divider/>
  50. <div class="flex flex-center flex-justify-between mt-5" v-for="item in proList" :key="item.id">
  51. <span class="bold">{{ item.name }}</span>
  52. <baseButton icon="Lock" title="关联" type="0" width="60" @click="connectProject(item)"/>
  53. </div>
  54. </div>
  55. </el-dialog>
  56. </div>
  57. </template>
  58. <script>
  59. import baseButton from '@/components/base-button.vue'
  60. import { ElMessageBox } from 'element-plus'
  61. export default {
  62. name: 'pro_relation',
  63. components: { baseButton },
  64. props: {
  65. showRelation: {
  66. type: Boolean,
  67. default: false
  68. },
  69. projectId: ''
  70. },
  71. watch: {
  72. showRelation: {
  73. handler (val) {
  74. console.log(val)
  75. },
  76. immediate: true
  77. }
  78. },
  79. data () {
  80. return {
  81. showAdd: false,
  82. data: [],
  83. form: {},
  84. option: {
  85. refreshBtn: false,
  86. tip: false,
  87. columnBtn: false,
  88. searchShow: true,
  89. editBtn: true,
  90. editBtnText: '解绑',
  91. editBtnIcon: 'Unlock',
  92. addBtn: true,
  93. delBtn: false,
  94. border: true,
  95. index: true,
  96. align: 'center',
  97. viewBtn: true,
  98. viewBtnText: '详情',
  99. menuWidth: 320,
  100. dialogClickModal: false,
  101. column: [
  102. {
  103. label: '项目名称',
  104. prop: 'name',
  105. addDisplay: false,
  106. editDisplay: false
  107. }]
  108. },
  109. page: {
  110. size: 10,
  111. current: 1,
  112. total: 0
  113. },
  114. keyWords: '',
  115. proList: []
  116. }
  117. },
  118. methods: {
  119. close () {
  120. this.$emit('close')
  121. },
  122. onLoad (query = {}) {
  123. this.loading = true
  124. this.$api.project.childrenList({ parentId: this.projectId }).then(res => {
  125. this.loading = false
  126. if (res.code === 200) {
  127. this.data = res.data.childrenList
  128. this.page.total = res.data.total
  129. this.$emit('success', this.page.total)
  130. }
  131. }).finally(() => {
  132. this.loading = false
  133. })
  134. },
  135. beforeOpen (done, type) {
  136. if (['edit'].includes(type)) {
  137. ElMessageBox.confirm(
  138. '点击确定将解除项目绑定关系?',
  139. '提示',
  140. {
  141. confirmButtonText: '确定',
  142. cancelButtonText: '取消',
  143. type: 'warning'
  144. }
  145. )
  146. .then((res) => {
  147. console.log(res)
  148. this.$api.project.removeContact({ id: this.form.id }).then(res => {
  149. if (res.code === 200) {
  150. this.onLoad()
  151. this.$message.success(res.msg)
  152. } else {
  153. this.$message.error(res.msg)
  154. }
  155. })
  156. })
  157. .catch(() => {
  158. })
  159. } else if (type === 'view') {
  160. this.$router.push({
  161. path: '/home/pro_detail',
  162. query: { id: this.form.id }
  163. })
  164. } else if (type === 'add') {
  165. this.showAdd = true
  166. this.showRelation = false
  167. }
  168. },
  169. currentChange (currentPage) {
  170. this.page.current = currentPage
  171. },
  172. sizeChange (pageSize) {
  173. this.page.size = pageSize
  174. },
  175. refreshChange () {
  176. this.onLoad()
  177. },
  178. rowDel (row) {
  179. this.$confirm('确定删除选择的项目?', {
  180. confirmButtonText: '确定',
  181. cancelButtonText: '取消',
  182. type: 'warning'
  183. })
  184. .then(() => {
  185. this.$api.project.projectRemove({ ids: row.id }).then(res => {
  186. if (res.code === 200) {
  187. this.$message.success(res.msg)
  188. this.onLoad()
  189. } else {
  190. this.$message.error(res.msg)
  191. }
  192. })
  193. })
  194. },
  195. searchPro () {
  196. const data = { projectName: this.keyWords }
  197. this.$api.project.projectList(this.page.current, this.page.size, data).then(res => {
  198. if (res.code === 200) {
  199. this.proList = res.data.records.filter(sub => sub.id !== this.projectId)
  200. }
  201. })
  202. },
  203. connectProject (item) {
  204. const params = {
  205. projectId: this.projectId,
  206. childrenIdList: [item.id]
  207. }
  208. this.$api.project.proContact(params).then(res => {
  209. if (res.code === 200) {
  210. this.showAdd = false
  211. this.onLoad()
  212. this.$message.success(res.msg)
  213. } else {
  214. this.$message.error(res.msg)
  215. }
  216. })
  217. }
  218. }
  219. }
  220. </script>
  221. <style scoped>
  222. </style>