Newer
Older
GDT_FRONT / src / views / property / orderList.vue
wangxitong on 9 Feb 2023 12 KB 0209
<template>
  <app-container>
    <search-area :need-clear="true" :need-search-more="false" type="seperate" size="small" search-more-type="default" @search="fetchData(false)" @clear="clearInput">
      <!--一般查询条件-->
      <search-item>
        <el-input v-model.trim="listQuery.keywords" size="small" placeholder="工单号/描述" @change="fetchData(false)"/>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.orderType" size="small" placeholder="工单类型" clearable @change="fetchData(false)">
          <el-option
            v-for="item in typeList"
            :key="item.value"
            :label="item.name"
            :value="item.value"
          />
        </el-select>
      </search-item>
      <search-item>
        <el-select v-model="listQuery.status" size="small" placeholder="工单状态" clearable @change="fetchData(false)">
          <el-option label="已分配" value="1" />
          <el-option label="未分配" value="0" />
        </el-select>
      </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-edit" @click="add()">
          添加
        </el-button>
        <el-button size="small" class="edit_btn" icon="el-icon-delete" @click="batchDel()">
          删除
        </el-button>
        <el-button size="small" class="edit_btn" icon="el-icon-download" @click="exportFile()">
          导出
        </el-button>
      </template>
      <template slot="columns">
        <el-table-column label="操作" align="center" width="120">
          <template slot-scope="scope">
            <el-button type="text" size="small" @click.stop="detail(scope.row)">
              详情
            </el-button>
            <el-button type="text" size="small" @click.stop="edit(scope.row)">
              编辑
            </el-button>
            <el-button type="text" size="small" @click.stop="del(scope.row)">
              删除
            </el-button>
          </template>
        </el-table-column>
      </template>
    </normal-table>
    <edit-order v-show="dialogFormVisible" ref="editOrder" @watchChild="fetchData" />
  </app-container>
</template>

