jiangping
2023-10-16 d7fe8ae3888c8e2b1eea3c1e3769be0d42a21cc9
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<template>
  <div class="bsb">
    <div class="bsb_box">
      <div class="bsb_box_item">
        <span>设备编码</span>
        <span>{{info.code}}</span>
      </div>
      <div class="bsb_box_item">
        <span>设备名称</span>
        <span>{{info.name}}</span>
      </div>
      <div class="bsb_box_item">
        <span>设备型号</span>
        <span>{{info.model}}</span>
      </div>
      <div class="bsb_box_item">
        <span>关联用户</span>
        <span>{{store.state.userInfo.realname}}/{{store.state.userInfo.companyUser.dmodel.name}}</span>
      </div>
    </div>
    <div class="bsb_footer">
      <div class="bsb_footer_jx" @click="continueScanning">重新扫码</div>
      <div class="bsb_footer_tj" @click="submit">提交</div>
    </div>
    <v-ScanCode
        :openCode="openCode"
        :infos="['请扫描设备码']"
        @closePopup="closePopup"
        @onDecode="onDecode" />
  </div>
</template>
 
<script setup lang="ts">
  import { ref, onMounted, nextTick } from 'vue'
  import { useRoute, useRouter } from "vue-router"
  import { useStore } from "vuex"
  import { QRCodeType } from '@/enum'
  import { Toast } from 'vant'
  import { getSbInfo, getBarcodeContent, bindingDevice } from '@/apis/WorkOrderAPI'
  import vScanCode from '@/components/common/ScanCode.vue'
 
  const route = useRoute()
 
  const router = useRouter()
 
  const store = useStore()
 
  let openCode = ref<boolean>(false)
 
  let info: any = ref({})
 
  const closePopup = () => {
      openCode.value = false
  }
 
  // 扫码回调
  const onDecode = (data: string[]): void => {
      nextTick(() => {
          openCode.value = false
      })
      getBarcodeContent({
          barcode: data[0]
      }).then(res => {
          if (res.code === 200 && res.data.barcodeType === QRCodeType.SB) {
              getInfo(res.data.id)
          } else {
              Toast({ message: '请扫描正确的设备码' })
          }
      })
  }
 
  //重新扫码
  const continueScanning = () => {
      openCode.value = true
  }
 
  // 互殴设备信息
  const getInfo = (id: string) => {
      getSbInfo(id)
        .then(res => {
            if (res.code === 200) {
                info.value = res.data
            }
        })
  }
 
  // 提交
  const submit = () => {
      bindingDevice({
          deviceId: info.value.id,
          userIds: store.state.userInfo.companyUser.id
      }).then(res => {
          if (res.code === 200) {
              Toast.success({ message: '绑定成功', duration: 2000, forbidClick: true })
              setTimeout(() => {
                  router.go(-1)
              }, 2000)
          }
      })
  }
 
  onMounted(() => {
      let id: any = route.query.id
      getInfo(id)
  })
</script>
 
<style lang="scss" scoped>
.bsb {
  width: 100%;
  height: 100%;
  position: absolute;
  background: #F7F7F7;
  .bsb_box {
    padding: 0 30px;
    background: white;
    .bsb_box_item {
      height: 98px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-bottom: 1px solid #E5E5E5;
      &:last-child {
        border: none;
      }
      span {
        &:nth-child(1) {
          font-size: 30px;
          font-weight: 400;
          color: #222222;
        }
        &:nth-child(2) {
          font-size: 28px;
          font-weight: 400;
          color: #333333;
        }
      }
    }
  }
  .bsb_footer {
    position: fixed;
    bottom: 0;
    width: 100%;
    padding: 0 30px 68px 30px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-between;
    .bsb_footer_jx {
      width: 334px;
      height: 88px;
      background: #FFFFFF;
      box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
      border-radius: 8px;
      color: $nav-color;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 30px;
      font-weight: 500;
    }
    .bsb_footer_tj {
      width: 334px;
      height: 88px;
      background: $nav-color;
      box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.08);
      border-radius: 8px;
      font-size: 30px;
      font-weight: 500;
      color: #FFFFFF;
      display: flex;
      align-items: center;
      justify-content: center;
    }
  }
}
</style>