<template>
  <div class="table-container">
    <!-- <vab-page-header description="功能强大的数据表格组件，支持排序、分页、搜索等功能" :icon="['fas', 'table']" title="表格管理" /> -->
    <!-- <vab-query-form> -->
      
      <el-col>
      <el-row style="display: flex;align-items: center;">
  
     <el-form ref="form" :inline="true" :model="queryForm" @submit.native.prevent>
         <vab-query-form-left-panel style="width:130px;">
        <el-button  icon="el-icon-delete" type="primary" @click="handleDelete">导出</el-button> 
      </vab-query-form-left-panel>
       <el-form-item label="查询时间"  style="margin-right:40px;">
            <el-date-picker
               v-model="queryForm.time"
                 unlink-panels
                value-format="yyyy-MM-dd"
               type="daterange"
               range-separator="-"
               start-placeholder="开始日期"
               end-placeholder="结束日期"
                :picker-options="pickerOptions"
            ></el-date-picker>
         </el-form-item>
           <el-form-item label="订单状态"  style="margin-right:40px;">
    <el-select v-model="queryForm.id" placeholder="请选择订单状态">
      <el-option label="未支付" value="1"></el-option>
      <el-option label="已支付" value="2"></el-option>
      <el-option label="已派单" value="3"></el-option>
      <el-option label="服务中" value="4"></el-option>
      <el-option label="已完成" value="5"></el-option>
      <el-option label="已取消" value="6"></el-option>
    </el-select>
  </el-form-item>
   <el-form-item>
            <el-input v-model="queryForm.status_Inquiry" placeholder="输入手机号或订单号查询" />
          </el-form-item>
          <el-form-item>
            <el-button icon="el-icon-search" native-type="submit" type="primary" @click="handleQuery">查询</el-button>
          </el-form-item>
        </el-form>
        </el-row>
  </el-col>
    <el-table
      ref="tableSort"
      v-loading="listLoading"
      :data="list"
      :element-loading-text="elementLoadingText"
      :height="height"
      @selection-change="setSelectRows"
      @sort-change="tableSortChange"
    >
      <!-- <el-table-column  type="selection" width="55" /> -->
      <!-- <el-table-column label="序号"  width="95">
        <template #default="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="订单ID"  prop="订单ID"  />
      <el-table-column align="center" width="180"     label="订单号"        prop="订单号"  />
      <el-table-column align="center" width="120"     label="订单状态"      prop="订单状态"  />
      <el-table-column align="center" label="客户姓名" prop="客户姓名"  /> 
      <el-table-column align="center" width="120"     label="小哇名字"      prop="小哇名字"  />
      <el-table-column align="center" width="120"     label="订单电话"      prop="订单电话"  />
      <el-table-column align="center" width="120"     label="用户电话"      prop="用户电话"  />
      <el-table-column align="center" width="100"     label="省"            prop="省"  />
      <el-table-column align="center" width="100"     label="市"            prop="市"  />
      <el-table-column align="center" width="100"     label="区"            prop="区"  />
      <el-table-column align="center" width="200"     label="地址"          prop="地址"  />
      <el-table-column align="center" width="100"     label="组ID"          prop="组ID"  />
      <el-table-column align="center" width="100"     label="时段ID"        prop="时段ID"  />
      <el-table-column align="center" width="100"     label="车辆ID"        prop="车辆ID"  />
      <el-table-column align="center" width="100"     label="小哇ID"        prop="小哇ID"  />
      <el-table-column align="center" width="180"     label="预约时段"       prop="预约时段"  />
      <el-table-column align="center" width="120"     label="预约日期"       prop="预约日期"  />
      <el-table-column align="center" width="120"     label="订单创建时间"   prop="订单创建时间"  />
      <el-table-column align="center" width="120"     label="订单取消时间"   prop="订单取消时间"  />
      <el-table-column align="center" label="种类"     prop="种类"  />
      <el-table-column align="center" label="重量ID"   prop="重量ID"  />
      <el-table-column align="center" label="重量区间" prop="重量区间"  />
      <el-table-column align="center" label="宠物昵称" prop="宠物昵称"  />
      <el-table-column align="center" label="宠物品种" prop="宠物品种"  />
      <el-table-column align="center" label="抵扣券ID" prop="抵扣券ID"  />
      <el-table-column align="center" label="补款链接" prop="补款链接"  />
      <el-table-column align="center" label="基础洗护" prop="基础洗护"  />
      <el-table-column align="center" width="150"     label="一次性毛巾"    prop="一次性毛巾"  />
      <el-table-column align="center" label="刷牙"     prop="刷牙"  />
      <el-table-column align="center" label="头部修剪" prop="头部修剪"  />
      <el-table-column align="center" label="屁屁修剪" prop="屁屁修剪"  />
      <el-table-column align="center" label="贵宾脚"   prop="贵宾脚"  />
      <el-table-column align="center" label="全身美容" prop="全身美容"  />
      <el-table-column align="center" label="纯手剪"   prop="纯手剪"  />
      <el-table-column align="center" label="去除废毛" prop="去除废毛"  />
      <el-table-column align="center" width="150"     label="开结半小时"     prop="开结半小时"  />
      <el-table-column align="center" width="150"     label="开结1小时"      prop="开结1小时"  />
      <el-table-column align="center" width="150"     label="开结1.5小时"    prop="开结1.5小时"  />
      <el-table-column align="center" width="150"     label="开结2小时"      prop="开结2小时"  />
      <el-table-column align="center" width="150"     label="局部"           prop="局部"  />
      <el-table-column align="center" width="150"     label="全身"           prop="全身"  />
      <el-table-column width="120"    align="center"  label="附加项合计"      prop="附加项合计"  />
      <el-table-column align="center" label="调度费"   prop="调度费"  />
      <el-table-column align="center" label="夜间费"   prop="夜间费"  />
      <el-table-column width="120"    align="center"  label="抵扣券名称"      prop="抵扣券名称"  />
      <el-table-column align="center" label="抵扣金额" prop="抵扣金额"  />
      <el-table-column width="200"    align="center"  label="会员价"         prop="会员价"  />
      <el-table-column width="130"    align="center"  label="是否绑定会员"    prop="是否绑定会员"  />
      <el-table-column align="center" label="折扣"    prop="折扣"  />
      <el-table-column align="center" label="会员首单" prop="会员首单"  />
      <el-table-column align="center" label="订单合计" prop="订单合计"  />
      <el-table-column width="150"    align="center"  label="会员折扣后金额"   prop="会员折扣后金额"  />
      <el-table-column align="center" label="结算金额" prop="结算金额"  />
      <el-table-column width="150"    align="center"  label="订单实际支付价格" prop="订单实际支付价格"  />
      <el-table-column width="120"    align="center"  label="最终支付总额"     prop="最终支付总额"  />
      <el-table-column align="center" width="150"     label="追加一次性毛巾"   prop="追加一次性毛巾"  />
      <el-table-column align="center" label="追加刷牙" prop="追加刷牙"  />
      <el-table-column width="120"    align="center"  label="追加头部修建"     prop="追加头部修建"  />
      <el-table-column width="120"    align="center"  label="追加屁屁修建"     prop="追加屁屁修建"  />
      <el-table-column width="120"    align="center"  label="追加贵宾脚"       prop="追加贵宾脚"  />
      <el-table-column width="120"    align="center"  label="追加全身美容"     prop="追加全身美容"  />
      <el-table-column width="120"    align="center"  label="追加纯手剪"       prop="追加纯手剪"  />
      <el-table-column width="120"    align="center"  label="追加去除废毛"     prop="追加去除废毛"  />
      <el-table-column width="200"    align="center"  label="追加开结半小时"   prop="追加开结半小时"  />
      <el-table-column width="200"    align="center"  label="追加开结1小时"    prop="追加开结1小时"  />
      <el-table-column width="200"    align="center"  label="追加开结1.5小时"  prop="追加开结1.5小时"  />
      <el-table-column width="200"    align="center"  label="追加开结2小时"    prop="追加开结2小时"  />
      <el-table-column width="120"    align="center"  label="追加局部"         prop="追加局部"  />
      <el-table-column width="120"    align="center"  label="追加全身"         prop="追加全身"  />
      <!-- <el-table-column label="头像" >
        <template #default="{ row }">
          <el-image v-if="imgShow" :preview-src-list="imageList" :src="row.img" />
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="点击量" prop="pageViews"  sortable /> -->
      <!-- <el-table-column label="状态" >
        <template #default="{ row }">
          <el-tooltip class="item" :content="row.status" effect="dark" placement="top-start">
            <el-tag :type="row.status | statusFilter">
              {{ row.status }}
            </el-tag>
          </el-tooltip>
        </template>
      </el-table-column> -->
      <!-- <el-table-column label="时间" prop="datetime"  width="200" /> -->
      <el-table-column label="操作"  fixed="right" width="60px">
        <template #default="{ row }">
          <el-button v-if="row.订单状态 == '已派单' || row.订单状态 == '已支付'  " type="text" @click="handleEdit(row)">编辑</el-button>
          <!-- <el-button type="text" @click="handleDelete(row)">删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      :background="background"
      :current-page="queryForm.pageNo"
      :layout="layout"
      :page-size="queryForm.pageSize"
      :total="total"
      @current-change="handleCurrentChange"
      @size-change="handleSizeChange"
    />
    <table-edit ref="edit" />
  </div>
