Brak opisu

index.vue 14KB

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