formModel.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. <template>
  2. <ele-modal
  3. :visible.sync="visible"
  4. :title="title"
  5. width="50%"
  6. append-to-body
  7. @close="cancel"
  8. >
  9. <el-form ref="form" :model="form" :rules="rules" label-width="120px" v-loading="loading">
  10. <el-row>
  11. <el-col :span="12">
  12. <el-form-item label="预置位名称" prop="pointName">
  13. <el-input v-model="form.pointName" placeholder="请输入" :maxlength="20" class="!w-100%" />
  14. </el-form-item>
  15. </el-col>
  16. </el-row>
  17. <el-row>
  18. <el-col :span="16">
  19. <el-form-item label="行车距离">
  20. <el-progress :percentage="dirv">
  21. <el-button text>3500</el-button>
  22. </el-progress>
  23. </el-form-item>
  24. </el-col>
  25. <el-col :span="4">
  26. <el-form-item prop="dirv">
  27. <el-input
  28. v-model="form.dirv"
  29. @input="progressUpdate($event, 'dirv')"
  30. placeholder="请输入"
  31. />
  32. </el-form-item>
  33. </el-col>
  34. </el-row>
  35. <el-row>
  36. <el-col :span="16">
  37. <el-form-item label="升降距离">
  38. <el-progress :percentage="lift">
  39. <el-button text>3500</el-button>
  40. </el-progress>
  41. </el-form-item>
  42. </el-col>
  43. <el-col :span="4">
  44. <el-form-item prop="lift">
  45. <el-input
  46. v-model="form.lift"
  47. @input="progressUpdate($event, 'lift')"
  48. placeholder="请输入"
  49. />
  50. </el-form-item>
  51. </el-col>
  52. </el-row>
  53. <el-row>
  54. <el-col :span="12">
  55. <el-form-item label="排序号" prop="indexNo">
  56. <el-input-number
  57. v-model="form.indexNo"
  58. class="!w-100%"
  59. placeholder="请输入"
  60. :min="1"
  61. :max="99999"
  62. controls-position="right"
  63. />
  64. </el-form-item>
  65. </el-col>
  66. </el-row>
  67. </el-form>
  68. <template #footer>
  69. <el-button @click="cancel">取消</el-button>
  70. <el-button type="primary" @click="save" :loading="saving">确定</el-button>
  71. </template>
  72. </ele-modal>
  73. </template>
  74. <script>
  75. import * as DevicePointApi from '@/api/ledgerAssets/device/presetInfo'
  76. const defForm = {
  77. pointName: '',
  78. dirv: 2000,
  79. lift: 2000,
  80. indexNo: 100
  81. }
  82. export default {
  83. name: 'RobotPresetInfoForm',
  84. props: {
  85. dId: ''
  86. },
  87. data() {
  88. return {
  89. visible: false,
  90. title: '',
  91. loading: false,
  92. saving: false,
  93. type: '',
  94. dirv: 57,
  95. lift: 57,
  96. form: { ...defForm },
  97. rules: {
  98. pointName: [{ required: true, message: '预置位名称不能为空', trigger: 'blur' }],
  99. dirv: [{ required: true, message: '行车距离不能为空', trigger: 'blur' }],
  100. lift: [{ required: true, message: '升降距离不能为空', trigger: 'blur' }],
  101. indexNo: [{ required: true, message: '排序号不能为空', trigger: 'change' }]
  102. }
  103. }
  104. },
  105. methods: {
  106. /** 进度更新 */
  107. progressUpdate(value, type) {
  108. let num = parseInt(value) || 0
  109. if (num > 3500) {
  110. num = 3500
  111. this.form[type] = num
  112. } else if (num < -3500) {
  113. num = -3500
  114. this.form[type] = num
  115. }
  116. this[type] = Math.abs(Math.round(num / 35))
  117. },
  118. /** 打开弹窗 */
  119. open(type, id) {
  120. this.type = type
  121. this.title = type === 'create' ? '新增预置位' : '编辑预置位'
  122. this.resetForm()
  123. if (id) {
  124. this.loading = true
  125. DevicePointApi.getDevicePoint(id)
  126. .then((res) => {
  127. const pointJson = JSON.parse(res.pointJson || '{}')
  128. this.form = {
  129. ...res,
  130. dirv: pointJson.xcjl || 0,
  131. lift: pointJson.sjjl || 0
  132. }
  133. this.progressUpdate(this.form.dirv, 'dirv')
  134. this.progressUpdate(this.form.lift, 'lift')
  135. })
  136. .catch((e) => {
  137. this.$message.error(e.message)
  138. })
  139. .finally(() => {
  140. this.loading = false
  141. })
  142. }
  143. this.visible = true
  144. },
  145. /** 取消 */
  146. cancel() {
  147. this.resetForm()
  148. this.visible = false
  149. },
  150. /** 重置表单 */
  151. resetForm() {
  152. this.form = { ...defForm }
  153. this.dirv = 57
  154. this.lift = 57
  155. this.$refs.form?.resetFields()
  156. },
  157. /** 保存 */
  158. save() {
  159. this.$refs.form.validate((valid) => {
  160. if (valid) {
  161. this.saving = true
  162. const data = {
  163. ...this.form,
  164. deviceId: this.dId,
  165. pointJson: JSON.stringify({
  166. xcjl: this.form.dirv,
  167. sjjl: this.form.lift
  168. })
  169. }
  170. delete data.dirv
  171. delete data.lift
  172. const action =
  173. this.type === 'create'
  174. ? DevicePointApi.createDevicePoint(data)
  175. : DevicePointApi.updateDevicePoint(data)
  176. action
  177. .then(() => {
  178. this.$message.success(this.type === 'create' ? '新增成功' : '修改成功')
  179. this.cancel()
  180. this.$emit('success')
  181. })
  182. .catch((e) => {
  183. this.$message.error(e.message)
  184. })
  185. .finally(() => {
  186. this.saving = false
  187. })
  188. }
  189. })
  190. }
  191. }
  192. }
  193. </script>
  194. <style lang="scss" scoped>
  195. .el-col-4 {
  196. .el-form-item {
  197. :deep(.el-form-item__content) {
  198. margin-left: 20px !important;
  199. }
  200. }
  201. }
  202. .tit {
  203. margin-left: 10px;
  204. font-weight: bold;
  205. border-left: 3px solid #9266f9;
  206. padding-left: 10px;
  207. margin-bottom: 14px;
  208. }
  209. </style>