areaAdmin.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <template>
  2. <div>
  3. <el-container>
  4. <!-- form表单 -->
  5. <el-header>
  6. <div class="rect rect-form">
  7. <el-form :inline="true" :model="form" size="mini" ref="form">
  8. <el-form-item style="width:200px">
  9. <el-input v-model="form.keyword" style="width:200px" placeholder="请输入区域"></el-input>
  10. </el-form-item>
  11. <el-form-item>
  12. <el-button @click="getDataList()" icon="el-icon-search">查 询</el-button>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button
  16. icon="el-icon-circle-close"
  17. @click="clearAll">清 空</el-button>
  18. </el-form-item>
  19. </el-form>
  20. </div>
  21. </el-header>
  22. <el-main>
  23. <div class="rect" style="margin-top: 20px">
  24. <el-form size="mini" :inline="true">
  25. <el-form-item>
  26. <el-button
  27. icon="el-icon-plus"
  28. @click="visible = true">
  29. 新 增
  30. </el-button>
  31. <el-button
  32. icon="el-icon-delete"
  33. @click="delAll"
  34. type="danger"
  35. :disabled="selectList.length <= 0">
  36. 删 除
  37. </el-button>
  38. </el-form-item>
  39. </el-form>
  40. <el-table
  41. :data="dataList"
  42. border
  43. stripe
  44. v-loading="dataListLoading"
  45. style="width: 100%;"
  46. @selection-change="selectionChangeHandle"
  47. size="mini"
  48. height="578"
  49. :header-cell-style="{background:'rgb(245,245,245)',color:'#000',height: '45px',fontSize: '13px',fontWeight: 'normal',borderBottom: '1px solid #ccc'}"
  50. :cell-style="{color: '#888',fontSize: '13px'}">
  51. <el-table-column
  52. type="selection"
  53. header-align="center"
  54. align="center"
  55. width="50">
  56. </el-table-column>
  57. <el-table-column
  58. prop="id"
  59. header-align="center"
  60. align="center"
  61. label="id">
  62. </el-table-column>
  63. <el-table-column
  64. prop="name"
  65. header-align="center"
  66. align="center"
  67. label="区域名称">
  68. </el-table-column>
  69. <el-table-column
  70. header-align="center"
  71. align="center"
  72. label="操作">
  73. <template slot-scope="scope">
  74. <el-button
  75. v-if="isAuth('sys:user:update')"
  76. type="text"
  77. size="medium"
  78. @click="addOrUpdateHandle(scope.row)"
  79. style="color: rgb(24,144,255)">
  80. 修改
  81. </el-button>
  82. <el-button
  83. v-if="isAuth('sys:user:delete')"
  84. type="text"
  85. size="medium"
  86. @click="deleteHandle(scope.row)"
  87. style="color: rgb(24,144,255)">
  88. 删除
  89. </el-button>
  90. </template>
  91. </el-table-column>
  92. </el-table>
  93. <table-footer
  94. :totals="total"
  95. :size="limit"
  96. @sizeChange="sizeChange"
  97. @pageChange="pageChange"></table-footer>
  98. </div>
  99. <!-- 弹框 -->
  100. <el-dialog
  101. :title="!dataForm.id ? '新增' : '修改'"
  102. :close-on-click-modal="false"
  103. :visible.sync="visible"
  104. width="600px">
  105. <el-form
  106. :model="dataForm"
  107. :rules="dataRule"
  108. ref="dataForm"
  109. @keyup.enter.native="dataFormSubmit()"
  110. label-width="80px"
  111. size="mini"
  112. style="margin-left: 20px;width: 500px">
  113. <el-form-item label="区域名称" prop="name">
  114. <el-input v-model="dataForm.name" placeholder="请输入区域名称"></el-input>
  115. </el-form-item>
  116. </el-form>
  117. <span slot="footer" class="dialog-footer">
  118. <el-button size="mini" @click="onCancel">关闭</el-button>
  119. <el-button size="mini" type="primary" @click="dataFormSubmit()">确定</el-button>
  120. </span>
  121. </el-dialog>
  122. </el-main>
  123. </el-container>
  124. </div>
  125. </template>
  126. <script>
  127. import TableFooter from '../../../components/TableFooter'
  128. export default {
  129. name: 'areaAdmin',
  130. components: {
  131. TableFooter
  132. },
  133. data () {
  134. return {
  135. form: {
  136. keyword: ''
  137. },
  138. dataList: [],
  139. dataListLoading: false,
  140. visible: false,
  141. selectList: [],
  142. total: 0,
  143. page: 1,
  144. limit: 20,
  145. dataForm: {
  146. id: '',
  147. name: ''
  148. },
  149. dataRule: {
  150. name: [
  151. {required: true, message: '区域名称不能为空', trigger: 'blur'}
  152. ]
  153. }
  154. }
  155. },
  156. methods: {
  157. getDataList () {
  158. this.init()
  159. },
  160. clearAll () {
  161. this.form.keyword = ''
  162. },
  163. delAll () {
  164. let ids = this.selectList.map(item => item.id)
  165. let names = this.selectList.map(item => item.name)
  166. this.$confirm(`确定批量删除${names.join()}区域?`, '提示', {
  167. confirmButtonText: '确定',
  168. cancelButtonText: '取消',
  169. type: 'warning'
  170. }).then(() => {
  171. // 删除操作
  172. if (this.selectList.length < 0) {
  173. return
  174. }
  175. this.$http({
  176. url: this.$http.adornUrl('/management/pasturearea/delete'),
  177. method: 'post',
  178. data: this.$http.adornData(ids, false)
  179. }).then(res => {
  180. if (res.data.code === 0) {
  181. this.$message.success('删除成功')
  182. this.init()
  183. } else {
  184. this.$message.error(res.data.msg)
  185. }
  186. })
  187. })
  188. },
  189. sizeChange (val) {
  190. this.limit = val
  191. this.init()
  192. },
  193. pageChange (val) {
  194. this.page = val
  195. this.init()
  196. },
  197. init () {
  198. this.dataListLoading = true
  199. let params = {
  200. page: this.page,
  201. limit: this.limit,
  202. keyword: this.form.keyword
  203. }
  204. this.$http({
  205. url: this.$http.adornUrl('/management/pasturearea/list'),
  206. method: 'get',
  207. params: this.$http.adornParams(params)
  208. })
  209. .then(res => {
  210. if (res.data.code === 0) {
  211. this.dataListLoading = false
  212. this.dataList = res.data.page.list
  213. this.total = res.data.page.totalCount
  214. }
  215. })
  216. },
  217. selectionChangeHandle (val) {
  218. this.selectList = val
  219. // val.forEach(item => {
  220. // this.selectList.push(item.id)
  221. // })
  222. },
  223. addOrUpdateHandle (row) {
  224. this.dataForm = {
  225. id: row.id,
  226. name: row.name
  227. }
  228. this.visible = true
  229. },
  230. deleteHandle (area) {
  231. let ids = [area.id]
  232. let name = area.name
  233. this.$confirm(`确定删除${name}区域?`, '提示', {
  234. confirmButtonText: '确定',
  235. cancelButtonText: '取消',
  236. type: 'warning'
  237. }).then(() => {
  238. // 删除操作
  239. if (this.selectList.length < 0) {
  240. return
  241. }
  242. this.$http({
  243. url: this.$http.adornUrl('/management/pasturearea/delete'),
  244. method: 'post',
  245. data: this.$http.adornData(ids, false)
  246. }).then(res => {
  247. if (res.data.code === 0) {
  248. this.$message.success('删除成功!')
  249. this.init()
  250. } else {
  251. this.$message.error(res.data.msg)
  252. }
  253. })
  254. })
  255. },
  256. dataFormSubmit () {
  257. this.$refs['dataForm'].validate((valid) => {
  258. if (valid) {
  259. let params = {
  260. id: this.dataForm.id == '' ? undefined : this.dataForm.id,
  261. name: this.dataForm.name
  262. }
  263. this.$http({
  264. url: this.$http.adornUrl(`${!this.dataForm.id ? '/management/pasturearea/save' : '/management/pasturearea/update'}`),
  265. method: 'post',
  266. data: this.$http.adornData(params, true)
  267. }).then(({data}) => {
  268. if (data && data.code === 0) {
  269. this.visible = false
  270. this.$message({
  271. message: '操作成功',
  272. type: 'success',
  273. duration: 1500
  274. })
  275. this.init()
  276. this.reset()
  277. } else {
  278. this.$message.error(data.msg)
  279. }
  280. })
  281. }
  282. })
  283. },
  284. // 关闭模态框
  285. onCancel () {
  286. this.visible = false
  287. this.reset()
  288. },
  289. reset () {
  290. this.dataForm = {
  291. id: '',
  292. name: ''
  293. }
  294. }
  295. },
  296. mounted () {
  297. this.init()
  298. }
  299. }
  300. </script>
  301. <style scoped>
  302. .rect {
  303. background-color: #fff;
  304. padding: 30px 15px;
  305. border-radius: 5px;
  306. border: 1px solid #e8e8e8;
  307. }
  308. .rect-form {
  309. padding-bottom: 10px;
  310. }
  311. .rect-table {
  312. margin-top: 20px;
  313. }
  314. /deep/ .el-table--mini td, .el-table--mini th {
  315. padding: 3px 0 !important;
  316. height: 20px !important;
  317. }
  318. /deep/ .el-checkbox__input.is-checked+.el-checkbox__label {
  319. color: rgb(24,144,255);
  320. background-color: rgb(24,144,255);
  321. border-color: rgb(24,144,255);
  322. }
  323. /deep/.el-table .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  324. background-color: rgb(24,144,255);
  325. border-color: rgb(24,144,255);
  326. }
  327. /deep/.el-table .el-checkbox__inner:hover {
  328. border-color: rgb(24,144,255);
  329. }
  330. /deep/.el-table .el-checkbox__input.is-focus .el-checkbox__inner {
  331. border-color: rgb(24,144,255);
  332. }
  333. /deep/.el-table #select .cell .el-checkbox__input.is-checked .el-checkbox__inner, .el-checkbox__input.is-indeterminate .el-checkbox__inner {
  334. background-color: rgb(24,144,255);
  335. border-color: rgb(24,144,255);
  336. }
  337. </style>