<script>
import NormalTable from '@/components/NormalTable'
import AppContainer from '@/components/layout/AppContainer'
import SearchArea from '@/components/SearchArea/SearchArea'
import SearchItem from '@/components/SearchArea/SearchItem'
import { getOrderListPage, delOrder, batchDelOrder, getOrderExport } from '@/api/property'
import { getDictByCode } from '@/api/system/dict'
import EditOrder from './editOrder'
export default {
  name: 'OrderList',
  components: { EditOrder, SearchItem, SearchArea, AppContainer, NormalTable },
  data() {
    return {
      listQuery: {
        keywords: '',
        orderType: '',
        status: '',
        offset: 1,
        limit: 20
      }, // 筛选条件
      columns: [
        {
          text: '工单号',
          value: 'orderCode',
          align: 'center'
        },
        {
          text: '工单描述',
          value: 'description',
          align: 'center',
          width: 200
        },
        {
          text: '工单类型',
          value: 'orderTypeName',
          align: 'center',
          width: 100
        },
        {
          text: '工单状态',
          value: 'statusName',
          align: 'center',
          width: 100
        },
        {
          text: '工单紧急程度',
          value: 'urgentName',
          align: 'center',
          width: 100
        },
        {
          text: '解决开始时间',
          value: 'startTime',
          align: 'center'
        },
        {
          text: '解决结束时间',
          value: 'endTime',
          align: 'center'
        },
        {
          text: '接单人工号',
          value: 'staffCode',
          align: 'center'
        },
        {
          text: '接单人姓名',
          value: 'staffName',
          align: 'center',
          width: 100
        },
        {
          text: '接单人联系方式',
          value: 'staffPhone',
          align: 'center'
        },
        {
          text: '备注',
          value: 'remarks',
          align: 'center'
        }
      ], // 显示列
      dialogFormVisible: false, // 是否显示编辑框
      timeRange: [], // 时间范围
      multipleSelection: [], // 多选选中项
      list: [], // 列表数据
      typeList: [],
      areaList: [],
      total: 0, // 数据总数
      listLoading: true, // 列表加载动画
      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.fetchOptions()
    this.fetchData()
  },
  methods: {
    fetchOptions() {
      getDictByCode('orderType').then(response => {
        if (response.code === 200) {
          this.typeList = response.data
        }
      })
      getDictByCode('areaType').then(response => {
        if (response.code === 200) {
          this.areaList = response.data
        }
      })
    },
    fetchData(isNowPage = true) {
      this.listLoading = true
      if (!isNowPage) { // 是否显示当前页,否则跳转第一页
        this.listQuery.offset = 1
      }
      const urgentArr = {
        '0': '低',
        '1': '中',
        '2': '高' }
      // getOrderListPage(this.listQuery).then(response => {
      //   if (response.code === 200) {
      //     this.list = response.data.rows.map(item => {
      //          item.statusName = item.status === '1'?  '已分配': '未分配'
      //          item.urgentName = urgentArr[item.urgent]
      //          return item
      //     })
      //     this.total = parseInt(response.data.total)
      //     this.listLoading = false
      //   }
      // })
      const that = this
      setTimeout(function() {
        that.list = [
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' },
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' },
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' },
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' },
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' },
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' },
          { id: '', orderCode: 'gdh0032421', description: '这是一张维修工单', orderType: '0', orderTypeName: '维修', status: '0', urgent: '0', startTime: '2022-05-06 09:23:22', endTime: '2022-05-07 09:23:22', staffCode: 'gh004356', staffName: '张三', staffPhone: '132*********', remarks: '' }
        ]
        that.list = that.list.map(item => {
          item.statusName = item.status === '1' ? '已分配' : '未分配'
          item.urgentName = urgentArr[item.urgent]
          return item
        })
        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()
    },
    exportFile() {
      const loading = this.$loading({
        lock: true,
        text: '数据处理中,请稍后...',
        spinner: 'el-icon-loading',
        background: 'rgba(0, 0, 0, 0.7)'
      })
      getOrderExport(this.listQuery).then(res => {
        loading.close() // 关闭加载动画
        console.log('download===', res)
        const blob = new Blob([res.data])
        const downloadElement = document.createElement('a')
        const href = window.URL.createObjectURL(blob) // 创建下载的链接
        downloadElement.href = href
        downloadElement.download = `工单列表.xlsx` // 下载后文件名
        document.body.appendChild(downloadElement)
        downloadElement.click() // 点击下载
        document.body.removeChild(downloadElement) // 下载完成移除元素
        window.URL.revokeObjectURL(href) // 释放blob对象
      }).catch((res) => {
        loading.close()
        this.$message.error(res.message)
      })
    },
    batchDel() {
      const ids = this.multipleSelection.map(item => item.id)
      if (ids.length === 0) {
        this.$message.warning('请至少选择一行')
        return
      }
      this.$confirm(
        '确定要删除所选数据吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        batchDelOrder(ids).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      })
    },
    // 打开详情对话框
    detail(row) {
      this.$refs.editOrder.initDialog('detail', row)
    },

    // 新增区域
    add() {
      this.dialogFormVisible = true
      this.$refs.editOrder.initDialog('create')
    },
    // 编辑区域信息
    edit(row) {
      this.dialogFormVisible = true
      this.$refs.editOrder.initDialog('update', row)
    },
    del(row) {
      this.$confirm(
        '确定要删除该条数据吗?',
        '确认操作',
        {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }
      ).then(() => {
        delOrder(row.id).then(response => {
          if (response.code === 200) {
            this.$message.success('删除成功')
            this.fetchData()
          }
        })
      })
    },
    handleSelectionChange(val) {
      this.multipleSelection = val
    },
    clearInput() {
      this.listQuery = {
        keywords: '',
        orderType: '',
        status: '',
        offset: 1,
        limit: 20
      }
      this.timeRange = []
      this.fetchData()
    }
  }
}
</script>

<style scoped>

</style>