ChannelCustomListDlg.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. <template>
  2. <div :class="['modal', {fade: fade}]" data-backdrop="static" data-disable="false" data-keyboard="true" tabindex="-1">
  3. <div :class="['modal-dialog', size]">
  4. <div class="modal-content">
  5. <div class="modal-header">
  6. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  7. <span aria-hidden="true">&times;</span>
  8. </button>
  9. <h4 class="modal-title text-center text-primary"><span>{{title}}</span></h4>
  10. </div>
  11. <div class="modal-body">
  12. <form class="form-inline" autocomplete="off" spellcheck="false">
  13. <div class="form-group form-group-sm">
  14. <label>搜索</label>
  15. <input type="text" class="form-control" placeholder="关键字" v-model.trim="q" @keydown.enter.prevent ref="q">
  16. </div>
  17. <span class="hidden-xs">&nbsp;&nbsp;</span>
  18. <div class="form-group form-group-sm">
  19. <label>通道类型</label>
  20. <select class="form-control" v-model.trim="channel_type">
  21. <option value="">全部</option>
  22. <option value="device">设备</option>
  23. <option value="dir">子目录</option>
  24. </select>
  25. </div>
  26. <span class="hidden-xs">&nbsp;&nbsp;</span>
  27. <div class="form-group form-group-sm">
  28. <div class="checkbox">
  29. <el-checkbox style="margin-top:-5px;padding-left:0;" size="small" v-model.trim="related" name="Related">
  30. 只看已选({{relateCnt}})
  31. </el-checkbox>
  32. </div>
  33. </div>
  34. </form>
  35. <br>
  36. <el-table :data="channels" stripe @sort-change="sortChange" @select="select" @select-all="selectAll" :max-height="500"
  37. ref="channelTable" v-loading="loading" element-loading-text="加载中...">
  38. <el-table-column type="selection" width="55" fixed :selectable="selectable"></el-table-column>
  39. <el-table-column prop="DeviceID" label="设备国标编号" min-width="200" show-overflow-tooltip sortable="custom"></el-table-column>
  40. <el-table-column prop="ID" label="通道国标编号" min-width="200" show-overflow-tooltip sortable="custom"></el-table-column>
  41. <el-table-column prop="Name" label="通道名称" min-width="120" :formatter="formatName" show-overflow-tooltip></el-table-column>
  42. <!-- <el-table-column prop="Status" label="在线状态" min-width="100">
  43. <template slot-scope="props">
  44. <span v-if="props.row.SubCount > 0">-</span>
  45. <span v-else-if="props.row.Status == 'ON'" class="text-success">在线</span>
  46. <span v-else>离线</span>
  47. </template>
  48. </el-table-column> -->
  49. <!-- <el-table-column prop="SubCount" label="子节点数" min-width="100" sortable="custom"></el-table-column> -->
  50. <el-table-column prop="Manufacturer" label="厂家" min-width="120" :formatter="formatManufacturer" show-overflow-tooltip></el-table-column>
  51. </el-table>
  52. <el-pagination v-if="total > 0" layout="total,prev,pager,next,sizes" :pager-count="isMobile() ? 3 : 5" class="pull-right" :total="total" :page-size.sync="pageSize" :current-page.sync="currentPage"></el-pagination>
  53. <div class="clearfix"></div>
  54. </div>
  55. <div class="modal-footer">
  56. <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
  57. </div>
  58. </div>
  59. </div>
  60. </div>
  61. </template>
  62. <script>
  63. import 'jquery-ui/ui/widgets/draggable'
  64. import $ from 'jquery'
  65. import _ from "lodash";
  66. export default {
  67. props: {
  68. title: {
  69. default: ''
  70. },
  71. size: {
  72. type: String,
  73. default: ''
  74. },
  75. fade: {
  76. type: Boolean,
  77. default: false
  78. }
  79. },
  80. data() {
  81. return {
  82. q: "",
  83. channel_type: "",
  84. total: 0,
  85. relateCnt: 0,
  86. pageSize: 10,
  87. currentPage: 1,
  88. sort: "",
  89. order: "",
  90. related: false,
  91. loading: false,
  92. channels: [],
  93. selection: [],
  94. bak: {}, // serial:code <-> custom
  95. pcode: '', //外部关联 code
  96. }
  97. },
  98. watch: {
  99. q: function(newVal, oldVal) {
  100. this.doDelaySearch();
  101. },
  102. channel_type: function(newVal, oldVal) {
  103. this.doSearch();
  104. },
  105. related: function(newVal, oldVal) {
  106. this.doSearch();
  107. },
  108. currentPage: function(newVal, oldVal) {
  109. this.doSearch(newVal);
  110. },
  111. pageSize: function(newVal, oldVal) {
  112. this.doSearch();
  113. }
  114. },
  115. mounted() {
  116. $(this.$el).find('.modal-content').draggable({
  117. handle: '.modal-header',
  118. cancel: ".modal-title span",
  119. addClasses: false,
  120. containment: 'document',
  121. delay: 100,
  122. opacity: 0.5
  123. });
  124. $(this.$el).on("shown.bs.modal", () => {
  125. this.$emit("show");
  126. }).on("hidden.bs.modal", () => {
  127. this.errors.clear();
  128. this.reset();
  129. this.$emit("hide");
  130. })
  131. },
  132. methods: {
  133. sortChange(data) {
  134. this.sort = data.prop;
  135. this.order = data.order == "ascending" ? "asc" : "desc";
  136. this.getChannels();
  137. },
  138. select(selection, row) {
  139. var idx = selection.indexOf(row);
  140. if(idx >= 0) {
  141. $.get("/api/v1/channel/setcustomparent", {
  142. customs: [`${row.DeviceID}:${row.ID}:${this.pcode}`]
  143. }).then(() => {
  144. this.bak[`${row.DeviceID}:${row.ID}`] = row.CustomParentID || "";
  145. }).always(() => {
  146. this.getChannels();
  147. })
  148. } else {
  149. var bakCustom = this.bak[`${row.DeviceID}:${row.ID}`] || "";
  150. $.get("/api/v1/channel/setcustomparent", {
  151. customs: [`${row.DeviceID}:${row.ID}:${bakCustom}`]
  152. }).always(() => {
  153. this.getChannels();
  154. })
  155. }
  156. },
  157. selectAll(selection) {
  158. var keys = [];
  159. var baks = {};
  160. if(selection.length) {
  161. for(var row of selection) {
  162. var idx = this.selection.indexOf(row);
  163. if(idx < 0) {
  164. keys.push(`${row.DeviceID}:${row.ID}:${this.pcode}`)
  165. baks[`${row.DeviceID}:${row.ID}`] = row.CustomParentID || "";
  166. }
  167. }
  168. $.get("/api/v1/channel/setcustomparent", {
  169. customs: keys,
  170. }).then(() => {
  171. this.bak = Object.assign(this.bak, baks);
  172. }).always(() => {
  173. this.getChannels();
  174. })
  175. } else {
  176. for(var row of this.selection) {
  177. var bakCustom = this.bak[`${row.DeviceID}:${row.ID}`] || "";
  178. keys.push(`${row.DeviceID}:${row.ID}:${bakCustom}`)
  179. }
  180. $.get("/api/v1/channel/setcustomparent", {
  181. customs: keys,
  182. }).always(() => {
  183. this.getChannels();
  184. })
  185. }
  186. },
  187. doSearch(page = 1) {
  188. this.currentPage = page;
  189. this.getChannels();
  190. },
  191. doDelaySearch: _.debounce(function() {
  192. this.doSearch();
  193. }, 500),
  194. formatName(row, col, cell) {
  195. return row.CustomName || row.Name || "-";
  196. },
  197. formatManufacturer(row, col, cell) {
  198. if (cell) return cell;
  199. return "-";
  200. },
  201. selectable(row, index) {
  202. return true;
  203. },
  204. getChannels() {
  205. if(!this.pcode) return;
  206. this.loading = true;
  207. $.get("/api/v1/channel/customlist", {
  208. pcode: this.pcode,
  209. q: this.q,
  210. start: (this.currentPage -1) * this.pageSize,
  211. limit: this.pageSize,
  212. channel_type: this.channel_type,
  213. related: this.related,
  214. sort: this.sort,
  215. order: this.order
  216. }).then(ret => {
  217. this.$refs["channelTable"].clearSelection();
  218. this.total = ret.ChannelCount;
  219. this.relateCnt = ret.ChannelRelateCount;
  220. this.channels = ret.ChannelList || [];
  221. this.selection = [];
  222. this.$nextTick(() => {
  223. this.channels.forEach(row => {
  224. var sel = row.CustomParentID == this.pcode;
  225. this.$refs["channelTable"].toggleRowSelection(row, sel);
  226. if(sel) {
  227. this.selection.push(row);
  228. }
  229. })
  230. })
  231. }).always(() => {
  232. this.loading = false;
  233. });
  234. },
  235. reset() {
  236. this.pcode = '';
  237. this.$refs["channelTable"].clearSelection();
  238. this.channels = [];
  239. this.selection = [];
  240. this.bak = {};
  241. this.q = "";
  242. this.channel_type = "";
  243. this.related = false;
  244. this.currentPage = 1;
  245. this.pageSize = 10;
  246. },
  247. show(pcode) {
  248. this.pcode = pcode;
  249. $(this.$el).modal("show");
  250. this.getChannels();
  251. },
  252. hide() {
  253. $(this.$el).modal("hide");
  254. }
  255. }
  256. }
  257. </script>
  258. <style lang="less" scoped>
  259. label.el-switch {
  260. margin-bottom: -10px;
  261. }
  262. </style>