<template>
  <div>
    <div id="order-list">
      <search-module :search="search" :table="table" />
      <table-module :table="table">
        <template #status="{ row }">
          <el-switch
            v-model="row.status"
            :active-value="'online'"
            :inactive-value="'down'"
            size="small"
          />
        </template>
      </table-module>
    </div>
  </div>
</template>

<script lang="ts" setup>
import { initConfig } from './config'

/** 打包 */
const onPack = async (row: any) => {
  handleMessageBox({
    msg: `是否确认打包?`,
    success: api.order.packOrder.post!,
    data: { id: row.id }
  }).then(() => {
    table.value.$onGetData(table.value, 1)
  })
}

// 取消打包
const onCancelPack = (row: any) => {
  handleMessageBox({
    msg: `是否确认取消打包?`,
    success: api.order.unpackOrder.post!,
    data: { id: row.id }
  }).then(() => {
    table.value.$onGetData(table.value, 1)
  })
}

// 妥投
const onFinishDeliver = (row: any) => {
  handleMessageBox({
    msg: `是否确认妥投?`,
    success: api.order.finishDeliver.post!,
    data: { id: row.id }
  }).then(() => {
    table.value.$onGetData(table.value, 1)
  })
}

const router = useRouter()
const onGoDetail = (row: any) => {
  router.push({ path: '/order/detail/index', query: { id: row.id } })
}

/** 初始化页面 */
const ConfigData = initConfig()
const { search, table } = handleInit(ConfigData, api.order.getOrderList.post, [
  onGoDetail,
  onPack,
  onCancelPack,
  onFinishDeliver
])
table.value.$onGetData(table.value, 1)

/** 页面缓存 */
defineOptions({ name: 'OrderList' })
</script>
