<template>
  <div class="page-container row-container">
    <!-- 左侧区域 -->
    <section class="list-part-container">
      <!-- 搜索区域 -->
      <el-form class="list-search-container" :model="queryParams" ref="queryRef" :inline="true">
        <el-form-item label="车间管理" />
        <el-form-item>
          <el-button type="primary" icon="Plus" @click="handleAdd" v-hasPermi="['system:menu:add']">新增</el-button>
        </el-form-item>
      </el-form>
      <!-- 列表区 -->
      <div class="el-table-container">
        <div class="el-table-inner-container">
          <el-table
            v-loading="loading"
            :data="vehicleCategoryList"
            highlight-current-row
            height="100%"
            @selection-change="handleSelectionChange"
            @current-change="handleProcess"
          >
            <el-table-column type="selection" width="40" align="center" />
            <el-table-column label="行号" type="index" width="50" align="center" />
            <el-table-column label="工段名称" prop="name" align="center" />
            <el-table-column label="操作" width="150" align="center">
              <template #default="scope">
                <el-button link type="warning" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:vehicle:edit']">编辑</el-button>
                <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:vehicle:remove']">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </section>

    <!-- 右侧区域 -->
    <section class="list-part-container" style="flex: 2">
      <!-- 搜索区域 -->
      <el-form class="list-search-container" :model="queryParams" ref="queryRef" :inline="true">
        <el-form-item label="周转位置" />
      </el-form>
      <!-- 按钮区域 -->
      <div class="list-btns-container">
        <el-button type="primary" icon="Plus" @click="handleAdd" v-hasPermi="['system:menu:add']">新增</el-button>
      </div>
      <!-- 列表区 -->
      <div class="el-table-container">
        <div class="el-table-inner-container">
          <el-table v-loading="loading" :data="vehicleList" height="100%" @selection-change="handleSelectionChange">
            <el-table-column type="selection" width="40" align="center" />
            <el-table-column label="行号" type="index" width="50" align="center" />
            <el-table-column label="周转位置" prop="position" width="150" align="center" />
            <el-table-column label="备注" prop="remark" align="center" />
            <el-table-column label="操作" width="150" align="center">
              <template #default="scope">
                <el-button link type="warning" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['business:process:edit']">编辑</el-button>
                <!-- <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:process:remove']">删除</el-button> -->
                <el-button link type="info" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['business:process:remove']">废弃</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </div>
    </section>
  </div>
</template>

<script setup name="Process">
import { listProcess, delProcess } from '@/api/business/process'
const { proxy } = getCurrentInstance()
const { vehicle_status } = proxy.useDict('vehicle_status')

/** 查询 对象 */
const vehicleCategoryList = ref([
  {
    name: '工段名称一',
    leaderName: '李四',
    revision: '1',
    vehicleList: [
      { id: 1, status: 0, position: 'D23101128', remark: '外径：20，振摆：0.01，圆度：0.003（无3棱5棱）', code: '005210' },
      { id: 2, status: 1, position: 'D23101128', remark: '外径：20，振摆：0.01，圆度：0.003（无3棱5棱）', code: '005211' }
    ]
  },
  {
    name: '工段名称二',
    leaderName: '张三',
    revision: '1',
    vehicleList: [
      { id: 3, status: 1, position: 'D23101128', remark: '外径：20，振摆：0.01，圆度：0.003（无3棱5棱）', code: '005212' },
      { id: 4, status: 0, position: 'D23101128', remark: '外径：20，振摆：0.01，圆度：0.003（无3棱5棱）', code: '005213' }
    ]
  },
  {
    name: '工段名称三',
    leaderName: '王五',
    revision: '1',
    vehicleList: [
      { id: 5, status: 1, position: 'D23101128', remark: '外径：20，振摆：0.01，圆度：0.003（无3棱5棱）', code: '005211' },
      { id: 6, status: 0, position: 'D23101128', remark: '外径：20，振摆：0.01，圆度：0.003（无3棱5棱）', code: '005212' }
    ]
  }
])
const editStatus = ref(false)
const vehicleList = ref([])
const loading = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
/** 查询对象 */
const queryParams = ref({
  pageNum: 1,
  pageSize: 10,
  code: null,
  name: null
})

/***********************  方法区  ****************************/

/** 查询标准工序管理列表 */
function getList() {
  loading.value = false
  handleProcess(vehicleCategoryList.value[0])
  //   listProcess(queryParams.value).then((response) => {
  //     processList.value = response.rows
  //     total.value = response.total
  //     loading.value = false
  //   })
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}
function unEditStatus() {
  editStatus.value = !editStatus.value
}
/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm('queryRef')
  handleQuery()
}
const getRowKey = (row) => {
  return row.id
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map((item) => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  proxy.$refs.processRef.open()
}
/**工艺名称表点击事件 */
function handleProcess(row) {
  console.log(row)
  vehicleList.value = row.vehicleList
}
/** 修改按钮操作 */
function handleUpdate(row) {
  const id = row.id || ids.value
  proxy.$refs.processRef.open(id)
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal
    .confirm('是否确认删除选中的数据项？')
    .then(function () {
      return
    })
    .then(() => {
      getList()
      proxy.$modal.msgSuccess('删除成功！')
    })
    .catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download(
    'business/process/export',
    {
      ...queryParams.value
    },
    `process_${new Date().getTime()}.xlsx`
  )
}

onMounted(() => {
  getList()
})
</script>
<style scoped>
.move-handle {
  cursor: move;
  background-color: #eee;
}
</style>
