<script setup>
import { onMounted, reactive } from 'vue'
import { ref, computed, watch } from 'vue'
import { AiFillRead } from 'vue-icons-plus/ai'
import { ElMessage,ElRadioGroup, ElRadio, } from 'element-plus'
import { Plus } from '@element-plus/icons-vue'
import axios from 'axios'
import { ElMessageBox } from 'element-plus'
import API from '@/util/http'
import moment from 'moment'
// import _ from 'lodash'

//新增退款相关逻辑---------------------------------------------------------------------------
const addRe = ref({
  typeR: '0'
})
//这是获取用户信息的接口，金币退款明细也会用到
const adminData = ref({})
const getAdminData = async function () {
  try {
    const result = await API({ url: '/admin/userinfo', data: {} })
    adminData.value = result
    addRefund.value.adminId = adminData.value.adminId
    console.log('用户信息请求成功', user.value)
    console.log('adminData信息', adminData.value)
  } catch (error) {
    console.log('用户信息请求失败', error)

  }
}
// 精网号去空格
const trimJwCode = () => {
  if (addRefund.value.jwcode) {
    addRefund.value.jwcode = addRefund.value.jwcode.replace(/\s/g, ''); 
  }
}
// 这是添加退款信息的表单
const addRefund = ref({
  updateType: '3',
  allCoin: 0,
  orderCode: '',
  refundGoods: '',
  freeCoin: 0,
  rechargeCoin: 0,
  taskCoin: 0
})
// 取消按钮
const cancel = function () {
  addRefund.value = {}
  addRefund.value.updateType = '3'
  addRefund.value.rechargeCoin = 0
  addRefund.value.freeCoin = 0
  addRefund.value.taskCoin = 0
  addRefund.value.allCoin = 0
  addRe.value.typeR = 0
  addRefund.value.adminId = adminData.value.adminId
}
// 这是添加退款信息的接口
const add = async function () {
  try {
    // 发送POST请求
    const result = await API({ url: '/refund/add', data: addRefund.value })
    if (result.code === 0) {
      ElMessage.error(result.msg)
      return
    }
    console.log('add请求成功', result)
    ElMessage.success('添加成功')
    // 重置表单
    addRefund.value = {}
    addRefund.value.adminId = adminData.value.adminId
    addRefund.value.updateType = '3'
    addRefund.value.allCoin = 0
    addRefund.value.orderCode = ''
    addRefund.value.refundGoods = ''
    addRefund.value.freeCoin = 0
    addRefund.value.rechargeCoin = 0
    addRefund.value.taskCoin = 0
    addRefund.value.typeR = 0
    user.value = {}
  } catch (error) {
    console.log('添加退款请求失败', error)
    // 在这里可以处理错误逻辑，比如显示错误提示等
  }
}
const addBefore = () => {
  Ref.value.validate(async (valid) => {
    if (valid) {
      ElMessageBox.confirm('确认添加？')
        .then(() => {
          add()
          console.log('添加成功')
          addRefund.value.allCoin = 0
          ;(addRefund.value.freeCoin = 0),
            (addRefund.value.rechargeCoin = 0),
            (addRefund.value.taskCoin = 0),
            (addRefund.value = {})
        })
        .catch(() => {
          console.log('取消添加')
        })
    } else {
      //提示
      ElMessage({
        type: 'error',
        message: '请检查输入内容'
      })
    }
  })
}

// 表单验证
// 开始时间改变时，重新验证结束时间
const Ref = ref(null)
const startChange = (val) => {}

const rules = reactive({
  jwcode: [{ required: true, message: '请输入精网号', trigger: 'blur' }],
  refundType: [{ required: true, message: '请选择退款类型', trigger: 'blur' }],
  orderCode: [{ required: true, message: '请选择退款商品', trigger: 'blur' }],
  taskCoin: [{ required: true, message: '请输入任务金币', trigger: 'blur' },
    {
      validator: (rule, value) => {
        if (value < 0) {
          return Promise.reject(new Error('任务金币至少为0'))
        }
        return Promise.resolve()
      }, 
    }
  ],
  freeCoin: [{ required: true, message: '请输入免费金币', trigger: 'blur' },
    {
      validator: (rule, value) => {
        if (value < 0) {
          return Promise.reject(new Error('免费金币至少为0'))
        }
        return Promise.resolve()
      }, 
    }
  ],
  rechargeCoin: [
    { required: true, message: '请输入永久金币', trigger: 'blur' },
    {
      validator: (rule, value) => {
        if (value < 0) {
          return Promise.reject(new Error('永久金币至少为0'))
        }
        return Promise.resolve()
      }, 
    }
  ],
  allCoin: [
    { required: true, message: '请选择付款方式', trigger: 'blur' },
    {
      validator: (rule, value) => {
        if (value === 0) {
          return Promise.reject(new Error('总金币不能为0'))
        }
        return Promise.resolve()
      },
      trigger: 'blur'
    }
  ]
})

