ludc
2023-06-19 fdaad68c0715d6f7858b956071e3b01cd543a5cd
Source/UBCS-WEB/src/components/Crud/Crud.vue
@@ -1,140 +1,462 @@
<template>
<basic-container>
  <avue-crud ref="crud"
             :data="data"
             :option="option"
             @sort-change="sortChange"
             v-loading="loading"
             :page="page"
             @selection-change="selectionChange"
             @on-load="onLoad">
      <template slot="menu">
        <el-button type="text">文字按钮</el-button>
      </template>
  </avue-crud>
</basic-container>
  <basic-container>
    <div class="testbox">
      <div style="margin-top: 10px;display: flex;flex-wrap: wrap;width: 100%;">
        <el-button plain size="small" type="primary" @click="addvisible=true">增加
        </el-button>
        <FormTemplateDialog
          :codeClassifyOid="this.codeClassifyOid"
          :codeRuleOid="this.codeRuleOid"
          :disabledProp="disabledProp"
          :templateOid="templateOid"
          :type="add"
          :visible.sync="addvisible"
        >
        </FormTemplateDialog>
        <el-button plain size="small" type="primary" @click="editHandler">编辑
        </el-button>
        <FormTemplateDialog
          :codeClassifyOid="this.codeClassifyOid"
          :codeRuleOid="this.codeRuleOid"
          :disabledProp="disabledProp"
          :rowOid="rowOid"
          :templateOid="templateOid"
          :type="edit"
          :title="'修改编码信息'"
          :visible.sync="editvisible"
        ></FormTemplateDialog>
        <el-button plain size="small" type="primary">批量导入申请</el-button>
        <el-button plain size="small" type="primary">历史数据导入</el-button>
        <el-button plain size="small" type="primary">批量申请编码</el-button>
        <el-button plain size="small" type="primary">批量发布</el-button>
        <el-button plain size="small" type="primary">查看流程历史</el-button>
        <el-button plain size="small" type="primary">删除</el-button>
        <el-button plain size="small" type="primary" @click="setHandler">发布</el-button>
        <set-personnel :visible.sync="visibleFlow"  :parameter="parameter"
                       type="PUBLIC"></set-personnel>
        <el-button plain size="small" type="primary" @click="DataChange">数据更改</el-button>
        <FormTemplateDialog
          :codeClassifyOid="this.codeClassifyOid"
          :codeRuleOid="this.codeRuleOid"
          :disabledProp="disabledProp"
          :rowOid="rowOid"
          :templateOid="templateOid"
          :type="edit"
          :title="'已发布数据更改'"
          :visible.sync="DataVisible"
        ></FormTemplateDialog>
        <el-button plain size="small" type="primary" @click="huishouHandler">回收</el-button>
        <el-button plain size="small" type="primary" @click="openD">导出
          <integration-transfer :data="transferData" :props="transferProps"
                                :visible.sync="dialogPush" @save="handelTransferSave"></integration-transfer>
        </el-button>
        <el-button plain size="small" type="primary" @click="findHandler">查询
          <advanced-query :options="this.options" :visible.sync="findvisible"
                          @echoContion="echoContion"></advanced-query>
        </el-button>
        <el-button plain size="small" type="primary">相似项查询</el-button>
        <el-button plain size="small" style="margin-left: 1px;margin-top:10px" type="primary">刷新</el-button>
        <el-input placeholder="请输入关键字按回车查询" size="small"
                  style="width: 180px;margin-left: 5px;margin-top:10px"></el-input>
      </div>
      <el-row style="height: 700px;width: 100%">
        <el-table v-loading="isLoading" :data="tableData" max-height="700" style="" @cell-click="handleCellClick"
                  @selection-change="handleSelectionChange" @sort-change="sortChange">
          <el-table-column
            fixed
            type="selection"
            width="55">
          </el-table-column>
          <el-table-column
            fixed
            label="序号"
            type="index"
            width="55">
          </el-table-column>
