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.

275 lines
6.6 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
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 { createCraft, updateCraft } from '@/apis/crafts'
  3. import { ElMessage } from 'element-plus'
  4. import { ref } from 'vue'
  5. import { useRoute } from 'vue-router'
  6. import { StepCmdDescMap } from '../../views/craft/craft_constant'
  7. import FtButton from '../common/FTButton/index.vue'
  8. import FTDialog from '../common/FTDialog/index.vue'
  9. import TransferLeft from './TransferLeft.vue'
  10. import TransferRight from './TransferRight.vue'
  11. const emit = defineEmits<{
  12. (e: 'ok'): void
  13. }>()
  14. const visible = ref(false)
  15. const stepStructs = ref<CraftTypes.StepStruct[]>([])
  16. const craftObj = ref<CraftTypes.Craft>({})
  17. const loading = ref(false)
  18. const saveRef = ref<CraftTypes.SaveRef | null>(null)
  19. const tempStepStructs = ref<CraftTypes.StepStruct[]>([])
  20. const route = useRoute()
  21. const oresId: number = route.query.oreId as unknown as number
  22. const stepCmds: CraftTypes.StepCmd[] = [
  23. // 'upTray',
  24. // 'downTray',
  25. 'addLiquid',
  26. // 'moveToSol',
  27. // 'moveToHeat',
  28. 'shaking',
  29. 'startHeating',
  30. // 'stopHeating',
  31. 'takePhoto',
  32. // 'delay',
  33. ]
  34. const openDialog = () => {
  35. visible.value = true
  36. }
  37. const closeDialog = () => {
  38. stepStructs.value = []
  39. craftObj.value.name = ''
  40. visible.value = false
  41. }
  42. const editDialog = (craftInfo: CraftTypes.Craft) => {
  43. craftObj.value = { ...craftInfo }
  44. if (craftInfo && craftInfo.steps) {
  45. const step = JSON.parse(craftInfo.steps)
  46. if (step && step.length) {
  47. step.forEach((item: CraftTypes.StepStruct) => {
  48. if (item.method === 'addLiquid') {
  49. const list = item.params.tubeSolList
  50. if (list && list.length === 16 && item.params.tubeSolList) {
  51. item.params.tubeSolList = [{
  52. tubeNum: 0,
  53. addLiquidList: item.params.tubeSolList[0].addLiquidList,
  54. }]
  55. }
  56. }
  57. })
  58. }
  59. stepStructs.value = step
  60. }
  61. openDialog()
  62. }
  63. function onConfirm() {
  64. if (!craftObj.value.name) {
  65. ElMessage.warning('请输入工艺名称')
  66. return
  67. }
  68. const stepList = JSON.parse(JSON.stringify(stepStructs.value))
  69. for (const step of stepList) {
  70. if (step.method === 'addLiquid') {
  71. const list: CraftTypes.TubeSolStruct[] = step.params.tubeSolList
  72. if (list && list.length) {
  73. list.forEach((item) => {
  74. const tubeNum = item.tubeNum
  75. if (tubeNum === 0) {
  76. const tubeSolList: CraftTypes.TubeSolStruct[] = []
  77. for (let index = 0; index < 16; index++) {
  78. tubeSolList.push({
  79. tubeNum: index + 1,
  80. addLiquidList: item.addLiquidList,
  81. })
  82. }
  83. step.params.tubeSolList = tubeSolList
  84. }
  85. })
  86. }
  87. }
  88. }
  89. craftObj.value.steps = JSON.stringify(stepList)
  90. confirmCraftEdit(craftObj.value)
  91. }
  92. const confirmCraftEdit = (craft: CraftTypes.Craft) => {
  93. let req
  94. if (craft.id) {
  95. req = updateCraft(craft)
  96. }
  97. else {
  98. craft = { name: craft.name, steps: craft.steps, oresId }
  99. req = createCraft(craft)
  100. }
  101. loading.value = true
  102. saveRef.value && saveRef.value.setLoading(true)
  103. req.then(() => {
  104. saveRef.value && saveRef.value.setLoading(false)
  105. ElMessage.success('保存成功')
  106. emit('ok')
  107. closeDialog()
  108. }).catch(() => {
  109. saveRef.value && saveRef.value.setLoading(false)
  110. })
  111. }
  112. function addStep(step: CraftTypes.StepCmd) {
  113. let st: CraftTypes.StepStruct
  114. if (step === 'addLiquid') {
  115. st = {
  116. method: step,
  117. params: {
  118. tubeSolList: [{
  119. tubeNum: 0,
  120. addLiquidList: [{
  121. solId: 1,
  122. volume: 10,
  123. }],
  124. }],
  125. },
  126. }
  127. }
  128. else if (step === 'startHeating') {
  129. st = {
  130. method: step,
  131. params: {
  132. temperature: 100,
  133. second: 10,
  134. },
  135. }
  136. }
  137. else if (step === 'delay') {
  138. st = {
  139. method: step,
  140. params: {
  141. second: 10,
  142. },
  143. }
  144. }
  145. else if (step === 'shaking') {
  146. st = {
  147. method: step,
  148. params: {
  149. second: 30,
  150. },
  151. }
  152. }
  153. else {
  154. st = {
  155. method: step,
  156. }
  157. }
  158. stepStructs.value = [...stepStructs.value, st]
  159. tempStepStructs.value = JSON.parse(JSON.stringify(stepStructs.value))
  160. }
  161. function onStepItemDel(order: number) {
  162. stepStructs.value = stepStructs.value.filter((s, i) => i !== order - 1)
  163. }
  164. function transferChange(stepData: CraftTypes.StepStruct, order: number) {
  165. console.log('order === ', stepStructs.value, stepData, order)
  166. }
  167. defineExpose({
  168. openDialog,
  169. closeDialog,
  170. editDialog,
  171. })
  172. </script>
  173. <template>
  174. <FTDialog v-model="visible" title="添加工艺" style="width:70vw; height:70vh">
  175. <div>
  176. <div class="mt-5 mb-8 flex items-center">
  177. <label class="font-medium mr-4">工艺名称</label>
  178. <el-input
  179. v-model.trim="craftObj.name"
  180. style="width: 200px"
  181. type="text"
  182. placeholder="请输入名称"
  183. class="flex-auto bg-[#f6f6f6] h-11 leading-10 rounded-sm px-4"
  184. />
  185. </div>
  186. <div class="craft-title">
  187. <div>
  188. 工艺步骤
  189. </div>
  190. <div class="title-right">
  191. 选择的步骤
  192. </div>
  193. </div>
  194. <div class="step-content">
  195. <div class="transfer-left">
  196. <TransferLeft v-for="cmd in stepCmds" :key="cmd" :title="StepCmdDescMap[cmd]" @click="addStep(cmd)" />
  197. </div>
  198. <div v-if="stepStructs && stepStructs.length" class="transfer-right">
  199. <TransferRight v-for="(step, idx) in stepStructs" :key="idx" :order="idx + 1" :step="step" type="add" @del="onStepItemDel" @transfer-change="transferChange" />
  200. </div>
  201. <div v-else>
  202. <el-empty description="description">
  203. <template #description>
  204. 未选择工艺步骤
  205. </template>
  206. </el-empty>
  207. </div>
  208. </div>
  209. </div>
  210. <template #footer>
  211. <div class="footer">
  212. <FtButton @click="closeDialog">
  213. 取消
  214. </FtButton>
  215. <FtButton ref="saveRef" type="primary" :loading="loading" :click-handle="onConfirm">
  216. 确定
  217. </FtButton>
  218. </div>
  219. </template>
  220. </FTDialog>
  221. </template>
  222. <style lang="scss" scoped>
  223. .transfer-left{
  224. display: grid;
  225. grid-template-columns: 1fr 1fr;
  226. gap: 1.4rem;
  227. width: 10rem;
  228. place-items: center;
  229. height: 3rem;
  230. }
  231. .transfer-right{
  232. max-height: 40vh;
  233. overflow: auto;
  234. width:30rem;
  235. }
  236. .step-content{
  237. margin-top:1rem;
  238. display: grid;
  239. grid-template-columns: 1fr 1fr;
  240. height: 21rem;
  241. }
  242. .footer{
  243. display: flex;
  244. height: 5rem;
  245. justify-content: center;
  246. align-items: center;
  247. }
  248. .craft-title{
  249. display: grid;
  250. grid-template-columns: 1fr 1fr;
  251. div{
  252. font-size:12px;
  253. margin-top: 5px;
  254. }
  255. .title-right{
  256. display: flex;
  257. justify-content: center;
  258. }
  259. }
  260. </style>