deviceManager.vue 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. <template>
  2. <div>
  3. <ag-grid-layout
  4. toolbar
  5. :table-height="tableHeight"
  6. theme="ag-theme-alpine"
  7. :column-defs="columnDefs"
  8. :row-data="rowData"
  9. :locale-text="localeText"
  10. :grid-options="gridOptions"
  11. :debounce-vertical-scrollbar="true"
  12. :default-col-def="defaultColDef"
  13. :animate-rows="true"
  14. :row-selection="rowSelection"
  15. :framework-components="frameworkComponents"
  16. @filterChanged="filterModifed"
  17. @sortChanged="gridSortChange"
  18. >
  19. <div slot="toolbar" class="inner-toolbar">
  20. <div class="toolbar-search">
  21. <en-table-search :placeholder="this.$t('action.keywords')" @search="handlerSearch" />
  22. </div>
  23. <div class="toolbar-btns">
  24. <el-button v-if="part_view" type="primary" size="mini" @click="handleAdd">{{ this.$t('deviceManage.deviceAdd') }}</el-button>
  25. <el-button v-if="part_view" type="danger" size="mini" @click="batchDelete">{{ this.$t('action.deleteList') }}</el-button>
  26. <el-button v-if="!part_view" type="primary" size="mini" @click="deviceServerChange">{{ this.$t('deviceManage.deviceServerChange') }}</el-button>
  27. </div>
  28. </div>
  29. <el-pagination
  30. v-if="pageData"
  31. slot="pagination"
  32. :current-page="pageData.page_no"
  33. :page-sizes="[10, 20, 50, 100]"
  34. :page-size="pageData.page_size"
  35. layout="total, sizes, prev, pager, next, jumper"
  36. :total="pageData.data_total"
  37. @size-change="handlePageSizeChange"
  38. @current-change="handlePageCurrentChange"
  39. />
  40. </ag-grid-layout>
  41. <!-- 设备编辑弹窗 -->
  42. <el-dialog :title="deviceEditTitle" :visible.sync="deviceDialogVisible" :width="this.$i18n.locale === 'zh' ? '60%' : '70%'">
  43. <el-form ref="deviceEditForm" :rules="deviceRules" :label-width="this.$i18n.locale === 'zh' ? '120px' : '165px'" :model="deviceModel">
  44. <el-row>
  45. <el-col :span="12">
  46. <el-form-item :label="this.$t('deviceManage.deviceType')" prop="device_type">
  47. <el-select v-model="deviceModel.device_type" :placeholder="this.$t('deviceManage.choiceDeviceType')" :disabled="deviceTypeDisabled" clearable @change="deviceTypeChange">
  48. <!-- <el-option v-for="(item,index) in deviceTypeTransfer" :key="index" :label="item.key" :value="item.value" />-->
  49. <el-option v-for="(item, index) in Object.keys(deviceTypeEnum)" :key="index" :label="deviceTypeEnum[item]" :value="parseInt(item)" />
  50. </el-select>
  51. </el-form-item>
  52. </el-col>
  53. <el-col :span="12">
  54. <el-form-item :label="this.$t('deviceManage.deviceName')" prop="name">
  55. <el-input v-model="deviceModel.name" clearable :maxlength="20" :placeholder="this.$t('deviceManage.inputDeviceName')" />
  56. </el-form-item>
  57. </el-col>
  58. </el-row>
  59. <el-row>
  60. <el-col :span="12">
  61. <el-form-item :label="this.$t('deviceManage.code')" prop="code">
  62. <el-input v-model="deviceModel.code" clearable :placeholder="this.$t('deviceManage.inputCode')" />
  63. </el-form-item>
  64. </el-col>
  65. <el-col :span="12">
  66. <el-form-item :label="this.$t('deviceManage.model')" prop="model">
  67. <el-input v-model="deviceModel.model" clearable :placeholder="this.$t('deviceManage.inputModel')" />
  68. </el-form-item>
  69. </el-col>
  70. </el-row>
  71. <el-row>
  72. <el-col :span="12">
  73. <el-form-item :label="this.$t('deviceManage.ethMac')" prop="eth_mac">
  74. <el-input v-model="deviceModel.eth_mac" clearable :placeholder="this.$t('deviceManage.inputEthMac')" />
  75. </el-form-item>
  76. </el-col>
  77. <el-col :span="12">
  78. <el-form-item :label="this.$t('deviceManage.ethIp')" prop="eth_ip">
  79. <el-input v-model="deviceModel.eth_ip" clearable :placeholder="this.$t('deviceManage.inputEthIp')" />
  80. </el-form-item>
  81. </el-col>
  82. </el-row>
  83. <el-row>
  84. <el-col :span="12">
  85. <el-form-item :label="this.$t('deviceManage.wifiMac')" prop="wifi_mac">
  86. <el-input v-model="deviceModel.wifi_mac" clearable :placeholder="this.$t('deviceManage.inputWifiMac')" readonly />
  87. </el-form-item>
  88. </el-col>
  89. <el-col :span="12">
  90. <el-form-item :label="this.$t('deviceManage.wifiIp')" prop="wifi_ip">
  91. <el-input v-model="deviceModel.wifi_ip" clearable :placeholder="this.$t('deviceManage.inputWifiIp')" readonly />
  92. </el-form-item>
  93. </el-col>
  94. </el-row>
  95. <el-row>
  96. <el-col :span="12">
  97. <el-form-item :label="this.$t('deviceManage.softVer')" prop="soft_ver">
  98. <el-input v-model="deviceModel.soft_ver" clearable :placeholder="this.$t('deviceManage.inputSoftVer')" />
  99. </el-form-item>
  100. </el-col>
  101. <el-col :span="12">
  102. <el-form-item :label="this.$t('deviceManage.hardVer')" prop="hard_ver">
  103. <el-input v-model="deviceModel.hard_ver" clearable :placeholder="this.$t('deviceManage.inputHardVer')" />
  104. </el-form-item>
  105. </el-col>
  106. </el-row>
  107. <el-row>
  108. <el-col :span="12">
  109. <el-form-item :label="this.$t('deviceManage.wifiHostname')">
  110. <el-input v-model="deviceModel.wifi_hostname" :readonly="true" clearable :placeholder="this.$t('deviceManage.inputWifiHostname')" />
  111. </el-form-item>
  112. </el-col>
  113. <el-col :span="12">
  114. <el-form-item :label="this.$t('deviceManage.wifiPassword')">
  115. <el-input v-model="deviceModel.wifi_password" :readonly="true" clearable :placeholder="this.$t('deviceManage.inputPassword')" />
  116. </el-form-item>
  117. </el-col>
  118. </el-row>
  119. <el-row>
  120. <el-col :span="12">
  121. <el-form-item :label="this.$t('deviceManage.frameName')" prop="frame_id">
  122. <el-select v-model="deviceModel.frame_id" filterable clearable :disabled="frameSelectabled" :placeholder="this.$t('deviceManage.choiceFrameName')">
  123. <el-option v-for="(item,index) in typeFrames" :key="index" :label="item.full_name" :value="item.id" />
  124. </el-select>
  125. </el-form-item>
  126. </el-col>
  127. <el-col :span="12">
  128. <el-form-item :label="this.$t('deviceManage.phoneNumber')">
  129. <el-input v-model="deviceModel.phone_number" clearable :placeholder="this.$t('deviceManage.inputPhoneNumber')" />
  130. </el-form-item>
  131. </el-col>
  132. </el-row>
  133. <el-row>
  134. <el-col :span="12">
  135. <el-form-item :label="this.$t('deviceManage.priority')">
  136. <el-input-number v-model="deviceModel.priority" controls-position="right" :min="1" :max="99" />
  137. </el-form-item>
  138. </el-col>
  139. <el-col :span="12">
  140. <el-form-item :label="this.$t('deviceManage.backupId')">
  141. <el-input v-model="deviceModel.backup_id" clearable placeholder="" />
  142. </el-form-item>
  143. </el-col>
  144. <el-col :span="12">
  145. <el-form-item :label="this.$t('deviceManage.deviceStatus')">
  146. <el-checkbox v-model="deviceModel.status" :true-label="1" :false-label="0">{{ this.$t('deviceManage.choiceDeviceStatus') }}</el-checkbox>
  147. <!-- <el-radio v-model="formmodel.status" :label="1">启用</el-radio>-->
  148. <!-- <el-radio v-model="formmodel.status" :label="0">不启用</el-radio>-->
  149. </el-form-item>
  150. </el-col>
  151. </el-row>
  152. <el-row v-if="hasRoleId">
  153. <el-col :span="12">
  154. <el-form-item :label="this.$t('deviceManage.roleName')" prop="role_id">
  155. <el-select v-model="deviceModel.role_id" :placeholder="this.$t('deviceManage.roleName')" clearable>
  156. <el-option v-for="item in rolesOptions" :key="item.role_id" :label="item.role_name" :value="item.role_id" />
  157. </el-select>
  158. </el-form-item>
  159. </el-col>
  160. </el-row>
  161. <el-row v-if="hasAudioId">
  162. <el-col :span="12">
  163. <el-form-item :label="this.$t('deviceManage.transAudio')" prop="trans_audio_id">
  164. <el-select v-model="deviceModel.trans_audio_id" :placeholder="this.$t('deviceManage.transAudio')" clearable>
  165. <el-option v-for="item in audioOptions" :key="item.id" :label="item.name" :value="item.id" />
  166. </el-select>
  167. </el-form-item>
  168. </el-col>
  169. <el-col :span="12">
  170. <el-form-item :label="this.$t('deviceManage.transRs485')" prop="trans_rs485_id">
  171. <el-select v-model="deviceModel.trans_rs485_id" :placeholder="this.$t('deviceManage.transRs485')" clearable>
  172. <el-option v-for="item in rs485Options" :key="item.id" :label="item.name" :value="item.id" />
  173. </el-select>
  174. </el-form-item>
  175. </el-col>
  176. </el-row>
  177. <el-row v-if="hasAudioId">
  178. <el-col :span="12">
  179. <el-form-item :label="this.$t('deviceManage.re485SipId')" prop="sip_id">
  180. <el-input v-model="deviceModel.sip_id" clearable :placeholder="this.$t('deviceManage.inputRe485SipId')" />
  181. </el-form-item>
  182. </el-col>
  183. </el-row>
  184. <el-row v-if="isVitalSigns">
  185. <el-col :span="12">
  186. <el-form-item :label="this.$t('deviceManage.signType')" prop="sign_type">
  187. <el-select v-model="deviceModel.sign_type" :placeholder="this.$t('deviceManage.choiceSignType')" clearable>
  188. <el-option v-for="(item, index) in Object.keys(vitalSignsDeviceEnum)" :key="index" :label="vitalSignsDeviceEnum[item]" :value="parseInt(item)" />
  189. </el-select>
  190. </el-form-item>
  191. </el-col>
  192. </el-row>
  193. <el-row v-if="hasSosDeviceSettings">
  194. <el-col :span="12">
  195. <el-form-item :label="this.$t('deviceManage.sosDeviceSettingType')" prop="type">
  196. <el-select v-model="sosDeviceSetting.type" :placeholder="this.$t('deviceManage.sosDeviceSettingType')" clearable>
  197. <!-- <el-option v-for="item in sosDeviceSettingsTypeOptions" :key="item.value" :label="item.label" :value="item.value" /><el-option v-for="(item, index) in Object.keys(sosDeviceSettingEnum)" :key="index" :label="sosDeviceSettingEnum[item]" :value="parseInt(item)" />-->
  198. <el-option v-for="(item, index) in Object.keys(sosDeviceSettingEnum)" :key="index" :label="sosDeviceSettingEnum[item]" :value="parseInt(item)" />
  199. </el-select>
  200. </el-form-item>
  201. </el-col>
  202. </el-row>
  203. <el-row v-if="sosDeviceSetting.type === 2">
  204. <el-col :span="12">
  205. <el-form-item :label="this.$t('deviceManage.sosDeviceSettingTime')" prop="setting_time">
  206. <el-input-number v-model="sosDeviceSetting.setting_time" controls-position="right" :min="0" :max="60" />
  207. </el-form-item>
  208. </el-col>
  209. <el-col :span="12">
  210. <el-form-item :label="this.$t('deviceManage.sosDeviceSettingUnit')" prop="unit">
  211. <el-radio-group v-model="sosDeviceSetting.unit" size="mini" prop="unit">
  212. <el-radio :label="this.$t('action.time')">{{ this.$t('action.time') }}</el-radio>
  213. <el-radio :label="this.$t('action.minute')">{{ this.$t('action.minute') }}</el-radio>
  214. <el-radio :label="this.$t('action.second')">{{ this.$t('action.second') }}</el-radio>
  215. </el-radio-group>
  216. </el-form-item>
  217. </el-col>
  218. </el-row>
  219. <el-row v-if="isLedDevice">
  220. <el-col :span="12">
  221. <el-form-item :label="this.$t('deviceManage.ledResolutionRatio')" prop="led_resolution_ratio">
  222. <el-input v-model="deviceModel.led_resolution_ratio" clearable :placeholder="this.$t('deviceManage.ledResolutionRatio')" />
  223. </el-form-item>
  224. </el-col>
  225. <el-col :span="12">
  226. <el-form-item :label="this.$t('deviceManage.ledVoice')" prop="led_voice">
  227. <el-checkbox v-model="deviceModel.led_voice" :true-label="1" :false-label="0">
  228. {{ this.$t('deviceManage.ledVoiceStatus') }}</el-checkbox>
  229. <!-- <el-radio-group v-model="deviceModel.led_voice" size="mini" prop="led_voice">-->
  230. <!-- <el-radio :label=1>开启语音</el-radio>-->
  231. <!-- <el-radio :label=0>关闭语音</el-radio>-->
  232. <!-- </el-radio-group>-->
  233. </el-form-item>
  234. </el-col>
  235. </el-row>
  236. <el-row v-if="isLedDevice">
  237. <el-col :span="12">
  238. <el-form-item :label="this.$t('deviceManage.ledFontSize')" prop="led_font_size">
  239. <el-input-number v-model="deviceModel.led_font_size" controls-position="right" :min="0" :max="60" />
  240. </el-form-item>
  241. </el-col>
  242. </el-row>
  243. </el-form>
  244. <div slot="footer" class="dialog-footer">
  245. <el-button type="primary" @click="handlerFormSubmit('deviceEditForm')">{{ this.$t('action.yes') }}</el-button>
  246. </div>
  247. </el-dialog>
  248. <!-- 设备编辑弹窗 -->
  249. <el-dialog :title="this.$t('deviceManage.deviceServerChange')" :visible.sync="serverAddressDialogVisible" width="30%">
  250. <el-form ref="deviceServerChange" :rules="serverAddressRules" label-width="120px" :model="serverAddress">
  251. <el-row>
  252. <el-form-item :label="this.$t('deviceManage.serverIp')" >
  253. <el-input v-model="serverAddress.server_ip" clearable :maxlength="20" :placeholder="this.$t('deviceManage.inputServerIp')" />
  254. </el-form-item>
  255. </el-row>
  256. <el-row>
  257. <el-form-item :label="this.$t('deviceManage.serverPort')">
  258. <el-input v-model="serverAddress.server_port" clearable :maxlength="20" :placeholder="this.$t('deviceManage.inputServerPort')" />
  259. </el-form-item>
  260. </el-row>
  261. </el-form>
  262. <div slot="footer" class="dialog-footer">
  263. <el-button type="primary" @click="updateDevicesServerIp()">{{ this.$t('action.yes') }}</el-button>
  264. </div>
  265. </el-dialog>
  266. </div>
  267. </template>
  268. <script>
  269. import { AG_GRID_LOCALE_CN } from '@/utils/AgGridVueLocaleCn'
  270. import { unix2Date } from '@/utils/Foundation'
  271. import ButtonCellRender from '@/components/AgGridCellRender/ButtonCellRender'
  272. import ListFilter from '@/components/AgGridCustomFilter/ListFilter'
  273. import RadioFilter from '@/components/AgGridCustomFilter/RadioFilter'
  274. import * as API_Device from '@/api/ncs_device'
  275. import * as API_Frame from '@/api/ncs_hospitalFrame'
  276. import * as API_SosDeviceSetting from '@/api/ncs_sos_device_settings'
  277. import * as clerk_API from '@/api/ncs_clerk'
  278. import { FRAME_TYPE } from '@/utils/enum/FrameTypeEnum'
  279. import { DEVICE_TYPE } from '@/utils/enum/DeviceTypeEnum'
  280. import { SOS_DEVICE_SETTING_TYPE } from "@/utils/enum/SosDeviceSettingTypeEnum";
  281. import { VITAL_SIGNS_DEVICE_TYPE } from "@/utils/enum/VitalSignsDeviceEnum";
  282. import * as shop_API from "@/api/ncs_shop";
  283. const DeviceUrl = domain.DeviceUrl
  284. export default {
  285. name: 'DeviceManager',
  286. components: { ButtonCellRender, ListFilter, RadioFilter },
  287. props: {
  288. frame: {
  289. type: Object,
  290. default: () => {}
  291. },
  292. part_view: { // 是否为科室视图
  293. type: Boolean,
  294. default: true
  295. }
  296. },
  297. data() {
  298. return {
  299. /** ag-grid参数 **/
  300. pageData: {}, // 翻页数据
  301. errorId: null,
  302. shopVisible: false,
  303. columnDefs: null,
  304. rowData: null,
  305. defaultColDef: null,
  306. gridOptions: null,
  307. gridApi: null,
  308. columnApi: null,
  309. localeText: AG_GRID_LOCALE_CN,
  310. filterState: null,
  311. rowSelection: null,
  312. frameworkComponents: null,
  313. /** 列表参数 */
  314. params: {
  315. page_size: 20,
  316. page_no: 1,
  317. fixedCondition: this.part_view ? ('part_id=' + this.$store.getters.partId) : '1=1'
  318. },
  319. /** device 弹窗 **/
  320. deviceDialogVisible: false,
  321. deviceEditTitle: this.$t('deviceManage.deviceAdd'),
  322. deviceModel: {},
  323. deviceTypeDisabled: false,
  324. deviceRules: {
  325. name: [
  326. this.MixinRequired(this.$t('deviceManage.inputDeviceName'))
  327. ],
  328. device_type: [
  329. { required: true, message: this.$t('deviceManage.choiceDeviceType'), trigger: 'blur' }
  330. ],
  331. code: [
  332. { required: true, message: this.$t('deviceManage.inputCode'), trigger: 'blur' }
  333. ],
  334. model: [
  335. { required: true, message: this.$t('deviceManage.inputModel'), trigger: 'blur' }
  336. ],
  337. eth_mac: [
  338. { required: true, message: this.$t('deviceManage.inputEthMac'), trigger: 'blur' },
  339. // { pattern: /^([0-9A-Fa-f]{2}:?){6}/gi, message: '请输入正确的MAC地址', trigger: 'blur' }
  340. { pattern: null, message: this.$t('deviceManage.inputTrueEthMac'), trigger: 'blur' }
  341. ],
  342. frame_id: [
  343. { required: Object.keys(this.frame).length === 0, message: this.$t('deviceManage.choiceFrameName'), trigger: 'blur' } // 没有传入frame 属性,必须选择安装位置
  344. ],
  345. phone_number: [
  346. { required: true, message: this.$t('deviceManage.phoneNumber'), trigger: 'blur' }
  347. ],
  348. role_id: [
  349. { required: true, message: this.$t('deviceManage.choiceRoleName'), trigger: 'blur' }
  350. ],
  351. trans_audio_id: [
  352. { required: true, message: this.$t('deviceManage.choiceTransAudio'), trigger: 'blur' }
  353. ],
  354. sign_type: [
  355. { required: true, message: this.$t('deviceManage.choiceSignType'), trigger: 'blur' }
  356. ],
  357. // trans_rs485_id: [
  358. // { required: true, message: '请选择485转换盒', trigger: 'blur' }
  359. // ],
  360. // sip_id: [
  361. // { required: true, message: '请输入485地址', trigger: 'blur' }
  362. // ]
  363. // type: [
  364. // { required: true, message: '报警设备模式', trigger: 'blur' }
  365. // ],
  366. // sosDeviceSetting: [
  367. // { required: true, message: '报警时间', trigger: 'blur' }
  368. // ],
  369. // unit: [
  370. // { required: true, message: '报警时间单位', trigger: 'blur' }
  371. // ],
  372. led_resolution_ratio: [
  373. { required: true, message: this.$t('deviceManage.ledResolutionRatio'), trigger: 'blur' }
  374. ],
  375. // led_voice: [
  376. // { required: true, message: this.$t('deviceManage.ledVoice'), trigger: 'blur' }
  377. // ],
  378. led_font_size: [
  379. { required: true, message: this.$t('deviceManage.ledFontSize'), trigger: 'blur' }
  380. ],
  381. },
  382. partFrames: [],
  383. typeFrames: [],
  384. /** 设备类型转换数组 **/
  385. deviceTypeTransfer: [
  386. { key: this.$t('deviceType.NURSE_HOST'), value: 1 },
  387. { key: this.$t('deviceType.DOCTOR_HOST'), value: 2 },
  388. { key: this.$t('deviceType.DOOR_DEVICE'), value: 3 },
  389. { key: this.$t('deviceType.DIGIT_BED_DEVICE'), value: 4 },
  390. { key: this.$t('deviceType.LCD_SCREEN'), value: 5 },
  391. { key: this.$t('deviceType.LED_SCREEN'), value: 6 },
  392. { key: this.$t('deviceType.NURSE_WATCH'), value: 7 },
  393. // { key: '护工腕表', value: 8 },
  394. { key: this.$t('deviceType.USER_WATCH'), value: 9 },
  395. { key: this.$t('deviceType.CELL_PHONE'), value: 10 },
  396. { key: this.$t('deviceType.TRANSFER_DEVICE'), value: 11 },
  397. { key: this.$t('deviceType.SIMULATE_BED_DEVICE'), value: 12 },
  398. { key: this.$t('deviceType.SIMULATE_EMERGENCY_BUTTON'), value: 13 },
  399. { key: this.$t('deviceType.SIMULATE_DOOR_LIGHT'), value: 14 },
  400. { key: this.$t('deviceType.REMOTE_CONTROL'), value: 15 },
  401. { key: this.$t('deviceType.BEACON'), value: 16 },
  402. { key: this.$t('deviceType.INFORMATION_BOARD'), value: 17 },
  403. { key: this.$t('deviceType.ENTRANCE_GUARD'), value: 18 },
  404. { key: this.$t('deviceType.VISITATION'), value: 19 },
  405. { key: this.$t('deviceType.RS485_TRANSFER'), value: 20 },
  406. { key: this.$t('deviceType.EMERGENCY_BUTTON'), value: 21 },
  407. { key: this.$t('deviceType.RS485_DOOR'), value: 22 },
  408. { key: this.$t('deviceType.ALARM_BODY_INDUCTIVE'), value: 23 },
  409. { key: this.$t('deviceType.ALARM_WATER_OVERFLOW'), value: 24 },
  410. { key: this.$t('deviceType.ALARM_HOUSEHOLD_GAS'), value: 25 },
  411. { key: this.$t('deviceType.ALARM_HOUSEHOLD_SMOKE'), value: 26 },
  412. { key: this.$t('deviceType.ALARM_BUTTON_SOS'), value: 27 },
  413. { key: this.$t('deviceType.VITAL_SIGNS_DEVICE'), value: 28 },
  414. { key: this.$t('deviceType.ALARM_RESTRAINT_BAND'), value: 29 },
  415. { key: this.$t('deviceType.DOOR_LOCK'), value: 30 },
  416. { key: this.$t('deviceType.EMERGENCY_GATEWAY'), value: 31 },
  417. { key: this.$t('deviceType.ALARM_433BUTTON'), value: 32 },
  418. { key: this.$t('deviceType.OTHER_HOST'), value: 33 },
  419. ],
  420. deviceTypeEnum: DEVICE_TYPE.getValueList(),
  421. deviceStatusTransfer: [
  422. { key: this.$t('deviceManage.statusTure'), value: 1, color: 'green' },
  423. { key: this.$t('deviceManage.statusFalse'), value: 0, color: 'red' }
  424. ],
  425. rolesOptions: [],
  426. hasRoleId: false,
  427. audioOptions: [],
  428. rs485Options: [],
  429. hasAudioId: false,
  430. isVitalSigns: false,
  431. hasSosDeviceSettings: false,
  432. sosDeviceSetting: {},
  433. sosDeviceSettingsTypeOptions: [
  434. {
  435. value: 0,
  436. label: '不开启'
  437. }, {
  438. value: 1,
  439. label: '疫情防控模式'
  440. }, {
  441. value: 2,
  442. label: '关爱老人模式'
  443. }
  444. ],
  445. sosDeviceSettingEnum: SOS_DEVICE_SETTING_TYPE.getValueList(),
  446. vitalSignsDeviceEnum: VITAL_SIGNS_DEVICE_TYPE.getValueList(),
  447. isLedDevice: false,
  448. websock: null,
  449. onlineDevice: [],
  450. // 请求当前科室的数据
  451. shop: {},
  452. serverAddress: {
  453. server_ip: '172.28.100.100',
  454. server_port: '8006'
  455. },
  456. serverAddressDialogVisible: false,
  457. serverAddressRules: {
  458. serverIp: [
  459. this.MixinRequired(this.$t('deviceManage.inputServerIp'))
  460. ],
  461. serverPort: [
  462. this.MixinRequired(this.$t('deviceManage.inputServerPort'))
  463. ]
  464. }
  465. }
  466. },
  467. computed: {
  468. tableHeight() {
  469. return Object.keys(this.frame).length === 0 ? this.mainAreaHeight - 130 : this.mainAreaHeight - 174
  470. },
  471. frameSelectabled() { return Object.keys(this.frame).length > 0 }
  472. },
  473. watch: {
  474. frame(val, oldvalue) {
  475. console.log('watch', val)
  476. this.params.fixedCondition = Object.keys(this.frame).length === 0 ? 'part_id=' + this.$store.getters.partId :
  477. (this.frame.part_id ? 'part_id=' + this.frame.part_id + ' and frame_id =' + this.frame.id :
  478. 'part_id=' + this.frame.hospital_id + ' and frame_id =' + this.frame.id)
  479. this.getList()
  480. }
  481. },
  482. beforeMount() {
  483. this.gridOptions = {
  484. }
  485. this.columnDefs = [
  486. {
  487. headerName: '#',
  488. headerCheckboxSelection: true,
  489. headerCheckboxSelectionFilteredOnly: true,
  490. checkboxSelection: true,
  491. sortable: false, filter: false,
  492. width: 80,
  493. resizable: false,
  494. valueGetter: this.hashValueGetter
  495. },
  496. { headerName: 'ID', field: 'id', sortable: true, filter: 'agNumberColumnFilter', width: 100 },
  497. { headerName: this.$t('deviceManage.deviceType'), field: 'device_type', sortable: true,
  498. filterFramework: 'ListFilter', width: 160,
  499. filterParams: {
  500. listData: this.deviceTypeTransfer
  501. },
  502. valueGetter: this.deviceTypeGetter
  503. },
  504. // lockPosition 锁定位置,会在第一列
  505. // lockPinned = true 不能拖动然后固定
  506. // resizeable 单元个大小是否可以调整
  507. { headerName: this.$t('deviceManage.deviceName'), field: 'name', sortable: true, filter: 'agTextColumnFilter' },
  508. { headerName: this.$t('deviceManage.status'), field: 'status', sortable: true,
  509. filterFramework: 'RadioFilter',
  510. filterParams: {
  511. listData: this.deviceStatusTransfer
  512. },
  513. cellRenderer: this.deviceStatusFormatter
  514. },
  515. { headerName: this.$t('deviceManage.connect'), field: 'online_state', sortable: false, filter: 'agTextColumnFilter',
  516. filterParams: {
  517. textCustomComparator: (filter, value, filterText) => {
  518. if (filterText) {
  519. const filterTextLowerCase = filterText.toLowerCase()
  520. const valueLowerCase = value.toString().toLowerCase()
  521. switch (filter) {
  522. case 'contains':
  523. return valueLowerCase.indexOf(filterTextLowerCase) >= 0
  524. case 'notContains':
  525. return valueLowerCase.indexOf(filterTextLowerCase) === -1
  526. case 'equals':
  527. return valueLowerCase === filterTextLowerCase
  528. case 'notEqual':
  529. return valueLowerCase !== filterTextLowerCase
  530. case 'startsWith':
  531. return valueLowerCase.indexOf(filterTextLowerCase) === 0
  532. case 'endsWith':
  533. var index = valueLowerCase.lastIndexOf(filterTextLowerCase)
  534. return index >= 0 && index === (valueLowerCase.length - filterTextLowerCase.length)
  535. default:
  536. // should never happen
  537. console.warn('invalid filter type ' + filter)
  538. return false
  539. }
  540. }
  541. }
  542. },
  543. cellRenderer: this.onlineStateFormatter
  544. },
  545. { headerName: this.$t('deviceManage.frameFullName'), field: 'full_name', sortable: true, filter: 'agTextColumnFilter' },
  546. { headerName: this.$t('deviceManage.phoneNumber'), field: 'phone_number', sortable: true, filter: 'agTextColumnFilter' },
  547. { headerName: this.$t('deviceManage.ethMac'), field: 'eth_mac', sortable: true, filter: 'agTextColumnFilter' },
  548. { headerName: this.$t('deviceManage.ethIp'), field: 'eth_ip', sortable: true, filter: 'agTextColumnFilter' },
  549. { headerName: this.$t('deviceManage.ethIpPort'), field: 'eth_ip_port', sortable: true, filter: 'agNumberColumnFilter' },
  550. { headerName: this.$t('deviceManage.model'), field: 'model', sortable: true, filter: 'agTextColumnFilter' },
  551. { headerName: this.$t('deviceManage.code'), field: 'code', sortable: true, filter: 'agTextColumnFilter' },
  552. { headerName: this.$t('deviceManage.softVer'), field: 'soft_ver', sortable: true, filter: 'agTextColumnFilter' },
  553. { headerName: this.$t('deviceManage.hardVer'), field: 'hard_ver', sortable: true, filter: 'agTextColumnFilter' },
  554. { headerName: this.$t('deviceManage.wifiMac'), field: 'wifi_mac', sortable: true, filter: 'agTextColumnFilter' },
  555. { headerName: this.$t('deviceManage.wifiIp'), field: 'wifi_ip', sortable: true, filter: 'agTextColumnFilter' },
  556. { headerName: this.$t('deviceManage.sipId'), field: 'sip_id', sortable: true, filter: 'agTextColumnFilter' },
  557. { headerName: this.$t('deviceManage.updateTime'), field: 'update_time', sortable: true, filter: 'agDateColumnFilter', valueFormatter: this.unixDateFormatter, filterParams: {
  558. comparator: (filterLocalDateAtMidnight, cellValue) => { // 所有数据都由服务器端过滤,此处只需返回0 即可
  559. const celldate = unixToDate(cellValue, 'yyyy-MM-dd 00:00:00')
  560. return (new Date(celldate).getTime() / 1000) - (filterLocalDateAtMidnight.getTime() / 1000)
  561. }
  562. }},
  563. { headerName: this.$t('action.edit'), field: 'id',
  564. cellRendererFramework: 'ButtonCellRender',
  565. cellRendererParams: {
  566. onClick: this.handleEdit,
  567. label: this.$t('action.edit'),
  568. buttonType: 'primary',
  569. buttonSize: 'mini'
  570. },
  571. filter: false,
  572. pinned: 'right',
  573. lockPinned: true,
  574. width: 90,
  575. resizable: false,
  576. sortable: false },
  577. { headerName: this.$t('action.delete'), field: 'id',
  578. cellRendererFramework: 'ButtonCellRender',
  579. cellRendererParams: param => {
  580. return {
  581. onClick: this.deleteSingle,
  582. label: this.$t('action.delete'),
  583. buttonType: 'danger',
  584. buttonSize: 'mini',
  585. disabled: param.data['member_name'] === 'superadmin'
  586. }
  587. },
  588. pinned: 'right',
  589. lockPinned: true,
  590. width: 90,
  591. resizable: false,
  592. filter: false,
  593. sortable: false }
  594. ]
  595. this.defaultColDef = {
  596. // filter: 'agTextColumnFilter',
  597. sortable: true,
  598. resizable: true,
  599. enableValue: true,
  600. filter: true,
  601. // comparator: this.dateCustomComparator,
  602. filterParams: {
  603. debounceMs: 500,
  604. newRowsAction: 'keep',
  605. textCustomComparator: this.textCustomComparator
  606. }
  607. }
  608. this.rowSelection = 'multiple'
  609. },
  610. mounted() {
  611. window.onresize = this.windowResize
  612. this.gridApi = this.gridOptions.api
  613. this.gridColumnApi = this.gridOptions.columnApi
  614. this.gridColumnApi.applyColumnState({
  615. state: [
  616. {
  617. colId: 'id',
  618. sort: 'desc'
  619. }
  620. ]
  621. })
  622. this.getShop(this.$store.getters.partId)
  623. this.initWebSocket()
  624. },
  625. methods: {
  626. windowResize() {
  627. this.$set(this, 'mainAreaHeight', Number(document.documentElement.clientHeight) - 84)
  628. },
  629. /** 加载列表数据 */
  630. getList() {
  631. const param = this.MixinClone(this.params)
  632. this.gridApi.showLoadingOverlay()
  633. API_Device.getList(param).then(response => {
  634. const deviceData = [...response.data]
  635. deviceData.forEach(item => {
  636. if (this.onlineDevice.length > 0) {
  637. if (this.isCannotBeOnline(item.device_type)) {
  638. if (item.eth_mac) {
  639. const mac = this.onlineDevice.filter(p => p.toLowerCase() === item.eth_mac.toLowerCase())[0]
  640. // console.log('在线设备1', mac)
  641. if (mac !== undefined && mac !== null) {
  642. item['online_state'] = this.$t('deviceManage.connectTrue')
  643. } else {
  644. item['online_state'] = this.$t('deviceManage.connectFalse')
  645. }
  646. }
  647. } else {
  648. item['online_state'] = '/'
  649. }
  650. } else {
  651. if (this.isCannotBeOnline(item.device_type)) {
  652. item['online_state'] = this.$t('deviceManage.connectFalse')
  653. } else {
  654. item['online_state'] = '/'
  655. }
  656. }
  657. })
  658. this.rowData = deviceData
  659. this.pageData = {
  660. page_no: response.page_no,
  661. page_size: response.page_size,
  662. data_total: response.data_total
  663. }
  664. this.$nextTick(() => {
  665. const node = this.gridApi.getDisplayedRowAtIndex(0)
  666. if (node !== null && node !== undefined) {
  667. node.setSelected(true)
  668. }
  669. })
  670. })
  671. this.typeFrames = this.partFrames
  672. },
  673. getTypeFrame(partId) {
  674. if (this.shop.shop_type === "0" && this.shop.parent_id === -1) {
  675. API_Frame.getAllFrames(partId).then(res => {
  676. this.partFrames = [...res]
  677. })
  678. } else {
  679. API_Frame.getFramesPartId(partId).then(res => {
  680. this.partFrames = [...res]
  681. })
  682. }
  683. },
  684. /** 将partFrames做分割 */
  685. getFramesByType(frame_type) {
  686. if (this.partFrames != null) {
  687. if (frame_type === FRAME_TYPE.HOSPITAL || frame_type === FRAME_TYPE.PART) {
  688. this.typeFrames = this.partFrames.filter(item => item.type === FRAME_TYPE.HOSPITAL || item.type === FRAME_TYPE.PART)
  689. } else {
  690. this.typeFrames = this.partFrames.filter(item => item.type === frame_type)
  691. }
  692. }
  693. },
  694. /**
  695. * 过滤状态发生变化,发送到服务器检索数据
  696. */
  697. filterModifed(param) {
  698. var model = param.api.getFilterModel()
  699. // 连接状态不经过服务器过滤
  700. delete model.online_state
  701. this.params.filter = JSON.stringify(model)
  702. this.getList()
  703. },
  704. gridSortChange(param) {
  705. const columnState = param.columnApi.getColumnState()
  706. // 排序状态
  707. const sortState = columnState.filter(function(s) {
  708. return s.sort != null
  709. }).map(function(s) {
  710. return {
  711. colId: s.colId,
  712. sort: s.sort,
  713. sortIndex: s.sortIndex
  714. }
  715. }).sort(function(a, b) {
  716. return a.sortIndex - b.sortIndex
  717. })
  718. if (sortState.length > 0) {
  719. if (sortState.length === 1) {
  720. this.params.sort = sortState[0].colId
  721. this.params.dir = sortState[0].sort
  722. } else {
  723. let sortstring = ''
  724. sortState.forEach(function(item) {
  725. sortstring += item.colId + ' ' + item.sort + ','
  726. })
  727. this.params.sort = sortstring.substring(0, sortstring.length - 1)
  728. this.params.dir = ' '
  729. }
  730. } else {
  731. delete this.params.sort
  732. delete this.params.dir
  733. }
  734. this.getList()
  735. },
  736. /** 处理搜索 */
  737. handlerSearch(keywords) {
  738. this.params.query = keywords
  739. this.getList()
  740. },
  741. /** 获取设备类型文字显示,从deviceTypeTransfer 中找出value值对应的key显示出来 */
  742. deviceTypeGetter(params) {
  743. const gridVal = params.data.device_type
  744. // return this.deviceTypeTransfer.filter(p => p.value === gridVal).map(p => p.key)
  745. return DEVICE_TYPE.getDescFromValue(gridVal)
  746. },
  747. /** 格式化时间函数 */
  748. unixDateFormatter(param) {
  749. if (!param.value) return ''
  750. return unix2Date(param.value * 1000)
  751. },
  752. /** 设备状态格式化 **/
  753. deviceStatusFormatter(params) {
  754. if (params.value === null || params.value === undefined) return ''
  755. const item = this.deviceStatusTransfer.filter(p => p.value === params.value)[0]
  756. if (item) {
  757. return '<span style="color:' + item.color + ';">' + item.key + '</span>'
  758. } else {
  759. return ''
  760. }
  761. },
  762. /** 设备连接状态格式化 **/
  763. onlineStateFormatter(params) {
  764. if (params.value === this.$t('deviceManage.connectTrue')) {
  765. // return '<span style="color:green;">在线</span>'
  766. return '<span style="color:green;">' + this.$t('deviceManage.connectTrue') + '</span>'
  767. } else if (params.value === this.$t('deviceManage.connectFalse')) {
  768. // return '<span style="color:gray;">离线</span>'
  769. return '<span style="color:gray;">' + this.$t('deviceManage.connectFalse') + '</span>'
  770. } else {
  771. return '<span style="color:gray;"> / </span>'
  772. }
  773. },
  774. /** 删除设备 **/
  775. deleteSingle(row) {
  776. this.handlerDelete(row.id)
  777. },
  778. /** 删除设备 **/
  779. handlerDelete(id) {
  780. this.$confirm(this.$t('action.sureDelete'), this.$t('action.waring'), {
  781. confirmButtonText: this.$t('action.yes'),
  782. cancelButtonText: this.$t('action.cancel'),
  783. type: 'warning'
  784. }).then(() => {
  785. API_Device.remove(id).then(
  786. response => {
  787. this.getList()
  788. }
  789. ).catch(response => {
  790. this.$message({
  791. type: 'info',
  792. message: response.message
  793. })
  794. })
  795. if (this.hasSosDeviceSettings) {
  796. API_SosDeviceSetting.deleteByDeviceId(id).then(() => {
  797. this.hasSosDeviceSettings = false
  798. this.getList()
  799. })
  800. }
  801. }).catch(() => {
  802. this.$message({
  803. type: 'info',
  804. message: this.$t('action.cancelDelete')
  805. })
  806. })
  807. },
  808. /** 设备类型选中变化 **/
  809. deviceTypeChange(val) {
  810. this.deviceTypeChangeToFrameTypeChange(val)
  811. if (val === DEVICE_TYPE.SIMULATE_BED_DEVICE || // 只能直接在后面加设备,会判断错误,必须重新用val = 设备
  812. val === DEVICE_TYPE.RS485_DOOR ||
  813. val === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  814. val === DEVICE_TYPE.SIMULATE_DOOR_LIGHT ||
  815. val === DEVICE_TYPE.EMERGENCY_BUTTON) { // 模拟设备不需要mac地址
  816. this.deviceRules.eth_mac[0].required = false
  817. this.deviceRules.eth_mac[1].pattern = null
  818. } else if (val === DEVICE_TYPE.REMOTE_CONTROL) {
  819. this.deviceRules.eth_mac[1].pattern = null
  820. this.deviceRules.eth_mac[0].required = true
  821. } else if (val === DEVICE_TYPE.DIGIT_BED_DEVICE) {
  822. this.deviceRules.eth_mac[1].pattern = null
  823. this.deviceRules.eth_mac[0].required = true
  824. } else {
  825. // this.deviceRules.eth_mac[1].pattern = /^([0-9A-Fa-f]{2}:?){6}/gi
  826. this.deviceRules.eth_mac[1].pattern = null
  827. this.deviceRules.eth_mac[0].required = true
  828. }
  829. this.hasRoleId = val === DEVICE_TYPE.NURSE_WATCH
  830. this.hasAudioId = val === DEVICE_TYPE.SIMULATE_BED_DEVICE ||
  831. val === DEVICE_TYPE.RS485_DOOR ||
  832. val === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  833. val === DEVICE_TYPE.SIMULATE_DOOR_LIGHT
  834. this.isVitalSigns = val === DEVICE_TYPE.VITAL_SIGNS_DEVICE
  835. this.hasSosDeviceSettings = val === DEVICE_TYPE.ALARM_BODY_INDUCTIVE ||
  836. val === DEVICE_TYPE.DOOR_LOCK ||
  837. val === DEVICE_TYPE.ALARM_RESTRAINT_BAND
  838. this.isLedDevice = val === DEVICE_TYPE.LED_SCREEN
  839. },
  840. /** 设备类型选中对应的空间结构 **/
  841. deviceTypeChangeToFrameTypeChange(val) {
  842. if (val === DEVICE_TYPE.NURSE_HOST ||
  843. val === DEVICE_TYPE.OTHER_HOST ||
  844. val === DEVICE_TYPE.NURSE_HOST ||
  845. val === DEVICE_TYPE.DOCTOR_HOST ||
  846. val === DEVICE_TYPE.LED_SCREEN ||
  847. val === DEVICE_TYPE.LCD_SCREEN ||
  848. val === DEVICE_TYPE.NURSE_WATCH ||
  849. val === DEVICE_TYPE.WORKER_WATCH ||
  850. val === DEVICE_TYPE.TRANSFER_DEVICE ||
  851. val === DEVICE_TYPE.INFORMATION_BOARD ||
  852. val === DEVICE_TYPE.RS485_TRANSFER) {
  853. this.getFramesByType(FRAME_TYPE.PART)
  854. } else if (val === DEVICE_TYPE.DOOR_DEVICE ||
  855. val === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  856. val === DEVICE_TYPE.RS485_DOOR ||
  857. val === DEVICE_TYPE.SIMULATE_DOOR_LIGHT ||
  858. val === DEVICE_TYPE.BEACON) {
  859. this.getFramesByType(FRAME_TYPE.ROOM)
  860. } else if (val === DEVICE_TYPE.DIGIT_BED_DEVICE ||
  861. val === DEVICE_TYPE.SIMULATE_BED_DEVICE ||
  862. val === DEVICE_TYPE.REMOTE_CONTROL ||
  863. val === DEVICE_TYPE.CELL_PHONE ||
  864. val === DEVICE_TYPE.ALARM_433BUTTON
  865. ) {
  866. this.getFramesByType(FRAME_TYPE.BED)
  867. } else {
  868. this.getTypeFrame(this.$store.getters.partId)
  869. this.typeFrames = this.partFrames
  870. }
  871. },
  872. /** 添加设备事件 **/
  873. handleAdd() {
  874. this.deviceModel = {
  875. soft_ver: 'SV1.0',
  876. hard_ver: 'HV1.0',
  877. priority: 1,
  878. code: 'C' + parseInt(Math.random() * 100000),
  879. model: 'M' + parseInt(Math.random() * 100000),
  880. status: 1
  881. }
  882. this.sosDeviceSetting = {
  883. type: 0,
  884. unit: '小时',
  885. setting_time: 0,
  886. }
  887. if (Object.keys(this.frame).length > 0) {
  888. this.$set(this.deviceModel, 'frame_id', this.frame.id)
  889. }
  890. delete this.deviceModel.id
  891. this.hasRoleId = false
  892. this.getRoles({ page_size: 200, page_no: 1, fixedCondition: ' shop_id = -1', sort: ' role_id', dir: 'desc' })
  893. this.hasAudioId = false
  894. this.isVitalSigns = false
  895. this.hasSosDeviceSettings = false
  896. this.isLedDevice = false
  897. this.getDevices(this.$store.getters.partId)
  898. this.deviceEditTitle = this.$t('deviceManage.deviceAdd')
  899. this.deviceDialogVisible = true
  900. this.deviceTypeDisabled = false // 新增设备可以选择设备类型
  901. this.typeFrames = this.partFrames
  902. },
  903. /** 修改设备 **/
  904. handleEdit(params) {
  905. this.getRoles({ page_size: 200, page_no: 1, fixedCondition: ' shop_id = -1', sort: ' role_id', dir: 'desc' })
  906. this.getDevices(params.part_id)
  907. this.deviceTypeChangeToFrameTypeChange(params.device_type)
  908. this.hasRoleId = params.device_type === DEVICE_TYPE.NURSE_WATCH
  909. this.hasAudioId = params.device_type === DEVICE_TYPE.SIMULATE_BED_DEVICE ||
  910. params.device_type === DEVICE_TYPE.RS485_DOOR ||
  911. params.device_type === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  912. params.device_type === DEVICE_TYPE.SIMULATE_DOOR_LIGHT
  913. this.isVitalSigns = params.device_type === DEVICE_TYPE.VITAL_SIGNS_DEVICE
  914. if (params.device_type === DEVICE_TYPE.ALARM_BODY_INDUCTIVE ||
  915. params.device_type === DEVICE_TYPE.DOOR_LOCK ||
  916. params.device_type === DEVICE_TYPE.ALARM_RESTRAINT_BAND) {
  917. this.hasSosDeviceSettings = true
  918. this.getSosDeviceSetting(params.id)
  919. } else {
  920. this.hasSosDeviceSettings = false
  921. }
  922. this.isLedDevice = params.device_type === DEVICE_TYPE.LED_SCREEN
  923. this.deviceModel = {
  924. ...params
  925. }
  926. this.deviceEditTitle = this.$t('deviceManage.deviceEdit')
  927. this.deviceDialogVisible = true
  928. this.deviceTypeDisabled = true // 修改设备时,不能改变设备类型
  929. },
  930. /** 新增 提交表单 */
  931. handlerFormSubmit(formName) {
  932. this.$refs[formName].validate((valid) => {
  933. if (valid) {
  934. const _this = this;
  935. if (this.frame.type != null) {
  936. this.deviceModel.part_id = this.frame.type === FRAME_TYPE.HOSPITAL ? this.frame.hospital_id : this.frame.part_id
  937. } else {
  938. this.deviceModel.part_id = this.$store.getters.partId
  939. }
  940. console.log('this.deviceModel', this.deviceModel)
  941. /** 新增 */
  942. if (!this.deviceModel.id) {
  943. API_Device.add(this.deviceModel).then(r => {
  944. this.$message.success(this.$t('action.saveSuccess'))
  945. _this.device = r
  946. this.sosDeviceSetting.device_id = _this.device.id
  947. this.sosDeviceSetting.part_id = _this.device.part_id
  948. if (this.hasSosDeviceSettings) {
  949. API_SosDeviceSetting.add(this.sosDeviceSetting).then(() => {
  950. this.$message.success(this.$t('action.saveSuccess'))
  951. this.hasSosDeviceSettings = false
  952. })
  953. }
  954. this.deviceDialogVisible = false
  955. this.getList()
  956. })
  957. } else {
  958. /** 修改 */
  959. API_Device.update(this.deviceModel.id, this.deviceModel).then(() => {
  960. this.$message.success(this.$t('action.editSuccess'))
  961. if (this.hasSosDeviceSettings) {
  962. this.sosDeviceSetting.device_id = this.deviceModel.id
  963. this.sosDeviceSetting.part_id = this.deviceModel.part_id
  964. API_SosDeviceSetting.updateByDeviceId(this.deviceModel.id, this.sosDeviceSetting).then(() => {
  965. this.$message.success(this.$t('action.saveSuccess'))
  966. this.hasSosDeviceSettings = false
  967. })
  968. }
  969. this.deviceDialogVisible = false
  970. this.getList()
  971. })
  972. }
  973. }
  974. })
  975. },
  976. /** 分页大小发生改变 */
  977. handlePageSizeChange(size) {
  978. this.params.page_size = size
  979. this.getList()
  980. },
  981. /** 分页页数发生改变 */
  982. handlePageCurrentChange(page) {
  983. this.params.page_no = page
  984. this.getList()
  985. },
  986. getRoles(param) {
  987. // 获取角色
  988. clerk_API.getRoles(param).then(response => {
  989. this.rolesOptions = response.data
  990. })
  991. },
  992. getDevices(partId) {
  993. // 获取设备列表
  994. API_Device.getDeviceByType(partId, DEVICE_TYPE.TRANSFER_DEVICE).then(response => {
  995. this.audioOptions = response
  996. })
  997. API_Device.getDeviceByType(partId, DEVICE_TYPE.RS485_TRANSFER).then(response => {
  998. this.rs485Options = response
  999. })
  1000. },
  1001. getSosDeviceSetting(deviceId) {
  1002. API_SosDeviceSetting.getSosDeviceSetting(deviceId).then(r => {
  1003. this.sosDeviceSetting = r;
  1004. })
  1005. },
  1006. getShop(shopId) {
  1007. shop_API.getShop(shopId).then(res => {
  1008. this.shop = res;
  1009. this.getTypeFrame(shopId)
  1010. })
  1011. },
  1012. initWebSocket: function() {
  1013. var stockbase = DeviceUrl.replace('http', 'ws')
  1014. this.websock = new WebSocket(stockbase + '/deviceonline/' + this.$store.getters.uuid)
  1015. this.websock.onopen = this.websocketonopen
  1016. this.websock.onerror = this.websocketonerror
  1017. this.websock.onmessage = this.websocketonmessage
  1018. this.websock.onclose = this.websocketclose
  1019. },
  1020. websocketonopen: function() {
  1021. console.log(this.$t('deviceManage.webSocketSuccess'))
  1022. },
  1023. websocketonerror: function(e) {
  1024. console.log(this.$t('deviceManage.webSocketError'))
  1025. },
  1026. websocketonmessage: function(e) {
  1027. this.onlineDevice = JSON.parse(e.data)
  1028. if (this.rowData !== null) {
  1029. for (let i = 0; i < this.rowData.length; i++) {
  1030. if (this.isCannotBeOnline(this.rowData[i].device_type)) {
  1031. if (this.rowData[i].eth_mac) {
  1032. const mac = this.onlineDevice.filter(p => p.toLowerCase() === this.rowData[i].eth_mac.toLowerCase())[0]
  1033. this.rowData[i]['online_state'] = (mac !== undefined && mac !== null) ? this.$t('deviceManage.connectTrue') : this.$t('deviceManage.connectFalse')
  1034. }
  1035. } else {
  1036. this.rowData[i]['online_state'] = '/'
  1037. }
  1038. }
  1039. //只刷新在线状态列数据
  1040. var params = {
  1041. columns: ['online_state']
  1042. }
  1043. this.gridApi.refreshCells(params);
  1044. }
  1045. },
  1046. websocketclose: function(e) {
  1047. console.log('connection closed (' + e.code + ')')
  1048. },
  1049. batchDelete() {
  1050. const rows = this.gridApi.getSelectedRows()
  1051. if (rows.length === 0) {
  1052. this.$message({ type: 'info', message: this.$t('action.pleaseChoiceDelete') })
  1053. return
  1054. }
  1055. const ids = []
  1056. rows.forEach(function(item) {
  1057. ids.push(item.id)
  1058. })
  1059. this.handlerDelete(ids.join(','))
  1060. },
  1061. deviceServerChange() {
  1062. this.serverAddressDialogVisible = true
  1063. },
  1064. updateDevicesServerIp() {
  1065. API_Device.updateDevicesServerIp(this.serverAddress).then(r => {
  1066. this.$message.success(this.$t('action.settingsSuccess'))
  1067. this.serverAddressDialogVisible = false
  1068. })
  1069. },
  1070. /**
  1071. * 判断设备是否为模拟分机这种,无法在线是设备
  1072. */
  1073. isCannotBeOnline(val){
  1074. return val === DEVICE_TYPE.NURSE_HOST ||
  1075. val === DEVICE_TYPE.OTHER_HOST ||
  1076. val === DEVICE_TYPE.NURSE_HOST ||
  1077. val === DEVICE_TYPE.DOCTOR_HOST ||
  1078. val === DEVICE_TYPE.NURSE_WATCH ||
  1079. val === DEVICE_TYPE.WORKER_WATCH ||
  1080. val === DEVICE_TYPE.TRANSFER_DEVICE ||
  1081. val === DEVICE_TYPE.DOOR_DEVICE ||
  1082. val === DEVICE_TYPE.DIGIT_BED_DEVICE ||
  1083. val === DEVICE_TYPE.CELL_PHONE;
  1084. }
  1085. }
  1086. }
  1087. </script>
  1088. <style scoped>
  1089. </style>