// 查找客户信息的方法
const user = ref({
  firstRechargeTime: ''
})
const getUser = async function (jwcode) {
  trimJwCode();
  try {
    // 发送POST请求
    const result = await API({
      url: '/recharge/user',
      data: {
        jwcode: addRefund.value.jwcode,
        area: adminData.value.area
      }
    })
    console.log('请求成功', result)

    //在此处错误逻辑的提示做了注释，在后续商品查询接口返回错误时，提示信息会显示在弹窗中
    if (result.code === 0) {
      
      //ElMessage.error(result.msg)
    } else {
      user.value = result.data
      user.value.A =
        Number(user.value.pendingRechargeTimes) +
        Number(user.value.pendingSpendTimes)
      console.log('用户信息', user.value)
      //ElMessage.success(result.msg)
    }
  } catch (error) {
    console.log('用户信息请求失败', error)
    ElMessage.error('查询失败，请检查精网号是否正确')
  }
}
const calculatedAllGold = computed(() => {
  const sum =
    Number(addRefund.value.freeCoin) +
    Number(addRefund.value.rechargeCoin) +
    Number(addRefund.value.taskCoin)
  return !isNaN(sum) ? sum : 0
})

watch(calculatedAllGold, (newVal) => {
  addRefund.value.allCoin = newVal
})

const AAA = computed(() => {
  return addRefund.value.jwcode
})

watch(AAA, (newVal) => {})

// 退款类型选项
const refundType = [
  {
    value: '退款商品',
    label: '退款商品'
  }
]

// 根据精网号查询商品
// 查询对应精网号购买过的商品
const goods = ref([])
const getGoods = async function (jwcode) {
  trimJwCode();
  try {
    // 发送POST请求
    const result = await API({
      url: '/consume/getDeatil',
      data: {
        jwcode: addRefund.value.jwcode,
        area: adminData.value.area
      }
    })
    console.log('goods请求成功', result)

    if (result.code === 0) {
      ElMessage.error(result.msg)
    } else {
      // 存储表格数据
      goods.value = result.data
      console.log('用户信息', goods.value)
      ElMessage.success(result.msg)
    }
  } catch (error) {
    console.log('商品goods请求失败', error)
    ElMessage.error('商品查询失败')
    // 在这里可以处理错误逻辑，比如显示错误提示等
  }
}
const calculatedRechargeGoods = computed(() => {
  return (
    +addRefund.value.freeCoin +
    +addRefund.value.rechargeCoin +
    +addRefund.value.taskCoin
  )
})
watch(calculatedRechargeGoods, (newVal) => {
  addRefund.value.allCoin = newVal
})
watch(calculatedRechargeGoods, (newVal) => {
  addRefund.value.allCoin = newVal
  console.log('计算的总金币', newVal)
})

// 绑定两个数据

// 这是根据订单号查询消费信息的方法
const getProductByOrderCode = async function (item) {
  try {
    // 发送POST请求
    const result = await API({
      url: '/refund/searchByOrderCode?orderCode=' + item,
      data: {}
    })
    addRefund.value.contactId = result.data.detailyId
    addRefund.value.refundGoods = result.data.productName
    addRefund.value.orderCode = result.data.orderCode
    addRefund.value.taskCoin = (result.data.taskCoin * -1) / 100
    addRefund.value.freeCoin = (result.data.freeCoin * -1) / 100
    addRefund.value.rechargeCoin = (result.data.rechargeCoin * -1) / 100
    addRefund.value.allCoin =
      (result.data.taskCoin * -1 +
        result.data.freeCoin * -1 +
        result.data.rechargeCoin * -1) /
      100
    console.log('addRefund请求成功', addRefund.value)
    if (result.data.code === 0) {
      ElMessage.error(result.data.msg)
    } else {
      ElMessage.success('选择成功')
    }
  } catch (error) {
    console.log('精网号查询请求失败', error)
    ElMessage.error('查询失败，请检查精网号是否正确')
    // 在这里可以处理错误逻辑，比如显示错误提示等
  }
}
const handleSelectionChange = (value) => {
  getProductByOrderCode(value)
  console.log('选择的订单号', value)
  const selectedItem = goods.value.find((item) => item.detailId === value)
}


