index.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <template>
  2. <div class="page-container row-container">
  3. <!-- 左侧区域 -->
  4. <section class="list-part-container" style="flex: 2">
  5. <!-- 搜索区 -->
  6. <el-form class="list-search-container" :model="queryDeptParams" ref="queryRef" :inline="true">
  7. <el-form-item class="section-title" label="车间管理" />
  8. <el-form-item>
  9. <el-button type="primary" icon="Plus" @click="handleAdd">新增</el-button>
  10. </el-form-item>
  11. <el-form-item label="车间名称:" prop="name">
  12. <el-input v-model.trim="queryParams.name" placeholder="请输入车间名称" @keydown.enter.prevent @keyup.enter="handleSearch" clearable style="width: 155px" />
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button type="info" icon="Search" @click="handleSearch">搜索</el-button>
  16. </el-form-item>
  17. </el-form>
  18. <!-- 列表区 -->
  19. <div class="el-table-container">
  20. <div class="el-table-inner-container">
  21. <!-- 列表区 -->
  22. <el-table ref="workshopTable" v-loading="loading" :data="workshopList" row-key="id" height="100%" :indent="20" default-expand-all highlight-current-row @current-change="handleGetDept">
  23. <el-table-column label="行号" type="index" width="50" align="center" />
  24. <el-table-column label="车间名称" prop="name" align="center" />
  25. <el-table-column label="操作" width="150" align="center">
  26. <template #default="scope">
  27. <el-button link type="warning" icon="Edit" @click="handleUpdateWorkshop(scope.row)">编辑</el-button>
  28. <el-button link type="danger" icon="Delete" @click="handleDeleteWorkshop(scope.row)">删除</el-button>
  29. </template>
  30. </el-table-column>
  31. </el-table>
  32. </div>
  33. </div>
  34. </section>
  35. <!-- 右侧区域 -->
  36. <section class="list-part-container" style="flex: 3">
  37. <!-- 搜索区 -->
  38. <el-form class="list-search-container" :model="queryDeptParams" ref="queryRef" :inline="true">
  39. <el-form-item class="section-title" label="工段" />
  40. <el-form-item>
  41. <el-button type="primary" icon="Plus" @click="handleAddDept">新增</el-button>
  42. <el-button type="danger" icon="Delete" :disabled="ids.length == 0" @click="handleDeptDelete">
  43. 删除</el-button>
  44. </el-form-item>
  45. </el-form>
  46. <!-- 列表区 -->
  47. <div class="el-table-container">
  48. <div class="el-table-inner-container">
  49. <el-table v-loading="deptLoading" :data="deptList" :row-key="getRowKey" height="100%" @selection-change="handleSelectionChange">
  50. <el-table-column type="selection" width="40" align="center" />
  51. <el-table-column type="index" label="行号" width="50" align="center" />
  52. <el-table-column label="工段名称" prop="deptName" align="center" />
  53. <el-table-column label="工段编码" prop="deptCode" align="center" />
  54. </el-table>
  55. </div>
  56. </div>
  57. <!-- 分页 -->
  58. <pagination v-show="total > 0" :total="total" v-model:page="queryDeptParams.pageNum" v-model:limit="queryDeptParams.pageSize" @pagination="getdeptList" />
  59. </section>
  60. <!-- 表单 -->
  61. <workshop-form ref="workshopRef" @handleSaveSuccess="getList" />
  62. <dept-form ref="deptChoiceRef" :multiple="true" :multiple-selected="handleDeptSelected" />
  63. </div>
  64. </template>
  65. <script setup >
  66. import { listWorkshop, delWorkshop } from '@/api/business/workshop'
  67. import { listDept, updateDeptWorkshop, updateDeptWorkshopByDeptId } from '@/api/system/dept'
  68. import deptForm from '@/views/business/workshop/DialogDept'
  69. import workshopForm from './form'
  70. const { proxy } = getCurrentInstance()
  71. const workshopList = ref([])
  72. const deptList = ref([])
  73. const loading = ref(false)
  74. const deptLoading = ref(false)
  75. const currentWorkshop = ref({})
  76. const total = ref(0)
  77. const ids = ref([])
  78. const workshopIds = ref([])
  79. /** 查询对象 */
  80. const queryParams = ref({
  81. name: ''
  82. })
  83. const queryDeptParams = ref({
  84. deptCode: ''
  85. })
  86. /*********************** 方法区 ****************************/
  87. /** 查询车间管理列表 */
  88. function getList() {
  89. loading.value = true
  90. listWorkshop(queryParams.value).then((res) => {
  91. if (res.code == 200) {
  92. workshopList.value = res.rows
  93. if (workshopList.value.length > 0) {
  94. proxy.$refs.workshopTable.setCurrentRow(workshopList.value[0])
  95. } else {
  96. deptList.value = []
  97. }
  98. }
  99. })
  100. loading.value = false
  101. }
  102. function handleSearch() {
  103. getList()
  104. }
  105. //打开添加工段
  106. const handleAddDept = () => {
  107. handleAddBatchDept()
  108. }
  109. /** 多选添加 */
  110. function handleAddBatchDept() {
  111. let deptIds = []
  112. deptIds = deptList.value.map((item) => {
  113. return item.deptId
  114. })
  115. proxy.$refs.deptChoiceRef.open(deptIds)
  116. }
  117. // 多选框选中数据
  118. function handleSelectionChange(selection) {
  119. ids.value = selection.map((item) => {
  120. return item.deptId
  121. })
  122. console.log(ids.value)
  123. }
  124. /** 获取行 id */
  125. function getRowKey(row) {
  126. return row.deptId
  127. }
  128. /** 新增按钮操作 */
  129. function handleAdd() {
  130. proxy.$refs.workshopRef.open()
  131. }
  132. /** 修改按钮操作 */
  133. function handleUpdateWorkshop(row) {
  134. proxy.$refs.workshopRef.open(row)
  135. }
  136. /**车间表点击事件 */
  137. function handleGetDept(row) {
  138. if (row) {
  139. currentWorkshop.value = row
  140. }
  141. getdeptList()
  142. }
  143. //工段多选带回
  144. function handleDeptSelected(selection) {
  145. let deptInfo = {}
  146. let deptIds = []
  147. deptIds = selection.map((item) => {
  148. return item.deptId
  149. })
  150. deptInfo.workshopId = currentWorkshop.value.id
  151. deptInfo.ids = deptIds
  152. console.log(deptInfo)
  153. updateDeptWorkshop(deptInfo).then((res) => {
  154. if (res.code == 200) {
  155. handleGetDept(currentWorkshop.value)
  156. proxy.$modal.msgSuccess('添加成功!')
  157. }
  158. })
  159. }
  160. function getdeptList() {
  161. queryDeptParams.value.workshopId = currentWorkshop.value.id
  162. listDept(queryDeptParams.value).then((res) => {
  163. console.log(res)
  164. if (res.code == 200) {
  165. deptList.value = res.rows
  166. total.value = res.total
  167. deptLoading.value = false
  168. }
  169. })
  170. }
  171. /** 删除按钮操作 */
  172. function handleDeleteWorkshop(row) {
  173. const _ids = row.id
  174. proxy.$modal
  175. .confirm('是否确认删除选中的车间?')
  176. .then(function () {
  177. return delWorkshop(_ids)
  178. })
  179. //删除车间的同时删除工段上workId
  180. .then(function () {
  181. return updateDeptWorkshopByDeptId({ workshopId: _ids })
  182. })
  183. .then(() => {
  184. getList()
  185. proxy.$modal.msgSuccess('删除成功!')
  186. })
  187. .catch(() => {})
  188. }
  189. /** 车间工段删除按钮操作 */
  190. function handleDeptDelete(row) {
  191. updateDeptWorkshop({ ids: ids.value }).then((res) => {
  192. if (res.code == 200) {
  193. handleGetDept(currentWorkshop.value)
  194. proxy.$modal.msgSuccess('删除成功!')
  195. }
  196. })
  197. }
  198. onMounted(() => {
  199. getList()
  200. })
  201. </script>