廖井涛
2024-10-14 6ac9391135ded7e668d2d42f408f4a6c59b27d23
north-glass-erp/northglass-erp/src/views/pp/machine/SelectMachine.vue
@@ -1,150 +1,179 @@
<script lang="ts" setup>
import {reactive, ref} from 'vue'
import {Search} from "@element-plus/icons-vue"
import {useRouter} from "vue-router"
const router = useRouter()
// do not use same name with ref
const value = ref('')
const options = [
  {
    value: 'Option1',
    label: 'Option1',
  },
  {
    value: 'Option2',
    label: 'Option2',
  },
  {
    value: 'Option3',
    label: 'Option3',
  },
]
<script setup>
import {reactive, ref} from "vue";
import {useRouter} from  'vue-router'
import request from "@/utils/request";
import deepClone from "@/utils/deepClone";
import {ElDatePicker, ElMessage} from "element-plus";
import { useI18n } from 'vue-i18n'
import {changeFilterEvent, filterChanged} from "@/hook"
import {Search} from "@element-plus/icons-vue";
//语言获取
const { t } = useI18n()
let router=useRouter()
//定义数据返回结果
let produceList = ref([])
const getBasicData = ref({
  id: '',
  basic_type: '',
  basic_name: '',
  d_basic_name: '',
})
//表尾求和
const sumNum = (list, field) => {
  let count = 0
  list.forEach(item => {
    count += Number(item[field])
  })
  return count.toFixed(2)
}
const hasDecimal = (value) => {
  const regex = /\./; // 定义正则表达式,查找小数点
  return regex.test(value); // 返回true/false
}
//首次加载
request.post(`/maintenance/selectMachine`).then((res) => {
  if (res.code == 200) {
    xGrid.value.loadData(res.data.data)
    gridOptions.loading = false
  } else {
    ElMessage.warning(res.msg)
  }
})
const tableData = [
  {
    1: 'SB2209211',
    2: '钢化炉(22E)',
    3: '钢化炉(22E)',
    4: '2022-03-16',
    5:'2022-03-16',
    6:'313',
    7:'使用中',
    8:'0',
    9:'0',
    10:'',
    11:'',
    12:'',
    13:'',
    14:'钢化',
    15:'正常',
//子组件接收参数
const xGrid = ref()
const gridOptions = reactive({
  border:  "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe:true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true,height: 30},//鼠标移动或选择高亮
  id: 'CustomerList',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY:{ enabled: true },//开启虚拟滚动
  showOverflow:true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  {
    1: 'SB2209211',
    2: '钢化炉(22E)',
    3: '钢化炉(22E)',
    4: '2022-03-16',
    5:'2022-03-16',
    6:'313',
    7:'使用中',
    8:'0',
    9:'0',
    10:'',
    11:'',
    12:'',
    13:'',
    14:'钢化',
    15:'正常',
  filterConfig: {   //筛选配置项
    // remote: true
  },
  {
    1: 'SB2209211',
    2: '钢化炉(22E)',
    3: '钢化炉(22E)',
    4: '2022-03-16',
    5:'2022-03-16',
    6:'313',
    7:'使用中',
    8:'0',
    9:'0',
    10:'',
    11:'',
    12:'',
    13:'',
    14:'钢化',
    15:'正常',
  customConfig: {
    storage: true
  },
]
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },//表头参数
  columns:[
    {type:'expand',fixed:"left",slots: { content:'content' },width: 50},
    { type: 'seq',fixed:"left", title: t('basicData.Number'), width: 50 },
    {field: 'deviceId', width: 120, title: t('machine.basicId'),filters:[{ data: '' }],slots: { filter: 'num1_filter' },filterMethod: filterChanged },
    {field: 'deviceName', width: 130,title: t('machine.basicName') ,filters:[{ data: '' }],slots: { filter: 'num1_filter' },filterMethod: filterChanged},
    {field: 'type',width: 100, title:  t('machine.type'),filters:[{ data: '' }],slots: { filter: 'num1_filter' },filterMethod: filterChanged },
    {field: 'faultCount',width: 120, title: t('machine.faultCount') ,showOverflow:"ellipsis"},
    {field: 'maintenanceCount', width: 120,title: t('machine.maintenanceCount'), },
    {field: 'faultLastTime',width: 120, title: t('machine.faultLastTime'), },
    {field: 'maintenanceLastTime',width: 120, title: t('machine.maintenanceLastTime'), },
    {field: 'faultCost',width: 120, title: t('machine.faultCost'), },
    {field: 'maintenanceCost',width: 120, title: t('machine.maintenanceCost'), },
    {field: 'process',width: 120, title: t('machine.basicCategory'),filters:[{ data: '' }],slots: { filter: 'num1_filter' },filterMethod: filterChanged }
  ],
  //表头按钮
  toolbarConfig: {
    // buttons: [{
    //
    // }],
    import: false,
    export: true,
    print: true,
    zoom: true,
    custom: true
  },
  data:  [
  ],//table body实际数据
  //脚部求和
  footerMethod ({ columns, data }) {//页脚函数
    let footList=['','','','']
    return[
      columns.map((column, columnIndex) => {
        if (columnIndex === 0) {
          return t('basicData.total')
        }
        if (footList.includes(column.field)) {
          return sumNum(data, column.field)
        }
        return ''
      })
    ]
  }
})
const size = ref<'default' | 'large' | 'small'>('default')
const value1 = ref('')
const dialogFormVisible = ref(false)
const formLabelWidth = '140px'
const form = reactive({
  name: '',
  region: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: '',
  desc: '',
})
</script>
<template>
  <div>
<!--    <div id="selectForm">-->
<!--      <el-row :gutter="0">-->
<!--        <el-select v-model="value" class="m-2" placeholder="所在工艺">-->
<!--          <el-option-->
<!--              v-for="item in options"-->
<!--              :key="item.value"-->
<!--              :label="item.label"-->
<!--              :value="item.value"-->
<!--          />-->
<!--        </el-select>-->
<!--        &nbsp;&nbsp;-->
<!--        <el-button type="primary">查询</el-button>-->
<!--      </el-row>-->
  <div class="main-div-customer">
    <vxe-grid
        max-height="100%"
        class="mytable-scrollbar"
        ref="xGrid"
        v-bind="gridOptions"
<!--    </div>-->
    <el-table :data="tableData" border style="width: 100%" height="100%">
      <el-table-column fixed label="操作" width="100"  >
        <el-button link type="primary" size="small" @click="dialogFormVisible = true">编辑</el-button>
        <el-button link type="primary" size="small">删除</el-button>
    >
      <!--      @toolbar-button-click="toolbarButtonClickEvent"-->
      <!--      下拉显示所有信息插槽-->
      <template #content="{ row}">
        <ul class="expand-wrapper">
          <li  v-for="(item,key,index) in row">
            <span style="font-weight: bold">{{key+':  '}}</span>
            <span>{{ item }}</span>
          </li>
        </ul>
      </template>
      </el-table-column>
      <el-table-column prop="1" label="设备编号" width="95" />
      <el-table-column prop="2" label="标准名称" width="105" />
      <el-table-column prop="3" label="设备名称" width="105" />
      <el-table-column prop="4" label="购买时间" :show-overflow-tooltip='true' width="115" />
      <el-table-column prop="5" label="安装时间" :show-overflow-tooltip='true' width="115" />
      <el-table-column prop="6" label="使用周期(年)" width="105" />
      <el-table-column prop="7" label="使用状态" width="85" />
      <el-table-column prop="8" label="维修次数" width="85" />
      <el-table-column prop="9" label="保养次数" width="85" />
      <el-table-column prop="10" label="最后维修时间" :show-overflow-tooltip='true' width="115" />
      <el-table-column prop="11" label="最后保养时间" width="115" />
      <el-table-column prop="12" label="维修费用" width="105" />
      <el-table-column prop="13" label="保养费用" width="85" />
      <el-table-column prop="14" label="所在工艺" width="85" />
      <el-table-column prop="15" label="作废状态" width="85" />
    </el-table><!-- <h1>{{msg}}</h1> -->
    <el-dialog v-model="dialogFormVisible" title="设备编辑">
      <template #num1_filter="{ column, $panel }">
        <div>
          <div v-for="(option, index) in column.filters" :key="index">
            <input type="text" v-model="option.data"
                   @keyup.enter.native="$panel.confirmFilter()"
                   @input="changeFilterEvent($event, option, $panel)"/>
          </div>
        </div>
      </template>
    </vxe-grid>
    <el-dialog v-model="dialogFormVisible" :title="$t('machine.deviceEditing')">
      <el-form :model="form">
        <el-form-item label="标准名称" :label-width="formLabelWidth">
        <el-form-item :label="$t('machine.standardName')" :label-width="formLabelWidth">
          <el-input v-model="form.name"  autocomplete="off"  style="width: 220px"/>
        </el-form-item>
        <el-form-item label="设备名称" :label-width="formLabelWidth">
        <el-form-item :label="$t('machine.basicName')" :label-width="formLabelWidth">
          <el-input v-model="form.name"  autocomplete="off"  style="width: 220px"/>
        </el-form-item>
        <el-form-item label="购买时间" :label-width="formLabelWidth">
        <el-form-item :label="$t('machine.purchaseTime')" :label-width="formLabelWidth">
          <el-date-picker
              v-model="value1"
              type="date"
@@ -152,7 +181,7 @@
              :size="size"
          />
        </el-form-item>
        <el-form-item label="安装时间" :label-width="formLabelWidth">
        <el-form-item :label="$t('machine.installationTime')" :label-width="formLabelWidth">
          <el-date-picker
              v-model="value1"
              type="date"
@@ -160,22 +189,22 @@
              :size="size"
          />
        </el-form-item>
        <el-form-item label="保养周期" :label-width="formLabelWidth">
        <el-form-item :label="$t('machine.maintenanceCycle')" :label-width="formLabelWidth">
          <el-input v-model="form.name"  autocomplete="off"  style="width: 220px"/>
        </el-form-item>
        <el-form-item label="所在工艺" :label-width="formLabelWidth">
          <el-select v-model="form.region" placeholder="钢化" style="width: 220px">
            <el-option label="切割" value="shanghai" />
            <el-option label="磨边" value="mobian" />
            <el-option label="钢化" value="ganghua" />
        <el-form-item :label="$t('machine.standardName')" :label-width="formLabelWidth">
          <el-select v-model="form.region" :placeholder="$t('machine.tempering')" style="width: 220px">
            <el-option :label="$t('machine.cutting')" value="shanghai" />
            <el-option :label="$t('machine.edgeGrinding')" value="mobian" />
            <el-option :label="$t('machine.tempering')" value="ganghua" />
          </el-select>
        </el-form-item>
      </el-form>
      <template #footer>
      <span class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button @click="dialogFormVisible = false">{{$t('basicData.cancelButtonText')}}</el-button>
        <el-button type="primary" @click="dialogFormVisible = false">
          确认
          {{$t('basicData.confirmButtonText')}}
        </el-button>
      </span>
      </template>
@@ -184,11 +213,8 @@
</template>
<style scoped>
#selectForm {
  width: 40%;
.main-div-customer{
  width: 99%;
  height: 100%;
  text-align: center;
}
</style>