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.

274 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
  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 { StepCmdDescMap } from '../../views/craft/craft_constant'
  6. import FtButton from '../common/FTButton/index.vue'
  7. import FTDialog from '../common/FTDialog/index.vue'
  8. import TransferLeft from './TransferLeft.vue'
  9. import TransferRight from './TransferRight.vue'
  10. const emit = defineEmits<{
  11. (e: 'ok'): void
  12. }>()
  13. const visible = ref(false)
  14. const stepStructs = ref<CraftTypes.StepStruct[]>([])
  15. const craftObj = ref<CraftTypes.Craft>({})
  16. const loading = ref(false)
  17. const saveRef = ref<CraftTypes.SaveRef | null>(null)
  18. const tempStepStructs = ref<CraftTypes.StepStruct[]>([])
  19. const oresId = 1
  20. const stepCmds: CraftTypes.StepCmd[] = [
  21. // 'upTray',
  22. // 'downTray',
  23. 'addLiquid',
  24. // 'moveToSol',
  25. // 'moveToHeat',
  26. 'shaking',
  27. 'startHeating',
  28. // 'stopHeating',
  29. 'takePhoto',
  30. // 'delay',
  31. ]
  32. const openDialog = () => {
  33. visible.value = true
  34. }
  35. const closeDialog = () => {
  36. stepStructs.value = []
  37. craftObj.value.name = ''
  38. visible.value = false
  39. }
  40. const editDialog = (craftInfo: CraftTypes.Craft) => {
  41. craftObj.value = { ...craftInfo }
  42. if (craftInfo && craftInfo.steps) {
  43. const step = JSON.parse(craftInfo.steps)
  44. /* eslint-disable no-debugger */
  45. if (step && step.length) {
  46. step.forEach((item: CraftTypes.StepStruct) => {
  47. if (item.method === 'addLiquid') {
  48. const list = item.params.tubeSolList
  49. if (list && list.length === 16 && item.params.tubeSolList) {
  50. item.params.tubeSolList = [{
  51. tubeNum: 0,
  52. addLiquidList: item.params.tubeSolList[0].addLiquidList,
  53. }]
  54. }
  55. }
  56. })
  57. }
  58. stepStructs.value = step
  59. }
  60. openDialog()
  61. }
  62. function onConfirm() {
  63. if (!craftObj.value.name) {
  64. ElMessage.warning('请输入工艺名称')
  65. return
  66. }
  67. const stepList = JSON.parse(JSON.stringify(stepStructs.value))
  68. for (const step of stepList) {
  69. if (step.method === 'addLiquid') {
  70. const list = step.params.tubeSolList
  71. if (list && list.length) {
  72. list.forEach((item: any) => {
  73. const tubeNum = item.tubeNum
  74. if (tubeNum === 0) {
  75. const tubeSolList: CraftTypes.TubeSolStruct[] = []
  76. for (let index = 0; index < 16; index++) {
  77. tubeSolList.push({
  78. tubeNum: index + 1,
  79. addLiquidList: item.addLiquidList,
  80. })
  81. }
  82. step.params.tubeSolList = tubeSolList
  83. }
  84. })
  85. }
  86. }
  87. }
  88. craftObj.value.steps = JSON.stringify(stepList)
  89. confirmCraftEdit(craftObj.value)
  90. }
  91. const confirmCraftEdit = (craft: CraftTypes.Craft) => {
  92. let req
  93. if (craft.id) {
  94. req = updateCraft(craft)
  95. }
  96. else {
  97. craft = { name: craft.name, steps: craft.steps, oresId }
  98. req = createCraft(craft)
  99. }
  100. loading.value = true
  101. saveRef.value && saveRef.value.setLoading(true)
  102. req.then(() => {
  103. saveRef.value && saveRef.value.setLoading(false)
  104. ElMessage.success('保存成功')
  105. emit('ok')
  106. closeDialog()
  107. }).catch((e) => {
  108. console.log('保存工艺失败---', e, tempStepStructs.value)
  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. },
  134. }
  135. }
  136. else if (step === 'delay') {
  137. st = {
  138. method: step,
  139. params: {
  140. second: 10,
  141. },
  142. }
  143. }
  144. else if (step === 'shaking') {
  145. st = {
  146. method: step,
  147. params: {
  148. second: 30,
  149. },
  150. }
  151. }
  152. else {
  153. st = {
  154. method: step,
  155. }
  156. }
  157. stepStructs.value = [...stepStructs.value, st]
  158. tempStepStructs.value = JSON.parse(JSON.stringify(stepStructs.value))
  159. }
  160. function onStepItemDel(order: number) {
  161. stepStructs.value = stepStructs.value.filter((s, i) => i !== order - 1)
  162. }
  163. function transferChange(stepData: CraftTypes.StepStruct, order: number) {
  164. console.log('order === ', stepStructs.value, stepData, order)
  165. }
  166. defineExpose({
  167. openDialog,
  168. closeDialog,
  169. editDialog,
  170. })
  171. </script>
  172. <template>
  173. <FTDialog v-model="visible" title="添加工艺" style="width:70vw; height:70vh">
  174. <div>
  175. <div class="mt-5 mb-8 flex items-center">
  176. <label class="font-medium mr-4">工艺名称</label>
  177. <el-input
  178. v-model.trim="craftObj.name"
  179. style="width: 200px"
  180. size="small"
  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" :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: 12.5rem;
  228. place-items: center;
  229. height: 3rem;
  230. }
  231. .transfer-right{
  232. max-height: 40vh;
  233. overflow: auto;
  234. }
  235. .step-content{
  236. margin-top:1rem;
  237. display: grid;
  238. grid-template-columns: 1fr 1fr;
  239. height: 21rem;
  240. }
  241. .footer{
  242. display: flex;
  243. height: 5rem;
  244. justify-content: center;
  245. align-items: center;
  246. }
  247. .craft-title{
  248. display: grid;
  249. grid-template-columns: 1fr 1fr;
  250. div{
  251. font-size:12px;
  252. margin-top: 5px;
  253. }
  254. .title-right{
  255. display: flex;
  256. justify-content: center;
  257. }
  258. }
  259. </style>