equipmentModal.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332
  1. <template>
  2. <a-modal
  3. centered
  4. class="edit-network-modal"
  5. :footer="null"
  6. :maskClosable="false"
  7. title="绑定设备"
  8. v-model="isShow"
  9. @cancle="isShow=false"
  10. :width="1000">
  11. <!-- 搜索设备 -->
  12. <div class="search-con" @blur="isFocus=false">
  13. <a-input-search
  14. id="equipment-search"
  15. class="search-s"
  16. allow-clear
  17. placeholder="请通过设备编号或MAC地址搜索"
  18. enter-button="查询"
  19. size="large"
  20. v-model="searchVal"
  21. @blur="noData=0"
  22. @focus="isFocus=true"
  23. @search="onSearch"
  24. />
  25. <a-card class="search-sub" :bordered="false">
  26. <div class="noData" v-if="noData==1" style="text-align: center;">未查询到结果</div>
  27. <div class="search-sub-item" v-if="resultData && isFocus">
  28. <p>{{ resultData.srcDeviceCode }}</p>
  29. <a-button
  30. id="equipment-unbind"
  31. v-if="resultData.bindingFlag == 0"
  32. type="primary"
  33. ghost
  34. size="small"
  35. @click="onBundling(resultData)">立即绑定</a-button>
  36. <a-button id="equipment-bind" v-else disabled type="link">已绑定</a-button>
  37. </div>
  38. </a-card>
  39. </div>
  40. <!-- 已绑设备 -->
  41. <div class="eq-tit">已绑设备:</div>
  42. <a-spin tip="Loading..." :spinning="isLoading">
  43. <a-table
  44. class="table"
  45. ref="table"
  46. bordered
  47. size="small"
  48. :rowKey="(record) => record.id"
  49. :columns="columns"
  50. :data-source="equipmentData"
  51. :pagination="false">
  52. <!-- 设备状态 -->
  53. <template slot="onlineFlag" slot-scope="record">
  54. <span v-if="record.deviceType!='STEELYARD'" :style="{'color':(record.onlineFlag==0 ? 'red' : record.onlineFlag==1 ? 'green' : '')}">{{ record.onlineFlag == 0 ? '离线' : record.onlineFlag == 1 ? '在线' :'--' }}</span>
  55. <span v-else>--</span>
  56. </template>
  57. <!-- 箱体类型 -->
  58. <template slot="type" slot-scope="record">
  59. <a-select
  60. id="equipment-type"
  61. placeholder="请选择箱体类型"
  62. style="width: 100%;"
  63. v-model="record.deviceTypeNo"
  64. :disabled="record.state == 1&&record.deviceType!='STEELYARD'"
  65. @change="typeChange($event, record)">
  66. <a-select-option v-for="(item,index) in record.deviceTypeList" :key="index" :value="item.deviceTypeNo">
  67. {{ item.name }}
  68. </a-select-option>
  69. </a-select>
  70. </template>
  71. <!-- 工作状态 -->
  72. <template slot="workStatus" slot-scope="record">
  73. <a-switch
  74. checkedChildren="启用"
  75. unCheckedChildren="禁用"
  76. id="equipment-changeFlagHandle"
  77. v-if="record.state && record.deviceType!='STEELYARD'"
  78. v-model="record.state == 1 ? true : false"
  79. @change="changeFlagHandle(record)"
  80. />
  81. <span v-else>--</span>
  82. </template>
  83. <!-- 操作 -->
  84. <template slot="action" slot-scope="record">
  85. <a-button
  86. type="primary"
  87. ghost
  88. size="small"
  89. id="equipment-unBind"
  90. @click="onUnbundling(record)">解绑</a-button>
  91. </template>
  92. </a-table>
  93. </a-spin>
  94. </a-modal>
  95. </template>
  96. <script>
  97. import { deviceEnable, deviceListQuery, deviceFindDevice, deviceUpdateDeviceType } from '@/api/device'
  98. import { stationBind, stationUnBind } from '@/api/station'
  99. import { deviceTypeListQuery } from '@/api/boxSetting'
  100. export default {
  101. name: 'EquipmentModal',
  102. props: {
  103. openModal: { // 弹框显示状态
  104. type: Boolean,
  105. default: false
  106. },
  107. networkId: {
  108. type: [Number, String],
  109. default: ''
  110. },
  111. networkNo: {
  112. type: String,
  113. default: ''
  114. }
  115. },
  116. data () {
  117. return {
  118. isShow: this.openModal, // 是否打开弹框
  119. resultData: null, // 设备搜索结果
  120. noData: 0,
  121. isFocus: false, // 搜索框是否获取焦点
  122. searchVal: '', // 搜索框值
  123. columns: [
  124. { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
  125. { title: '设备编号', dataIndex: 'srcDeviceCode', width: 100, align: 'center' },
  126. { title: '设备状态', scopedSlots: { customRender: 'onlineFlag' }, width: 150, align: 'center' },
  127. { title: '设备类型', dataIndex: 'deviceTypeDictValue', width: 150, align: 'center' },
  128. { title: '箱体类型', scopedSlots: { customRender: 'type' }, width: 150, align: 'center' },
  129. { title: '工作状态', scopedSlots: { customRender: 'workStatus' }, width: 150, align: 'center' },
  130. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center' }
  131. ],
  132. equipmentData: [],
  133. typeList: [], // 箱体类型
  134. isLoading: true // 加载状态
  135. }
  136. },
  137. methods: {
  138. // 已绑设备
  139. getDevice () {
  140. deviceListQuery({ stationNo: this.networkNo }).then(res => {
  141. if (res.status == 200) {
  142. this.equipmentData = res.data
  143. this.equipmentData.map((item, index) => {
  144. item.no = index + 1
  145. // 处理每个设备所对应的箱体类型
  146. item.deviceTypeList = this.typeList.filter(tk => !item.boxNum || tk.boxNum == item.boxNum)
  147. })
  148. } else {
  149. this.equipmentData = []
  150. }
  151. this.isLoading = false
  152. })
  153. },
  154. // 箱体类型下拉数据
  155. getDeviceType () {
  156. deviceTypeListQuery({}).then(res => {
  157. if (res.status == 200) {
  158. this.typeList = res.data
  159. } else {
  160. this.typeList = []
  161. }
  162. this.getDevice()
  163. })
  164. },
  165. // 搜索设备
  166. onSearch (value) {
  167. if (value) {
  168. deviceFindDevice({ srcDeviceCode: value }).then(res => {
  169. if (res.status == 200) {
  170. if (res.data) {
  171. this.noData = 2
  172. this.resultData = res.data
  173. } else {
  174. this.noData = 1
  175. this.resultData = null
  176. }
  177. }
  178. })
  179. } else {
  180. this.noData = 0
  181. this.resultData = null
  182. this.isFocus = false
  183. }
  184. },
  185. // 解绑
  186. onUnbundling (item) {
  187. const _this = this
  188. _this.$confirm({
  189. title: '提示',
  190. centered: true,
  191. content: '确定解绑该设备吗?',
  192. onOk () {
  193. stationUnBind({ srcDeviceCode: item.srcDeviceCode, stationNo: _this.networkNo }).then(res => {
  194. if (res.status == 200) {
  195. _this.$message.success(res.message)
  196. _this.getDevice()
  197. }
  198. })
  199. }
  200. })
  201. },
  202. // 绑定
  203. onBundling (item) {
  204. const _this = this
  205. _this.$confirm({
  206. title: '提示',
  207. centered: true,
  208. content: '确定要绑定该设备吗?',
  209. onOk () {
  210. stationBind({ srcDeviceCode: item.srcDeviceCode, stationNo: _this.networkNo }).then(res => {
  211. if (res.status == 200) {
  212. _this.$message.success(res.message)
  213. _this.resultData = null
  214. _this.isFocus = false
  215. _this.getDevice()
  216. }
  217. })
  218. }
  219. })
  220. },
  221. // 箱体类型 change
  222. typeChange (deviceTypeNo, record) {
  223. deviceUpdateDeviceType({ id: record.id, deviceTypeNo: deviceTypeNo }).then(res => {
  224. console.log(res)
  225. if (res.status == 200) {
  226. this.$message.success(res.message)
  227. }
  228. })
  229. },
  230. // 更改启用禁用状态
  231. changeFlagHandle (record) {
  232. const _data = {
  233. id: record.id,
  234. state: record.state == 1 ? '0' : '1'
  235. }
  236. deviceEnable(_data).then(res => {
  237. if (res.status == 200) {
  238. this.$message.success(res.message)
  239. this.getDevice()
  240. }
  241. })
  242. }
  243. },
  244. watch: {
  245. // 父页面传过来的弹框状态
  246. openModal (newValue, oldValue) {
  247. this.isShow = newValue
  248. },
  249. // 重定义的弹框状态
  250. isShow (newValue, oldValue) {
  251. if (!newValue) {
  252. this.$emit('close')
  253. }
  254. },
  255. networkId (newValue, oldValue) {
  256. if (this.isShow && newValue) {
  257. this.searchVal = ''
  258. this.resultData = null // 设备搜索结果
  259. this.noData = 0
  260. this.isFocus = false // 搜索框是否获取焦点
  261. this.isLoading = true
  262. this.equipmentData = []
  263. this.getDeviceType()
  264. }
  265. }
  266. }
  267. }
  268. </script>
  269. <style scoped>
  270. .spin-content {
  271. border: 1px solid #91d5ff;
  272. background-color: #e6f7ff;
  273. padding: 30px;
  274. }
  275. </style>
  276. <style lang="less">
  277. .edit-network-modal{
  278. .search-con{
  279. position: relative;
  280. .search-s{
  281. .ant-input-group-addon{
  282. padding: 0;
  283. border: none;
  284. }
  285. }
  286. .search-sub{
  287. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  288. position: absolute;
  289. left: 0;
  290. top: 45px;
  291. width: 100%;
  292. z-index: 1;
  293. border-radius: 6px;
  294. .ant-card-body{
  295. padding: 15px 24px;
  296. }
  297. .search-sub-item{
  298. display: flex;
  299. justify-content: space-between;
  300. align-items: center;
  301. padding: 8px 0;
  302. border-bottom: 1px dashed #f8f8f8;
  303. p{
  304. margin: 0;
  305. }
  306. &:last-child{
  307. border-bottom: none;
  308. }
  309. }
  310. }
  311. }
  312. .eq-tit{
  313. line-height: 40px;
  314. font-size: 16px;
  315. margin: 85px 0 5px;
  316. }
  317. .eq-subTit{
  318. margin: 0 0 10px;
  319. }
  320. .table{
  321. padding-bottom: 50px;
  322. }
  323. }
  324. .btn-cont{
  325. text-align: center;
  326. .cancel{
  327. margin-left: 40px;
  328. }
  329. }
  330. </style>