huan.vue 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div class="mod-role">
  3. <div class="rect rect-form">
  4. <el-form size="mini" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  5. <el-form-item style="width: 200px">
  6. <el-input v-model="dataForm.keyword" placeholder="设备编号" style="width: 200px" clearable></el-input>
  7. </el-form-item>
  8. <el-form-item style="width: 140px">
  9. <el-select placeholder="请选择猪舍" v-model="dataForm.pigstyId" style="width: 100%">
  10. <el-option
  11. v-for="item in pigstyList"
  12. :key="item.value"
  13. :label="item.label"
  14. :value="item.value">
  15. </el-option>
  16. </el-select>
  17. </el-form-item>
  18. <el-form-item>
  19. <el-button
  20. icon="el-icon-search"
  21. @click="getDataList()">
  22. 查 询
  23. </el-button>
  24. </el-form-item>
  25. </el-form>
  26. </div>
  27. <div class="rect rect-table">
  28. <el-form size="mini" :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
  29. <el-form-item>
  30. <el-button
  31. icon="el-icon-plus"
  32. v-if="isAuth('sys:role:save')"
  33. type="primary"
  34. @click="addOrUpdateHandle()">新 增</el-button>
  35. <el-button
  36. icon="el-icon-delete"
  37. v-if="isAuth('sys:role:delete')"
  38. type="danger"
  39. @click="deleteHandle()"
  40. :disabled="dataListSelections.length <= 0">删 除</el-button>
  41. </el-form-item>
  42. </el-form>
  43. <el-table
  44. :data="dataList"
  45. border
  46. stripe
  47. size="mini"
  48. height="540"
  49. v-loading="dataListLoading"
  50. @selection-change="selectionChangeHandle"
  51. style="width: 100%;"
  52. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  53. :cell-style="{color: '#888',fontSize: '13px'}">
  54. <el-table-column
  55. type="selection"
  56. header-align="center"
  57. align="center">
  58. </el-table-column>
  59. <el-table-column
  60. prop="deviceId"
  61. header-align="center"
  62. align="center"
  63. label="设备编号">
  64. </el-table-column>
  65. <el-table-column
  66. prop="pigstyName"
  67. header-align="center"
  68. align="center"
  69. label="猪舍">
  70. </el-table-column>
  71. <!-- <el-table-column
  72. prop="stage"
  73. header-align="center"
  74. align="center"
  75. label="使用阶段">
  76. </el-table-column>
  77. <el-table-column
  78. prop="remark"
  79. header-align="center"
  80. align="center"
  81. label="备注">
  82. </el-table-column> -->
  83. <el-table-column
  84. header-align="center"
  85. align="center"
  86. label="操作">
  87. <template slot-scope="scope">
  88. <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.deviceId)">修改</el-button>
  89. <el-button type="text" size="small" @click="deleteHandle(scope.row.deviceId)">删除</el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <el-pagination
  94. @size-change="sizeChangeHandle"
  95. @current-change="currentChangeHandle"
  96. :current-page="pageIndex"
  97. :page-sizes="[10, 20, 50, 100]"
  98. :page-size="pageSize"
  99. :total="totalPage"
  100. layout="total, sizes, prev, pager, next, jumper">
  101. </el-pagination>
  102. <!-- 弹窗, 新增 / 修改 -->
  103. <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
  104. </div>
  105. </div>
  106. </template>
  107. <script>
  108. import AddOrUpdate from './huan-add-or-update'
  109. export default {
  110. data () {
  111. return {
  112. dataForm: {
  113. pigstyId: '',
  114. keyword: ''
  115. },
  116. dataList: [],
  117. pageIndex: 1,
  118. pageSize: 10,
  119. totalPage: 0,
  120. dataListLoading: false,
  121. dataListSelections: [],
  122. addOrUpdateVisible: false,
  123. pigstyList: []
  124. }
  125. },
  126. components: {
  127. AddOrUpdate
  128. },
  129. activated () {
  130. this.getDataList()
  131. },
  132. methods: {
  133. // 获取数据列表
  134. getDataList () {
  135. this.dataListLoading = true
  136. this.$http({
  137. url: this.$http.adornUrl('/management/device/list'),
  138. method: 'get',
  139. params: this.$http.adornParams({
  140. 'page': this.pageIndex,
  141. 'limit': this.pageSize,
  142. 'pigstyId': this.dataForm.pigstyId || undefined,
  143. 'keyword': this.dataForm.keyword || undefined
  144. })
  145. }).then(async ({data}) => {
  146. this.pigstyList = []
  147. let pigstyR = await this.$http({
  148. url: this.$http.adornUrl("/management/pigsty/findAll"),
  149. method: "get",
  150. params: this.$http.adornParams({})
  151. })
  152. if (pigstyR.data && pigstyR.data.code === 0) {
  153. console.log(pigstyR.data.all);
  154. pigstyR.data.all.forEach(pigsty => {
  155. let item = {
  156. value: pigsty.id,
  157. label: pigsty.number
  158. }
  159. this.pigstyList.push(item)
  160. })
  161. }
  162. if (data && data.code === 0) {
  163. this.dataList = data.page.list
  164. this.totalPage = data.page.totalCount
  165. } else {
  166. this.dataList = []
  167. this.totalPage = 0
  168. this.$message.error(data.msg)
  169. }
  170. this.dataListLoading = false
  171. })
  172. },
  173. // 每页数
  174. sizeChangeHandle (val) {
  175. this.pageSize = val
  176. this.pageIndex = 1
  177. this.getDataList()
  178. },
  179. // 当前页
  180. currentChangeHandle (val) {
  181. this.pageIndex = val
  182. this.getDataList()
  183. },
  184. // 多选
  185. selectionChangeHandle (val) {
  186. this.dataListSelections = val
  187. },
  188. // 新增 / 修改
  189. addOrUpdateHandle (id) {
  190. console.log(id);
  191. this.addOrUpdateVisible = true
  192. this.$nextTick(() => {
  193. this.$refs.addOrUpdate.init(id)
  194. })
  195. },
  196. // 删除
  197. deleteHandle (id) {
  198. var ids = id ? [id] : this.dataListSelections.map(item => {
  199. return item.id
  200. })
  201. this.$confirm(`确定对[id=${ids.join(',')}]进行[${id ? '删除' : '批量删除'}]操作?`, '提示', {
  202. confirmButtonText: '确定',
  203. cancelButtonText: '取消',
  204. type: 'warning'
  205. }).then(() => {
  206. this.$http({
  207. url: this.$http.adornUrl('/management/device/delete'),
  208. method: 'post',
  209. data: this.$http.adornData(ids, false)
  210. }).then(({data}) => {
  211. if (data && data.code === 0) {
  212. this.getDataList()
  213. this.$message({
  214. message: '操作成功',
  215. type: 'success',
  216. duration: 1500,
  217. // onClose: () => {
  218. // this.getDataList()
  219. // }
  220. })
  221. } else {
  222. this.$message.error(data.msg)
  223. }
  224. })
  225. }).catch(() => {})
  226. }
  227. }
  228. }
  229. </script>
  230. <style scoped>
  231. .rect {
  232. background-color: #fff;
  233. padding: 30px 15px;
  234. border-radius: 5px;
  235. border: 1px solid #e8e8e8;
  236. }
  237. .rect-form {
  238. padding-bottom: 10px;
  239. }
  240. .rect-table {
  241. margin-top: 20px;
  242. }
  243. .demo-table-expand {
  244. font-size: 0;
  245. margin-left: 40px;
  246. }
  247. .demo-table-expand label {
  248. width: 90px;
  249. color: #99a9bf;
  250. }
  251. .demo-table-expand .el-form-item {
  252. margin-right: 0;
  253. margin-bottom: 0;
  254. width: 80%;
  255. }
  256. .el-table .height {
  257. background: rgba(254, 254, 254, 0.5);
  258. }
  259. /deep/ .el-table--mini td, .el-table--mini th {
  260. padding: 3px 0 !important;
  261. height: 20px !important;
  262. }
  263. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  264. color: rgb(24,144,255);
  265. background-color: rgb(24,144,255);
  266. border-color: rgb(24,144,255);
  267. }
  268. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  269. background-color: rgb(24,144,255);
  270. border-color: rgb(24,144,255);
  271. }
  272. /deep/.el-table .el-checkbox__inner:hover {
  273. border-color: rgb(24,144,255);
  274. }
  275. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  276. border-color: rgb(24,144,255);
  277. }
  278. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  279. background-color: rgb(24,144,255);
  280. border-color: rgb(24,144,255);
  281. }
  282. </style>