<template>
  <div class="ma-content-block">
    <sa-table
      ref="crudRef"
      :options="options"
      :columns="columns"
      :searchForm="searchForm"
    >
      <template #tableSearch>
        <a-col :sm="6" :xs="24">
          <a-form-item label="订单号" field="order_id">
            <a-input
              v-model="searchForm.order_id"
              placeholder="请输入订单号"
              allow-clear
            />
          </a-form-item>
        </a-col>
        <a-col :sm="6" :xs="24">
          <a-form-item label="状态" field="status">
            <a-select
              v-model="searchForm.status"
              placeholder="请选择状态"
              allow-clear
            >
              <a-option value="0">未发货</a-option>
              <a-option value="1">发放中</a-option>
              <a-option value="2">已发货</a-option>
              <a-option value="3">已拒绝</a-option>
            </a-select>
          </a-form-item>
        </a-col>
        <a-col :sm="6" :xs="24">
          <a-form-item label="申请类型" field="resend_type">
            <a-select
              v-model="searchForm.resend_type"
              placeholder="请选择申请类型"
              allow-clear
            >
              <a-option value="1">人工</a-option>
              <a-option value="2">自动</a-option>
            </a-select>
          </a-form-item>
        </a-col>
      </template>
      <!-- 操作前 -->
      <template #operationCell="{ record }">
        <a-button
          type="primary"
          size="mini"
          v-if="record.status === 0"
          @click="handleAudit(record)"
          >审核</a-button
        >
      </template>
    </sa-table>
    <!-- 审核表单弹框 -->
    <audit-form ref="auditRef" @success="refresh" />
  </div>
</template>

<script setup>
import { ref, reactive, onMounted } from "vue";
import AuditForm from "./edit.vue";
import api from "../../api/customer/sdkOrder";

const auditRef = ref();
const crudRef = ref();

const searchForm = ref({
  order_id: "",
  status: "",
  resend_type: "",
});

const options = reactive({
  api: api.getReissueAuditList,
  pk: "id",
  rowSelection: { showCheckedAll: true },
  showSort: false,
});

const columns = reactive([
  {
    title: "订单号",
    dataIndex: "order_id",
  },
  {
    title: "申请类型",
    type: "dict",
    dict: "resend_type",
    dataIndex: "resend_type",
  },
  {
    title: "状态",
    type: "dict",
    dict: "resissue_status",
    dataIndex: "status",
  },
  {
    title: "申请时间",
    dataIndex: "create_time",
    width: 160,
  },
  {
    title: "申请人",
    dataIndex: "created_user_name",
  },
  {
    title: "审批人",
    dataIndex: "update_user_name",
  },

  {
    title: "补单异常描述",
    dataIndex: "error",
  },
  {
    title: "更新时间",
    width: 160,
    dataIndex: "update_time",
  },
]);

const handleAudit = (record) => {
  auditRef.value.open("audit");
  auditRef.value.setFormData(record);
};

onMounted(() => {
  refresh();
});

// 刷新表格
const refresh = () => {
  crudRef.value.refresh();
};
</script>