// 金币退款明细相关逻辑----------------------------------------------------------------------
//充值明细表格
const tableData = ref([])
//搜索==================================
//搜索detail
const detail = ref([])
// 搜索对象
const getObj = ref({
  pageNum: 1,
  pageSize: 50
})
//分页总条目
const total = ref(100)
// 搜索对象时间
const getTime = ref([])
// 所有信息
const allData = ref([])
// 搜索地区列表
const area = ref([])

//标签页默认高亮选项
const activeName = ref('all')

//退款类型
const consumeType = [
  {
    value:"退款商品",
    label:"退款商品"
  }
]
// 方法
// 统计合计数
const trueGold = ref(0)
const truePgold = ref(0)
const trueFgold = ref(0)
const trueTgold = ref(0)
// 待审核各种类金币数
const pendingPgold = ref(0)
const pendingFgold = ref(0)
const pendingTgold = ref(0)
// 待审核金币数
const pendingGold = ref(0)
// 已通过各种类金币数
const approvedPgold = ref(0)
const approvedFgold = ref(0)
const approvedTgold = ref(0)
// 已通过金币数
const approvedGold = ref(0)
// 已驳回各种类金币数
const rejectedPgold = ref(0)
const rejectedFgold = ref(0)
const rejectedTgold = ref(0)
// 已驳回金币数
const rejectedGold = ref(0)
// 搜索==============================================================
// 搜索方法
const get = async function (val) {
  try {
    // 地区赋值
    if (adminData.value.area === '泰国') {
      detail.value.areas = ['泰国', '越南']
    } else if (adminData.value.area !== '总部') {
      detail.value.area = adminData.value.area
    }
    // 搜索参数页码赋值
    if (typeof val === 'number') {
      getObj.value.pageNum = val
    }
    // 搜索参数时间赋值
    if (getTime.value != null) {
      if (getTime.value.startDate != '' && getTime.value.endDate != '') {
        detail.value.startDate = getTime.value[0]
        detail.value.endDate = getTime.value[1]
      }
    } else {
      detail.value.startDate = ''
      detail.value.endDate = ''
    }
    // 添加排序字段和排序方式到请求参数
    detail.value.sortField = sortField.value
    detail.value.sortOrder = sortOrder.value
    console.log('搜索参数', getObj.value)
    // 发送POST请求
    const result = await API({
      url: '/refund/search',
      data: {
        ...getObj.value,
        detail: { ...detail.value }
      }
    })
    // 复制一份 detail.value 并移除排序字段和排序方式，这是不同审核状态时使用的参数
    const detailWithoutSort = { ...detail.value }
    delete detailWithoutSort.sortField
    delete detailWithoutSort.sortOrder

    const result2 = await API({
      url: '/refund/RefundA',
      data: {
        ...detailWithoutSort
      }
    })
    // 统计合计数
    if (result2.data) {
      result2.data.forEach((item) => {
        switch (item.status) {
          case '待审核':
            // 若 item.raudit 为空则赋值为 0
            pendingPgold.value = item.sumRaudit1 || 0
            pendingFgold.value = item.sumRaudit2 || 0
            pendingTgold.value = item.sumRaudit3 || 0
            // 若 item.sumRaudit 为空则赋值为 0
            pendingGold.value = item.sumRaudit || 0
            break
          case '已通过':
            approvedPgold.value = item.sumRaudit1 || 0
            approvedFgold.value = item.sumRaudit2 || 0
            approvedTgold.value = item.sumRaudit3 || 0
            approvedGold.value = item.sumRaudit || 0
            break
          case '已驳回':
            rejectedPgold.value = item.sumRaudit1 || 0
            rejectedFgold.value = item.sumRaudit2 || 0
            rejectedTgold.value = item.sumRaudit3 || 0
            rejectedGold.value = item.sumRaudit || 0
            break
        }
      })
    }

    trueFgold.value =
      pendingFgold.value + approvedFgold.value + rejectedFgold.value
    truePgold.value =
      pendingPgold.value + approvedPgold.value + rejectedPgold.value
    trueTgold.value =
      pendingTgold.value + approvedTgold.value + rejectedTgold.value
    trueGold.value = pendingGold.value + approvedGold.value + rejectedGold.value
    // 将响应结果存储到响应式数据中
    //console.log('请求成功', result)
    // 存储表格数据
    tableData.value = result.data.list
    console.log('tableData请求成功', tableData.value)
    // 存储分页总数
    total.value = result.data.total
    console.log('total', total.value)
    // 调用分类的方法
    handleClick()
  } catch (error) {
    console.log('表格数据请求失败', error)

  }
}
//搜索
//每次搜索都执行对应搜索操作，并将页码重置为1
const search = function () {
  getObj.value.pageNum = 1
  get()
}
//重置
const reset = function () {
  detail.value.jwcode = ''
  detail.value.refundGoods = ''
  detail.value.refundType = ''
  detail.value.area = ''
  detail.value.startDate = ''
  detail.value.endDate = ''
  sortField.value = ''
  sortOrder.value = ''
  getTime.value = {}
}
//今天
const getToday = function (){
  const today = new Date()
  const startDate = new Date(
    today.getFullYear(),
    today.getMonth(),
    today.getDate()
  )
  const endDate = new Date(
    today.getFullYear(),
    today.getMonth(),
    today.getDate() + 1
  )
  getTime.value = [startDate, endDate]
  console.log('今天', getTime.value)
  get()
}
//昨天
const getYesterday = function (){
  const yesterday = new Date()
  yesterday.setDate(yesterday.getDate() - 1)
  const startDate = new Date(
    yesterday.getFullYear(),
    yesterday.getMonth(),
    yesterday.getDate()
  )
  const endDate = new Date(
    yesterday.getFullYear(),
    yesterday.getMonth(),
    yesterday.getDate() + 1
  )
  getTime.value = [startDate, endDate]
  console.log('昨天', getTime.value)
  get()
}
//近7天
const get7Days = function (){
  const today = new Date()
  const startDate = new Date(
    today.getFullYear(),
    today.getMonth(),
    today.getDate() - 6
  )
  const endDate = new Date(
    today.getFullYear(),
    today.getMonth(),
    today.getDate() + 1
  )
  getTime.value = [startDate, endDate]
  console.log('近7天', getTime.value)
  get()
}
//全部充值明细 
const adminAll = function () {
  console.log('全部充值明细')
  detail.value.status = ''
  getObj.value.pageNum = 1
  get()
  //计算免费金币、永久金币、任务金币所有审核状态分别的总数以及总金币数
  trueFgold.value = 
    pendingFgold.value + approvedFgold.value + rejectedFgold.value
  truePgold.value = 
    pendingPgold.value + approvedPgold.value + rejectedPgold.value
  trueTgold.value = 
    pendingTgold.value + approvedTgold.value + rejectedTgold.value
  trueGold.value =
    pendingGold.value + approvedGold.value + rejectedGold.value
}
//三个审核状态采用的async和await方法，因为需要等待异步请求结果，才能计算总金币数；
// 而上边的adminAll方法不需要等待异步请求结果，所以采用同步方法。
//待审核充值明细
const adminWait = async function () {
  detail.value.status = 0
  getObj.value.pageNum = 1
  await get()
  console.log('待审核充值明细')
  trueFgold.value = pendingFgold.value
  truePgold.value = pendingPgold.value
  trueTgold.value = pendingTgold.value
  trueGold.value = pendingGold.value
}
//已通过充值明细
const adminPass = async function () {
  detail.value.status = 1
  getObj.value.pageNum = 1
  await get()
  console.log('已通过充值明细')
  trueFgold.value = approvedFgold.value
  truePgold.value = approvedPgold.value
  trueTgold.value = approvedTgold.value
  trueGold.value = approvedGold.value
}
//已驳回充值明细
const adminReject = async function () {
  detail.value.status = 2
  getObj.value.pageNum = 1
  await get()
  console.log('已驳回充值明细')
  trueFgold.value = rejectedFgold.value
  truePgold.value = rejectedPgold.value
  trueTgold.value = rejectedTgold.value
  trueGold.value = rejectedGold.value
}
//点击标签页
// 设置tab.props.name默认为all
const tabName = ref('all')
const handleClick = function (tab, event) {
  if (tab.props.name === 'all') {
    adminAll()
  } else if (tab.props.name === 'wait') {
    adminWait()
  } else if (tab.props.name === 'pass') {
    adminPass()
  } else if (tab.props.name === 'reject') {
    adminReject()
  }
}
//获取地区
const getArea = async function () {
  try {
    const result = await API({url:'/recharge/user/search',data:{}})
    //console.log('地区请求成功', result)
    area.value = result.data
    console.log('地区请求成功', area.value)
  }catch (error) {
    console.log('地区请求失败', error)
    ElMessage.error('获取地区失败')
  }
}

