<template>
    <div class="default-main ">
        <el-alert class="ba-table-alert" v-if="baTable.table.remark" :title="baTable.table.remark" type="info"
                  show-icon/>
        <el-row>
            <el-col :span="24">

                <!-- 表格顶部菜单 -->
                <TableHeader :buttons="['refresh', 'add', 'edit', 'delete', 'comSearch']"
                             quick-search-placeholder="通过标题模糊搜索"
                             @action="baTable.onTableHeaderAction"/>
                <!-- 表格 -->
                <!-- 要使用`el-table`组件原有的属性，直接加在Table标签上即可 -->
              <Table @action="baTable.onTableAction">
              </Table>

            </el-col>
        </el-row>

        <!-- 表单 -->
        <PopupForm ref="formRef"/>

    </div>
</template>

<script setup lang="ts">
import {ref, onMounted, provide} from 'vue'
import {map} from '/@/api/controllerUrls'
import Table from '/@/components/table/index.vue'
import TableHeader from '/@/components/table/header/index.vue'
import {defaultOptButtons} from '/@/components/table'
import PopupForm from './popupForm.vue'
import {baTableApi} from '/@/api/common'
import baTableClass from '/@/utils/baTable'


//重写baTableClass类，在获取编辑行数据的同时，将数据抛出，用于进行后续数据请求
class newBaTable extends baTableClass{

  public mapInfo = ref({})

  requestEdit = (id: string) => {
    if (this.runBefore('requestEdit', {id}) === false) return
    this.form.loading = true
    this.form.items = {}
    return this.api
      .edit({
        id: id,
      })
      .then((res) => {
        this.form.loading = false
        // this.form.items =  Object.assign(res.data.row, this.form.defaultItems)
        this.form.items = res.data.row
        if (res.data.row.hasOwnProperty('status')) {
          this.form.items!.status = res.data.row.status + ''
        }
        this.mapInfo.value = res.data.row
        this.runAfter('requestEdit', {res})

      })
  }
}


const baTable = new newBaTable(
    new baTableApi(map),
    {
        dblClickNotEditColumn: [undefined, 'status'],
        column: [
            {type: "selection", align: "center", operator: false },
          { label: "所在区县", prop: "districtName", align: "left", "min-width": "150", operator: "LIKE" },
          { label: "小区名称", prop: "communityName", align: "left", "min-width": "150", operator: "LIKE" },
          { label: "地图名称", prop: "mapName", align: "left", "min-width": "150", operator: "LIKE" },
          { label: "关联楼号", prop: "buildingName", align: "left", "min-width": "150", operator: "LIKE" },
          { label: "创建人", prop: "creatorName", align: "center", width: "120", operator: false },
          { label: "创建时间", prop: "createTime", align: "center", width: "180", operator: false },
            {
                label: '操作',
                align: 'center',
                width: '160',
                render: 'buttons',
                buttons: defaultOptButtons(),
                operator: false
            },
        ],
    },
    {
        defaultItems: {},
    },
    {
        // 获得编辑数据后
        requestEdit: () => {
            if (baTable.form.items && !baTable.form.items.icon) baTable.form.items.icon = 'el-icon-Minus'
        },
    },

)

provide('baTable', baTable)

onMounted(() => {
    baTable.mount()
    baTable.getIndex()
})
</script>


<style scoped lang="scss"></style>
