Няма описание

index.vue 14KB

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