//删除气泡的id标识
const delObj = ref({})
const del  = function (row) {
  delObj.value.detailId = row.detailId
  console.log('delObj', delObj.value)
}
//删除按钮的气泡弹框
const delConfirm = async function () {
  try {
    console.log('delObj', delObj.value)
    // 发送请求POST
    const result = await API({
      url: '/refund/softDelete?detailId=' + delObj.value.detailId,
      data: {}
    })
    //将响应结果存储到响应式数据中
    console.log('气泡弹窗请求成功', result)
    get()
  }catch(error){
    console.log('删除的气泡弹窗请求失败', error)
    ElMessage.error('删除失败')
  }
}

// 查询商品的接口
const allGoods = ref([])
const getAllGoods = async function () {
  try {
    // 发送POST请求
    const result = await API({ url: '/product', data: {} })
    // 将响应结果存储到响应式数据中
    console.log('allGoods请求成功', result)
    // 存储全部数据
    goods.value = result.data
  } catch (error) {
    console.log('商品请求失败', error)
    ElMessage.error('商品查询失败')
  }
}
getAllGoods()

// 验证跳转输入框的数字是否合法，此处待检查是否用上
const checPagekNumber = function () {
  if (typeof parseInt(getObj.value.pageNum) === 'number') {
    console.log('总共有多少页' + Math.ceil(total.value / getObj.value.pageSize))
    if (
      getObj.value.pageNum > 0 &&
      getObj.value.pageNum <= Math.ceil(total.value / getObj.value.pageSize)
    ) {
      getObj.value.pageNum = parseInt(getObj.value.pageNum)
      console.log('输入的数字合法')
      get()
    } else {
      //提示
      ElMessage({
        type: 'error',
        message: '请检查输入内容'
      })
    }
  } else {
    //提示
    ElMessage({
      type: 'error',
      message: '非数字输入内容'
    })
  }
}

