<!--
 * @Company: 沈阳信诚科技
 * @Email: html_venustar@163.com
 * @Author: Liuqiming
 * @Description: 设备坐标设定
 * @LastEditors: Liuqiming
 * @LastEditTime: 2024-03-18 14:37:32
 * @Date: 2024-03-18 12:30:23
-->
<template>
    <div class="app-container">
      <els-table
        :columns="columns"
        :tableData="tableData"
        :searchList="searchList"
        @getTableData="getTableData"
        :option="tableOption"
        :tableLoading="tableLoading"
      ></els-table>
    </div>
</template>

<script setup name="Coordinate">
import { init } from './index.jsx'
import { equipmentList, equipmentEdit } from "@/api/produce/coordinate.js";
const { proxy } = getCurrentInstance();
const tableLoading = ref(false)
//表单数据
const tableData = ref([])
const tempTableData = ref([])
//表单接口请求
const getTableData = (searchVal) => {
  tableLoading.value = true
  equipmentList(searchVal).then(res=>{
    tableData.value = res.rows
    tableData.value = tableData.value.map(item => {
      if (item.dataType === 0) {
        return {...item, equipmentCoordinate: parseFloat(item.equipmentCoordinate), is_edit: false}
      } else {
        return {...item, is_edit: false}
      }
    })
    tempTableData.value = tableData.value
    tableLoading.value = false
  }).catch(err=>{console.log(err)})
}
// 编辑
const edit = (row) => {
  cancel(row)
  tableData.value = tableData.value.map(item => {
    if (row.id === item.id) {
      return {...item, is_edit: true}
    } else {
      return {...item, is_edit: false}
    }
  })
}
// 保存
const save = (row) => {
  tableLoading.value = true
  equipmentEdit(row).then(res => {
    proxy.$modal.msgSuccess(res.msg)
    getTableData({ pageSize:30, pageNum:1 })
  }).catch(err=>{console.log(err)})
}
// 取消
const cancel = (row) => {
  tableData.value = tableData.value.map(item => {
    return {...item, is_edit: false}
  })
  tableData.value = tempTableData.value
}
getTableData({ pageSize:30, pageNum:1 })
const {
  searchList,
  columns,
  tableOption
} = init({ edit, save, cancel })
</script>

<style lang="scss" scoped>

</style>
