廖井涛
2024-07-25 15fa56463061f1e94140e23e98987aa3131714bf
north-glass-erp/northglass-erp/src/views/pp/reportingWorks/QualityInspectionReview.vue
@@ -1,157 +1,448 @@
<script lang="ts" setup>
import { reactive } from 'vue'
import { ref } from 'vue'
const value = ref('')
const defaultTime = ref<[Date, Date]>([
  new Date(2000, 1, 1, 0, 0, 0),
  new Date(2000, 2, 1, 23, 59, 59),
])
<script setup>
// do not use same name with ref
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 {Search} from "@element-plus/icons-vue";
import { useI18n } from 'vue-i18n'
import useUserInfoStore from "@/stores/userInfo";
import footSum from "@/hook/footSum"
//语言获取
const { t } = useI18n()
let router=useRouter()
const userStore = useUserInfoStore()
const username = userStore.user.userName
const getTableRow = (row,type) =>{
  switch (type) {
    case 'edit' :{
      //alert('我接收到子组件传送的编辑信息')
      router.push({path: '/main/reportingWorks/AddReportingWork', query: { reportingWorkId: row.reportingWorkId,reviewStatus:"1" }})
      break
    }
    case 'delete':{
      alert('我接收到子组件传送的删除信息')
      break
    }
    case  'setType':{
      let startTime = form.date1[0]
      let endTime = form.date1[1]
      let state = optionVal.value
      let inputVal = form.processId
      request.post(`/reportingWork/updateQualityStatus/${row.reportingWorkId}/${username}`).then((res) => {
        if (res.code == 200) {
          ElMessage.success(t('processCard.modifySuccessfully'))
          router.push({path: '/main/reportingWorks/QualityInspectionReview', query: {startTime:startTime,endTime:endTime,state:state,inputVal:inputVal, random:Math.random()}})
        } else {
          ElMessage.warning(res.msg)
        }
      })
      break
    }
  }
}
//定义时间
const form = reactive({
  name: '',
  region: '',
  date1: '',
  date2: '',
  delivery: false,
  type: [],
  resource: '',
  desc: '',
  processId:'',
})
const tableData = [
//定义转单状态
const optionVal = ref('1')
const options = [
  {
    reportingWorkNo: 'BG2312070001',
    reportingWorkTime: '2023-12-01 08:01:22',
    processCard: 'NG231207A01',
    entryName: '信合春天里',
    customerName: 'XXXX',
    thisProcess: '中空',
    teamName:"中空一班",
    finishedNumber: '11',
    wornNumber: '1',
    responsibilityProcess: '钢化',
    previousProcess:'钢化',
    nextProcess:'包装',
    qualityInspector: 'XXX',
    qualityState: '1',
    notes: '1)按企标2)每片玻璃标签贴室外面。内片玻璃打“3C商标”,统一打在玻璃“宽度”方向右下角4)按批次单独落架。',
    value: '1',
    label: t('reportingWorks.unqualified'),
  },
  {
    reportingWorkNo: 'BG2312070002',
    reportingWorkTime: '2023-12-01 08:01:22',
    processCard: 'NG231207A01',
    entryName: '信合春天里',
    customerName: 'XXXX',
    thisProcess: '中空',
    teamName:"中空一班",
    finishedNumber: '11',
    wornNumber: '1',
    responsibilityProcess: '钢化',
    previousProcess:'钢化',
    nextProcess:'包装',
    qualityInspector: 'XXX',
    qualityState: '1',
    notes: '1)按企标2)每片玻璃标签贴室外面。内片玻璃打“3C商标”,统一打在玻璃“宽度”方向右下角4)按批次单独落架。',
    value: '2',
    label: t('reportingWorks.qualified'),
  },
  {
    reportingWorkNo: 'BG2312070003',
    reportingWorkTime: '2023-12-01 08:01:22',
    processCard: 'NG231207A01',
    entryName: '信合春天里',
    customerName: 'XXXX',
    thisProcess: '中空',
    teamName:"中空一班",
    finishedNumber: '11',
    wornNumber: '1',
    responsibilityProcess: '钢化',
    previousProcess:'钢化',
    nextProcess:'包装',
    qualityInspector: 'XXX',
    qualityState: '1',
    notes: '1)按企标2)每片玻璃标签贴室外面。内片玻璃打“3C商标”,统一打在玻璃“宽度”方向右下角4)按批次单独落架。',
]
//表尾求和
const sumNum = (list, field) => {
  let count = 0
  list.forEach(item => {
    count += Number(item[field])
  })
  return count.toFixed(2)
}
//定义滚动条高度
let scrollTop = ref(null)
let scrollHeight = ref(null)
let clientHeight = ref(null)
const scrollEvnt = (row) => {
  // 内容高度
  scrollTop.value = row.$event.target.scrollTop
  scrollHeight.value = row.$event.target.scrollHeight
  clientHeight.value = row.$event.target.clientHeight
}
//筛选条件,有外键需要先定义明细里面的数据
let filterData = ref({
  order: {
    project: '',
    customerName:''
  },
  {
    reportingWorkNo: 'BG2312070004',
    reportingWorkTime: '2023-12-01 08:01:22',
    processCard: 'NG231207A01',
    entryName: '信合春天里',
    customerName: 'XXXX',
    thisProcess: '中空',
    teamName:"中空一班",
    finishedNumber: '11',
    wornNumber: '1',
    responsibilityProcess: '钢化',
    previousProcess:'钢化',
    nextProcess:'包装',
    qualityInspector: 'XXX',
    qualityState: '1',
    notes: '1)按企标2)每片玻璃标签贴室外面。内片玻璃打“3C商标”,统一打在玻璃“宽度”方向右下角4)按批次单独落架。',
  damageDetails: {
    qualityInsStatus: '',
  },
]
})
//定义页面总页数
let pageTotal = ref('')
//定义数据返回结果
let produceList = ref([])
//定义当前页数
let pageNum=ref(1)
let pageState = null
//获取七天前到当前时间
function getNowTime() {
  const start = new Date(new Date().getTime() - 3600 * 1000 * 24 * 7)
      .toISOString()
      .replace('T', ' ')
      .slice(0, 10) //默认开始时间7天前
  const end = new Date(new Date().getTime()+3600 * 1000 * 24)
      .toISOString()
      .replace('T', ' ')
      .slice(0, 10)//默认结束时间当前时间
  return [start, end]
}
//第一次加载获取近七天时间和默认状态
form.date1 = getNowTime()
let startTime = form.date1[0]
let endTime = form.date1[1]
let state = optionVal.value
let total = reactive({
  pageTotal : 0,
  dataTotal : 0,
  pageSize : 100
})
let inputVal = form.processId
if (inputVal == '') {
  inputVal = null
}
//第一次加载数据
request.post(`/reportingWork/selectQualityTesting/1/${total.pageSize}/${startTime}/${endTime}/${state}/${inputVal}`, filterData.value).then((res) => {
  if (res.code == 200) {
    total.dataTotal = res.data.total.total*1
    total.pageTotal= res.data.total.pageTotal
    pageTotal.value = res.data.total
    produceList = produceList.value.concat(deepClone(res.data.data))
    xGrid.value.reloadData(produceList)
    gridOptions.loading = false
  } else {
    ElMessage.warning(res.msg)
  }
})
//页脚翻页查询
const selectPageList = ()=>{
  let startTime = form.date1[0]
  let endTime = form.date1[1]
  request.post(`/reportingWork/selectQualityTesting/${pageNum.value}/${total.pageSize}/${startTime}/${endTime}/${state}/${inputVal}`,filterData.value).then((res) => {
    if(res.code==200){
      produceList = deepClone(res.data.data)
      xGrid.value.reloadData(produceList)
    }else{
      ElMessage.warning(res.msg)
    }
  })
}
//点击查询
const getWorkOrder = () => {
  let startTime = form.date1[0]
  let endTime = form.date1[1]
  let state = optionVal.value
  let inputVal = form.processId
  if (inputVal == '') {
    inputVal = null
  }
  request.post(`/reportingWork/selectQualityTesting/${pageNum.value}/${total.pageSize}/${startTime}/${endTime}/${state}/${inputVal}`, filterData.value).then((res) => {
    if (res.code == 200) {
      total.dataTotal = res.data.total.total*1
      total.pageTotal= res.data.total.pageTotal
      pageTotal.value = res.data.total
      produceList = deepClone(res.data.data)
      produceList.forEach(item => {
        if (item.damageDetails.qualityInsStatus === 2) {
          item.damageDetails.qualityInsStatus = '已质检';
        }
        else if (item.damageDetails.qualityInsStatus === 1){
          item.damageDetails.qualityInsStatus = '待质检';
        }
        else if (item.damageDetails.qualityInsStatus === 0){
          item.damageDetails.qualityInsStatus = '无需质检';
        }
      });
      xGrid.value.reloadData(produceList)
      gridOptions.loading = false
    } else {
      ElMessage.warning(res.msg)
    }
  })
}
//页脚跳转
const handlePageChange = ({ currentPage, pageSize }) => {
  pageNum.value=currentPage
  total.pageTotal    = pageSize
  selectPageList()
}
/*使用筛选,后端获取数据*/
const changeFilterEvent = (event, option, $panel,) => {
  // 手动触发筛选
  $panel.changeOption(event, !!option.data, option)
}
function filterChanged(column) {
  gridOptions.loading = true
  //筛选条件发生变化条件发生变化
  let value = column.datas[0] != undefined ? column.datas[0] : ''
  value = value.trim()
  //判断是否存在外键
  if (column.property.indexOf('.') > -1) {
    const columnArr = column.property.split('.')
    filterData.value[columnArr[0]] = {
      [columnArr[1]]: value
    }
  } else {
    filterData.value[column.property] = value
  }
//获取选中时间和是否转单状态
  let startTime = form.date1[0]
  let endTime = form.date1[1]
  let state = optionVal.value
  let inputVal = form.processId
  if (inputVal == '') {
    inputVal = null
  }
  request.post(`/reportingWork/selectQualityTesting/1/${total.pageSize}/${startTime}/${endTime}/${state}/${inputVal}`, filterData.value).then((res) => {
    if (res.code == 200) {
      total.dataTotal = res.data.total.total*1
      total.pageTotal=parseInt(res.data.total)
      pageNum.value=1
      produceList = deepClone(res.data.data)
      xGrid.value.reloadData(produceList)
      gridOptions.loading=false
    } else {
      ElMessage.warning(res.msg)
    }
  })
}
/*后端返回结果多层嵌套展示*/
const hasDecimal = (value) => {
  const regex = /\./; // 定义正则表达式,查找小数点
  return regex.test(value); // 返回true/false
}
//子组件接收参数
const xGrid = ref()
const gridOptions = reactive({
  border:  "full",//表格加边框
  keepSource: true,//保持源数据
  align: 'center',//文字居中
  stripe:true,//斑马纹
  rowConfig: {isCurrent: true, isHover: true,height: 30},//鼠标移动或选择高亮
  id: 'QualityInspectionReview',
  showFooter: true,//显示脚
  printConfig: {},
  importConfig: {},
  exportConfig: {},
  scrollY:{ enabled: true },//开启虚拟滚动
  showOverflow:true,
  columnConfig: {
    resizable: true,
    useKey: true
  },
  filterConfig: {   //筛选配置项
    remote: true
  },
  customConfig: {
    storage: true
  },
  editConfig: {
    trigger: 'click',
    mode: 'row',
    showStatus: true
  },//表头参数
  columns:[
    {type:'expand',fixed:"left",slots: { content:'content' }},
    {title: t('basicData.operate'), width: 100, slots: { default: 'button_slot' },fixed:"left"},
    { type: 'seq',fixed:"left", title: t('basicData.Number'),},
    {field: 'reportingWorkId',width: 130,  title: t('reportingWorks.reportingWorkId'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }, },
    {field: 'reportingWorkTime',width: 120, title: t('reportingWorks.reportingWorkTime'),showOverflow:"ellipsis" },
    {field: 'processId',width: 130, title: t('processCard.processId'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }},
    {field: 'order.project',width: 120, title: t('order.project'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }},
    {field: 'order.customerName',width: 120, title: t('customer.customerName'),filters:[{ data: '' }],slots: { filter: 'num1_filter' }},
    {field: 'thisProcess',width: 100, title: t('reportingWorks.thisProcess'),showOverflow:"ellipsis"},
    {field: 'thisCompletedQuantity',width: 100, title: t('reportingWorks.thisCompletedQuantity')},
    {field: 'thisWornQuantity', width: 100,title: t('reportingWorks.thisWornQuantity')},
    {field: 'teamsGroupsName',width: 110, title: t('reportingWorks.teamsType')},
    {field: 'deviceName',width: 110, title: t('reportingWorks.deviceType')},
    {field: 'previousProcess', width: 100,title: t('reportingWorks.previousProcess')},
    {field: 'nextProcess',width: 100, title: t('reportingWorks.nextProcess')},
    {field: 'qualityInspector',width: 120, title: t('reportingWorks.qualityInspector')},
    {field: 'qualityInsTime',width: 120, title: t('reportingWorks.qualityInsTime')},
    {field: 'damageDetails.qualityInsStatus',width: 120, title: t('reportingWorks.qualityInsStatus')}
  ],//表头按钮
  toolbarConfig: {
    // buttons: [{
    //
    // }],
    // import: false,
    // export: true,
    // print: true,
    zoom: true,
    custom: true
  },
  data:  [
  ],//table body实际数据
  //脚部求和
  footerMethod ({ columns, data }) {//页脚函数
    return[
      columns.map((column, columnIndex) => {
        if (columnIndex === 0) {
          return t('basicData.total')
        }
        const List = ["thisCompletedQuantity",'thisWornQuantity','area','perimeter']
        if (List.includes(column.field)) {
          return footSum(data, column.field)
        }
        return ''
      })
    ]
  }
})
</script>
<template>
  <div>
    <div style="width: 600px">
  <div class="main-div-customer">
    <div id="selectForm">
      <el-row :gutter="0">
<!--        <el-input placeholder="流程卡号" v-model="form.name" style="width: 200px"/>-->
<!--        &nbsp;&nbsp;-->
        <select class="processesSt">
          <option value="未审核">未审核</option>
          <option value="已审核">已审核</option>
        </select>
        &nbsp;&nbsp;
        <el-date-picker
            v-model="value"
            v-model="form.date1"
            type="daterange"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
            format="YYYY/MM/DD"
            value-format="YYYY-MM-DD"
            :start-placeholder="$t('basicData.startDate')"
            :end-placeholder="$t('basicData.endDate')"
            :default-time="defaultTime"
        />
        &nbsp;&nbsp;
        <el-button type="primary">查询</el-button>
      </el-row>
    </div>
    <div>
      <el-table :data="tableData" border style="width: 100%" height="100%">
        <el-table-column fixed label="操作" width="60"  >
          <el-button link type="primary" size="small">通过</el-button>
        </el-table-column>
        <el-table-column sortable prop="reportingWorkNo" label="报工编号" width="120" >
          <template v-slot="scope">
            <router-link :to="{path:'QualityInReviewDetail'}" >{{scope.row.reportingWorkNo}}</router-link>
          </template>
        </el-table-column>
        <el-table-column prop="reportingWorkTime" label="报工时间" width="155" />
        <el-table-column prop="processCard" label="流程卡号" width="125" />
        <el-table-column prop="entryName" label="项目名称"  :show-overflow-tooltip='true' width="155" />
        <el-table-column prop="customerName" label="客户名称"  :show-overflow-tooltip='true' width="155" />
        <el-table-column prop="thisProcess" label="本工序" width="70" />
        <el-table-column prop="teamName" label="报工班组" width="95" />
        <el-table-column prop="finishedNumber" label="完工数量" width="85" />
        <el-table-column prop="wornNumber" label="次破数量" width="85" />
        <el-table-column prop="responsibilityProcess" label="责任工序" width="85" />
        <el-table-column prop="previousProcess" label="上工序" width="70" />
        <el-table-column prop="nextProcess" label="下工序" width="70" />
        <el-table-column prop="qualityInspector" label="质检员" width="80" />
        <el-table-column prop="qualityState" label="质检状态" width="90" />
        <el-table-column prop="notes" label="备注" :show-overflow-tooltip='true' width="350" />
      </el-table><!-- <h1>{{msg}}</h1> -->
    </div>
        <el-select :default-first-option="true" ref="getSelect" style="width: 100px" v-model="optionVal" class="m-2"
        >
          <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
          />
        </el-select>
        &nbsp;&nbsp;
        <el-input v-model="form.processId" clearable :placeholder="$t('processCard.processId')" style="width: 130px"></el-input>
        &nbsp;
        <el-button
            @click="getWorkOrder"
            id="select"
            type="primary" :icon="Search">{{$t('basicData.search')}}
        </el-button>
      </el-row>
    </div>
    <vxe-grid
        height="100%"
        @filter-change="filterChanged"
        class="mytable-scrollbar"
        ref="xGrid"
        v-bind="gridOptions"
    >
      <!--      @toolbar-button-click="toolbarButtonClickEvent"-->
      <!--      下拉显示所有信息插槽-->
      <template #content="{ row }">
        <ul class="expand-wrapper">
          <li v-for="(item,index) in gridOptions.columns" v-show="item.field!=undefined ">
            <span style="font-weight: bold">{{ item.title + ':  ' }}</span>
            <span v-if="hasDecimal(item.field)">{{ row[item.field.split('.')[0]][item.field.split('.')[1]] }}</span>
            <span v-else>{{ row[item.field] }}</span>
          </li>
        </ul>
      </template>
      <!--左边固定显示的插槽-->
      <template #button_slot="{ row }">
<!--        <el-button @click="getTableRow(row,'edit')" link type="primary" size="small">编辑</el-button>-->
        <el-button @click="getTableRow(row,'edit')"
                   v-if="userStore.user.permissions.indexOf('QualityInspectionReview.edit') > -1"
                   link
                   type="primary"
                   size="small">
          {{ $t('basicData.edit') }}
        </el-button>
        <el-button v-if="row.damageDetails.qualityInsStatus==='已质检'||row.damageDetails.qualityInsStatus==='无需质检'" disabled @click="getTableRow(row,'setType')" link type="primary" size="small">{{ $t('basicData.review') }}</el-button>
        <el-button v-else  @click="getTableRow(row,'setType')" link type="primary" size="small">{{ $t('basicData.review') }}</el-button>
      </template>
      <template #num1_filter="{ column, $panel }">
        <div>
          <div v-for="(option, index) in column.filters" :key="index">
            <input type="type" v-model="option.data" @input="changeFilterEvent($event, option, $panel)"/>
          </div>
        </div>
      </template>
      <template #pager>
        <!--使用 pager 插槽-->
        <!--        'PrevJump','NextJump', -->
        <vxe-pager
            @page-change="handlePageChange"
            :layouts="[  'PrevPage', 'Jump','PageCount', 'NextPage',  'Total']"
            v-model:current-page="pageNum"
            v-model:page-size="total.pageSize"
            v-model:pager-count="total.pageTotal"
            :total="total.dataTotal"
        >
        </vxe-pager>
      </template>
    </vxe-grid>
  </div>
</template>
<style scoped>
.processesSt{
  height: 33px;
  width: 80px;
  background-color: #409eff;
  color: white;
  border: none;
  border-radius: 5px;
.main-div-customer{
  width: 99%;
  height: 95%;
}
#selectForm {
  width: 60%;
  text-align: center;
}
</style>