<template>
  <order-page ref="pageRef" :pageConfig="pageConfig">
    <template #toolbar>
      <el-button
        type="warning"
        plain
        class="ele-btn-icon"
        v-permission="'recycleOrder:search:batchAudit'"
        @click="handleBatchAudit"
      >
        批量初审
      </el-button>
      <el-button
        type="success"
        plain
        class="ele-btn-icon"
        :icon="DownloadOutlined"
        v-permission="'recycleOrder:search:batchAuditComplete'"
        @click="handleBatchAuditComplete"
      >
        批量审核完成
      </el-button>
    </template>

    <template #action="{ row }">
      <div>
        <el-button
          type="success"
          link
          v-permission="'recycleOrder:search:detail'"
          @click="toOrderDetail(row)"
        >
          [订单详情]
        </el-button>
        <el-button
          type="warning"
          link
          v-permission="'recycleOrder:search:log'"
          @click="openOrderLog(row)"
        >
          [订单日志]
        </el-button>
        <el-button
          type="danger"
          link
          v-permission="'recycleOrder:search:cancel'"
          @click="cancelOrder(row)"
        >
          [取消订单]
        </el-button>
        <el-button
          type="primary"
          link
          v-permission="'recycleOrder:search:fallback'"
          @click="fallbackOrder(row)"
        >
          [回退状态]
        </el-button>
        <el-button
          type="success"
          link
          v-permission="'recycleOrder:search:materialPickup'"
          @click="materialPickup(row)"
        >
          [确认收货]
        </el-button>
        <el-button
          type="warning"
          link
          v-permission="'recycleOrder:search:userTag'"
          @click="openEditUserTag(row)"
        >
          [用户标签]
        </el-button>
        <el-button
          type="success"
          link
          v-permission="'recycleOrder:search:sendSMS'"
          @click="handleSendSMS(row)"
        >
          [推送短信]
        </el-button>
        <el-button
          type="info"
          link
          v-permission="'recycleOrder:search:smsLog'"
          @click="handleSmsLog(row)"
        >
          [短信记录]
        </el-button>
      </div>
    </template>

    <order-log ref="orderLogRef" />
    <userBindTag ref="userTagRef" />
    <audit-screenshot ref="auditScreenshotRef"></audit-screenshot>
    <afterSalesPayment ref="paymentRef" />
    <applyforOrderClaim ref="claimRef"></applyforOrderClaim>
    <sendSMS ref="smsRef"></sendSMS>
    <orderSmsLog ref="smsLogRef"></orderSmsLog>
  </order-page>
</template>

<script setup>
  import { ref, reactive } from 'vue';
  import { ElMessageBox } from 'element-plus/es';
  import { EleMessage } from 'ele-admin-plus/es';
  import { DownloadOutlined } from '@/components/icons';
  import OrderPage from '@/views/recycleOrder/components/order-page.vue';
  import { useDictData } from '@/utils/use-dict-data';
  import { useRouter } from 'vue-router';

  //订单日志
  import orderLog from '@/views/recycleOrder/components/order-log.vue';
  //用户标签
  import userBindTag from '@/views/recycleOrder/components/user-bind-tag.vue';
  //推送短信
  import sendSMS from '@/views/recycleOrder/components/send-SMS.vue';
  //短信记录
  import orderSmsLog from '@/views/recycleOrder/components/order-sms-log.vue'

  defineOptions({ name: 'recycleOrderAwaitAudit' });

  let router = useRouter();
  /** 页面组件实例 */
  const pageRef = ref(null);

  const pageConfig = reactive({
    pageUrl: '',
    exportUrl: '',
    fileName: '待审核订单',
    cacheKey: 'awaitAuditTable'
  });

  //批量初审
  function handleBatchAudit() {
    pageRef.value?.operatBatch({
      title: '确认批量初审？',
      url: '/recycleOrder/batchAudit'
    });
  }

  //批量审核完成
  function handleBatchAuditComplete() {
    pageRef.value?.operatBatch({
      title: '确认批量审核完成？',
      url: '/recycleOrder/batchAudit'
    });
  }
  //订单详情
  function toOrderDetail(row) {
    router.push({ path: '/recycleOrder/detail', query: { id: row.postId } });
  }

  //订单日志
  const orderLogRef = ref(null);
  function openOrderLog(row) {
    console.log(row, orderLogRef.value, 'row');

    orderLogRef.value?.handleOpen(row);
  }

  //用户绑定标签
  const userTagRef = ref(null);
  function openEditUserTag(row) {
    userTagRef.value?.handleOpen(row);
  }

  function messageBoxConfirm({ message, url, row }) {
    ElMessageBox.confirm(message, '提示', {
      confirmButtonText: '确定',
      cancelButtonText: '关闭',
      type: 'warning'
    }).then(() => {
      console.log(row, 'row');
    });
  }

  //取消订单
  function cancelOrder(row) {
    messageBoxConfirm({ message: '确认取消?', url: '', row });
  }
  //回退状态
  function fallbackOrder(row) {
    messageBoxConfirm({ message: '确认回退状态?', url: '', row });
  }
  //物流揽件
  function materialPickup(row) {
    messageBoxConfirm({ message: '确认物流揽件?', url: '', row });
  }
  //短信记录
  const smsLogRef = ref(null);
  function handleSmsLog(row) {
    smsLogRef.value?.handleOpen(row);
  }
  //推送短信
  const smsRef = ref(null);
  function handleSendSMS(row) {
    smsRef.value?.handleOpen(row);
  }
</script>
