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.

232 lines
5.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
  1. <script lang="ts" setup>
  2. import { updateContainer } from '@/apis/container'
  3. import { useSolutionStore } from '@/stores/useSolutionStore'
  4. import { Plus } from '@element-plus/icons-vue'
  5. import { FtMessage } from 'libs/message'
  6. import { computed, ref } from 'vue'
  7. import { useRouter } from 'vue-router'
  8. const props = defineProps({
  9. itemIndex: {
  10. type: Number,
  11. required: true,
  12. },
  13. solutionItem: {
  14. type: Object,
  15. default: () => {},
  16. },
  17. })
  18. const emits = defineEmits<{
  19. (e: 'ok'): void
  20. }>()
  21. const router = useRouter()
  22. const visible = ref(false)
  23. const solutionStore = useSolutionStore()
  24. const solutionId = ref()
  25. const selectedSolutionItem = ref()
  26. const solutionInfo = ref(props.solutionItem)
  27. const solutionStyle = computed(() => {
  28. const difference = solutionInfo.value.capacityUsed / solutionInfo.value.capacityTotal
  29. const process = 100 - (difference * 100)
  30. const filter = difference > 0.4 ? 'hue-rotate(270deg) saturate(100) brightness(81%)' : difference > 0.1 ? 'hue-rotate(150deg) saturate(100)' : 'hue-rotate(120deg) saturate(100)'
  31. return {
  32. 'filter': filter,
  33. '-webkit-mask': `linear-gradient(to bottom, transparent ${process}%, #EEEFF8 ${process + 0.1}%)`,
  34. }
  35. })
  36. const onInputBlur = () => {
  37. if (solutionInfo.value.capacityUsed > 5000) {
  38. FtMessage.error('容器容量不能超过5000ml')
  39. solutionInfo.value.capacityUsed = 5000
  40. }
  41. saveContainer()
  42. }
  43. const onSelectSolution = () => {
  44. visible.value = true
  45. }
  46. const saveContainer = () => {
  47. if (!solutionInfo.value.capacityUsed) {
  48. FtMessage.warning('请输入当前容量')
  49. return
  50. }
  51. if (!solutionInfo.value.solutionId) {
  52. FtMessage.warning('请选择酸液')
  53. return
  54. }
  55. const params: Container.ContainerItem = {
  56. id: solutionInfo.value.id,
  57. type: 0,
  58. solutionId: solutionInfo.value.solutionId,
  59. pumpId: solutionInfo.value.pumpId,
  60. capacityTotal: solutionInfo.value.capacityTotal,
  61. capacityUsed: solutionInfo.value.capacityUsed,
  62. filled: solutionInfo.value.filled,
  63. }
  64. updateContainer(params).then(() => {
  65. FtMessage.success('保存成功')
  66. emits('ok')
  67. })
  68. }
  69. const onSolutionChange = (value: number) => {
  70. if (value) {
  71. solutionId.value = value
  72. solutionInfo.value.solutionId = value
  73. selectedSolutionItem.value = solutionStore.solutionList.filter(item => item.id === value)[0]
  74. }
  75. }
  76. const onClose = () => {
  77. solutionId.value = null
  78. visible.value = false
  79. }
  80. const onSubmitSolution = () => {
  81. if (!solutionStore.solutionList.length) {
  82. // 跳转至配置酸液页面
  83. router.push('/solution')
  84. return
  85. }
  86. solutionInfo.value.solutionName = selectedSolutionItem.value.name
  87. solutionInfo.value.solutionId = selectedSolutionItem.value.id
  88. saveContainer()
  89. onClose()
  90. }
  91. </script>
  92. <template>
  93. <div class="liquied-item">
  94. <div class="header">
  95. <div>{{ itemIndex + 1 }}</div>
  96. <div class="solution-select">
  97. <div class="solution-name">
  98. <span v-if="solutionInfo.solutionName">{{ solutionInfo.solutionName }}</span>
  99. <span v-else style="color:#d2d2d2">选择酸液</span>
  100. </div>
  101. <div class="add-icon">
  102. <el-button :icon="Plus" class="button-icon" @click="onSelectSolution" />
  103. </div>
  104. </div>
  105. </div>
  106. <div class="content">
  107. <div class="bottle_base">
  108. <img class="content-img" src="@/assets/images/liquied/liquied_bottle.svg" alt="chemical-bottle">
  109. </div>
  110. <div class="bottle" :style="solutionStyle">
  111. <img class="content-img" src="@/assets/images/liquied/liquied_bottle.svg" alt="chemical-bottle">
  112. </div>
  113. </div>
  114. <div class="footer">
  115. <div class="footer-content">
  116. <span>{{ solutionInfo.capacityTotal }}ml</span>
  117. </div>
  118. <div class="footer-edit">
  119. <span>剩余</span>
  120. <el-input v-model.number="solutionInfo.capacityUsed" type="number" max="5000" size="small" @blur="onInputBlur">
  121. <template #append>
  122. ml
  123. </template>
  124. </el-input>
  125. </div>
  126. </div>
  127. <FtDialog v-model="visible" title="选择酸液" :ok-handle="onSubmitSolution" @cancel="onClose">
  128. <div v-if="solutionStore.solutionList.length">
  129. <el-radio-group v-model="solutionId" size="large" class="radio-group" @change="onSolutionChange">
  130. <el-radio-button v-for="item in solutionStore.solutionList" :key="item.id" :label="item.name" :value="item.id" class="radio-marge" />
  131. </el-radio-group>
  132. </div>
  133. <div v-else>
  134. <el-empty description="description">
  135. <template #description>
  136. 未添加酸液请在溶液管理中配置
  137. </template>
  138. </el-empty>
  139. </div>
  140. </FtDialog>
  141. </div>
  142. </template>
  143. <style scoped>
  144. .liquied-item {
  145. border: 1px solid #ccc;
  146. border-radius: 10px;
  147. width: 200px;
  148. height: 300px;
  149. text-align: center;
  150. display: flex;
  151. flex-direction: column;
  152. align-items: center;
  153. justify-content: space-between;
  154. }
  155. .content{
  156. position: relative;
  157. display: flex;
  158. justify-content: center;
  159. }
  160. .bottle_base{
  161. position: relative;
  162. }
  163. .bottle {
  164. position: absolute;
  165. }
  166. .header {
  167. display: flex;
  168. align-items: center;
  169. background: rgba(25, 137, 250, 0.1216);
  170. justify-content: center;
  171. border-radius: 10px 10px 0 0;
  172. padding:10px;
  173. width: 100%;
  174. }
  175. .content-img{
  176. height: 150px;
  177. margin: 10px;
  178. }
  179. .footer-content{
  180. display: flex;
  181. justify-content: center;
  182. }
  183. .footer-edit {
  184. display: flex;
  185. justify-content: space-around;
  186. align-items: center;
  187. padding: 10px 0;
  188. .el-input {
  189. margin-left: 10px;
  190. width: 120px;
  191. }
  192. }
  193. .checked {
  194. text-decoration: line-through;
  195. }
  196. .solution-select{
  197. display:flex;
  198. width: 120px;
  199. height: 25px;
  200. text-align: center;
  201. margin-left: 5px;
  202. align-items: center;
  203. background: white;
  204. border-radius: 5px;
  205. }
  206. .solution-name{
  207. width: 100px;
  208. height: 25px;
  209. display: flex;
  210. align-items: center;
  211. justify-content: center;
  212. }
  213. .add-icon{
  214. margin-right: -4px;
  215. }
  216. .button-icon{
  217. height: 25px;
  218. width: 25px;
  219. margin: 3px;
  220. }
  221. .radio-marge{
  222. margin: 10px;
  223. border: 1px solid #e0e0e0;
  224. }
  225. </style>