You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.9 KiB

3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
  1. <script lang="ts" setup>
  2. import type { AddCraftType, Craft } from './craftType'
  3. import { createCraft, delCraft, getCraftList, setCraft, startCraft, updateCraft } from '@/apis/crafts'
  4. import { ElMessage, ElMessageBox } from 'element-plus'
  5. import { onMounted, ref } from 'vue'
  6. import AddCraftDialog from './AddCraftDialog.vue'
  7. const tableData = ref([])
  8. const addCraftRef = ref<AddCraftType | null>(null)
  9. const selectable = ref()
  10. const multipleSelection = ref<Craft[]>()
  11. const heatVisible = ref(false)
  12. const heatId = ref()
  13. const oresId = 1
  14. onMounted(() => {
  15. queryCrafList()
  16. })
  17. const queryCrafList = () => {
  18. const params = {
  19. oresId: 1,
  20. }
  21. getCraftList(params).then((res) => {
  22. tableData.value = res
  23. })
  24. }
  25. const onAddCraft = () => {
  26. if (addCraftRef.value) {
  27. addCraftRef.value.openDialog()
  28. }
  29. }
  30. const onEditCraft = () => {
  31. if (addCraftRef.value && multipleSelection.value) {
  32. addCraftRef.value.editDialog(multipleSelection.value[0])
  33. }
  34. }
  35. const handleSelectionChange = (rows: Craft[]) => {
  36. if (rows && rows.length) {
  37. console.log('rows---', rows)
  38. multipleSelection.value = rows
  39. }
  40. }
  41. const onDelCraft = () => {
  42. if (!multipleSelection.value || !multipleSelection.value.length) {
  43. ElMessage.warning('请选择要删除的数据')
  44. return
  45. }
  46. ElMessageBox.confirm(
  47. '确认删除选中的数据吗?',
  48. '确认提示',
  49. {
  50. confirmButtonText: '确认',
  51. cancelButtonText: '取消',
  52. type: 'warning',
  53. },
  54. ).then(() => {
  55. if (multipleSelection.value && multipleSelection.value.length) {
  56. const ids = multipleSelection.value.map(item => item.id)
  57. delCraft(ids.join(',')).then((res) => {
  58. console.log('删除成功', res)
  59. ElMessage.success('删除成功')
  60. queryCrafList()
  61. })
  62. }
  63. })
  64. }
  65. const onSelectHeatId = () => {
  66. if (!multipleSelection.value || multipleSelection.value.length !== 1) {
  67. ElMessage.warning('每次只可执行一次工艺')
  68. return
  69. }
  70. heatVisible.value = true
  71. }
  72. const confirmCraftEdit = (craft: Craft) => {
  73. // const req = createCraft({ name: craft.name, steps: craft.steps, oresId })
  74. let req
  75. if (craft.id) {
  76. req = updateCraft(craft)
  77. }
  78. else {
  79. req = createCraft({ name: craft.name, steps: craft.steps, oresId })
  80. }
  81. req.then(() => {
  82. ElMessage.success('保存成功')
  83. queryCrafList()
  84. if (addCraftRef.value) {
  85. addCraftRef.value.closeDialog()
  86. }
  87. })
  88. }
  89. // 开始执行工艺
  90. const onStart = () => {
  91. if (!heatId.value) {
  92. ElMessage.warning('请选择加热区')
  93. return
  94. }
  95. if (multipleSelection.value && multipleSelection.value.length && heatId) {
  96. const craft = multipleSelection.value[0]
  97. // 先进行配置
  98. const craftId = craft.id
  99. if (craftId && heatId.value) {
  100. const params = {
  101. craftId: craft.id,
  102. heatId: heatId.value,
  103. }
  104. setCraft(params).then(() => {
  105. console.log('配置成功==')
  106. startCraft({ heatId: heatId.value }).then(() => {
  107. console.log('开始执行')
  108. ElMessage.success('工艺已开始执行')
  109. heatVisible.value = false
  110. })
  111. })
  112. }
  113. }
  114. }
  115. </script>
  116. <template>
  117. <div class="component-page">
  118. <section class="flex items-center h-20 gap-3 pl-3">
  119. <el-button type="primary" size="small" @click="onAddCraft">
  120. 添加工艺
  121. </el-button>
  122. <el-button type="primary" size="small" @click="onEditCraft">
  123. 编辑工艺
  124. </el-button>
  125. <el-button type="primary" size="small" @click="onDelCraft">
  126. 删除工艺
  127. </el-button>
  128. <el-button type="primary" size="small" @click="onSelectHeatId">
  129. 执行工艺
  130. </el-button>
  131. </section>
  132. <main>
  133. <el-table :data="tableData" style="width: 100%" size="small" @selection-change="handleSelectionChange">
  134. <el-table-column type="selection" width="55" :selectable="selectable" />
  135. <el-table-column prop="name" label="工艺名称" />
  136. <el-table-column prop="orgName" label="矿石名称">
  137. <template #default="scope">
  138. <!-- 测试数据 -->
  139. <span v-if="scope.row.oresId === 1">硫酸</span>
  140. <span v-else>硝酸</span>
  141. </template>
  142. </el-table-column>
  143. <el-table-column prop="createTime" label="创建日期" />
  144. </el-table>
  145. </main>
  146. <AddCraftDialog ref="addCraftRef" @ok="confirmCraftEdit" />
  147. <!-- 执行工艺选择加热区 -->
  148. <el-dialog v-model="heatVisible" title="执行工艺" width="30vw">
  149. <div style="display: flex; justify-content: center;align-items: center;">
  150. <label>选择加热区</label>
  151. <el-select v-model="heatId" style="width:200px">
  152. <el-option v-for="el in 6" :key="el" :label="`加热区${el}`" :value="el" />
  153. </el-select>
  154. </div>
  155. <div style="display: flex; justify-content: center;align-items: center; height:100px">
  156. <el-button type="primary" @click="onStart">
  157. 开始执行
  158. </el-button>
  159. </div>
  160. </el-dialog>
  161. </div>
  162. </template>