stateRadio.vue 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <template>
  2. <el-radio-group v-model="radio" @change="change">
  3. <el-radio :label="1">在线</el-radio>
  4. <el-radio :label="0">休眠</el-radio>
  5. </el-radio-group>
  6. </template>
  7. <script setup>
  8. import { otherEquipState } from '@/api/base/equipment.js'
  9. import { nextTick, ref, onMounted } from 'vue'
  10. const emit = defineEmits();
  11. const radio = ref(null)
  12. const props = defineProps({
  13. propConfig:{},
  14. propValue:{},
  15. parentValue:{}
  16. })
  17. const setValue = data => {
  18. radio.value = data ? data : 0
  19. }
  20. const getValue = () => {
  21. return radio.value
  22. }
  23. const change = () => {
  24. emit('onChange',radio.value);
  25. if(props.parentValue.equipmentCode&&props.parentValue.equipmentId){
  26. otherEquipState({
  27. equipmentCode:props.parentValue.equipmentCode,
  28. change:radio.value ? true : false
  29. }).then(() => {
  30. proxy.$message({
  31. message:'设备状态更新成功!',
  32. type:'success'
  33. });
  34. }).catch(() => {
  35. proxy.$message({
  36. message:'设备状态更新失败!',
  37. type:'error'
  38. });
  39. })
  40. }
  41. }
  42. defineExpose({
  43. setValue,getValue
  44. })
  45. // const onMounted = () =>{
  46. // nextTick(() => {
  47. // if(props.parentValue && Number(props.parentValue.onState) >= 0){
  48. // setValue(props.parentValue.onState)
  49. // }else{
  50. // radio.value = 1
  51. // change()
  52. // }
  53. // })
  54. // }
  55. </script>
  56. <style lang="scss" scoped>
  57. </style>