<template>
  <div>
    <crud-template ref="crudRef" class="as-weight" :submit-state="false" :home-data="field" :tableData="tableData"
      @btnSearch="btnSearch" @CurrentChange="handleCurrentChange" @importData="importData" @download="downloadHandle"
      @refreshLeft="refreshLeft" @add="Adds" @cancel="cancel" @submit="submitAdd" @handleEdit="itemEdit">
      <template #search>
        <el-input maxlength="60" v-trim clearable v-model="searchForm.batchNo" style="width: 200px" placeholder="请输入批次号" />
        <el-input maxlength="60" v-trim clearable v-model="searchForm.serialNo" style="width: 200px" placeholder="请输入合同序列号" />
<!--        <el-input maxlength="60" v-trim clearable v-model="searchForm.startSerialNo" style="width: 200px" placeholder="请输入起始OBU合同序列号" />-->
<!--        <el-input maxlength="60" v-trim clearable v-model="searchForm.endSerialNo" style="width: 200px" placeholder="请输入结束OBU合同序列号" />-->
        <el-select maxlength="60" v-trim clearable v-model="searchForm.encryptType" style="width: 200px" placeholder="请选OBU择类型" >
          <el-option v-for="item in ENCRYPT_TYPE" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
        <el-select maxlength="60" v-trim clearable v-model="searchForm.status" style="width: 200px" placeholder="请选择发行状态" >
          <el-option v-for="item in ISSUE_STATUS" :key="item.value" :label="item.label" :value="item.value"/>
        </el-select>
<!--        <el-input maxlength="60" v-trim clearable v-model="searchForm.formatTime" style="width: 200px" placeholder="请输入格式化日期" />-->
<!--        <el-input maxlength="60" v-trim clearable v-model="searchForm.lastUpdateTime" style="width: 200px" placeholder="请输入最后修改日期" />-->
      </template>
    </crud-template>
  </div>
</template>
<script setup lang="ts">
import { ref, onMounted } from 'vue'
// @ts-ignore crudFrom模板
import CrudTemplate from '@/crud/index.vue'
import BaseService from '@/utils/baseService' //引入接口请求
import {
  ElMessage,
} from 'element-plus' //提示
import { getZxqdFindConfig,ISSUE_STATUS,ENCRYPT_TYPE } from "./data.js";
import { useRoute } from 'vue-router'
import { exportFn } from '@/views/settlement/exportFn'
//或取路由传入过来的对象数据
const route = useRoute()
const widthBase = '120px';
const crudRef = ref()
let tableData: any = ref([])
const itemStartValue = ref("1")
//查询参数
const searchForm = ref({ agencyId: '' })
const agencyIdList = ref([])
const field = ref(getZxqdFindConfig(route, agencyIdList));
onMounted(() => {
  getList()
})

// 导出
function downloadHandle() {
  exportFn('/invw/api/queryGmobus/export', searchForm.value, 'OBU一发')
}
//获取列表
function getList() {
  crudRef.value.tableLoding = true
  let params: any = {
    pageNo: field.value.paging.currentPage,
    pageSize: field.value.paging.pageSize,
  }
  //赋值查询参数
  let searchFormList = { ...searchForm.value }
  for (let key in searchFormList) {
    if (searchFormList[key]) {
      params[key] = searchFormList[key]
    }
  }
  if(searchFormList.status === 0){
    params.status = 0
  }
  BaseService.postN('/invw/api/queryGmobus/page', params).then((res: any) => {
    if (res && res.code === 0) {
      //数据转换
      let bizContent = res.data
      let data = bizContent.result || []
      //数据渲染
      tableData.value = data
      crudRef.value.tableLoding = false
      //分页总数
      field.value.paging.total = bizContent.totalCount
    } else {
      crudRef.value.tableLoding = false
      ElMessage.error(res.message)
    }
  })
}



const Adds = () => {
  itemStartValue.value = 1
}
//表单编辑按钮
function itemEdit(idx: any, row: any) {
  itemStartValue.value = 2
}

// 添加
const submitAdd = (data: any) => {
  request(data, itemStartValue.value)
}

const request = (data: any, type: any) => {
  data.optType = type //操作类型 1新增 2修改 
  BaseService.postN(itemStartValue.value == 1 ? '/userw/wxCar/add' : '/userw/wxCar/update', data).then((res: any) => {
    if (res && res.code === 0) {
      getList()
      crudRef.value.reset();
      crudRef.value.dialogFormVisible = false;
    } else {
      ElMessage.error(res.message)
    }
  })
}
// 删除
const deleteHandle = (index) => {
  addForm.value.locationModels.splice(index, 1)
}
// 搜索按钮
function btnSearch() {
  field.value.paging.currentPage = 1
  getList()
}

//标签分页
function handleClick(tab, event) {
  orderStep.value = tab.props.name
  getList()
}

//分页
function handleCurrentChange(val: number) {
  field.value.paging.currentPage = val
  getList()
}
function handleAvatarSuccess(response: any, row) {

}
// 搜索重置
function refreshLeft() {
  searchForm.value = {}
  getList()
}

// 获取所有渠道
function getAgencyList() {

}

//编辑
function handleEdit() {

}
// 删除
function handleDetele() {

}

// 取消
function cancel() {

}
</script>
<style lang="scss" scoped></style>
