index.vue 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <!-- -->
  2. <template>
  3. <div>
  4. <main-top :crumb="crumbData"></main-top>
  5. <div class="table-interface">
  6. <div class="top-body">
  7. <div class="info-top">
  8. <div class="info-left"></div>
  9. <div class="info-right">
  10. <el-button type="primary" @click="show('','add')">新增设备</el-button>
  11. </div>
  12. </div>
  13. <el-table :data="tableData" style="width: 100%">
  14. <el-table-column
  15. v-for="(item, idx) in data"
  16. :key="idx"
  17. :prop="item.prop"
  18. :label="item.label"
  19. >
  20. <template slot-scope="scope">
  21. <span>{{scope.row[item.prop]}}</span>
  22. </template>
  23. </el-table-column>
  24. <el-table-column label="操作">
  25. <template slot-scope="scope">
  26. <span class="o-span" @click="show(scope.row,'edit')">编辑</span>
  27. <span class="o-span" @click="changeState(scope.row)">{{scope.row.qiyong==='启用'?'停用':'启用'}}</span>
  28. </template>
  29. </el-table-column>
  30. <div class="e-pagination">
  31. <el-pagination @current-change="handleCurrentChange" :current-page.sync="currentPage" :page-size="size" layout="prev, pager, next, jumper" :total="total">
  32. </el-pagination>
  33. </div>
  34. </el-table>
  35. </div>
  36. </div>
  37. <el-dialog title="新增设备" :visible.sync="dialogFormVisible" width="40%">
  38. <el-form :model="form">
  39. <el-form-item label="设备名称:" style="width:50%;" :label-width="formLabelWidth">
  40. <el-input v-model="form.name" placeholder="请输入设备名称" autocomplete="off"></el-input>
  41. </el-form-item>
  42. <el-form-item label="设备ID:" style="width:50%;" :label-width="formLabelWidth">
  43. <el-input v-model="form.uuid" placeholder="请输入设备ID" autocomplete="off"></el-input>
  44. </el-form-item>
  45. <el-form-item label="所在位置:" :label-width="formLabelWidth">
  46. <el-select v-model="form.positionId" placeholder="请选择活动区域">
  47. <el-option v-for="(item,i) in plist" :key="i" :label="item.name" :value="item.id"></el-option>
  48. </el-select>
  49. </el-form-item>
  50. <el-form-item label="是否启用:" :label-width="formLabelWidth">
  51. <el-radio-group v-model="form.state">
  52. <el-radio :label="0" >是</el-radio>
  53. <el-radio :label="1" >否</el-radio>
  54. </el-radio-group>
  55. </el-form-item>
  56. </el-form>
  57. <div slot="footer" class="dialog-footer">
  58. <el-button type="primary" @click="save">保 存</el-button>
  59. <el-button @click="dialogFormVisible = false">取 消</el-button>
  60. </div>
  61. </el-dialog>
  62. </div>
  63. </template>
  64. <script>
  65. // 这里可以导入其他文件(比如:组件,工具js,第三方插件js,json文件,图片文件等等)
  66. // 例如:import 《组件名称》 from '《组件路径》';
  67. import MainTop from '@/components/main-top'
  68. const crumbData = [
  69. {
  70. name: '设备管理',
  71. id: 10
  72. }
  73. ]
  74. let juese = {
  75. 0: '高级管理员',
  76. 1: '普通管理员'
  77. }
  78. let zt = {
  79. 0: '启用',
  80. 1: '停用'
  81. }
  82. let urlType = {
  83. add: '/equipment/addEquipment',
  84. edit: '/equipment/updateEquipment'
  85. }
  86. export default {
  87. // import引入的组件需要注入到对象中才能使用
  88. components: {
  89. MainTop
  90. },
  91. data () {
  92. // 这里存放数据
  93. let data = [
  94. {
  95. prop: 'id',
  96. label: '序号'
  97. },
  98. {
  99. prop: 'name',
  100. label: '设备名称'
  101. },
  102. {
  103. prop: 'uuid',
  104. label: '设备ID'
  105. },
  106. {
  107. prop: 'positionName',
  108. label: '所在位置'
  109. },
  110. {
  111. prop: 'qiyong',
  112. label: '状态'
  113. }
  114. ]
  115. return {
  116. crumbData,
  117. data,
  118. region: 0,
  119. infoName: '',
  120. tableData: [],
  121. dialogTableVisible: false,
  122. dialogFormVisible: false,
  123. form: {
  124. id: '',
  125. name: '',
  126. uuid: '',
  127. positionId: '',
  128. state: '',
  129. positionName: ''
  130. },
  131. plist: [],
  132. inputKey: '',
  133. currentPage: 1,
  134. size: 10,
  135. total: 0,
  136. formLabelWidth: '120px',
  137. imageUrl: '',
  138. type: 'add'
  139. }
  140. },
  141. watch: {
  142. currentPage () {
  143. this.refresh()
  144. },
  145. size () {
  146. this.refresh()
  147. },
  148. region () {
  149. this.refresh()
  150. },
  151. inputKey () {
  152. this.refresh()
  153. }
  154. },
  155. mounted () {
  156. this.getPositionList()
  157. this.refresh()
  158. },
  159. methods: {
  160. goto (item) {
  161. window.localStorage.setItem('editInfo', JSON.stringify(item))
  162. this.$router.push({name: 'edit-information', params: {type: 1}})
  163. this.$bus.$emit('editinfo', item)
  164. },
  165. upload_success (data) {
  166. this.form.head = data.data
  167. },
  168. refresh () {
  169. this.loading = true
  170. this.getInformation()
  171. this.loading = false
  172. },
  173. handleCurrentChange (val) {
  174. this.currentPage = val
  175. },
  176. save () {
  177. let {userName, roleId, phone, head, state} = this.form
  178. let data = {userName, roleId, phone, head, state}
  179. this.$http.post(urlType[this.type], data).then(res => {
  180. if (res.code === 0) {
  181. this.$alert('操作成功', '提示', {
  182. confirmButtonText: '确定',
  183. callback: action => {
  184. this.dialogFormVisible = false
  185. this.refresh()
  186. }
  187. })
  188. } else {
  189. this.$notify.error({
  190. title: '错误',
  191. message: res.message,
  192. duration: 2000
  193. })
  194. }
  195. })
  196. },
  197. show (item = '', type) {
  198. this.dialogFormVisible = true
  199. this.type = type
  200. this.form = {
  201. id: '',
  202. name: '',
  203. uuid: '',
  204. positionId: '',
  205. state: '',
  206. positionName: ''
  207. }
  208. if (type === 'edit') {
  209. this.form = item
  210. }
  211. },
  212. async getPositionList () {
  213. let result = await this.$http({
  214. method: 'post',
  215. url: '/position/list'
  216. })
  217. this.plist = result.data
  218. },
  219. changeState (item) {
  220. let state = item.state === 1 ? 0 : 1
  221. let data = {
  222. id: item.id,
  223. state
  224. }
  225. this.$confirm('此操作将导致设备状态发生改变, 是否继续?', '提示', {
  226. confirmButtonText: '确定',
  227. cancelButtonText: '取消',
  228. type: 'warning'
  229. }).then(() => {
  230. this.$http.post('/equipment/updateState', data).then(res => {
  231. if (res.code === 0) {
  232. this.$alert('修改成功', '提示', {
  233. confirmButtonText: '确定',
  234. callback: action => {
  235. this.refresh()
  236. }
  237. })
  238. } else {
  239. this.$notify.error({
  240. title: '错误',
  241. message: res.msg,
  242. duration: 2000
  243. })
  244. }
  245. })
  246. }).catch(() => {
  247. this.$message({
  248. type: 'info',
  249. message: '已取消'
  250. })
  251. })
  252. },
  253. async getInformation () {
  254. let params = {
  255. pageNum: this.currentPage,
  256. pageSize: this.size
  257. }
  258. let result = await this.$http({
  259. method: 'post',
  260. data: params,
  261. url: '/equipment/list'
  262. })
  263. if (result.code !== 0) {
  264. return
  265. }
  266. this.tableData = result.data.list
  267. this.total = result.data.total
  268. this.tableData.forEach(item => {
  269. item['date'] = this.$base.timestampToTime(item['startTime']) + '至' + this.$base.timestampToTime(item['endTime'])
  270. item['role'] = juese[item['roleId']]
  271. item['qiyong'] = zt[item['state']]
  272. })
  273. }
  274. }
  275. }
  276. </script>
  277. <style scoped>
  278. /* 引入公共css类 */
  279. @import url(./style);
  280. </style>