Newer
Older
GDT_FRONT / src / views / security / scheduleList.vue
[wangxitong] on 21 Jun 2022 8 KB first commit
<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData" @clear="clearInput" >
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.orderCode" size="small" placeholder="值班单号" clearable />
      </search-item>
      <search-item>
        <el-input v-model.trim="listQuery.staffName" size="small" placeholder="员工姓名" clearable />
      </search-item>
       <search-item>
         <el-date-picker
           v-model="timeRange"
           type="daterange"
           range-separator="至"
           value-format="yyyy-MM-dd"
           start-placeholder="起始日期"
           end-placeholder="终止日期"
           size="small"/>
       </search-item>
    </search-area>
    <normal-table :data="list" :head="tableOption.head" :query="listQuery" :total="total" :columns="columns" :list-loading="listLoading" :options="tableOption.options" :tools-option="tableOption.toolsOption" size="small" @change="changePage" @selectionChange="handleSelectionChange">
      <template slot="btns">
        <el-button size="small" class="edit_btn" icon="el-icon-delete" @click="batchDel()">
          删除
        </el-button>
        <download-template :filename="filename"/>
        <el-upload
          :limit="1"
          :show-file-list="false"
          :http-request="uploadFile"
          :file-list="fileList"
          action="string"
          style="float:right; margin:0 3px;"
          accept=".xls,.xlsx">
          <el-button slot="trigger" size="small" icon="el-icon-folder-add">批量导入</el-button>
        </el-upload>
      </template>
    </normal-table>
  </app-container>
</template>

<script>
import {  getDictByCode } from '@/api/system/dict'
import DownloadTemplate from '@/components/DownloadTemplate/index'
import NormalTable from '@/components/NormalTable'
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import {  getScheduleListPage, batchDelSchedule, batchImportSchedule } from '@/api/security'
export default {
  name: 'ScheduleList',
  components: { SearchItem, SearchArea, AppContainer, NormalTable ,DownloadTemplate},
  data() {
    return {
      listQuery: {
        orderCode: '',
        staffName: '',
        startTime:'',
        endTime:'',
        offset: 1,
        limit: 20
      }, // 筛选条件
      columns: [
        {
          text: '值班单号',
          value: 'orderCode',
          align: 'center'
        },
        {
          text: '员工编号',
          value: 'staffCode',
          align: 'center'
        },
        {
          text: '姓名',
          value: 'staffName',
          align: 'center'
        },
        {
          text: '值班区域',
          value: 'areaName',
          align: 'center'
        },
        {
          text: '值班开始时间',
          value: 'startTime',
          align: 'center'
        },
        {
          text: '值班结束时间',
          value: 'endTime',
          align: 'center'
        },
        {
          text: '备注',
          value: 'remarks',
          align: 'center'
        }
      ], // 显示列
      dialogFormVisible: false, // 是否显示编辑框
      timeRange: [], // 时间范围
      multipleSelection: [], // 多选选中项
      list: [], // 列表数据
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      filename: 'schedule_template.xlsx',
      fileList: [],
      tableOption: {
        head: {
          show: true, // 是否需要标题栏,
          text: '数据列表' // 标题名称
        },
        options: {
          needIndex: true // 是否需要序号列
        },
        toolsOption: {
          selectColumns: false, // 是否需要筛选列
          refresh: false, // 是否需要刷新按钮
          needCheckBox: true
        }
      } // 表格属性
    }
  },
  watch: {
    timeRange(val) {
      if (val && val.length > 0) {
        this.listQuery.startTime = val[0]
        this.listQuery.endTime = val[1]
      } else {
        this.listQuery.startTime = ''
        this.listQuery.endTime = ''
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    batchDel(){
      const ids = this.multipleSelection.map(item => item.id)
      if(ids.length === 0) {
        this.$message.warning('请至少选择一行')
        return
      }
      this.$confirm(
        '确定要删除所选数据吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        batchDelSchedule(ids).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      })
    },
    uploadFile(param) {
      // 判断文件大小是否符合要求
      const _file = param.file
      const isLt5M = _file.size / 1024 / 1024 < 5
      if (!isLt5M) {
        this.$message.error('请上传5M以下的excel文件')
        return false
      }
      // 全屏加载动画
      const loading = this.$loading({
        lock: true,
        text: '导入中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      // 发起导入请求
      batchImportSchedule(_file).then(res => {
        loading.close() // 关闭加载动画
        if (res.code === 200) {
          this.$message.success('导入成功')
          this.fetchData(false)
        } else {
          this.$message.error(res.message)
        }
      }).catch(() => {
        loading.close() // 关闭加载动画
      })
      this.fileList = []
    },
    fetchData() {
      this.listLoading = true
      // getScheduleListPage(this.listQuery).then(response => {
      //   if (response.code === 200) {
      //     this.list = response.data.rows
      //     this.total = parseInt(response.data.total)
      //     this.listLoading = false
      //   }
      // })
      const that = this
      setTimeout(function() {
        that.list = [
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
          {id:'', orderCode:'zbdh0001', staffCode:'gh0023221', staffName:'张三', startTime:'2022-05-06 09:00:00', endTime:'2022-05-06 16:00:00', area:'0', areaName:'区域1', remarks:''},
        ]
        that.total = 200
        that.listLoading = false
      }, 100)
    },
    // 页数发生变化后的操作,可能是页码变化,可能是每页容量变化,此函数必写
    changePage(val) {
      if (val && val.size) {
        this.listQuery.limit = val.size
      }
      if (val && val.page) {
        this.listQuery.offset = val.page
      }
      this.fetchData()
    },
    edit(row) {
      this.$confirm(
        '确定要修改该事件状态吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        console.log(row.status)
        const data = {
          id: row.id,
          status: row.status
        }
        updateSchedule(data).then(response => {
          if (response.code === 200) {
            this.$message.success('修改成功')
            this.fetchData()
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    clearInput() {
      this.listQuery = {
        orderCode: '',
        staffName: '',
        startTime:'',
        endTime:'',
        offset: 1,
        limit: 20
      }
      this.fetchData()
    }
  }
}
</script>

<style scoped>

</style>