<!--          <div>-->
            <el-table-column  v-for="(item,index) in this.tableHeadFindData" :key="item.id" :label="item.label" :prop="item.prop" :sortable="item.sortable" >
              <!-- 编辑和展示逻辑 -->
              <!--              <template slot-scope="{ row }">-->
              <!--                <el-input v-if="editingRow === row && editShow== item.prop" v-model="row[item.prop]" @blur="saveRow"></el-input>-->
              <!--                <span v-else>{{row[item.prop]}}</span>-->
              <!--                <el-switch-->
              <!--                  v-if="editShow === 'true'"-->
              <!--                  v-model="row[item.prop]"-->
              <!--                  active-color="#13ce66"-->
              <!--                  inactive-color="#ff4949">-->
              <!--                </el-switch>-->
              <!--              </template>-->
            </el-table-column>
<!--          </div>-->
        </el-table>
      </el-row>
    </div>
    <div class="block" style="display: flex;justify-content: flex-end">
      <el-pagination
        :current-page="page.currentPage"
        :page-size="page.pageSizes"
        :page-sizes="page.pageSizes"
        :total="page.total"
        layout="total, sizes, prev, pager, next, jumper"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange">
      </el-pagination>
    </div>
  </basic-container>
</template>
<script>
import { MasterTable,TableData } from "@/api/GetItem";
import {MasterTable, TableData,FindData} from "@/api/GetItem";
import {listCodeAttributeByClassId} from '@/api/integration/integration.js'
import integrationTransfer from '@/views/integration/integrationTransfer'
import SetPersonnel from '@/components/template/SetPersonnel'
export default {
  components: {
    integrationTransfer,
    SetPersonnel
  },
  name: "Crud.vue",
  data(){
    return{
      loading:false,
      data:[],
      option:{
        //默认高度,
        align:'center',
        menuAlign:'center',
        addBtn:false,
        editBtn:false,
        selection:true,
        selectionFixed:false,
        index:true,
        column:[]
  props: {
    page: {
      type: Object,
      default: () => {
        return {}
      }
    },
    codeClassifyOid: {
      type: String,
      default: ""
    },
    coderuleoid: {
      type: String,
      default: ""
    },
    tableDataArray: {
      type: Array,
    },
    total: {
      type: String,
      default: ""
    },
    templateOid: {
      type: String,
    },
    tableHeadDataFateher: {
      type: Array,
    },
    isLoading: {
      type: Boolean,
      default: false
    },
    tableHeadFindData:{
      type:Array,
    }
  },
  data() {
    return {
      //发布
      parameter:{
        ids:['0000','22222222'],
        code:'8b5e2017-990f-454a-9c39-4c4eeeb57553',
        type:'PUBLIC',
        name:'模板name',
        template:'模板template'
      },
      List:[],
      visibleFlow: false,
      transferData: [],
      transferProps: {
        key: 'oid',
        label: 'name'
      },
      tableHeadFindDatas:[],
      templateOid: "",
      addvisible: false,
      editvisible: false,
      findvisible: false,
      dialogPush: false,
      rowOid: '',
      disabledProp: ["id"],
      editingRow: null,
      editShow: "",
      editAttr: "",
      data: [],
      options: {},
      option: {
        column: []
      },
      List: [],
      columnType: {
        text: "input",
        combox: "select",
        truefalse: "switch",
        number: "number",
        datetime:"datetime",
        datetime: "datetime",
      },
      page:{
        total: 0,
        currentPage: 1,
        pageSize: 10,
        pageSizes: [10, 30, 50, 100, 200],
      },
      tableData: [],
      DataVisible:false,
      tableHeadData: [],
      items: {},
      seniorQueryColumns: [],
      selectRow: []
    }
  },
  computed: {},
  created() {
      this.CrudHeaderRend();
      this.CrudRend()
    // this.CrudHeaderRend();
    // this.tableHeadHandle()
  },
  mounted() {
  },
  activated() {
    this.doLayout()
  },
  methods:{
  watch: {
    codeClassifyOid: {
      handler(newval, oldval) {
        this.codeClassifyOid = newval;
        this.CrudHeaderRend()
      },
      deep: true
    },
    tableDataArray: {
      handler(newval, oldval) {
        this.tableData = newval;
      }
    },
    tableHeadFindData:{
      handler(newval, oldval) {
        this.tableHeadFindDatas = newval;
      }
    },
    total: {
      handler(newval, oldval) {
        this.page.total = newval;
      }
    },
    // tableHeadDataFateher: {
    //   handler(newval, oldval) {
    //     let List = newval.tableDefineVO.cols[0];
    //     List.forEach(item => {
    //       let columnItem = {
    //         label: item.title,
    //         prop: item.field,
    //         type: this.columnType[item.type],
    //         sortable: item.sort,
    //         width: item.minWidth
    //       };
    //       this.tableHeadData.push(columnItem);
    //       console.log('table',this.tableHeadData)
    //     })
    //   }
    // }
  },
  methods: {
    setHandler() {
      this.visibleFlow = true
    },
    huishouHandler() {
      console.log('tem', this.templateOid)
      console.log('table', this.tableData)
      console.log('tabheadle', this.tableHeadData)
      console.log('tableFather', this.tableHeadDataFateher)
    },
    openD() {
      this.dialogPush = true;
      this.getListCodeByClassId()
    },
    async getListCodeByClassId() {
      this.transferData = []
      const response = await listCodeAttributeByClassId({codeClassifyId: this.codeClassifyOid})
      if (response.status === 200) {
        const data = response.data.data
        this.transferData = data
      }
    },
    rend() {
      this.tableData = this.tableHeadData
    },
    handleSizeChange(val) {
      this.isLoading = true;
      setTimeout(() => {
        this.page.pageSize = val
        this.$emit('pageSize', val)
        this.CrudRend()
      }, 3000);
    },
    handleCurrentChange(val) {
      this.isLoading = true;
      setTimeout(() => {
        this.page.currentPage = val
        this.$emit('currentPage', val)
        this.CrudRend()
      }, 3000);
    },
    // 监听单元格点击事件并存储正在编辑的行
    handleCellClick(row, column) {
      this.editingRow = row;
      this.editShow = column.property;
      this.rowOid = row.oid
    },
    //删除
    enumDeleteRow(row) {
      this.tableData.splice(row, 1)
    },
    // 将正在编辑的行的状态变为 null ,即退出编辑状态
    saveRow() {
      this.editingRow = null;
    },
    doLayout() {
      this.$nextTick(() => {
        this.$refs.crud.doLayout();
      });
    },
    //表格头渲染
    CrudHeaderRend(){
      MasterTable({codeClassifyOid:"D9CF223F-317D-71EB-BD11-433A94CAD9F3",functionId: 5,_: 1685067339479}).then(res=>{
        this.List=res.data.tableDefineVO.cols[0];
        this.List.forEach(item=>{
          let columnItem={
            label:item.title,
            prop:item.field,
            type:this.columnType[item.type],
            sortable:item.sort,
            width:item.minWidth
          };
          this.option.column.push(columnItem);
        })
    tableHeadHandle() {
      this.options = this.tableHeadDataFateher.tableDefineVO.seniorQueryColumns
      this.List = this.tableHeadDataFateher.tableDefineVO.cols[0];
      this.List.forEach(item => {
        let columnItem = {
          label: item.title,
          prop: item.field,
          type: this.columnType[item.type],
          sortable: item.sort,
          width: item.minWidth
        };
        this.option.column.push(columnItem);
        this.option.column = this.tableHeadData;
      })
    },
    //表格头渲染
    CrudHeaderRend() {
      if (this.codeClassifyOid != "") {
        MasterTable({
          codeClassifyOid: this.codeClassifyOid,
          functionId: 5,
        }).then(res => {
          this.options = res.data.tableDefineVO.seniorQueryColumns
          this.List = res.data.tableDefineVO.cols[0];
          this.List.forEach(item => {
            let columnItem = {
              label: item.title,
              prop: item.field,
              type: this.columnType[item.type],
              sortable: item.sort,
              width: item.minWidth
            };
            this.option.column.push(columnItem);
            this.option.column = this.tableHeadData;
            this.templateOid = res.data.tableDefineVO.oid
            this.$emit('templateOid', this.templateOid)
          })
        })
      }
    },
    //表格数据
    CrudRend(){
      TableData({templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
    CrudRend() {
      TableData({
        templateOid: this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
        page: this.page.currentPage,
        limit: this.page.pageSize,
        _: 1685089123575
      }).then(res=>{
        this.page.total=res.data.total;
        this.data=res.data.data;
      }).then(res => {
        this.page.total = res.data.total;
        this.data = res.data.data;
        this.tableData = res.data.data;
      })
    },
    // 排序
    sortChange(val){
      this.loading=true;
      let order=""
      if(val.order == "ascending"){
        order="asc";
      }else {
        order="desc";
    sortChange(val) {
      this.isLoading = true;
      let order = ""
      if (val.order == "ascending") {
        order = "asc";
      } else {
        order = "desc";
      }
      TableData(  {
        templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
        order:order,
        sort:val.prop,
      TableData({
        templateOid: this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
        order: order,
        sort: val.prop,
        page: this.page.currentPage,
        limit: this.page.pageSize,
      }).then(res=>{
      }).then(res => {
        setTimeout(() => {
          this.data=res.data.data;
          this.loading=false;
          this.data = res.data.data;
          this.isLoading = false;
        }, 100);
      })
    },
    //分页刷新
    async onLoad(val){
      console.log(val)
     await TableData({templateOid: "A12826E4-2B66-6D56-DE30-92BB1D7F607F",
        codeClassifyOid: "D9CF223F-317D-71EB-BD11-433A94CAD9F3",
    async onLoad(val) {
      console.log('分页', this.templateOid)
      await TableData({
        templateOid: this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
        page: val.currentPage,
        limit: val.pageSize,
        _: 1685089123575
      }).then(res=>{
       this.data=res.data.data;
      }).then(res => {
        this.data = res.data.data;
      })
    },
    //多选
    selectionChange(row){
    handleSelectionChange(row) {
      console.log(row)
      this.rowOid = row.oid
      this.selectRow = row
    },
    //编辑
    editHandler() {
      if (this.selectRow.length <= 0) {
        this.$message.warning('请选择一条数据')
      } else if (this.selectRow.length > 1) {
        this.$message.warning('只能选择一条数据')
      } else if (this.selectRow[0].lcstatus != 'Editing') {
        this.$message.warning('编码状态不是“编辑中”,不可编辑')
      } else {
        this.editvisible = true
      }
    },
    //高级查询按钮
    findHandler(){
      this.findvisible=true;
      console.log(this.options)
    },
    // 高级查询
    echoContion(val) {
      console.log(val)
      FindData({templateOid:this.templateOid,
        codeClassifyOid: this.codeClassifyOid,
        ...val
      }).then(res=>{
        console.log(res)
      })
    },
    //数据更改
    DataChange(){
      if (this.selectRow.length <= 0) {
        this.$message.warning('请选择一条数据')
      } else if (this.selectRow.length > 1) {
        this.$message.warning('只能选择一条数据')
      } else if (this.selectRow[0].lcstatus != 'Released') {
        this.$message.warning('只有状态为已发布的数据才能进行数据更改')
      } else {
        this.DataVisible = true
      }
    }
  }
}
</script>
<style scoped>
<style lang="scss" scoped>
.testbox {
  .el-table--scrollable-x .el-table__body-wrapper {
    overflow: auto !important;
  }
  .el-table__fixed-right-patch {
    background-color: #f5f7fa !important;
  }
}
</style>