deviceManager.vue 46 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112
  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. { key: this.$t('deviceType.BREASTPLATE'), value: 34 },
  420. { key: this.$t('deviceType.OWON_X5_GATEWAY'), value: 35 },
  421. { key: this.$t('deviceType.FALL_DETECTION_RADAR'), value: 36 },
  422. ],
  423. deviceTypeEnum: DEVICE_TYPE.getValueList(),
  424. deviceStatusTransfer: [
  425. { key: this.$t('deviceManage.statusTure'), value: 1, color: 'green' },
  426. { key: this.$t('deviceManage.statusFalse'), value: 0, color: 'red' }
  427. ],
  428. rolesOptions: [],
  429. hasRoleId: false,
  430. audioOptions: [],
  431. rs485Options: [],
  432. hasAudioId: false,
  433. isVitalSigns: false,
  434. hasSosDeviceSettings: false,
  435. sosDeviceSetting: {},
  436. sosDeviceSettingsTypeOptions: [
  437. {
  438. value: 0,
  439. label: '不开启'
  440. }, {
  441. value: 1,
  442. label: '疫情防控模式'
  443. }, {
  444. value: 2,
  445. label: '关爱老人模式'
  446. }
  447. ],
  448. sosDeviceSettingEnum: SOS_DEVICE_SETTING_TYPE.getValueList(),
  449. vitalSignsDeviceEnum: VITAL_SIGNS_DEVICE_TYPE.getValueList(),
  450. isLedDevice: false,
  451. websock: null,
  452. onlineDevice: [],
  453. // 请求当前科室的数据
  454. shop: {},
  455. serverAddress: {
  456. server_ip: '172.28.100.100',
  457. server_port: '8006'
  458. },
  459. serverAddressDialogVisible: false,
  460. serverAddressRules: {
  461. serverIp: [
  462. this.MixinRequired(this.$t('deviceManage.inputServerIp'))
  463. ],
  464. serverPort: [
  465. this.MixinRequired(this.$t('deviceManage.inputServerPort'))
  466. ]
  467. }
  468. }
  469. },
  470. computed: {
  471. tableHeight() {
  472. return Object.keys(this.frame).length === 0 ? this.mainAreaHeight - 130 : this.mainAreaHeight - 174
  473. },
  474. frameSelectabled() { return Object.keys(this.frame).length > 0 }
  475. },
  476. watch: {
  477. frame(val, oldvalue) {
  478. console.log('watch', val)
  479. this.params.fixedCondition = Object.keys(this.frame).length === 0 ? 'part_id=' + this.$store.getters.partId :
  480. (this.frame.part_id ? 'part_id=' + this.frame.part_id + ' and frame_id =' + this.frame.id :
  481. 'part_id=' + this.frame.hospital_id + ' and frame_id =' + this.frame.id)
  482. this.getList()
  483. }
  484. },
  485. beforeMount() {
  486. this.gridOptions = {
  487. }
  488. this.columnDefs = [
  489. {
  490. headerName: '#',
  491. headerCheckboxSelection: true,
  492. headerCheckboxSelectionFilteredOnly: true,
  493. checkboxSelection: true,
  494. sortable: false, filter: false,
  495. width: 80,
  496. resizable: false,
  497. valueGetter: this.hashValueGetter
  498. },
  499. { headerName: 'ID', field: 'id', sortable: true, filter: 'agNumberColumnFilter', width: 100 },
  500. { headerName: this.$t('deviceManage.deviceType'), field: 'device_type', sortable: true,
  501. filterFramework: 'ListFilter', width: 160,
  502. filterParams: {
  503. listData: this.deviceTypeTransfer
  504. },
  505. valueGetter: this.deviceTypeGetter
  506. },
  507. // lockPosition 锁定位置,会在第一列
  508. // lockPinned = true 不能拖动然后固定
  509. // resizeable 单元个大小是否可以调整
  510. { headerName: this.$t('deviceManage.deviceName'), field: 'name', sortable: true, filter: 'agTextColumnFilter' },
  511. { headerName: this.$t('deviceManage.status'), field: 'status', sortable: true,
  512. filterFramework: 'RadioFilter',
  513. filterParams: {
  514. listData: this.deviceStatusTransfer
  515. },
  516. cellRenderer: this.deviceStatusFormatter
  517. },
  518. { headerName: this.$t('deviceManage.connect'), field: 'online_state', sortable: false, filter: 'agTextColumnFilter',
  519. filterParams: {
  520. textCustomComparator: (filter, value, filterText) => {
  521. if (filterText) {
  522. const filterTextLowerCase = filterText.toLowerCase()
  523. const valueLowerCase = value.toString().toLowerCase()
  524. switch (filter) {
  525. case 'contains':
  526. return valueLowerCase.indexOf(filterTextLowerCase) >= 0
  527. case 'notContains':
  528. return valueLowerCase.indexOf(filterTextLowerCase) === -1
  529. case 'equals':
  530. return valueLowerCase === filterTextLowerCase
  531. case 'notEqual':
  532. return valueLowerCase !== filterTextLowerCase
  533. case 'startsWith':
  534. return valueLowerCase.indexOf(filterTextLowerCase) === 0
  535. case 'endsWith':
  536. var index = valueLowerCase.lastIndexOf(filterTextLowerCase)
  537. return index >= 0 && index === (valueLowerCase.length - filterTextLowerCase.length)
  538. default:
  539. // should never happen
  540. console.warn('invalid filter type ' + filter)
  541. return false
  542. }
  543. }
  544. }
  545. },
  546. cellRenderer: this.onlineStateFormatter
  547. },
  548. { headerName: this.$t('deviceManage.frameFullName'), field: 'full_name', sortable: true, filter: 'agTextColumnFilter' },
  549. { headerName: this.$t('deviceManage.phoneNumber'), field: 'phone_number', sortable: true, filter: 'agTextColumnFilter' },
  550. { headerName: this.$t('deviceManage.ethMac'), field: 'eth_mac', sortable: true, filter: 'agTextColumnFilter' },
  551. { headerName: this.$t('deviceManage.ethIp'), field: 'eth_ip', sortable: true, filter: 'agTextColumnFilter' },
  552. { headerName: this.$t('deviceManage.ethIpPort'), field: 'eth_ip_port', sortable: true, filter: 'agNumberColumnFilter' },
  553. { headerName: this.$t('deviceManage.model'), field: 'model', sortable: true, filter: 'agTextColumnFilter' },
  554. { headerName: this.$t('deviceManage.code'), field: 'code', sortable: true, filter: 'agTextColumnFilter' },
  555. { headerName: this.$t('deviceManage.softVer'), field: 'soft_ver', sortable: true, filter: 'agTextColumnFilter' },
  556. { headerName: this.$t('deviceManage.hardVer'), field: 'hard_ver', sortable: true, filter: 'agTextColumnFilter' },
  557. { headerName: this.$t('deviceManage.wifiMac'), field: 'wifi_mac', sortable: true, filter: 'agTextColumnFilter' },
  558. { headerName: this.$t('deviceManage.wifiIp'), field: 'wifi_ip', sortable: true, filter: 'agTextColumnFilter' },
  559. { headerName: this.$t('deviceManage.sipId'), field: 'sip_id', sortable: true, filter: 'agTextColumnFilter' },
  560. { headerName: this.$t('deviceManage.updateTime'), field: 'update_time', sortable: true, filter: 'agDateColumnFilter', valueFormatter: this.unixDateFormatter, filterParams: {
  561. comparator: (filterLocalDateAtMidnight, cellValue) => { // 所有数据都由服务器端过滤,此处只需返回0 即可
  562. const celldate = unixToDate(cellValue, 'yyyy-MM-dd 00:00:00')
  563. return (new Date(celldate).getTime() / 1000) - (filterLocalDateAtMidnight.getTime() / 1000)
  564. }
  565. }},
  566. { headerName: this.$t('action.edit'), field: 'id',
  567. cellRendererFramework: 'ButtonCellRender',
  568. cellRendererParams: {
  569. onClick: this.handleEdit,
  570. label: this.$t('action.edit'),
  571. buttonType: 'primary',
  572. buttonSize: 'mini'
  573. },
  574. filter: false,
  575. pinned: 'right',
  576. lockPinned: true,
  577. width: 90,
  578. resizable: false,
  579. sortable: false },
  580. { headerName: this.$t('action.delete'), field: 'id',
  581. cellRendererFramework: 'ButtonCellRender',
  582. cellRendererParams: param => {
  583. return {
  584. onClick: this.deleteSingle,
  585. label: this.$t('action.delete'),
  586. buttonType: 'danger',
  587. buttonSize: 'mini',
  588. disabled: param.data['member_name'] === 'superadmin'
  589. }
  590. },
  591. pinned: 'right',
  592. lockPinned: true,
  593. width: 90,
  594. resizable: false,
  595. filter: false,
  596. sortable: false }
  597. ]
  598. this.defaultColDef = {
  599. // filter: 'agTextColumnFilter',
  600. sortable: true,
  601. resizable: true,
  602. enableValue: true,
  603. filter: true,
  604. // comparator: this.dateCustomComparator,
  605. filterParams: {
  606. debounceMs: 500,
  607. newRowsAction: 'keep',
  608. textCustomComparator: this.textCustomComparator
  609. }
  610. }
  611. this.rowSelection = 'multiple'
  612. },
  613. mounted() {
  614. window.onresize = this.windowResize
  615. this.gridApi = this.gridOptions.api
  616. this.gridColumnApi = this.gridOptions.columnApi
  617. this.gridColumnApi.applyColumnState({
  618. state: [
  619. {
  620. colId: 'id',
  621. sort: 'desc'
  622. }
  623. ]
  624. })
  625. this.getShop(this.$store.getters.partId)
  626. this.initWebSocket()
  627. },
  628. methods: {
  629. windowResize() {
  630. this.$set(this, 'mainAreaHeight', Number(document.documentElement.clientHeight) - 84)
  631. },
  632. /** 加载列表数据 */
  633. getList() {
  634. const param = this.MixinClone(this.params)
  635. this.gridApi.showLoadingOverlay()
  636. API_Device.getList(param).then(response => {
  637. const deviceData = [...response.data]
  638. deviceData.forEach(item => {
  639. if (this.onlineDevice.length > 0) {
  640. if (this.isCannotBeOnline(item.device_type)) {
  641. if (item.eth_mac) {
  642. const mac = this.onlineDevice.filter(p => p.toLowerCase() === item.eth_mac.toLowerCase())[0]
  643. // console.log('在线设备1', mac)
  644. if (mac !== undefined && mac !== null) {
  645. item['online_state'] = this.$t('deviceManage.connectTrue')
  646. } else {
  647. item['online_state'] = this.$t('deviceManage.connectFalse')
  648. }
  649. }
  650. } else {
  651. item['online_state'] = '/'
  652. }
  653. } else {
  654. if (this.isCannotBeOnline(item.device_type)) {
  655. item['online_state'] = this.$t('deviceManage.connectFalse')
  656. } else {
  657. item['online_state'] = '/'
  658. }
  659. }
  660. })
  661. this.rowData = deviceData
  662. this.pageData = {
  663. page_no: response.page_no,
  664. page_size: response.page_size,
  665. data_total: response.data_total
  666. }
  667. this.$nextTick(() => {
  668. const node = this.gridApi.getDisplayedRowAtIndex(0)
  669. if (node !== null && node !== undefined) {
  670. node.setSelected(true)
  671. }
  672. })
  673. })
  674. this.typeFrames = this.partFrames
  675. },
  676. getTypeFrame(partId) {
  677. if (this.shop.shop_type === "0" && this.shop.parent_id === -1) {
  678. API_Frame.getAllFrames(partId).then(res => {
  679. this.partFrames = [...res]
  680. })
  681. } else {
  682. API_Frame.getFramesPartId(partId).then(res => {
  683. this.partFrames = [...res]
  684. })
  685. }
  686. },
  687. /** 将partFrames做分割 */
  688. getFramesByType(frame_type) {
  689. if (this.partFrames != null) {
  690. if (frame_type === FRAME_TYPE.HOSPITAL || frame_type === FRAME_TYPE.PART) {
  691. this.typeFrames = this.partFrames.filter(item => item.type === FRAME_TYPE.HOSPITAL || item.type === FRAME_TYPE.PART)
  692. } else {
  693. this.typeFrames = this.partFrames.filter(item => item.type === frame_type)
  694. }
  695. }
  696. },
  697. /**
  698. * 过滤状态发生变化,发送到服务器检索数据
  699. */
  700. filterModifed(param) {
  701. var model = param.api.getFilterModel()
  702. // 连接状态不经过服务器过滤
  703. delete model.online_state
  704. this.params.filter = JSON.stringify(model)
  705. this.getList()
  706. },
  707. gridSortChange(param) {
  708. const columnState = param.columnApi.getColumnState()
  709. // 排序状态
  710. const sortState = columnState.filter(function(s) {
  711. return s.sort != null
  712. }).map(function(s) {
  713. return {
  714. colId: s.colId,
  715. sort: s.sort,
  716. sortIndex: s.sortIndex
  717. }
  718. }).sort(function(a, b) {
  719. return a.sortIndex - b.sortIndex
  720. })
  721. if (sortState.length > 0) {
  722. if (sortState.length === 1) {
  723. this.params.sort = sortState[0].colId
  724. this.params.dir = sortState[0].sort
  725. } else {
  726. let sortstring = ''
  727. sortState.forEach(function(item) {
  728. sortstring += item.colId + ' ' + item.sort + ','
  729. })
  730. this.params.sort = sortstring.substring(0, sortstring.length - 1)
  731. this.params.dir = ' '
  732. }
  733. } else {
  734. delete this.params.sort
  735. delete this.params.dir
  736. }
  737. this.getList()
  738. },
  739. /** 处理搜索 */
  740. handlerSearch(keywords) {
  741. this.params.query = keywords
  742. this.getList()
  743. },
  744. /** 获取设备类型文字显示,从deviceTypeTransfer 中找出value值对应的key显示出来 */
  745. deviceTypeGetter(params) {
  746. const gridVal = params.data.device_type
  747. // return this.deviceTypeTransfer.filter(p => p.value === gridVal).map(p => p.key)
  748. return DEVICE_TYPE.getDescFromValue(gridVal)
  749. },
  750. /** 格式化时间函数 */
  751. unixDateFormatter(param) {
  752. if (!param.value) return ''
  753. return unix2Date(param.value * 1000)
  754. },
  755. /** 设备状态格式化 **/
  756. deviceStatusFormatter(params) {
  757. if (params.value === null || params.value === undefined) return ''
  758. const item = this.deviceStatusTransfer.filter(p => p.value === params.value)[0]
  759. if (item) {
  760. return '<span style="color:' + item.color + ';">' + item.key + '</span>'
  761. } else {
  762. return ''
  763. }
  764. },
  765. /** 设备连接状态格式化 **/
  766. onlineStateFormatter(params) {
  767. if (params.value === this.$t('deviceManage.connectTrue')) {
  768. // return '<span style="color:green;">在线</span>'
  769. return '<span style="color:green;">' + this.$t('deviceManage.connectTrue') + '</span>'
  770. } else if (params.value === this.$t('deviceManage.connectFalse')) {
  771. // return '<span style="color:gray;">离线</span>'
  772. return '<span style="color:gray;">' + this.$t('deviceManage.connectFalse') + '</span>'
  773. } else {
  774. return '<span style="color:gray;"> / </span>'
  775. }
  776. },
  777. /** 删除设备 **/
  778. deleteSingle(row) {
  779. this.handlerDelete(row.id)
  780. },
  781. /** 删除设备 **/
  782. handlerDelete(id) {
  783. this.$confirm(this.$t('action.sureDelete'), this.$t('action.waring'), {
  784. confirmButtonText: this.$t('action.yes'),
  785. cancelButtonText: this.$t('action.cancel'),
  786. type: 'warning'
  787. }).then(() => {
  788. API_Device.remove(id).then(
  789. response => {
  790. this.getList()
  791. }
  792. ).catch(response => {
  793. this.$message({
  794. type: 'info',
  795. message: response.message
  796. })
  797. })
  798. if (this.hasSosDeviceSettings) {
  799. API_SosDeviceSetting.deleteByDeviceId(id).then(() => {
  800. this.hasSosDeviceSettings = false
  801. this.getList()
  802. })
  803. }
  804. }).catch(() => {
  805. this.$message({
  806. type: 'info',
  807. message: this.$t('action.cancelDelete')
  808. })
  809. })
  810. },
  811. /** 设备类型选中变化 **/
  812. deviceTypeChange(val) {
  813. this.deviceTypeChangeToFrameTypeChange(val)
  814. if (val === DEVICE_TYPE.SIMULATE_BED_DEVICE || // 只能直接在后面加设备,会判断错误,必须重新用val = 设备
  815. val === DEVICE_TYPE.RS485_DOOR ||
  816. val === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  817. val === DEVICE_TYPE.SIMULATE_DOOR_LIGHT ||
  818. val === DEVICE_TYPE.EMERGENCY_BUTTON) { // 模拟设备不需要mac地址
  819. this.deviceRules.eth_mac[0].required = false
  820. this.deviceRules.eth_mac[1].pattern = null
  821. } else if (val === DEVICE_TYPE.REMOTE_CONTROL) {
  822. this.deviceRules.eth_mac[1].pattern = null
  823. this.deviceRules.eth_mac[0].required = true
  824. } else if (val === DEVICE_TYPE.DIGIT_BED_DEVICE) {
  825. this.deviceRules.eth_mac[1].pattern = null
  826. this.deviceRules.eth_mac[0].required = true
  827. } else {
  828. // this.deviceRules.eth_mac[1].pattern = /^([0-9A-Fa-f]{2}:?){6}/gi
  829. this.deviceRules.eth_mac[1].pattern = null
  830. this.deviceRules.eth_mac[0].required = true
  831. }
  832. this.hasRoleId = val === DEVICE_TYPE.NURSE_WATCH
  833. this.hasAudioId = val === DEVICE_TYPE.SIMULATE_BED_DEVICE ||
  834. val === DEVICE_TYPE.RS485_DOOR ||
  835. val === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  836. val === DEVICE_TYPE.SIMULATE_DOOR_LIGHT
  837. this.isVitalSigns = val === DEVICE_TYPE.VITAL_SIGNS_DEVICE
  838. this.hasSosDeviceSettings = val === DEVICE_TYPE.ALARM_BODY_INDUCTIVE ||
  839. val === DEVICE_TYPE.DOOR_LOCK ||
  840. val === DEVICE_TYPE.ALARM_RESTRAINT_BAND
  841. this.isLedDevice = val === DEVICE_TYPE.LED_SCREEN
  842. },
  843. /** 设备类型选中对应的空间结构 **/
  844. deviceTypeChangeToFrameTypeChange(val) {
  845. if (val === DEVICE_TYPE.NURSE_HOST ||
  846. val === DEVICE_TYPE.OTHER_HOST ||
  847. val === DEVICE_TYPE.NURSE_HOST ||
  848. val === DEVICE_TYPE.DOCTOR_HOST ||
  849. val === DEVICE_TYPE.LED_SCREEN ||
  850. val === DEVICE_TYPE.LCD_SCREEN ||
  851. val === DEVICE_TYPE.NURSE_WATCH ||
  852. val === DEVICE_TYPE.WORKER_WATCH ||
  853. val === DEVICE_TYPE.TRANSFER_DEVICE ||
  854. val === DEVICE_TYPE.INFORMATION_BOARD ||
  855. val === DEVICE_TYPE.RS485_TRANSFER) {
  856. this.getFramesByType(FRAME_TYPE.PART)
  857. } else if (val === DEVICE_TYPE.DOOR_DEVICE ||
  858. val === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  859. val === DEVICE_TYPE.RS485_DOOR ||
  860. val === DEVICE_TYPE.SIMULATE_DOOR_LIGHT ||
  861. val === DEVICE_TYPE.BEACON) {
  862. this.getFramesByType(FRAME_TYPE.ROOM)
  863. } else if (val === DEVICE_TYPE.DIGIT_BED_DEVICE ||
  864. val === DEVICE_TYPE.SIMULATE_BED_DEVICE ||
  865. val === DEVICE_TYPE.REMOTE_CONTROL ||
  866. val === DEVICE_TYPE.CELL_PHONE ||
  867. val === DEVICE_TYPE.ALARM_433BUTTON
  868. ) {
  869. this.getFramesByType(FRAME_TYPE.BED)
  870. } else {
  871. this.getTypeFrame(this.$store.getters.partId)
  872. this.typeFrames = this.partFrames
  873. }
  874. },
  875. /** 添加设备事件 **/
  876. handleAdd() {
  877. this.deviceModel = {
  878. soft_ver: 'SV1.0',
  879. hard_ver: 'HV1.0',
  880. priority: 1,
  881. code: 'C' + parseInt(Math.random() * 100000),
  882. model: 'M' + parseInt(Math.random() * 100000),
  883. status: 1
  884. }
  885. this.sosDeviceSetting = {
  886. type: 0,
  887. unit: '小时',
  888. setting_time: 0,
  889. }
  890. if (Object.keys(this.frame).length > 0) {
  891. this.$set(this.deviceModel, 'frame_id', this.frame.id)
  892. }
  893. delete this.deviceModel.id
  894. this.hasRoleId = false
  895. this.getRoles({ page_size: 200, page_no: 1, fixedCondition: ' shop_id = -1', sort: ' role_id', dir: 'desc' })
  896. this.hasAudioId = false
  897. this.isVitalSigns = false
  898. this.hasSosDeviceSettings = false
  899. this.isLedDevice = false
  900. this.getDevices(this.$store.getters.partId)
  901. this.deviceEditTitle = this.$t('deviceManage.deviceAdd')
  902. this.deviceDialogVisible = true
  903. this.deviceTypeDisabled = false // 新增设备可以选择设备类型
  904. this.typeFrames = this.partFrames
  905. },
  906. /** 修改设备 **/
  907. handleEdit(params) {
  908. this.getRoles({ page_size: 200, page_no: 1, fixedCondition: ' shop_id = -1', sort: ' role_id', dir: 'desc' })
  909. this.getDevices(params.part_id)
  910. this.deviceTypeChangeToFrameTypeChange(params.device_type)
  911. this.hasRoleId = params.device_type === DEVICE_TYPE.NURSE_WATCH
  912. this.hasAudioId = params.device_type === DEVICE_TYPE.SIMULATE_BED_DEVICE ||
  913. params.device_type === DEVICE_TYPE.RS485_DOOR ||
  914. params.device_type === DEVICE_TYPE.SIMULATE_EMERGENCY_BUTTON ||
  915. params.device_type === DEVICE_TYPE.SIMULATE_DOOR_LIGHT
  916. this.isVitalSigns = params.device_type === DEVICE_TYPE.VITAL_SIGNS_DEVICE
  917. if (params.device_type === DEVICE_TYPE.ALARM_BODY_INDUCTIVE ||
  918. params.device_type === DEVICE_TYPE.DOOR_LOCK ||
  919. params.device_type === DEVICE_TYPE.ALARM_RESTRAINT_BAND) {
  920. this.hasSosDeviceSettings = true
  921. this.getSosDeviceSetting(params.id)
  922. } else {
  923. this.hasSosDeviceSettings = false
  924. }
  925. this.isLedDevice = params.device_type === DEVICE_TYPE.LED_SCREEN
  926. this.deviceModel = {
  927. ...params
  928. }
  929. this.deviceEditTitle = this.$t('deviceManage.deviceEdit')
  930. this.deviceDialogVisible = true
  931. this.deviceTypeDisabled = true // 修改设备时,不能改变设备类型
  932. },
  933. /** 新增 提交表单 */
  934. handlerFormSubmit(formName) {
  935. this.$refs[formName].validate((valid) => {
  936. if (valid) {
  937. const _this = this;
  938. if (this.frame.type != null) {
  939. this.deviceModel.part_id = this.frame.type === FRAME_TYPE.HOSPITAL ? this.frame.hospital_id : this.frame.part_id
  940. } else {
  941. this.deviceModel.part_id = this.$store.getters.partId
  942. }
  943. console.log('this.deviceModel', this.deviceModel)
  944. /** 新增 */
  945. if (!this.deviceModel.id) {
  946. API_Device.add(this.deviceModel).then(r => {
  947. this.$message.success(this.$t('action.saveSuccess'))
  948. _this.device = r
  949. this.sosDeviceSetting.device_id = _this.device.id
  950. this.sosDeviceSetting.part_id = _this.device.part_id
  951. if (this.hasSosDeviceSettings) {
  952. API_SosDeviceSetting.add(this.sosDeviceSetting).then(() => {
  953. this.$message.success(this.$t('action.saveSuccess'))
  954. this.hasSosDeviceSettings = false
  955. })
  956. }
  957. this.deviceDialogVisible = false
  958. this.getList()
  959. })
  960. } else {
  961. /** 修改 */
  962. API_Device.update(this.deviceModel.id, this.deviceModel).then(() => {
  963. this.$message.success(this.$t('action.editSuccess'))
  964. if (this.hasSosDeviceSettings) {
  965. this.sosDeviceSetting.device_id = this.deviceModel.id
  966. this.sosDeviceSetting.part_id = this.deviceModel.part_id
  967. API_SosDeviceSetting.updateByDeviceId(this.deviceModel.id, this.sosDeviceSetting).then(() => {
  968. this.$message.success(this.$t('action.saveSuccess'))
  969. this.hasSosDeviceSettings = false
  970. })
  971. }
  972. this.deviceDialogVisible = false
  973. this.getList()
  974. })
  975. }
  976. }
  977. })
  978. },
  979. /** 分页大小发生改变 */
  980. handlePageSizeChange(size) {
  981. this.params.page_size = size
  982. this.getList()
  983. },
  984. /** 分页页数发生改变 */
  985. handlePageCurrentChange(page) {
  986. this.params.page_no = page
  987. this.getList()
  988. },
  989. getRoles(param) {
  990. // 获取角色
  991. clerk_API.getRoles(param).then(response => {
  992. this.rolesOptions = response.data
  993. })
  994. },
  995. getDevices(partId) {
  996. // 获取设备列表
  997. API_Device.getDeviceByType(partId, DEVICE_TYPE.TRANSFER_DEVICE).then(response => {
  998. this.audioOptions = response
  999. })
  1000. API_Device.getDeviceByType(partId, DEVICE_TYPE.RS485_TRANSFER).then(response => {
  1001. this.rs485Options = response
  1002. })
  1003. },
  1004. getSosDeviceSetting(deviceId) {
  1005. API_SosDeviceSetting.getSosDeviceSetting(deviceId).then(r => {
  1006. this.sosDeviceSetting = r;
  1007. })
  1008. },
  1009. getShop(shopId) {
  1010. shop_API.getShop(shopId).then(res => {
  1011. this.shop = res;
  1012. this.getTypeFrame(shopId)
  1013. })
  1014. },
  1015. initWebSocket: function() {
  1016. var stockbase = DeviceUrl.replace('http', 'ws')
  1017. this.websock = new WebSocket(stockbase + '/deviceonline/' + this.$store.getters.uuid)
  1018. this.websock.onopen = this.websocketonopen
  1019. this.websock.onerror = this.websocketonerror
  1020. this.websock.onmessage = this.websocketonmessage
  1021. this.websock.onclose = this.websocketclose
  1022. },
  1023. websocketonopen: function() {
  1024. console.log(this.$t('deviceManage.webSocketSuccess'))
  1025. },
  1026. websocketonerror: function(e) {
  1027. console.log(this.$t('deviceManage.webSocketError'))
  1028. },
  1029. websocketonmessage: function(e) {
  1030. this.onlineDevice = JSON.parse(e.data)
  1031. if (this.rowData !== null) {
  1032. for (let i = 0; i < this.rowData.length; i++) {
  1033. if (this.isCannotBeOnline(this.rowData[i].device_type)) {
  1034. if (this.rowData[i].eth_mac) {
  1035. const mac = this.onlineDevice.filter(p => p.toLowerCase() === this.rowData[i].eth_mac.toLowerCase())[0]
  1036. this.rowData[i]['online_state'] = (mac !== undefined && mac !== null) ? this.$t('deviceManage.connectTrue') : this.$t('deviceManage.connectFalse')
  1037. }
  1038. } else {
  1039. this.rowData[i]['online_state'] = '/'
  1040. }
  1041. }
  1042. //只刷新在线状态列数据
  1043. var params = {
  1044. columns: ['online_state']
  1045. }
  1046. this.gridApi.refreshCells(params);
  1047. }
  1048. },
  1049. websocketclose: function(e) {
  1050. console.log('connection closed (' + e.code + ')')
  1051. },
  1052. batchDelete() {
  1053. const rows = this.gridApi.getSelectedRows()
  1054. if (rows.length === 0) {
  1055. this.$message({ type: 'info', message: this.$t('action.pleaseChoiceDelete') })
  1056. return
  1057. }
  1058. const ids = []
  1059. rows.forEach(function(item) {
  1060. ids.push(item.id)
  1061. })
  1062. this.handlerDelete(ids.join(','))
  1063. },
  1064. deviceServerChange() {
  1065. this.serverAddressDialogVisible = true
  1066. },
  1067. updateDevicesServerIp() {
  1068. API_Device.updateDevicesServerIp(this.serverAddress).then(r => {
  1069. this.$message.success(this.$t('action.settingsSuccess'))
  1070. this.serverAddressDialogVisible = false
  1071. })
  1072. },
  1073. /**
  1074. * 判断设备是否为模拟分机这种,无法在线是设备
  1075. */
  1076. isCannotBeOnline(val){
  1077. return val === DEVICE_TYPE.NURSE_HOST ||
  1078. val === DEVICE_TYPE.OTHER_HOST ||
  1079. val === DEVICE_TYPE.NURSE_HOST ||
  1080. val === DEVICE_TYPE.DOCTOR_HOST ||
  1081. val === DEVICE_TYPE.NURSE_WATCH ||
  1082. val === DEVICE_TYPE.WORKER_WATCH ||
  1083. val === DEVICE_TYPE.TRANSFER_DEVICE ||
  1084. val === DEVICE_TYPE.DOOR_DEVICE ||
  1085. val === DEVICE_TYPE.DIGIT_BED_DEVICE ||
  1086. val === DEVICE_TYPE.CELL_PHONE;
  1087. }
  1088. }
  1089. }
  1090. </script>
  1091. <style scoped>
  1092. </style>