</template>

<script>
  import { doDelete, getList,exportUserOperateAdmin } from '@/api/table'
  import TableEdit from './components/TableEdit'
  import VabPageHeader from '@/components/VabPageHeader'

  export default {
    name: 'ComprehensiveTable',
    components: {
      TableEdit,
      VabPageHeader,
    },
    filters: {
      statusFilter(status) {
        const statusMap = {
          published: 'success',
          draft: 'gray',
          deleted: 'danger',
        }
        return statusMap[status]
      },
    },
    data() {
      return {
          pickerOptions: {
          shortcuts: [{
            text: '最近一周',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 7);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近一个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 30);
              picker.$emit('pick', [start, end]);
            }
          }, {
            text: '最近三个月',
            onClick(picker) {
              const end = new Date();
              const start = new Date();
              start.setTime(start.getTime() - 3600 * 1000 * 24 * 90);
              picker.$emit('pick', [start, end]);
            }
          }]
        },
        imgShow: true,
        list: [],
        imageList: [],
        listLoading: true,
        layout: 'total, sizes, prev, pager, next, jumper',
        total: 0,
        background: true,
        selectRows: '',
        elementLoadingText: '正在加载...',
        queryForm: {
          pageNo: 1,
          pageSize: 20,
          title: '',
        },
        timeOutID: null,
      }
    },
    computed: {
      height() {
        return this.$baseTableHeight()
      },
    },
    created() {
      this.fetchData()
    },
    beforeDestroy() {
      clearTimeout(this.timeOutID)
    },
    mounted() {},
    methods: {
      tableSortChange() {
        const imageList = []
        this.$refs.tableSort.tableData.forEach((item, index) => {
          imageList.push(item.img)
        })
        this.imageList = imageList
      },
      setSelectRows(val) {
        this.selectRows = val
      },
      handleAdd() {
        this.$refs['edit'].showEdit()
      },
      handleEdit(row) {
        // console.log(row,'---')
        this.$refs['edit'].showEdit(row)
      },
      handleDelete() {
        exportUserOperateAdmin().then(
  response => {
     window.location.href = response.data.url;  
    // const url = window.URL.createObjectURL(new Blob([response.data])) // 创建下载链接
    // const link = document.createElement('a')
    // link.href = url
    // link.download = '全文导入模板.xlsx' // 设置文件名
    // document.body.appendChild(link)
    // link.click() // 触发下载
    // document.body.removeChild(link) // 下载后移除元素
  }
).catch(error => {
  console.error('下载失败', error)
  this.loading = false // 停止加载，隐藏加载状态
})
      
      },
      handleSizeChange(val) {
        this.queryForm.pageSize = val
        this.fetchData()
      },
      handleCurrentChange(val) {
        this.queryForm.pageNo = val
        this.fetchData()
      },
      handleQuery() {
        this.queryForm.pageNo = 1
        this.fetchData()
      },
      async fetchData() {
        this.listLoading = true
        const { data, total } = await getList(this.queryForm)
        this.list = data
        const imageList = []
        data.forEach((item, index) => {
          imageList.push(item.img)
        })
        this.imageList = imageList
        this.total = total
        this.timeOutID = setTimeout(() => {
          this.listLoading = false
        }, 500)
      },
      testMessage() {
        this.$baseMessage('test1', 'success')
      },
      testALert() {
        this.$baseAlert('11')
        this.$baseAlert('11', '自定义标题', () => {
          /* 可以写回调; */
        })
        this.$baseAlert('11', null, () => {
          /* 可以写回调; */
        })
      },
      testConfirm() {
        this.$baseConfirm(
          '你确定要执行该操作?',
          null,
          () => {
            /* 可以写回调; */
          },
          () => {
            /* 可以写回调; */
          }
        )
      },
      testNotify() {
        this.$baseNotify('测试消息提示', 'test', 'success', 'bottom-right')
      },
    },
  }
</script>
