zhouwx
2 天以前 1ea0d85b0fe2e7e4427fd484a9342d964c831b3d
src/views/hazardousChemicals/useCount/index.vue
@@ -12,6 +12,39 @@
              format="YYYY-MM-DD HH:mm:ss"
          />
        </el-form-item>
        <el-form-item label="所属部门:" prop="departId" >
          <el-cascader
              style="width: 100%"
              ref="classifyRef"
              v-model="state.tableData.listQuery.departId"
              :options="state.deptList"
              :props="state.props"
              clearable
              :show-all-levels="false"
              @change="handleChange"
          />
        </el-form-item>
        <el-form-item label="人员:" prop="userId" >
          <el-select
              clearable
              v-model="state.tableData.userName"
              filterable
              remote
              @change="selectValue"
              reserve-keyword
              placeholder="请输入人员名称"
              remote-show-suffix
              :remote-method="getPeopleList"
              style="width: 100%"
          >
            <el-option
                v-for="item in state.peopleList"
                :key="item.id"
                :label="item.name"
                :value="item.name"
            />
          </el-select>
        </el-form-item>
        <el-form-item >
          <el-button
              plain
@@ -67,7 +100,10 @@
import moment from "moment";
import axios from "axios";
import {getToken} from "@/utils/auth";
import {getDept} from "@/api/hazardousChemicals/deptment";
import Cookies from "js-cookie";
import {getUser} from "@/api/hazardousChemicals/user";
const classifyRef = ref(null)
const loading = ref(false)
const state = reactive({
  tableData: {
@@ -80,9 +116,19 @@
      startTime: null,
      endTime: null,
      time: [],
      userId: null,
      departId: null,
    },
    excelName: ''
  },
  deptList: [],
  peopleList: [],
  props: {
    checkStrictly: true,
  },
  userType: null,
  companyId: null,
  isAdmin: false
});
const fields = ref({
  '名称':'hazmatBasic.name',
@@ -94,11 +140,23 @@
  '最小包装': 'minPack',
  '用量':'count',
});
const userInfo = ref()
onMounted(
    () => {
      userInfo.value = JSON.parse(Cookies.get('userInfo'))
      console.log("userInfo",userInfo.value)
      state.userType = userInfo.value.userType
      if(userInfo.value.userType === 0){
        state.isAdmin = true;
      }else {
        state.isAdmin = false;
        state.companyId = userInfo.value.companyId;
        state.userType = 2
      }
      getNowTime();
      getList()
      getDeptList()
      getPeopleList("")
    }
);
const getNowTime = () => {
@@ -109,7 +167,17 @@
  eTime = `${eTime} ` + moment().format('HH:mm:ss')
  state.tableData.listQuery.time = [sTime ,eTime];
}
const handleChange = ()=> {
  if(classifyRef.value.getCheckedNodes().length>0){
    state.tableData.listQuery.departId = classifyRef.value.getCheckedNodes()[0].value
    if (classifyRef.value.popperVisible) {
      classifyRef.value.togglePopperVisible()
    }
  }else{
    state.tableData.listQuery.departId = null
  }
}
const getList = async () => {
  loading.value = true
  state.tableData.listQuery.startTime = state.tableData.listQuery.time[0]
@@ -129,6 +197,38 @@
    ElMessage.warning(res.message)
  }
  loading.value = false
}
const getDeptList = async ()=>{
  const param = {
    companyId: state.companyId
  }
  const res = await getDept(param)
  if (res.code == 200) {
    state.deptList = recursion(res.data)
  } else {
    ElMessage.warning(res.message)
  }
}
const recursion = (data) => {
  let tmp = []
  for (let i = 0; i < data.length; i++) {
    let item = data[i]
    // children为空
    if (item.children&& item.children.length==0) {
      tmp.push({
        value: item.id,
        label: item.name
      })
      // 有children
    } else {
      tmp.push({
        value: item.id,
        label: item.name,
        children:recursion(item.children)
      })
    }
  }
  return tmp;
}
const downloadExcel = async() => {
@@ -180,7 +280,51 @@
  // }
}
const getPeopleList = async (val)=>{
  if(val != ""){
    const queryParams = {
      name: val
    }
    const res = await getUser(queryParams)
    if (res.code == 200) {
      state.peopleList = res.data.list
    } else {
      ElMessage.warning(res.message)
    }
  }else {
    const queryParams = {
      pageNum: 1,
      pageSize: 10
    }
    const res = await getUser(queryParams)
    if (res.code == 200) {
      state.peopleList = res.data.list
    } else {
      ElMessage.warning(res.message)
    }
  }
}
const selectValue =  (val) => {
  if(!val){
    state.tableData.listQuery.userId = null
  }
  state.peopleList.forEach(item => {
    if(item.name === val){
      state.tableData.listQuery.userId = item.id
    }
  })
}
const reset = () => {
  state.tableData.listQuery= {
    pageNum: 1,
    pageSize: 10,
    startTime: null,
    endTime: null,
    time: [],
    userId: null,
    departId: null,
  }
  state.tableData.userName = ''
  getNowTime();
  getList();
}