StoreAssociatedEquipmentModal.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. <template>
  2. <a-modal
  3. class="StoreAssociatedEquipmentModal-wrap"
  4. centered
  5. title="关联摄像设备"
  6. :width="1000"
  7. :footer="null"
  8. :destroyOnClose="true"
  9. @cancel="isShow = false"
  10. v-model="isShow">
  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="请通过设备国标ID搜索"
  18. enter-button="查询"
  19. size="large"
  20. @blur="noData=0"
  21. @focus="isFocus=true"
  22. @search="onSearch"
  23. />
  24. <a-card class="search-sub" :bordered="false">
  25. <div class="noData" v-if="noData==1" style="text-align: center;">未查询到结果</div>
  26. <div class="search-sub-item" v-if="resultData && isFocus">
  27. <p>{{ resultData.name }}</p>
  28. <a-button
  29. id="equipment-bind"
  30. v-if="!resultData.params"
  31. type="primary"
  32. ghost
  33. size="small"
  34. @click="onBundling(resultData)"
  35. v-hasPermission="'B_store_device_bind'">立即绑定</a-button>
  36. <a-button v-else disabled type="link">已绑定</a-button>
  37. </div>
  38. </a-card>
  39. </div>
  40. <!-- 已绑设备 -->
  41. <div class="eq-tit">已绑设备:</div>
  42. <a-table
  43. class="table"
  44. ref="table"
  45. bordered
  46. size="small"
  47. :rowKey="(record) => record.id"
  48. :columns="columns"
  49. :data-source="equipmentData"
  50. :pagination="false"
  51. :expandedRowKeys="expandedRowKeys"
  52. @expand="eqExpand"
  53. @expandedRowsChange="expandedRowsChange">
  54. <div slot="expandedRowRender" slot-scope="record" style="margin: 30px 30px;">
  55. <div class="eq-subTit">设备通道(机位):</div>
  56. <a-table
  57. ref="tables"
  58. bordered
  59. size="small"
  60. :rowKey="(record) => record.gbId"
  61. :columns="passagewayColumns"
  62. :data-source="record.passagewayData"
  63. :pagination="false">
  64. <template slot="action" slot-scope="record">
  65. <a-button type="link" id="equipment-edit" @click="onEdit(record)" v-hasPermission="'B_store_deviceTd_edit'">编辑</a-button>
  66. </template>
  67. </a-table>
  68. </div>
  69. <template slot="action" slot-scope="record">
  70. <a-button
  71. type="primary"
  72. ghost
  73. size="small"
  74. id="equipment-unBind"
  75. @click="onUnbundling(record)"
  76. v-hasPermission="'B_store_device_unbind'">解绑</a-button>
  77. </template>
  78. </a-table>
  79. <!-- 编辑 通道/机位名称 -->
  80. <a-modal
  81. class="passagewayModal"
  82. title="编辑"
  83. centered
  84. :visible="visible"
  85. :footer="null"
  86. :closable="true"
  87. @cancel="visible=false"
  88. width="600px">
  89. <!-- 表单 -->
  90. <a-form-model ref="ruleForm" :model="form" :rules="rules">
  91. <a-form-model-item label="名称" prop="deviceName">
  92. <a-input v-model.trim="form.deviceName" id="equipment-name" :maxLength="30" placeholder="请输入名称,30个字以内" />
  93. </a-form-model-item>
  94. <a-form-model-item class="btn-cont">
  95. <a-button type="primary" id="equipment-save" @click="onSubmit">保存</a-button>
  96. <a-button class="cancel" id="equipment-cancel" @click="visible=false">取消</a-button>
  97. </a-form-model-item>
  98. </a-form-model>
  99. </a-modal>
  100. </a-modal>
  101. </template>
  102. <script>
  103. import { findStoreVsDevice, unbindVsDevice, findVsDevice, bindVsDevice } from '@/api/storeVsDevice.js'
  104. import { vsDeviceChannels, vsDeviceRename } from '@/api/vsDevice.js'
  105. export default {
  106. name: 'StoreAssociatedEquipmentModal',
  107. props: {
  108. openModal: {
  109. // 弹框是否展示
  110. type: Boolean,
  111. default: false
  112. },
  113. storeId: {
  114. // 门店id
  115. type: String,
  116. default: ''
  117. },
  118. storeCode: {
  119. // 门店code
  120. type: String,
  121. default: ''
  122. }
  123. },
  124. data () {
  125. return {
  126. isShow: this.openModal, // 弹框是否展示
  127. columns: [
  128. { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
  129. { title: '设备名称', dataIndex: 'vsDeviceName', width: 100, align: 'center' },
  130. { title: '设备ID', dataIndex: 'vsDeviceId', width: 150, align: 'center' },
  131. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center' }
  132. ],
  133. equipmentData: [], // 已绑设备
  134. passagewayData: [], // 设备通道
  135. passagewayColumns: [
  136. { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
  137. { title: '设备通道名称', dataIndex: 'name', width: 100, align: 'center' },
  138. { title: '设备ID', dataIndex: 'deviceId', width: 150, align: 'center' },
  139. { title: '操作', scopedSlots: { customRender: 'action' }, width: 80, align: 'center' }
  140. ],
  141. visible: false, // 编辑 通道/机位名称
  142. form: {
  143. deviceName: '' // 名称
  144. },
  145. rules: { // 表单校验规则
  146. deviceName: [{ required: true, message: '请输入名称', trigger: 'blur' }]
  147. },
  148. resultData: null, // 设备搜索结果
  149. noData: 0,
  150. isFocus: false, // 搜索框是否获取焦点
  151. vsDeviceId: '', // 设备id
  152. deviceId: '', // 设备通道id
  153. expandedRowKeys: []
  154. }
  155. },
  156. methods: {
  157. // 搜索设备
  158. onSearch (value) {
  159. if (value) {
  160. findVsDevice({ id: value }).then(res => {
  161. if (res.status == 200) {
  162. if (res.data) {
  163. this.noData = 2
  164. this.resultData = res.data
  165. } else {
  166. this.noData = 1
  167. this.resultData = null
  168. }
  169. }
  170. })
  171. } else {
  172. this.noData = 0
  173. this.resultData = null
  174. this.isFocus = false
  175. }
  176. },
  177. // 门店已绑设备
  178. getStoreEquipment (id) {
  179. findStoreVsDevice({ code: id }).then(res => {
  180. if (res.status == 200) {
  181. res.data.map((item, ind) => {
  182. item.no = ind + 1
  183. })
  184. this.equipmentData = res.data
  185. }
  186. })
  187. },
  188. // 解绑
  189. onUnbundling (item) {
  190. const _this = this
  191. _this.$confirm({
  192. title: '提示',
  193. centered: true,
  194. content: '确定解绑该设备吗?',
  195. onOk () {
  196. unbindVsDevice({ id: item.id }).then(res => {
  197. if (res.status == 200) {
  198. _this.$message.success(res.message)
  199. _this.getStoreEquipment(_this.storeCode)
  200. }
  201. })
  202. }
  203. })
  204. },
  205. // 绑定
  206. onBundling (item) {
  207. const _this = this
  208. _this.$confirm({
  209. title: '提示',
  210. centered: true,
  211. content: '确定要绑定该设备吗?',
  212. onOk () {
  213. bindVsDevice({ storeCode: _this.storeCode, vsDeviceId: item.id }).then(res => {
  214. if (res.status == 200) {
  215. _this.$message.success(res.message)
  216. _this.expandedRowKeys = []
  217. _this.resultData = null
  218. _this.isFocus = false
  219. _this.getStoreEquipment(_this.storeCode)
  220. }
  221. })
  222. }
  223. })
  224. },
  225. // 编辑 通道/机位名称
  226. onEdit (item) {
  227. this.form.deviceName = item.name
  228. this.deviceId = item.deviceId
  229. this.visible = true
  230. },
  231. // 提交更改的通道信息
  232. onSubmit () {
  233. const _this = this
  234. _this.$refs.ruleForm.validate(valid => {
  235. if (valid) {
  236. const formData = JSON.parse(JSON.stringify(_this.form))
  237. formData.deviceId = this.deviceId
  238. vsDeviceRename(formData).then(res => {
  239. if (res.status == 200) {
  240. _this.$message.success(res.message)
  241. _this.visible = false
  242. _this.getDeviceChannels()
  243. }
  244. })
  245. } else {
  246. return false
  247. }
  248. })
  249. },
  250. // 设备行展开事件
  251. eqExpand (expanded, record) {
  252. if (expanded) { // 展开行
  253. this.vsDeviceId = record.vsDeviceId
  254. this.getDeviceChannels()
  255. }
  256. },
  257. // 展开的行变化时触发
  258. expandedRowsChange (expandedRows) {
  259. this.expandedRowKeys = expandedRows
  260. },
  261. // 获取设备通道信息
  262. getDeviceChannels () {
  263. vsDeviceChannels({ id: this.vsDeviceId }).then(res => {
  264. if (res.status == 200) {
  265. if (res.data) {
  266. res.data.map((item, ind) => {
  267. item.no = ind + 1
  268. })
  269. const ind = this.equipmentData.findIndex(item => item.vsDeviceId == this.vsDeviceId)
  270. if (ind != -1) {
  271. this.$set(this.equipmentData[ind], 'passagewayData', res.data)
  272. }
  273. this.passagewayData = res.data
  274. } else {
  275. const ind = this.equipmentData.findIndex(item => item.vsDeviceId == this.vsDeviceId)
  276. if (ind != -1) {
  277. this.$set(this.equipmentData[ind], 'passagewayData', [])
  278. }
  279. }
  280. }
  281. })
  282. }
  283. },
  284. watch: {
  285. // 父页面传过来的弹框状态
  286. openModal (newValue, oldValue) {
  287. this.isShow = newValue
  288. },
  289. // 重定义的弹框状态
  290. isShow (val) {
  291. if (!val) {
  292. this.$emit('close')
  293. } else {
  294. // 重置信息
  295. this.expandedRowKeys = []
  296. this.resultData = null
  297. this.isFocus = false
  298. }
  299. },
  300. storeCode (newValue, oldValue) {
  301. if (newValue && this.isShow) {
  302. this.getStoreEquipment(newValue)
  303. }
  304. }
  305. }
  306. }
  307. </script>
  308. <style lang="less">
  309. .StoreAssociatedEquipmentModal-wrap{
  310. .search-con{
  311. position: relative;
  312. .search-s{
  313. .ant-input-group-addon{
  314. padding: 0;
  315. border: none;
  316. }
  317. }
  318. .search-sub{
  319. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  320. position: absolute;
  321. left: 0;
  322. top: 45px;
  323. width: 100%;
  324. z-index: 1;
  325. border-radius: 6px;
  326. .ant-card-body{
  327. padding: 15px 24px;
  328. }
  329. .search-sub-item{
  330. display: flex;
  331. justify-content: space-between;
  332. align-items: center;
  333. padding: 8px 0;
  334. border-bottom: 1px dashed #f8f8f8;
  335. p{
  336. margin: 0;
  337. }
  338. &:last-child{
  339. border-bottom: none;
  340. }
  341. }
  342. }
  343. }
  344. .eq-tit{
  345. line-height: 40px;
  346. font-size: 16px;
  347. margin: 85px 0 5px;
  348. }
  349. .eq-subTit{
  350. margin: 0 0 10px;
  351. }
  352. .table{
  353. padding-bottom: 50px;
  354. }
  355. }
  356. .btn-cont{
  357. text-align: center;
  358. .cancel{
  359. margin-left: 40px;
  360. }
  361. }
  362. </style>