element form 变 table

燕志学
2023-12-01
<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd ? '新增' : '编辑'" width="500px">
    <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
      <el-form-item label="路线名称" prop="name">
        <el-input v-model="form.name" style="width: 370px;"/>
      </el-form-item>
      <el-form-item label="所属分组" >
        <el-select v-model="groupId" style="width: 370px;" placeholder="请选择分组名称">
          <el-option
            v-for="(item, index) in moduleGroups"
            :key="item.groupName + index"
            :label="item.groupName"
            :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="封装形式" >
        <el-select v-model="encforId" style="width: 370px;" placeholder="请选择封装形式">
          <el-option
            v-for="(item, index) in encfors"
            :key="item.name + index"
            :label="item.name"
            :value="item.id"/>
        </el-select>
      </el-form-item>
      <el-form-item label="备注" >
        <el-input v-model="form.remarks" rows="3" type="textarea" style="width: 370px;"/>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button :loading="loading" type="primary" @click="doSubmit">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { add, edit } from '@/api/tcline'
import { getEncfor } from '@/api/encfor'
import { getAllModuleGroup } from '@/api/moduleGroup'
export default {
  props: {
    isAdd: {
      type: Boolean,
      required: true
    }
  },
  data() {
    return {
      loading: false, dialog: false,
      form: {
        id: '',
        group: { id: '' },
        encfor: { id: '' },
        encforId: '',
        name: '',
        lineDesc: '',
        remarks: ''
      },
      encfors: [],
      encforId: null,
      moduleGroups: [],
      groupId: null,
      rules: {
        name: [
          { required: true, message: '路线名称不能为空', trigger: 'blur' }
        ],
        lineDesc: [
          { required: true, message: '工艺路线不能为空', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.resetForm()
    },
    getAllModuleGroup() {
      getAllModuleGroup().then(res => {
        this.moduleGroups = res.content
      })
    },
    doSubmit() {
      this.form.group.id = this.groupId
      this.form.encfor.id = this.encforId
      if (this.groupId === null || this.groupId === undefined) {
        this.$message({
          message: '所属分组不能为空',
          type: 'warning'
        })
      } else if (this.encforId === null || this.encforId === undefined) {
        this.$message({
          message: '封装形式不能为空',
          type: 'warning'
        })
      } else {
        this.$refs['form'].validate((valid) => {
          if (valid) {
            this.loading = true
            if (this.isAdd) {
              this.doAdd()
            } else this.doEdit()
          }
        })
      }
    },
    doAdd() {
      add(this.form).then(res => {
        console.log(add)
        this.resetForm()
        this.$notify({
          title: '添加成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    doEdit() {
      edit(this.form).then(res => {
        this.resetForm()
        this.$notify({
          title: '修改成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    resetForm() {
      this.dialog = false
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
      this.encforId = null
      this.form = {
        group: { id: '' },
        encfor: { id: '' },
        id: '',
        encforId: '',
        name: '',
        lineDesc: '',
        remarks: ''
      }
    },
    getEncfor() {
      getEncfor().then(res => {
        this.encfors = res.content
      })
    }
  }
}
</script>

<style scoped>

</style>

<template>
  <div class="app-container">
    <!--表单组件-->
    <eForm ref="form" :is-add="isAdd"/>
    <el-row :gutter="10">
      <el-col :xs="24" :sm="24" :md="10" :lg="10" :xl="10">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>路线列表</span>
            <el-button
              v-permission="['ADMIN','DICT_ALL','DICT_CREATE']"
              class="filter-item"
              size="mini"
              style="float: right;padding: 4px 10px"
              type="primary"
              icon="el-icon-plus"
              @click="add">新增</el-button>
              <!-- @click="$refs.form.dialog = true;isAdd = true;">新增</el-button> -->

          </div>
          <!--工具栏-->
          <div class="head-container">
            <!-- 搜索 -->
            <el-input v-model="query.value" clearable placeholder="输入搜索内容" style="width: 200px;" class="filter-item" @keyup.enter.native="toQuery"/>
            <el-select v-model="query.type" clearable placeholder="类型" class="filter-item" style="width: 130px">
              <el-option v-for="item in queryTypeOptions" :key="item.key" :label="item.display_name" :value="item.key"/>
            </el-select>
            <el-button class="filter-item" size="mini" type="success" icon="el-icon-search" @click="toQuery">搜索</el-button>
          </div>
          <!--表格渲染-->
          <el-table v-loading="loading" :data="data" size="small" highlight-current-row style="width: 100%;" @current-change="handleCurrentChange">
            <el-table-column :show-overflow-tooltip="true" prop="name" label="名称"/>
            <el-table-column :show-overflow-tooltip="true" prop="group.groupName" label="所属分组"/>
            <el-table-column :show-overflow-tooltip="true" prop="encfor.name" label="封装形式"/>
            <el-table-column :show-overflow-tooltip="true" prop="remark" label="备注"/>
            <el-table-column v-if="checkPermission(['ADMIN','DICT_ALL','DICT_EDIT','DICT_DELETE'])" label="操作" width="130px" align="center">
              <template slot-scope="scope">
                <el-button v-permission="['ADMIN','TCLINEDESC_ALL','TCLINEDESC_EDIT']" size="mini" type="primary" icon="el-icon-edit" @click="edit(scope.row)"/>
                <el-popover
                  v-permission="['ADMIN','TCLINEDESC_ALL','TCLINEDESC_DELETE']"
                  :ref="scope.row.id"
                  placement="top"
                  width="180">
                  <p>此操作将删除字典与对应的字典详情,确定要删除吗?</p>
                  <div style="text-align: right; margin: 0">
                    <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
                    <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
                  </div>
                  <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
                </el-popover>
              </template>
            </el-table-column>
          </el-table>
          <!--分页组件-->
          <el-pagination
            :total="total"
            :current-page="page + 1"
            style="margin-top: 8px;"
            layout="total, prev, pager, next, sizes"
            @size-change="sizeChange"
            @current-change="pageChange"/>
        </el-card>
      </el-col>

      <el-col :xs="24" :sm="24" :md="14" :lg="14" :xl="14">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>路线描述</span>
            <el-button
              v-if="checkPermission(['ADMIN','TCLINEDESC_ALL','TCLINEDESC_CREATE']) && this.$refs.lineDesc && this.$refs.lineDesc.lineName"
              class="filter-item"
              size="mini"
              style="float: right;padding: 4px 10px"
              type="primary"
              icon="el-icon-plus"
              @click="addDesc">模块列表</el-button>
          </div>
          <lineDesc ref="lineDesc"/>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { del } from '@/api/tcline'
import { parseTime } from '@/utils/index'
import lineDesc from '../lineDesc/index'
import eForm from './form'

export default {
  components: { lineDesc, eForm },
  mixins: [initData],
  data() {
    return {
      loading: false, dialog: false,
      groupId: null,
      moduleId: null,
      lineId: null,
      delLoading: false,
      queryTypeOptions: [
        { key: 'name', display_name: '路线名称' }
      ]
    }
  },
  created() {
    this.$nextTick(() => {
      this.init()
    })
  },
  methods: {
    parseTime,
    checkPermission,
    beforeInit() {
      // this.$refs.permission.setCheckedKeys([])
      // this.$refs.menu.setCheckedKeys([])
      this.showButton = false
      this.url = 'api/tcline'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, sort: sort }
      const query = this.query
      const type = query.type
      const value = query.value
      if (type && value) { this.params[type] = value }
      if (this.$refs.lineDesc) {
        this.$refs.lineDesc.data = []
        this.$refs.lineDesc.lineName = ''
      }
      return true
    },
    handleCurrentChange(val) {
      console.log(val)
      if (val) {
        this.$refs.lineDesc.lineName = val.name
        this.$refs.lineDesc.groupId = val.group.id
        this.$refs.lineDesc.lineId = val.id
        this.$refs.lineDesc.init()
      }
    },
    subDelete(id) {
      this.delLoading = true
      del(id).then(res => {
        this.delLoading = false
        this.$refs[id].doClose()
        this.dleChangePage()
        this.init()
        this.$notify({
          title: '删除成功',
          type: 'success',
          duration: 2500
        })
      }).catch(err => {
        this.delLoading = false
        this.$refs[id].doClose()
        console.log(err.response.data.message)
      })
    },
    add() {
      this.isAdd = true
      this.$refs.form.getEncfor()
      this.$refs.form.getAllModuleGroup()
      this.$refs.form.resetForm()
      this.$refs.form.dialog = true
    },
    addDesc() {
      if (this.$refs.lineDesc.lineId === null) {
        this.$notify({
          title: '请先选择一条工艺路线',
          type: 'warning',
          duration: 2500
        })
        return
      }
      this.isAdd = true
      this.$refs.form.resetForm()
      this.$refs.lineDesc.$refs.module_list.groupId = this.$refs.lineDesc.groupId
      this.$refs.lineDesc.$refs.module_list.lineId = this.$refs.lineDesc.lineId
      this.$refs.lineDesc.$refs.module_list.dialog = true
      this.$refs.lineDesc.$refs.module_list.init()
    },
    edit(data) {
      this.isAdd = false
      const _this = this.$refs.form
      _this.getEncfor()
      _this.getAllModuleGroup()
      _this.resetForm()
      _this.form = {
        id: data.id,
        group: { id: data.group.id },
        encfor: { id: data.encfor.id },
        name: data.name,
        lineDesc: data.lineDesc,
        remarks: data.remarks
      }
      _this.groupId = data.group.id
      _this.encforId = data.encfor.id
      _this.dialog = true
    }
  }
}
</script>

<style scoped>

</style>


点击路线列表查看详情

<template>
  <el-dialog :append-to-body="true" :visible.sync="dialog" :title="isAdd ? '列表' : '模块列表'" width="800px">
    <el-table v-loading="loading" ref="table" :row-key="getRowKey" :data="data" size="small" style="width: 100%;" @selection-change="handleSelectionChange">
      <el-table-column :reserve-selection="true" prop="select" type="selection" width="55px"/>
      <el-table-column prop="moduleName" label="模块名称"/>
      <el-table-column prop="className" label="模块类名"/>
      <el-table-column :show-overflow-tooltip="true" prop="remarks" label="备注"/>
      <el-table-column v-if="checkPermission(['ADMIN','TCLINEDESC_ALL','TCLINEDESC_EDIT','TCLINEDESC_DELETE'])" label="操作" width="150px" align="center">
        <template slot-scope="scope">
          <el-popover
            v-permission="['ADMIN','TCLINEDESC_ALL','TCLINEDESC_DELETE']"
            :ref="scope.row.id"
            placement="top"
            width="180">
            <p>确定删除本条数据吗?</p>
            <div style="text-align: right; margin: 0">
              <el-button size="mini" type="text" @click="$refs[scope.row.id].doClose()">取消</el-button>
              <el-button :loading="delLoading" type="primary" size="mini" @click="subDelete(scope.row.id)">确定</el-button>
            </div>
            <el-button slot="reference" type="danger" icon="el-icon-delete" size="mini"/>
          </el-popover>
        </template>
      </el-table-column>
    </el-table>
    <div v-permission="['ADMIN','TCLINEDESC_ALL','TCLINEDESC_CREATE']" slot="footer" class="dialog-footer">
      <el-button
        :loading="loading"
        :disabled="data.length === 0 || $refs.table.selection.length === 0"
        class="filter-item"
        size="mini"
        type="primary"
        icon="el-icon-check"
        @click="saveMenu">保存</el-button>
    </div>
  </el-dialog>
</template>

<script>
import checkPermission from '@/utils/permission'
import initData from '@/mixins/initData'
import { saveAll } from '@/api/tclineDesc'
import { getToken } from '@/utils/auth'

export default {
  mixins: [initData],
  data() {
    return {
      saveAllLoading: false,
      delLoading: false,
      headers: {
        'Authorization': 'Bearer ' + getToken()
      },
      loading: false, dialog: false,
      groupId: null,
      moduleId: null,
      lineId: null,
      rules: {
      }
    }
  },
  methods: {
    checkPermission,
    cancel() {
      this.resetForm()
    },
    getRowKey(row) {
      return row.id
    },
    handleSelectionChange(val) {
      console.log(val + '==============')
    },
    clearSelect() {
      this.$refs.buyerTable.clearSelection()
    },
    doSave() {
      this.loading = true
      const data = this.$refs.table.selection
      const ids = []
      for (let i = 0; i < data.length; i++) {
        ids.push(data[i].id)
      }
      const params = { ids: ids, lineId: this.lineId }
      saveAll(params).then(res => {
        this.loading = false
        this.init()
        this.dleChangePage(ids.length)
        this.$notify({
          title: '保存成功',
          type: 'success',
          duration: 2500
        })
        this.loading = false
        this.$parent.init()
      }).catch(err => {
        this.loading = false
        console.log(err.response.data.message)
      })
    },
    saveMenu() {
      this.$confirm('你确定保存选中的数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.doSave()
        this.dialog = false
      })
    },
    beforeInit() {
      this.url = 'api/module'
      const sort = 'id,desc'
      this.params = { page: this.page, size: this.size, groupId: this.groupId, sort: sort }
      const query = this.query
      const type = query.type
      const value = query.value
      if (type && value) { this.params[type] = value }
      return true
    },
    doSubmit() {
      this.$refs['form'].validate((valid) => {
        if (valid) {
          this.loading = true
          if (this.isAdd) {
            console.log('add')
            this.doAdd()
          } else this.doEdit()
        }
      })
    },
    resetForm() {
      this.dialog = false
      if (this.$refs['form'] !== undefined) {
        this.$refs['form'].resetFields()
      }
    }
  }
}
</script>

<style scoped>

</style>

 类似资料: