FunctionArea.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div style="padding: 20px;">
  3. <el-form inline>
  4. <el-form-item label="区域">
  5. <el-input v-model="name"></el-input>
  6. </el-form-item>
  7. <el-form-item>
  8. <el-button type="primary" @click="search">查询</el-button>
  9. <el-button type="success" @click="add">新 增 区 域</el-button>
  10. </el-form-item>
  11. </el-form>
  12. <br>
  13. <el-table
  14. height="600"
  15. :data="list"
  16. border>
  17. <el-table-column label="区域名称" prop="functionName"></el-table-column>
  18. <el-table-column label="操作">
  19. <template slot-scope="scope">
  20. <el-button @click="open(scope.row)" size="mini" type="primary">添加下级功能区</el-button>
  21. <el-button @click="edit(scope.row)" size="mini" >编辑</el-button>
  22. <el-popconfirm
  23. title=" 确定要删除这个功能区吗?"
  24. @confirm="del(scope.row)"
  25. >
  26. <el-button style="margin-left: 10px" type="danger" size="mini" slot="reference">删除</el-button>
  27. </el-popconfirm>
  28. </template>
  29. </el-table-column>
  30. </el-table>
  31. <table-footer
  32. :page-num="pageNum"
  33. :totals="total"
  34. :size="pageSize"
  35. @sizeChange="sizeChange"
  36. @pageChange="pageChange"></table-footer>
  37. <el-dialog
  38. :title="showType ? '编 辑' : '新 增'"
  39. :visible.sync="dialogVisible"
  40. @close="reset"
  41. width="20%">
  42. <div>
  43. <el-form ref="form" :model="form" :rules="rules" label-width="80px" size="mini">
  44. <el-form-item label="功能名称" prop="functionName">
  45. <el-input v-model="form.functionName"></el-input>
  46. </el-form-item>
  47. <el-form-item label="备注">
  48. <el-input v-model="form.remark"></el-input>
  49. </el-form-item>
  50. </el-form>
  51. </div>
  52. <span slot="footer" class="dialog-footer">
  53. <el-button @click="reset">取 消</el-button>
  54. <el-button type="primary" @click="onSubmit('form')">{{showType ? '更 新' : '新 增'}}</el-button>
  55. </span>
  56. </el-dialog>
  57. <el-dialog title="选择功能区" :visible.sync="showModal" @close="modalReset">
  58. <el-table ref="multipleTable" :data="functionList" @selection-change="handleSelectionChange">
  59. <el-table-column
  60. type="selection"
  61. width="55">
  62. </el-table-column>
  63. <el-table-column label="功能区名称" prop="functionName"></el-table-column>
  64. </el-table>
  65. <span slot="footer" class="dialog-footer">
  66. <el-button @click="modalReset">取 消</el-button>
  67. <el-button type="primary" :disabled="isButton" @click="onCheckSave">保存</el-button>
  68. </span>
  69. </el-dialog>
  70. </div>
  71. </template>
  72. <script>
  73. import {getFunctionMonitList, getAreaFunctionList, addAreaFunction, editAreaFunction, delAreaFunction, saveCameraFunctionArea, getCameraFunctionArea} from "../../utils/api";
  74. import TableFooter from "../../components/TableFooter";
  75. export default {
  76. name: "FunctionArea",
  77. components: {
  78. TableFooter
  79. },
  80. data() {
  81. return {
  82. name: '',
  83. pageNum: 1,
  84. pageSize: 20,
  85. list: [],
  86. total: 0,
  87. showType: false,
  88. dialogVisible: false,
  89. rules: {
  90. functionName: [ { required: true, message: '区域名称不能为空', trigger: 'blur' } ],
  91. },
  92. form: {
  93. functionName: '',
  94. remark: '',
  95. },
  96. functionList: [],
  97. showModal: false,
  98. isButton: true,
  99. selectIdList: [],
  100. selectId: '',
  101. }
  102. },
  103. methods: {
  104. // 修改size
  105. sizeChange(val) {
  106. this.pageSize = val;
  107. this.init();
  108. },
  109. // 修改页数
  110. pageChange(val) {
  111. this.pageNum= val;
  112. this.init();
  113. },
  114. init() {
  115. let params = {
  116. current: this.pageNum,
  117. size: this.pageSize,
  118. functionName: this.name,
  119. }
  120. getAreaFunctionList(params).then(res => {
  121. if(res.code === 10000) {
  122. this.list = res.data.records;
  123. this.total = res.data.total;
  124. }
  125. })
  126. },
  127. search() {
  128. this.pageNum = 1;
  129. this.init()
  130. },
  131. reset() {
  132. this.form = {
  133. functionName: '',
  134. remark: '',
  135. }
  136. this.dialogVisible = false;
  137. this.showType = false;
  138. },
  139. add() {
  140. this.dialogVisible = true;
  141. this.showType = false;
  142. },
  143. edit(row) {
  144. this.dialogVisible = true;
  145. this.showType = true;
  146. this.form = {
  147. id: row.id,
  148. functionName: row.functionName,
  149. remark: row.remark
  150. }
  151. },
  152. del(row) {
  153. let params = {
  154. ids: row.id
  155. }
  156. delAreaFunction(params).then(res => {
  157. if(res.code === 10000) {
  158. this.init();
  159. this.$message.success(res.message)
  160. } else {
  161. this.$message.error(res.message)
  162. }
  163. })
  164. },
  165. onSubmit(formName) {
  166. this.$refs[formName].validate((valid) => {
  167. if (valid) {
  168. if (this.showType) {
  169. // 编辑
  170. let params = {
  171. id: this.form.id,
  172. functionName: this.form.functionName,
  173. remark: this.form.remark
  174. }
  175. editAreaFunction(params).then(res => {
  176. this.reset()
  177. if (res.code === 10000) {
  178. this.init();
  179. this.$message.success(res.message)
  180. } else {
  181. this.$message.error(res.message)
  182. }
  183. })
  184. } else {
  185. // 新增
  186. let params = {
  187. functionName: this.form.functionName,
  188. remark: this.form.remark
  189. }
  190. addAreaFunction(params).then(res => {
  191. if(res.code === 10000) {
  192. this.init();
  193. this.$message.success(res.message);
  194. } else {
  195. this.$message.error(res.message)
  196. }
  197. }).finally(() => {
  198. this.reset()
  199. })
  200. }
  201. } else {
  202. console.log('error submit!!');
  203. return false;
  204. }
  205. })
  206. },
  207. initFunction() {
  208. let params = {
  209. current: 1,
  210. size: 2000
  211. }
  212. getFunctionMonitList(params).then(res => {
  213. if(res.code === 10000) {
  214. this.functionList = res.data.records;
  215. }
  216. })
  217. },
  218. handleSelectionChange(val) {
  219. this.isButton = false;
  220. let arr = []
  221. val.forEach(item => {
  222. arr.push(item.id)
  223. })
  224. this.selectIdList = arr;
  225. },
  226. open(row) {
  227. this.selectId = row.id;
  228. this.showModal = true;
  229. let params = {
  230. id: row.id
  231. }
  232. getCameraFunctionArea(params).then(res => {
  233. if(res.code === 10000) {
  234. if(res.data.length > 0) {
  235. let list = [];
  236. this.functionList.forEach(item => {
  237. res.data.forEach(val => {
  238. if(item.id == val) {
  239. list.push(item)
  240. }
  241. })
  242. })
  243. if(list) {
  244. list.forEach((row) => {
  245. this.$refs.multipleTable.toggleRowSelection(row, true)
  246. })
  247. }
  248. }
  249. }
  250. })
  251. },
  252. modalReset() {
  253. this.showModal = false;
  254. this.selectIdList = [];
  255. this.selectId = '';
  256. this.$refs.multipleTable.clearSelection();
  257. },
  258. onCheckSave() {
  259. let params = {
  260. functionAreaId: this.selectId,
  261. functionIds: this.selectIdList.join(',')
  262. }
  263. saveCameraFunctionArea(params).then(res => {
  264. if(res.code === 10000) {
  265. this.$message.success(res.message);
  266. } else {
  267. this.$message.error(res.message);
  268. }
  269. }).finally(() => {
  270. this.modalReset()
  271. })
  272. }
  273. },
  274. mounted() {
  275. this.init()
  276. this.initFunction()
  277. }
  278. }
  279. </script>
  280. <style scoped>
  281. </style>