Newer
Older
smart-metering-front / src / views / measure / source / list.vue
MrTan on 7 Dec 2022 6 KB 溯源供方列表新增
<script lang="ts" setup name="ListSource">
import { reactive, ref } from 'vue'
import type { Ref } from 'vue'
import type { IlistQuery } from './list_interface'
import ListSourceAdd from './listAdd.vue'
import { getSoucreList, getSoucreListDelete } from '@/api/system/source'

// 查询条件
const listQuery: Ref<IlistQuery> = ref({
  supplierNo: '', // 业务内容
  supplierName: '', // 溯源供方名称
  businessContent: '', // 溯源供方编号
  offset: 1,
  limit: 20,
})
// 控制是否显示新增页面
const show = ref(true)
// 表格数据
const list = ref([])
// 总数
const total = ref(20)
// 表头
const columns = ref([
  {
    text: '溯源供方编号',
    value: 'supplierNo',
    width: '160',
  },
  {
    text: '溯源供方名称',
    value: 'supplierName',
    width: '120',
  },
  {
    text: '业务内容',
    value: 'businessContent',
  },
  {
    text: '业务资质',
    value: 'briefName',
  },
  {
    text: '负责人',
    value: 'director',
  },
  {
    text: '联系方式',
    value: 'mobile',
  },
  {
    text: '地址',
    value: 'companyCity',
  },
  {
    text: '创建时间',
    value: 'createTime',
    width: '200',
  },
  {
    text: '备注',
    value: 'remark',
  },
])

// 按钮数组
const buttons = ref(['批量导入', '模板下载', '新建', '导出', '打印'])
// 表格loding
const listLoading = ref(false)
const fetchData = (isNowPage: boolean) => {
  listLoading.value = true
  if (!isNowPage) {
    // 是否显示当前页,否则跳转第一页
    listQuery.value.offset = 1
  }
  getSoucreList(listQuery.value).then((response) => {
    list.value = response.data.rows
    total.value = parseInt(response.data.total)
    listLoading.value = false
  })
}
fetchData(true)
// 详情id
const infoId = ref('0')
// 点击按钮
const buttonType = ref('')
// 多选发生改变时
const handleSelectionChange = (e: any) => {
  console.log(e)
}
// 点击编辑/详情
const handleEdit = (index: string, row: object, value: string) => {
  buttonType.value = value
  infoId.value = row.id
  show.value = false
}
// 点击删除
const handleDelete = (index: string, row: object) => {
  getSoucreListDelete({ id: row.id }).then((res) => {
  })
}
// 分页
const handleSizeChange = (val: string) => {}
// 分页
const handleCurrentChange = (val: string) => {}
// 点击搜索
const searchList = () => {
  fetchData(true)
}
// 点击重置
const clearList = () => {
  listQuery.value = {
    supplierNo: '', // 业务内容
    supplierName: '', // 溯源供方名称
    businessContent: '', // 溯源供方编号
    offset: 1,
    limit: 20,
  }
}
// 关闭编辑
const close = () => {
  show.value = true
}
// 点击右上角一排按钮
const handelClick = (type: string) => {
  if (type === '新建') {
    buttonType.value = ''
    show.value = false
  }
}
</script>

<template>
  <div v-if="show">
    <app-container>
      <search-area
        type="seperate"
        need-clear
        @search="searchList"
        @clear="clearList"
      >
        <search-item>
          <el-input
            v-model.trim="listQuery.supplierNo"
            placeholder="溯源供方编号"
            clearable
          />
        </search-item>
        <search-item>
          <el-input
            v-model.trim="listQuery.supplierName"
            placeholder="溯源供方名称"
            clearable
          />
        </search-item>
        <search-item>
          <el-input
            v-model.trim="listQuery.businessContent"
            placeholder="业务内容"
            clearable
          />
        </search-item>
      </search-area>
    </app-container>
    <div style="padding: 10px;">
      <table-container>
        <div class="table-top">
          <h3 />
          <div>
            <el-button
              v-for="(item, index) in buttons"
              :key="index"
              type="primary"
              @click="handelClick(item)"
            >
              {{ item }}
            </el-button>
          </div>
        </div>
        <el-table
          :data="list"
          style="width: 100%;"
          @selection-change="handleSelectionChange"
        >
          <el-table-column type="selection" width="55" />
          <el-table-column align="center" label="序号" width="80" type="index" />
          <el-table-column
            v-for="(column, index) in columns"
            :key="index"
            :label="column.text"
            :prop="column.value"
            :width="column.width"
            align="center"
          />
          <el-table-column align="center" label="操作" width="200">
            <template #default="scope">
              <el-button
                size="small"
                type="primary"
                link
                @click="handleEdit(scope.$index, scope.row, '编辑')"
              >
                编辑
              </el-button>
              <el-button
                size="small"
                link
                type="primary"
                @click="handleEdit(scope.$index, scope.row, '详情')"
              >
                详情
              </el-button>
              <el-button
                size="small"
                link
                type="danger"
                @click="handleDelete(scope.$index, scope.row)"
              >
                删除
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </table-container>
    </div>
    <div class="pagination">
      <el-pagination
        v-model:current-page="listQuery.offset"
        v-model:page-size="listQuery.limit"
        :page-sizes="[10, 20, 30, 50]"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </div>
  <list-source-add
    v-else
    :info-id="infoId"
    :button-type="buttonType"
    @close="close"
  />
</template>

<style lang="scss" scoped>
.table-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.pagination {
  position: fixed;
  bottom: 0;
}

.el-button__text--expand {
  text-align: center !important;
}
</style>