//新增排序字段和排序方式
const sortField = ref('')
const sortOrder = ref('')
//处理排序事件
const handleSortChange = (column) => {
  console.log('column',column.prop)
  console.log('column',column.order)
  if(column.prop === 'rechargeCoin'){
    sortField.value = 'recharge_coin'
  } else if(column.prop === 'taskCoin'){
    sortField.value = 'task_coin'
  }else if(column.prop === 'freeCoin'){
    sortField.value = 'free_coin'
  }else if(column.prop === 'createTime'){
    sortField.value = 'create_time'
  }
  sortOrder.value = column.order === 'ascending' ? 'asc' : 'desc'
  get()
}

const handlePageSizeChange = function (val){
  getObj.value.pageSize = val
  get()
}
const handleCurrentChange = function (val){
  getObj.value.pageNum = val
  get()
}

//导出Excel，注意这里是虚拟接口，后端写完后替换正确的地址
const exportExcel = function () {
  window.open('/refund/exportExcel?detail=' + JSON.stringify(detail.value))
}



//切换新增退款和明细逻辑标签---------------------------------------------------------------
// 用于控制显示内容的变量
const activeTab = ref('addRefund')

// 切换标签页的方法
const changeTab = async (tabName) => {
  activeTab.value = tabName
  //切换至detail标签页时，再请求get方法，就不用挂载了，可减轻浏览器压力加快页面加载速度
  if (activeTab.value === 'detail') {
    await get()
  }
}


// 挂载
onMounted(async function () {
  await getAdminData()
  await getArea()
  //await get()
})
</script>

