branch.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306
  1. <template>
  2. <div class="branch">
  3. <el-form
  4. :inline="true"
  5. :model="dataForm"
  6. @keyup.enter.native="getDataList()">
  7. <!-- <el-form-item>
  8. <el-input
  9. v-model="dataForm.key"
  10. placeholder="用户名/用户操作"
  11. clearable
  12. ></el-input>
  13. </el-form-item>
  14. <el-form-item>
  15. <el-button @click="getDataList()">查询</el-button>
  16. </el-form-item> -->
  17. <el-form-item>
  18. <el-button v-if="isAuth('sys:role:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
  19. </el-form-item>
  20. <el-form-item>
  21. <el-button v-if="isAuth('sys:role:delete')" type="danger" @click="deleteHandle()" :disabled="selectionDataList.length <= 0">批量删除</el-button>
  22. </el-form-item>
  23. </el-form>
  24. <el-table
  25. :data="dataList"
  26. @selection-change="selectionChangeHandle"
  27. v-loading="dataListLoading"
  28. style="width: 100%">
  29. <el-table-column
  30. type="selection"
  31. header-align="center"
  32. align="center"
  33. width="50">
  34. </el-table-column>
  35. <el-table-column
  36. prop="name"
  37. header-align="center"
  38. align="center"
  39. label="名称">
  40. </el-table-column>
  41. <el-table-column
  42. prop="location"
  43. header-align="center"
  44. align="center"
  45. label="地址">
  46. </el-table-column>
  47. <el-table-column
  48. prop="manager"
  49. header-align="center"
  50. align="center"
  51. label="负责人">
  52. </el-table-column>
  53. <el-table-column
  54. prop="buildTime"
  55. header-align="center"
  56. align="center"
  57. :show-overflow-tooltip="true"
  58. label="建立日期">
  59. </el-table-column>
  60. <el-table-column
  61. fixed="right"
  62. header-align="center"
  63. align="center"
  64. label="操作">
  65. <template slot-scope="scope">
  66. <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row)">修改</el-button>
  67. <el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
  68. </template>
  69. </el-table-column>
  70. </el-table>
  71. <el-dialog
  72. :title="!form.id ? '新增' : '修改'"
  73. :close-on-click-modal="false"
  74. :visible.sync="visible">
  75. <el-form :model="form" ref="form" @keyup.enter.native="formSubmit()" label-width="80px">
  76. <el-form-item label="牧场名称" prop="name">
  77. <el-input v-model="form.name" placeholder="牧场名称"></el-input>
  78. </el-form-item>
  79. <el-form-item label="管理员" prop="manager">
  80. <el-input v-model="form.manager" placeholder="牧场管理员"></el-input>
  81. </el-form-item>
  82. <el-form-item label="地址" prop="location">
  83. <el-input v-model="form.location" placeholder="地址"></el-input>
  84. </el-form-item>
  85. <el-form-item label="日期" prop="buildTime">
  86. <el-date-picker
  87. v-model="form.buildTime"
  88. type="date"
  89. value-format="yyyy-MM-dd"
  90. placeholder="选择日期">
  91. </el-date-picker>
  92. </el-form-item>
  93. </el-form>
  94. <span slot="footer" class="dialog-footer">
  95. <el-button @click="visible = false">取消</el-button>
  96. <el-button type="primary" @click="formSubmit()">确定</el-button>
  97. </span>
  98. </el-dialog>
  99. </div>
  100. </template>
  101. <script>
  102. export default {
  103. data () {
  104. return {
  105. dataForm: {
  106. key: ''
  107. },
  108. dataList: [
  109. {
  110. buildTime: '',
  111. id: '',
  112. location: '',
  113. manager: '',
  114. name: '',
  115. }
  116. ],
  117. pageIndex: 1,
  118. pageSize: 10,
  119. totalPage: 0,
  120. dataListLoading: false,
  121. selectionDataList: [],
  122. visible: false,
  123. form: {
  124. id: '',
  125. location: '',
  126. manager: '',
  127. name: '',
  128. buildTime: ''
  129. }
  130. }
  131. },
  132. created () {
  133. this.getDataList()
  134. },
  135. methods: {
  136. // 获取数据列表
  137. getDataList () {
  138. this.dataListLoading = true
  139. this.$http({
  140. url: this.$http.adornUrl('/management/pasture/list'),
  141. method: 'post'
  142. }).then(({ data }) => {
  143. if (data && data.code === 0) {
  144. this.dataList = data.page.list
  145. this.totalPage = data.page.totalCount
  146. } else {
  147. this.dataList = []
  148. this.totalPage = 0
  149. }
  150. this.dataListLoading = false
  151. })
  152. },
  153. // 每页数
  154. sizeChangeHandle (val) {
  155. this.pageSize = val
  156. this.pageIndex = 1
  157. this.getDataList()
  158. },
  159. // 当前页
  160. currentChangeHandle (val) {
  161. this.pageIndex = val
  162. this.getDataList()
  163. },
  164. // 新增 or 修改牧场
  165. addOrUpdateHandle (row) {
  166. // 显示牧场新增 or 修改面板
  167. this.visible = true
  168. if (row) {
  169. this.form = row
  170. }
  171. },
  172. // 选择n个牧场
  173. selectionChangeHandle (val) {
  174. this.selectionDataList = []
  175. val.forEach(item => {
  176. this.selectionDataList.push(item.id)
  177. });
  178. },
  179. // 删除n个牧场
  180. deleteHandle (id) {
  181. this.$confirm(`确定删除牧场?`, '提示', {
  182. confirmButtonText: '确定',
  183. cancelButtonText: '取消',
  184. type: 'warning'
  185. }).then(() => {
  186. // 删除操作
  187. if (id) {
  188. this.selectionDataList.push(id)
  189. }
  190. if (this.selectionDataList.length <= 0) {
  191. return
  192. }
  193. this.$http({
  194. url: this.$http.adornUrl('/management/pasture/delete'),
  195. method: 'post',
  196. data: this.$http.adornData(this.selectionDataList, false)
  197. }).then(result => {
  198. console.log(result);
  199. if (result.data.code === 0) {
  200. this.getDataList()
  201. this.resetForm()
  202. this.$message({
  203. message: '成功删除牧场',
  204. type: 'success',
  205. duration: 1000
  206. })
  207. } else {
  208. this.$message.error('删除牧场失败');
  209. }
  210. this.selectionDataList = []
  211. })
  212. }).catch(() => {})
  213. },
  214. formSubmit () {
  215. if (this.form.id) {
  216. // 修改
  217. if (this.form.name && this.form.manager && this.form.location && this.form.buildTime) {
  218. // 进行修改操作
  219. this.$http({
  220. url: this.$http.adornUrl('/management/pasture/update'),
  221. method: 'post',
  222. data: this.$http.adornData({
  223. id: this.form.id,
  224. location: this.form.location,
  225. manager: this.form.manager,
  226. name: this.form.name,
  227. buildTime: this.form.buildTime
  228. })
  229. }).then(result => {
  230. if (result.data.code === 0) {
  231. this.getDataList()
  232. this.resetForm()
  233. this.$message({
  234. message: '成功修改牧场信息',
  235. type: 'success',
  236. duration: 1000
  237. })
  238. } else {
  239. this.$message.error('修改牧场信息失败');
  240. }
  241. })
  242. this.visible = false
  243. } else {
  244. // 请输入完整
  245. this.$confirm(`请输入完整`, '提示', {
  246. confirmButtonText: '确定',
  247. cancelButtonText: '取消',
  248. type: 'warning'
  249. }).then(() => {
  250. return
  251. }).catch(() => {})
  252. }
  253. console.log(this.form);
  254. } else {
  255. // 新增
  256. if (this.form.name && this.form.manager && this.form.location && this.form.buildTime) {
  257. // 进行新增操作
  258. this.$http({
  259. url: this.$http.adornUrl('/management/pasture/save'),
  260. method: 'post',
  261. data: this.$http.adornData({
  262. location: this.form.location,
  263. manager: this.form.manager,
  264. name: this.form.name,
  265. buildTime: this.form.buildTime
  266. })
  267. }).then(result => {
  268. console.log(result);
  269. if (result.data.code === 0) {
  270. this.getDataList()
  271. this.resetForm()
  272. this.$message({
  273. message: '成功添加牧场',
  274. type: 'success',
  275. duration: 1000
  276. })
  277. } else {
  278. this.$message.error('添加牧场失败');
  279. }
  280. })
  281. this.visible = false
  282. } else {
  283. // 请输入完整
  284. this.$confirm(`请输入完整`, '提示', {
  285. confirmButtonText: '确定',
  286. cancelButtonText: '取消',
  287. type: 'warning'
  288. }).then(() => {
  289. return
  290. }).catch(() => {})
  291. }
  292. }
  293. },
  294. // 清空form
  295. resetForm () {
  296. this.form.id = ''
  297. this.form.location = ''
  298. this.form.manager = ''
  299. this.form.name = ''
  300. this.form.buildTime = ''
  301. }
  302. }
  303. }
  304. </script>
  305. <style scoped>
  306. </style>