songshankun
2023-11-13 e6b7921fc2e2b95e4c2b666b372ad611c08e9d62
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
  <div class="deliver-params-config-modal">
    <CommonModal v-model="modelData" @close="modelData = false">
      <template #title>配置</template>
      <div class="config-content">
        <el-radio-group v-model="config" class="config-radio-group">
          <el-radio :label="false" size="large">无工艺参数,不允许下发生产任务</el-radio>
          <el-radio :label="true" size="large">无工艺参数,允许下发生产任务</el-radio>
        </el-radio-group>
      </div>
      <template #footer>
        <div class="config-footer">
          <BigButton class="btn" bg-color="#0dfde6" color="#333333" @click="setConfig">保存</BigButton>
        </div>
      </template>
    </CommonModal>
  </div>
</template>
<script setup lang="ts">
import BigButton from '@/views/dashboard/components/BigButton.vue'
import { useVModel } from '@vueuse/core'
import { ref, watch } from 'vue'
import { useDevicesStore } from '@/stores/devices'
import { storeToRefs } from 'pinia'
import { apiSetCurrentDeviceConfig } from '@/api'
import { ElMessage } from 'element-plus'
const props = withDefaults(
  defineProps<{
    modelValue: boolean
  }>(),
  {
    modelValue: false
  }
)
 
const emit = defineEmits<{
  'update:modelValue': [show: boolean]
}>()
const modelData = useVModel(props, 'modelValue', emit)
const deviceStore = useDevicesStore()
const { currentDeviceAllowNoParams } = storeToRefs(deviceStore)
watch(modelData, () => {
  // 打开弹窗时初始化选中项
  if (modelData.value) {
    config.value = currentDeviceAllowNoParams.value
  }
})
 
const config = ref(false)
 
function setConfig() {
  apiSetCurrentDeviceConfig({
    // 选中允许下发即不需要工艺参数 ,这俩是反的
    needSetProcessParams: !config.value
  })
    .then(() => {
      ElMessage({
        message: '设置成功',
        type: 'success',
        duration: 3 * 1000
      })
      modelData.value = false
      deviceStore.startPollingDevice()
    })
    .catch((err) => {
      console.error(err)
    })
}
</script>
<style scoped lang="scss">
.config-content {
  padding: 10px 20px;
}
.config-radio-group {
  display: flex;
  flex-direction: column;
  justify-content: start;
  align-items: start;
  :deep(.el-radio__label) {
    color: #fff;
  }
}
.config-footer {
  display: flex;
  align-items: center;
  justify-content: center;
  .btn {
    height: 40px;
    width: 100px;
    font-size: 14px;
    font-weight: 500;
    line-height: 40px;
    border-radius: 4px;
  }
}
</style>