No Description

index.vue 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390
  1. <template>
  2. <div class="app-container">
  3. <div class="filter-container" style="margin-bottom:20px">
  4. <el-input style="width: 200px;" class="filter-item" placeholder="所属服务器编号" v-model="listQuery.scode">
  5. </el-input>
  6. <el-input style="width: 200px;" class="filter-item" placeholder="采集盒编号" v-model="listQuery.code">
  7. </el-input>
  8. <el-button v-waves class="filter-item" style="margin-left: 10px;" @click="handleFilter" type="primary" icon="el-icon-search">查找</el-button>
  9. <el-button v-waves class="filter-item" style="margin-left: 10px;" @click="handleCreate" type="primary" icon="el-icon-edit">添加采集盒</el-button>
  10. </div>
  11. <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
  12. style="width: 100%;min-height:550px;">
  13. <el-table-column width="150px" align="center" label="采集盒编号">
  14. <template slot-scope="scope">
  15. <span>{{scope.row.code}}</span>
  16. </template>
  17. </el-table-column>
  18. <el-table-column width="150px" align="center" label="采集盒信道数量">
  19. <template slot-scope="scope">
  20. <span>{{scope.row.channels}}</span>
  21. </template>
  22. </el-table-column>
  23. <el-table-column min-width="150px" align="center" label="所属服务器编号">
  24. <template slot-scope="scope">
  25. <span>{{scope.row.serverName}}</span>
  26. </template>
  27. </el-table-column>
  28. <el-table-column min-width="200px" align="center" label="备注信息">
  29. <template slot-scope="scope">
  30. <span>{{scope.row.remark}}</span>
  31. </template>
  32. </el-table-column>
  33. <el-table-column align="center" label="操作" width="230" class-name="small-padding fixed-width">
  34. <template slot-scope="scope">
  35. <el-button v-waves v-waves type="primary" size="mini" @click="handleUpdate(scope.row)">编辑</el-button>
  36. <el-button v-waves size="mini" type="danger" @click="handleModifyStatus(scope.row,'deleted')">删除
  37. </el-button>
  38. </template>
  39. </el-table-column>
  40. </el-table>
  41. <el-dialog title="采集盒配置" ref="ruleForm" :visible.sync="dialogTableVisible" width="860px" @close='closed'>
  42. <el-form :model="ruleForm2" :rules="rules2" ref="ruleForm2" class="form-main" label-position='right' status-icon>
  43. <el-row>
  44. <el-col :span="12">
  45. <el-form-item label="采集盒编号" prop="code">
  46. <el-input placeholder="请输入采集盒编号" v-model="ruleForm2.code"></el-input>
  47. </el-form-item>
  48. </el-col>
  49. <el-col :span="12">
  50. <el-form-item label="采集盒信道数量" prop="channels">
  51. <el-input placeholder="请输入采集盒信道数量" v-model="ruleForm2.channels"></el-input>
  52. </el-form-item>
  53. </el-col>
  54. <el-col :span="12">
  55. <el-form-item label="所属服务器编号" prop="server">
  56. <el-autocomplete
  57. v-model="ruleForm2.server"
  58. :fetch-suggestions="querySearchAsync"
  59. placeholder="请选择服务器编号"
  60. @select="handleSelect">
  61. </el-autocomplete>
  62. </el-form-item>
  63. </el-col>
  64. <el-col :span="12">
  65. <el-form-item label="内部编号" prop="seq">
  66. <el-input placeholder="请输入内部编号" v-model="ruleForm2.seq"></el-input>
  67. </el-form-item>
  68. </el-col>
  69. <el-col :span="24" >
  70. <el-form-item label="备注" prop="remark">
  71. <el-input type="textarea" maxlength=100 v-model="ruleForm2.remark" rows=4></el-input>
  72. </el-form-item>
  73. </el-col>
  74. <el-col :span="24" class="el-btn-col">
  75. <div class="el-btn-col-box">
  76. <el-button v-waves type="primary" @click="submitForm('ruleForm2')">确认</el-button>
  77. <el-button v-waves type="info" @click="resetForm('ruleForm2')">返回</el-button>
  78. </div>
  79. </el-col>
  80. </el-row>
  81. </el-form>
  82. </el-dialog>
  83. <div class="pagination-container" style="text-align:center;">
  84. <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="listQuery.pageNo" :page-size="listQuery.pageSize" layout="prev, pager, next, jumper" :total="total">
  85. </el-pagination>
  86. </div>
  87. </div>
  88. </template>
  89. <script>
  90. import { addDevice, updateDevice, deleteDevice, pageQueryDevice, DeviceOfservice, checkDeviceCode, checkDeviceInternalCode, queryServer } from '@/api/collectionbox'
  91. import waves from '@/directive/waves'
  92. export default {
  93. name: 'complexTable',
  94. directives: {
  95. waves
  96. },
  97. data() {
  98. var server = (rule, value, callback) => {
  99. const that = this
  100. setTimeout(function() {
  101. if (that.ruleForm2.server === '' || that.ruleForm2.serverId === '') {
  102. callback(new Error('请选择服务器编号'))
  103. } else {
  104. callback()
  105. }
  106. }, 300)
  107. }
  108. var seq = (rule, value, callback) => {
  109. if (value === '') {
  110. callback(new Error('请输入内部编号'))
  111. } else {
  112. if (!this.ruleForm2.serverId) {
  113. callback('请先选择所属服务器编号')
  114. return
  115. }
  116. if (this.edit) {
  117. checkDeviceInternalCode({ seq: value, id: this.edit, serverId: this.ruleForm2.serverId }).then(response => {
  118. if (response.data) {
  119. callback(new Error('内部编号已存在,请重新输入'))
  120. } else {
  121. callback()
  122. }
  123. })
  124. } else {
  125. checkDeviceInternalCode({ seq: value, serverId: this.ruleForm2.serverId }).then(response => {
  126. if (response.data) {
  127. callback(new Error('内部编号已存在,请重新输入'))
  128. } else {
  129. callback()
  130. }
  131. })
  132. }
  133. }
  134. }
  135. var code = (rule, value, callback) => {
  136. if (value === '') {
  137. callback(new Error('请输入采集盒编号'))
  138. } else {
  139. if (this.edit) {
  140. checkDeviceCode({ code: value, id: this.edit }).then(response => {
  141. if (response.data) {
  142. callback(new Error('采集盒编号已存在,请重新输入'))
  143. } else {
  144. callback()
  145. }
  146. })
  147. } else {
  148. checkDeviceCode({ code: value }).then(response => {
  149. if (response.data) {
  150. callback(new Error('采集盒编号已存在,请重新输入'))
  151. } else {
  152. callback()
  153. }
  154. })
  155. }
  156. }
  157. }
  158. return {
  159. edit: '',
  160. ruleForm2: {
  161. code: '',
  162. channels: '',
  163. server: '',
  164. seq: '',
  165. serverId: '',
  166. remark: ''
  167. },
  168. rules2: {
  169. code: [
  170. { required: true, validator: code, trigger: 'blur' }
  171. ],
  172. channels: [
  173. { required: true, message: '请输入采集盒数量', trigger: 'blur' }
  174. ],
  175. server: [
  176. { required: true, validator: server, trigger: 'blur' }
  177. ],
  178. seq: [
  179. { required: true, validator: seq, trigger: 'blur' }
  180. ]
  181. },
  182. timeout: null,
  183. dialogTableVisible: false,
  184. tableKey: 0,
  185. list: null,
  186. total: null,
  187. listLoading: true,
  188. listQuery: {
  189. scode: '',
  190. code: '',
  191. active: 1,
  192. pageSize: 10,
  193. pageNo: 1
  194. }
  195. }
  196. },
  197. filters: {
  198. typeFilter(type) {
  199. }
  200. },
  201. created() {
  202. this.getList()
  203. },
  204. methods: {
  205. submitForm(formName) {
  206. const that = this
  207. this.$refs[formName].validate((valid) => {
  208. if (valid) {
  209. if (!this.edit) {
  210. addDevice(this.ruleForm2).then(response => {
  211. this.getList()
  212. setTimeout(function() {
  213. that.pop('已成功添加采集盒')
  214. }, 1000)
  215. this.resetForm('ruleForm2')
  216. this.dialogTableVisible = false
  217. }).catch(error => {
  218. console.log(error)
  219. })
  220. } else {
  221. const par = this.ruleForm2
  222. par.id = this.edit
  223. updateDevice(par).then(response => {
  224. if (response.success) {
  225. setTimeout(function() {
  226. that.pop('已成功更新采集盒')
  227. }, 1000)
  228. this.resetForm('ruleForm2')
  229. this.getList()
  230. this.dialogTableVisible = false
  231. this.edit = ''
  232. this.ruleForm2 = {
  233. code: '',
  234. channels: '',
  235. server: '',
  236. seq: '',
  237. serverId: '',
  238. remark: ''
  239. }
  240. }
  241. })
  242. }
  243. }
  244. })
  245. },
  246. resetForm(formName) {
  247. this.dialogTableVisible = false
  248. this.$refs[formName].resetFields()
  249. this.edit = ''
  250. },
  251. closed() {
  252. this.$refs['ruleForm2'].resetFields()
  253. this.edit = ''
  254. },
  255. getList() {
  256. this.listLoading = true
  257. pageQueryDevice(this.listQuery).then(response => {
  258. const $data = response.data.data
  259. for (let i = 0; i < $data.length; i++) {
  260. $data[i].serverName = ''
  261. queryServer({ id: $data[i].serverId }).then(response => {
  262. $data[i].serverName = response.data.code
  263. })
  264. }
  265. this.list = $data
  266. this.total = response.data.total
  267. setTimeout(() => {
  268. this.listLoading = false
  269. }, 1.5 * 1000)
  270. })
  271. },
  272. handleFilter() {
  273. this.listQuery.pageNo = 1
  274. this.getList()
  275. },
  276. handleSizeChange(val) {
  277. this.listQuery.pageSize = val
  278. this.getList()
  279. },
  280. handleCurrentChange(val) {
  281. this.listQuery.pageNo = val
  282. this.getList()
  283. },
  284. handleModifyStatus(row, status) {
  285. this.$confirm('确实要删除:采集盒' + row.code + '吗?', '提示', {
  286. confirmButtonText: '确定',
  287. cancelButtonText: '取消',
  288. type: 'warning',
  289. center: true
  290. }).then(() => {
  291. deleteDevice({ id: row.id }).then(response => {
  292. if (response.success) {
  293. this.getList()
  294. this.pop('已成功删除该采集盒')
  295. /* this.$message({
  296. type: 'success',
  297. message: '已成功删除该采集盒!'
  298. }) */
  299. }
  300. })
  301. }).catch(() => {
  302. })
  303. },
  304. pop($par) {
  305. this.$confirm($par, '提示', {
  306. confirmButtonText: '确定',
  307. cancelButtonText: '取消',
  308. type: 'success',
  309. showCancelButton: false,
  310. center: true
  311. }).then(() => {
  312. }).catch(() => {
  313. })
  314. },
  315. resetTemp(row) {
  316. this.ruleForm2 = {
  317. code: row.code,
  318. channels: row.channels,
  319. server: row.serverName,
  320. seq: row.seq,
  321. serverId: row.serverId,
  322. remark: row.remark
  323. }
  324. this.edit = row.id
  325. },
  326. handleCreate() {
  327. this.dialogTableVisible = true
  328. },
  329. handleUpdate(row) {
  330. const that = this
  331. setTimeout(function() {
  332. that.resetTemp(row)
  333. }, 500)
  334. this.dialogTableVisible = true
  335. },
  336. querySearchAsync(queryString, cb) {
  337. this.ruleForm2.serverId = ''
  338. clearTimeout(this.timeout)
  339. this.timeout = setTimeout(() => {
  340. DeviceOfservice({ code: this.ruleForm2.server }).then(response => {
  341. const $info = response.data
  342. if ($info.length) {
  343. const $data = $info.map(item => {
  344. return { 'value': item.code, 'id': item.id }
  345. })
  346. cb($data)
  347. if ($info.length === 1 && this.ruleForm2.server === $info[0].code) {
  348. this.ruleForm2.serverId = $info[0].id
  349. } else {
  350. this.ruleForm2.serverId = ''
  351. }
  352. } else {
  353. cb([])
  354. }
  355. })
  356. }, 3000 * Math.random())
  357. },
  358. handleSelect(item) {
  359. this.ruleForm2.serverId = item.id
  360. }
  361. }
  362. }
  363. </script>
  364. <style rel="stylesheet/scss" lang="scss" scoped>
  365. .el-autocomplete{
  366. display: block
  367. }
  368. .el-btn-col{
  369. margin-top: 45px
  370. }
  371. .el-form-item{
  372. margin: 0px 10px
  373. }
  374. .el-select{
  375. width: 100%
  376. }
  377. .el-col{
  378. margin-bottom: 15px
  379. }
  380. .el-form-item__label{
  381. padding: 0px
  382. }
  383. </style>