<template>

  <div>
  <el-button-group>
    <!-- 切换后状态显示样式否则是默认样式 -->
      <el-button 
        :type="activeTab === 'addRefund' ? 'primary' : 'default'" 
        @click="changeTab('addRefund')"
      >
        新增退款
      </el-button>
      <el-button 
        :type="activeTab === 'detail' ? 'primary' : 'default'" 
        @click="changeTab('detail')"
      >
        金币退款明细
      </el-button>
    </el-button-group>

  <!-- 根据activeTab切换显示内容 -->
   <!-- 新增退款的布局---------------------------------------------------------- -->
   <div v-if="activeTab === 'addRefund'">
  <!-- <div style="font-weight: bold">新增退款</div> -->

  <el-form
    :model="addRefund"
    ref="Ref"
    :rules="rules"
    label-width="auto"
    style="max-width: 750px"
    class="form-style"
  >
    <el-form-item prop="jwcode" label="精网号">
      <el-input
        v-model="addRefund.jwcode"
        style="width: 220px"
        @change="getGoods(addRefund.jwcode)"
      />
      <el-button
        type="primary"
        @click="getUser(addRefund.jwcode)"
        style="margin-left: 20px"
        >查询</el-button
      >
    </el-form-item>
    <el-form-item prop="refundType" label="退款类型">
      <el-select
        v-model="addRefund.refundType"
        placeholder="请选择"
        style="width: 300px"
      >
        <el-option
          v-for="item in refundType"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
    </el-form-item>
    <el-form-item prop="orderCode" label="商品名">
      <el-select
        v-model="addRefund.orderCode"
        placeholder="请选择"
        style="width: 300px"
        @change="handleSelectionChange"
      >
        <el-option
          v-for="item in goods"
          :key="item.value"
          :label="item.productName + item.orderCode"
          :value="item.orderCode"
        />
      </el-select>
    </el-form-item>

    <el-form-item prop="typeR" label="退款方式:">
      <el-radio-group v-model="addRe.typeR">
        <el-radio value="0" @change="addRe.typeR = '0'">全部退款</el-radio>
        <el-radio value="1">部分退款</el-radio>
      </el-radio-group>
    </el-form-item>

    <div style="display: flex; align-items: center">
      <el-form-item prop="rechargeCoin" label="永久金币" style="float: left">
        <el-input
          v-model="addRefund.rechargeCoin"
          style="width: 100px"
          :disabled="addRe.typeR === '0' ? true : false"
        >
        </el-input>
        <p>个</p>
      </el-form-item>
      <el-form-item
        prop="freeCoin"
        label="免费金币"
        style="margin-left: -20px; float: left"
      >
        <el-input
          v-model="addRefund.freeCoin"
          style="float: left; width: 100px"
          :disabled="addRe.typeR === '0' ? true : false"
        />
        <p>个</p>
      </el-form-item>
      <el-form-item prop="taskCoin" label="任务金币" style="margin-left: -20px">
        <el-input
          v-model="addRefund.taskCoin"
          style="float: left; width: 100px"
          :disabled="addRe.typeR === '0' ? true : false"
        />
        <p>个</p>
      </el-form-item>
    </div>
    <el-form-item prop="allCoin" label="退款金币总数">
      <el-input disabled v-model="addRefund.allCoin" style="width: 100px">
      </el-input>
    </el-form-item>
    <el-form-item prop="remark" label="备注">
      <el-input
        v-model="addRefund.remark"
        style="width: 300px"
        :rows="2"
        maxlength="100"
        show-word-limit
        type="textarea"
      />
    </el-form-item>
    <el-form-item prop="commitName" label="提交人">
      <el-input
        style="width: 300px"
        :value="adminData.name"
        disabled
        placeholder="提交人姓名"
      />
    </el-form-item>
    <el-button type="success" @click="cancel()" style="margin-left: 280px">重置</el-button>
    <el-button type="primary" @click="addBefore"> 提交 </el-button>
  </el-form>

  <!-- 客户信息栏 -->
  <el-card style="width: 850px; float: right" class="customer-info">
    <el-form
      :model="user"
      label-width="auto"
      style="max-width: 1000px"
      label-position="left"
    >
      <el-text size="large" style="margin-left: 20px">客户信息</el-text>
      <el-row style="margin-top: 20px">
        <el-col :span="10">
          <el-form-item label="姓名:">
            <p>{{ user.name }}</p>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="历史金币总数">
            <!-- 检查 user.totalRechargeGold 是否为有效的数字 -->
            <p v-if="!isNaN(Number(user.totalRechargeGold))">
              {{ Number(user.totalRechargeGold / 100) }}
            </p>
            <!-- 如果不是有效的数字，显示默认值 -->
            <p v-else></p>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="精网号">
            <p>{{ user.jwcode }}</p>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="当前金币总数" style="width: 500px">
            <span
              style="color: #2fa1ff; margin-right: 5px"
              v-if="user.buyJb !== undefined"
              >{{
                (user.buyJb + user.free6 + user.free12 + user.coreJb) / 100
              }}</span
            >
            <span
              style="display: inline; white-space: nowrap; color: #b1b1b1"
              v-if="user.buyJb !== undefined"
              >(永久金币:{{ user.buyJb / 100 }};免费金币:{{
                (user.free6 + user.free12) / 100
              }};任务金币:{{ user.coreJb / 100 }})</span
            >
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="首次充值日期">
            <p v-if="user.firstRechargeDate">
              {{ moment(user.firstRechargeDate).format('YYYY-MM-DD HH:mm:ss') }}
            </p>
          </el-form-item>
        </el-col>
        <el-col :span="14">
          <el-form-item label="充值次数">
            <p style="color: #2fa1ff">{{ user.rechargeTimes }}</p>
          </el-form-item>
        </el-col>
        
        <el-col :span="10">
          <el-form-item label="消费次数">
            <p style="color: #2fa1ff">{{ user.spendTimes }}</p>
          </el-form-item>
        </el-col>
        <el-col :span="10">
          <el-form-item label="所属门店">
            <p>{{ adminData.area }}</p>
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
  </el-card>
  </div>


  <!-- 金币退款明细的布局---------------------------------------------------------- -->
  <div v-else-if="activeTab === 'detail'">
      <el-row>
    <el-col>
      <el-card style="margin-bottom: 20px;margin-top:10px">
        <el-row style="margin-bottom: 10px">
          <el-col :span="5">
            <div class="head-card-element">
              <el-text class="mx-1" size="large">精网号：</el-text>
              
              <el-input
                v-model="detail.jwcode"
                placeholder="请输入精网号"
                size="large"
                style="width: 150px"
                clearable
              />
            </div>
          </el-col>
          <el-col :span="6">
            <div class="head-card-element">
              <el-text class="mx-1" size="large">退款类型：</el-text>
              <el-select
                v-model="detail.refundType"
                placeholder="请选择退款类型"
                size="large"
                style="width: 180px"
                clearable
              >
                <el-option
                  v-for="item in consumeType"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                />
              </el-select>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="head-card-element">
              <el-text class="mx-1" size="large">退款商品：</el-text>
              <el-select
                v-model="detail.refundGoods"
                placeholder="请选择退款商品"
                size="large"
                style="width: 180px"
                clearable
                
              >
                <el-option
                  v-for="item in goods"
                  :key="item.value"
                  :label="item.name"
                  :value="item.name"
                />
              </el-select>
            </div>
          </el-col>
          <el-col :span="6">
            <div class="head-card-element" v-if="adminData.area == '总部'">
              <el-text class="mx-1" size="large">所属地区：</el-text>
              <el-select
                v-model="detail.area"
                placeholder="请选择所属地区"
                size="large"
                style="width: 180px"
                clearable
              >
                <el-option
                  v-for="item in area"
                  :key="item"
                  :label="item"
                  :value="item"
                />
              </el-select>
            </div>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="21">
            <div class="head-card-element">
              <el-text class="mx-1" size="large">退款时间：</el-text>
              <el-date-picker
                v-model="getTime"
                type="datetimerange"
                range-separator="至"
                start-placeholder="起始时间"
                end-placeholder="结束时间"
              />
              <el-button style="margin-left: 10px" @click="getToday()"
                >今</el-button
              >
              <el-button @click="getYesterday()">昨</el-button>
              <el-button @click="get7Days()">近7天</el-button>
            
              <el-button type="success" @click="reset()">重置</el-button>
              <el-button type="primary" @click="search()">查询</el-button>
              <el-button type="primary" @click="exportExcel">导出Excel</el-button>
            </div>
          </el-col>
        </el-row>
      </el-card>
    </el-col>
  </el-row>
  <el-row>
    <el-col>
      <el-card>
        <!-- <el-tabs
          v-model="activeName"
          type="card"
          class="demo-tabs"
          @tab-click="handleClick"
        >
          <el-tab-pane label="全部" name="all"></el-tab-pane>
          <el-tab-pane label="待审核" name="wait"></el-tab-pane>
          <el-tab-pane label="已通过" name="pass"></el-tab-pane>
          <el-tab-pane label="已驳回" name="reject"></el-tab-pane>
        </el-tabs> -->

        <div>
          退款金币总数：{{ Math.abs(trueGold) }}，永久金币：{{
            Math.abs(truePgold)
          }}，免费金币：{{ Math.abs(trueFgold) }}，任务金币：{{
            Math.abs(trueTgold)
          }}
        </div>
        <!-- 设置表格容器的高度和滚动样式 -->
        <div style="height: 520px; overflow-y: auto;margin-top:10px">
          <el-table
            :data="tableData"
            style="width: 100%"
            @sort-change="handleSortChange"
            height="520px"
          >
            <el-table-column
              type="index"
              label="序号"
              width="100px"
              fixed="left"
            >
              <template #default="scope">
                <span>{{
                  scope.$index + 1 + (getObj.pageNum - 1) * getObj.pageSize
                }}</span>
              </template>
            </el-table-column>
            <el-table-column
              prop="username"
              label="姓名"
              fixed="left"
              width="100px"
            />
            <el-table-column
              prop="jwcode"
              label="精网号"
              fixed="left"
              width="110px"
            />
            <el-table-column prop="area" label="所属地区" width="110px" />
            <el-table-column prop="refundGoods" label="商品名称" width="100px" />
            <el-table-column prop="refundType" label="退款类型" width="100px" />

            <el-table-column label="退款金币总数" width="110px">
              <template #default="scope">
                {{
                  scope.row.rechargeCoin +
                  scope.row.freeCoin +
                  scope.row.taskCoin
                }}
              </template>
            </el-table-column>
            <el-table-column prop="typeR" label="退款方式" width="110px"/>
            <el-table-column
              prop="rechargeCoin"
              label="永久金币"
              width="110px"
              sortable="“custom”"
            />
            <el-table-column
              prop="freeCoin"
              sortable="“custom”"
              label="免费金币"
              width="110px"
            />
            <el-table-column
              prop="taskCoin"
              sortable="“custom”"
              label="任务金币"
              width="110px"
            />
            <!-- 修改prop为taskGold -->
            <el-table-column
              prop="remark"
              label="退款原因"
              width="160px"
              show-overflow-tooltip
            />
            <el-table-column prop="adminName" label="提交人" width="100px" />
             <!-- <el-table-column prop="status" label="审核状态" width="120px">
              <template #default="scope">
                <span v-if="scope.row.status == 1">
                  <div class="status">
                    <span class="green-dot"></span>
                    <span>已通过</span>
                  </div>
                </span>
                <span v-if="scope.row.status == 0">
                  <div class="status">
                    <span class="grey-dot"></span>
                    <span>待审核</span>
                  </div>
                </span>
                <span v-if="scope.row.status == 2">
                  <div class="status">
                    <span class="red-dot"></span>
                    <span>已驳回</span>
                  </div>
                </span>
              </template>
            </el-table-column> 
            <el-table-column
              prop="reson"
              label="驳回理由"
              width="200px"
              show-overflow-tooltip
            /> -->
            <el-table-column
              prop="createTime"
              sortable="“custom”"
              label="提交时间"
              width="180px"
            >
              <template #default="scope">
                {{ moment(scope.row.createTime).format('YYYY-MM-DD HH:mm:ss') }}
              </template>
            </el-table-column>
            <!-- <el-table-column
              prop="operation"
              label="操作"
              fixed="right"
              width="120px"
            >
              <template #default="scope">
                <el-popconfirm
                  title="确定将此条活动删除吗？"
                  @confirm="delConfirm"
                >
                  <template #reference>
                    <el-button type="primary" text @click="del(scope.row)">
                      删除
                    </el-button>
                  </template>
                  <template #actions="{ delConfirm, cancel }">
                    <el-button size="small" @click="cancel">取消</el-button>
                    <el-button type="primary" size="small" @click="delConfirm">
                      确定
                    </el-button>
                  </template>
                </el-popconfirm>
              </template>
            </el-table-column> -->
          </el-table>
        </div>

        <!-- 分页 -->
        <div class="pagination" style="margin-top: 20px">
          <el-pagination
            background
            :page-size="getObj.pageSize"
            :page-sizes="[5, 10, 20, 50, 100]"
            layout="total, sizes, prev, pager, next, jumper"
            :total="total"
            @size-change="handlePageSizeChange"
            @current-change="handleCurrentChange"
            @jump="checkPageNumber"
          ></el-pagination>
        </div>
      </el-card>
    </el-col>
  </el-row>
    </div>
  </div>
</template>

<style scoped>

.status {
  display: flex;
}

.head-card {
  display: flex;
}

.head-card-element {
  margin-right: 10px;
}

.head-card-btn {
  margin-left: auto;
}
.pagination {
  display: flex;
  margin-top: 20px;
}

p {
  margin: 0px;
}

.el-form-item {
  margin-left: 50px;
}

/* 上传图片的格式 */
.avatar-uploader .avatar {
  width: 50px;
  height: 50px;
  display: block;
}
</style>

<style>
.avatar-uploader .el-upload {
  border: 1px dashed var(--el-border-color);
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  transition: var(--el-transition-duration-fast);
}

.avatar-uploader .el-upload:hover {
  border-color: var(--el-color-primary);
}

.el-icon.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 50px;
  height: 50px;
  text-align: center;
}

.form-style {
  margin-top: 50px;
  max-width: 50%;
  float: left;
}

.form-style2 {
  max-width: 60%;
}

p {
  font-size: 13px;
  transform: scale(1);
}
</style>
