123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <template>
- <div class="branch">
- <el-form
- :inline="true"
- :model="dataForm"
- @keyup.enter.native="getDataList()">
- <!-- <el-form-item>
- <el-input
- v-model="dataForm.key"
- placeholder="用户名/用户操作"
- clearable
- ></el-input>
- </el-form-item>
- <el-form-item>
- <el-button @click="getDataList()">查询</el-button>
- </el-form-item> -->
- <el-form-item>
- <el-button v-if="isAuth('sys:role:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
- </el-form-item>
- <el-form-item>
- <el-button v-if="isAuth('sys:role:delete')" type="danger" @click="deleteHandle()" :disabled="selectionDataList.length <= 0">批量删除</el-button>
- </el-form-item>
- </el-form>
- <el-table
- :data="dataList"
- @selection-change="selectionChangeHandle"
- v-loading="dataListLoading"
- style="width: 100%">
- <el-table-column
- type="selection"
- header-align="center"
- align="center"
- width="50">
- </el-table-column>
- <el-table-column
- prop="name"
- header-align="center"
- align="center"
- label="名称">
- </el-table-column>
- <el-table-column
- prop="location"
- header-align="center"
- align="center"
- label="地址">
- </el-table-column>
- <el-table-column
- prop="manager"
- header-align="center"
- align="center"
- label="负责人">
- </el-table-column>
- <el-table-column
- prop="buildTime"
- header-align="center"
- align="center"
- :show-overflow-tooltip="true"
- label="建立日期">
- </el-table-column>
- <el-table-column
- fixed="right"
- header-align="center"
- align="center"
- label="操作">
- <template slot-scope="scope">
- <el-button v-if="isAuth('sys:user:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row)">修改</el-button>
- <el-button v-if="isAuth('sys:user:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
- </template>
- </el-table-column>
- </el-table>
- <el-dialog
- :title="!form.id ? '新增' : '修改'"
- :close-on-click-modal="false"
- :visible.sync="visible">
- <el-form :model="form" ref="form" @keyup.enter.native="formSubmit()" label-width="80px">
- <el-form-item label="牧场名称" prop="name">
- <el-input v-model="form.name" placeholder="牧场名称"></el-input>
- </el-form-item>
- <el-form-item label="管理员" prop="manager">
- <el-input v-model="form.manager" placeholder="牧场管理员"></el-input>
- </el-form-item>
- <el-form-item label="地址" prop="location">
- <el-input v-model="form.location" placeholder="地址"></el-input>
- </el-form-item>
- <el-form-item label="日期" prop="buildTime">
- <el-date-picker
- v-model="form.buildTime"
- type="date"
- value-format="yyyy-MM-dd"
- placeholder="选择日期">
- </el-date-picker>
- </el-form-item>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="visible = false">取消</el-button>
- <el-button type="primary" @click="formSubmit()">确定</el-button>
- </span>
- </el-dialog>
- </div>
- </template>
- <script>
- export default {
- data () {
- return {
- dataForm: {
- key: ''
- },
- dataList: [
- {
- buildTime: '',
- id: '',
- location: '',
- manager: '',
- name: '',
- }
- ],
- pageIndex: 1,
- pageSize: 10,
- totalPage: 0,
- dataListLoading: false,
- selectionDataList: [],
- visible: false,
- form: {
- id: '',
- location: '',
- manager: '',
- name: '',
- buildTime: ''
- }
- }
- },
- created () {
- this.getDataList()
- },
- methods: {
- // 获取数据列表
- getDataList () {
- this.dataListLoading = true
- this.$http({
- url: this.$http.adornUrl('/management/pasture/list'),
- method: 'post'
- }).then(({ data }) => {
- if (data && data.code === 0) {
- this.dataList = data.page.list
- this.totalPage = data.page.totalCount
- } else {
- this.dataList = []
- this.totalPage = 0
- }
- this.dataListLoading = false
- })
- },
- // 每页数
- sizeChangeHandle (val) {
- this.pageSize = val
- this.pageIndex = 1
- this.getDataList()
- },
- // 当前页
- currentChangeHandle (val) {
- this.pageIndex = val
- this.getDataList()
- },
- // 新增 or 修改牧场
- addOrUpdateHandle (row) {
- // 显示牧场新增 or 修改面板
- this.visible = true
- if (row) {
- this.form = row
- }
- },
- // 选择n个牧场
- selectionChangeHandle (val) {
- this.selectionDataList = []
- val.forEach(item => {
- this.selectionDataList.push(item.id)
- });
- },
- // 删除n个牧场
- deleteHandle (id) {
- this.$confirm(`确定删除牧场?`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- // 删除操作
- if (id) {
- this.selectionDataList.push(id)
- }
- if (this.selectionDataList.length <= 0) {
- return
- }
- this.$http({
- url: this.$http.adornUrl('/management/pasture/delete'),
- method: 'post',
- data: this.$http.adornData(this.selectionDataList, false)
- }).then(result => {
- console.log(result);
- if (result.data.code === 0) {
- this.getDataList()
- this.resetForm()
- this.$message({
- message: '成功删除牧场',
- type: 'success',
- duration: 1000
- })
- } else {
- this.$message.error('删除牧场失败');
- }
- this.selectionDataList = []
- })
- }).catch(() => {})
- },
- formSubmit () {
- if (this.form.id) {
- // 修改
- if (this.form.name && this.form.manager && this.form.location && this.form.buildTime) {
- // 进行修改操作
- this.$http({
- url: this.$http.adornUrl('/management/pasture/update'),
- method: 'post',
- data: this.$http.adornData({
- id: this.form.id,
- location: this.form.location,
- manager: this.form.manager,
- name: this.form.name,
- buildTime: this.form.buildTime
- })
- }).then(result => {
- if (result.data.code === 0) {
- this.getDataList()
- this.resetForm()
- this.$message({
- message: '成功修改牧场信息',
- type: 'success',
- duration: 1000
- })
- } else {
- this.$message.error('修改牧场信息失败');
- }
- })
- this.visible = false
- } else {
- // 请输入完整
- this.$confirm(`请输入完整`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- return
- }).catch(() => {})
- }
- console.log(this.form);
- } else {
- // 新增
- if (this.form.name && this.form.manager && this.form.location && this.form.buildTime) {
- // 进行新增操作
- this.$http({
- url: this.$http.adornUrl('/management/pasture/save'),
- method: 'post',
- data: this.$http.adornData({
- location: this.form.location,
- manager: this.form.manager,
- name: this.form.name,
- buildTime: this.form.buildTime
- })
- }).then(result => {
- console.log(result);
- if (result.data.code === 0) {
- this.getDataList()
- this.resetForm()
- this.$message({
- message: '成功添加牧场',
- type: 'success',
- duration: 1000
- })
- } else {
- this.$message.error('添加牧场失败');
- }
- })
- this.visible = false
- } else {
- // 请输入完整
- this.$confirm(`请输入完整`, '提示', {
- confirmButtonText: '确定',
- cancelButtonText: '取消',
- type: 'warning'
- }).then(() => {
- return
- }).catch(() => {})
- }
- }
- },
- // 清空form
- resetForm () {
- this.form.id = ''
- this.form.location = ''
- this.form.manager = ''
- this.form.name = ''
- this.form.buildTime = ''
- }
- }
- }
- </script>
- <style scoped>
- </style>
|