<!--进线管理界面-->
<template>
  <div class='default-main unitButton'>
    <TableHeader style='padding: 0 0 !important;' showCustomColumn>
      <template v-slot:operation>
        <el-button type='primary' @click='add' class='ml10' :icon='Plus'>新增</el-button>
      </template>
    </TableHeader>
    <!--表格-->
    <Table ref='tableRef' isGroup></Table>
    <!--弹框-->
    <unit-popup ref='unitPopup' />
  </div>
</template>
<script setup lang='ts'>
import { provide, ref } from 'vue'
import { Plus } from '@element-plus/icons-vue'
import Table from '@/components/table/index.vue'
import TableHeader from '@/components/table/header/index.vue'
import TableStore from '@/utils/tableStore'
import UnitPopup from '@/views/pqs/voltageSags/sagGovern/businessUser/sensitiveUnit/unitPopup.vue'
import { deleteSgSensitiveUnit } from '@/api/advance-boot/sgGroven/sgSensitiveUnit'
import { ElMessage } from 'element-plus'

const unitPopup = ref()

const tableStore = new TableStore({
  url: '/advance-boot/sgSensitiveUnit/list',
  method: 'POST',
  publicHeight: 300,
  showPage: false,
  column: [
    { title: '元器件名称', minWidth: 110, field: 'name' },
    {
      title: '灵敏度', minWidth: 80, field: 'sensitivity',
      formatter: (row: any) => {
        let temp
        switch (row.sensitivity) {
          case 1:
            temp = '高'
            break
          case 2:
            temp = '中'
            break
          case 3:
            temp = '低'
            break
          default:
            temp = '标准'
        }
        return temp
      }
    },
    {
      title: '耐受能力', minWidth: 90, field: 'standardFlag',
      formatter: (row: any) => {
        return row.standardFlag == 0 ? '否' : '是'
      }
    },
    {
      title: '上限曲线',
      children: [
        { title: '持续时间(ms)', minWidth: '110', field: 'vtcTimeUpper' },
        { title: '暂降幅值(p.u.)', minWidth: '110', field: 'vtcAmpUpper' }
      ]
    },
    {
      title: '下限曲线',
      children: [
        { title: '持续时间(ms)', minWidth: '110', field: 'vtcTimeLower' },
        { title: '暂降幅值(p.u.)', minWidth: '110', field: 'vtcAmpLower' }
      ]
    },
    {
       title: '操作',fixed: 'right',
      align: 'center',
      render: 'buttons',
      width: '140',
      
      buttons: [
        {
          name: 'update',
          title: '编辑',
          type: 'primary',
          icon: 'el-icon-EditPen',
          render: 'basicButton',
          click: row => {
            unitPopup.value.open('修改元器件', row)
          }
        },
        {
          name: 'update',
          title: '删除',
          type: 'danger',
          icon: 'el-icon-Delete',
          render: 'confirmButton',
          popconfirm: {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            confirmButtonType: 'danger',
            title: '确定删除吗？'
          },
          click: row => {
            deleteSgSensitiveUnit(row.id).then(res => {
                ElMessage.success('删除成功')
                tableStore.index()
            })
          }
        }
      ]
    }
  ],
  beforeSearchFun: () => {
    for (let key in tableStore.table.params) {
      if (tableStore.table.params[key] === '') {
        delete tableStore.table.params[key]
      }
    }

  }
})

const getTableData = (tempId: string) => {
  tableStore.table.params.machineId = tempId
  tableStore.index()
}


/**********新增、编辑元器件************/
//新增进线信息
const add = () => {
  const data = {
    machineId: tableStore.table.params.machineId
  }
  unitPopup.value.open('新增元器件', data)
}

provide('tableStore', tableStore)
defineExpose({ getTableData })

</script>

<style >
.unitButton .table-header {
  padding: 5px 15px !important;
}
</style>