<template>
    <div>
      <div class="app-container" style="margin-bottom: 12px;padding-bottom: 5px;border-radius: 10px;">
        <el-form
          ref="querform" 
          :model="queryParams" 
          :inline="true" 
        >
            <el-form-item label="订单号" prop="orderNo">
                <el-input v-model="queryParams.orderNo" placeholder="请输入订单号" clearable />
            </el-form-item>
            <el-form-item label="车牌号" prop="plateNum">
                <el-input v-model="queryParams.plateNum" placeholder="请输入车牌号" clearable />
            </el-form-item>
            <el-form-item label="订单开始时间" prop="orderTimeBegin">
              <el-date-picker
                v-model="queryParams.orderTimeBegin"
                value-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%;" 
                type="datetime"
                placeholder="请选择时间"
              />
            </el-form-item>
            <el-form-item label="订单结束时间" prop="orderTimeEnd">
              <el-date-picker
                v-model="queryParams.orderTimeEnd"
                value-format="YYYY-MM-DD HH:mm:ss"
                style="width: 100%;" 
                type="datetime"
                placeholder="请选择时间"
              />
            </el-form-item>
            <el-form-item label="换电站" prop="stationCode">
                <el-select v-model="queryParams.stationCode" placeholder="请选择换电站" style="width: 200px;">
                    <el-option v-for="n in yunList" :label="n.name" :value="n.code" />
                </el-select>
            </el-form-item>
            <el-form-item label="交易编码" prop="tradeNo">
                <el-input v-model="queryParams.tradeNo" placeholder="请输入交易编码" clearable />
            </el-form-item>
            <el-form-item>
              <el-button type="primary" icon="Search" @click="handBtnqu">搜索</el-button>
              <el-button icon="Refresh" @click="resetQuery">重置</el-button>
            </el-form-item>
          </el-form>
      </div>
      <div class="app-container" style="margin-bottom: 12px;border-radius: 10px;">
        <el-button 
          type="primary" 
          plain 
          icon="Plus" 
          @click="showpop(1)">新增</el-button>
        <el-table 
          style="width:100%;margin-top: 10px;"
          :data="yysList"
          border
          stripe
          max-height="600px"
        >
            <el-table-column label="订单号" min-width="120" align="center" prop="orderNo" :show-overflow-tooltip="true" />
            <el-table-column label="订单类型" min-width="80" align="center" prop="sourceFrom" :show-overflow-tooltip="true">
                <template #default="scope">
                    <div v-if="scope.row.status == 1">换电</div>
                    <div v-else-if="scope.row.status == 2">充电</div>
                </template>
            </el-table-column>
            <el-table-column label="车牌号" min-width="120" align="center" prop="plateNum" :show-overflow-tooltip="true" />
            <el-table-column label="订单时间" min-width="120" align="center" prop="orderTime" :show-overflow-tooltip="true" />
            <el-table-column label="金额账号" min-width="120" align="center" prop="accountCode" :show-overflow-tooltip="true" />
            <el-table-column label="订单金额" min-width="120" align="center" prop="amount" :show-overflow-tooltip="true" />
            <el-table-column label="订单状态" min-width="120" align="center" prop="status" :show-overflow-tooltip="true">
              <template #default="scope">
                <div v-if="scope.row.status == 1">等待受理</div>
                <div v-else-if="scope.row.status == 2">换电中</div>
                <div v-else-if="scope.row.status == 3">换电完成</div>
                <div v-else-if="scope.row.status == 4">出现异常</div>
                <div v-else-if="scope.row.status == 5">未结算</div>
                <div v-else-if="scope.row.status == 6">订单取消</div>
                <div v-else-if="scope.row.status == 7">已结算</div>
              </template>
            </el-table-column>
            <el-table-column label="计费方式" min-width="120" align="center" prop="feeType" :show-overflow-tooltip="true">
              <template #default="scope">
                <div v-if="scope.row.feeType == 1">ODO</div>
                <div v-else-if="scope.row.feeType == 2">SOC</div>
                <div v-else-if="scope.row.feeType == 3">换电量</div>
              </template>
            </el-table-column>
            <el-table-column label="基础费用" min-width="120" align="center" prop="basicFee" :show-overflow-tooltip="true" />
            <el-table-column label="服务开始时间" min-width="120" align="center" prop="serviceTimeBegin" :show-overflow-tooltip="true" />
            <el-table-column label="服务结束时间" min-width="120" align="center" prop="serviceTimeEnd" :show-overflow-tooltip="true" />
            
            <el-table-column label="服务费" min-width="120" align="center" prop="serviceFee" :show-overflow-tooltip="true" />
            <el-table-column label="上次租赁电池时车辆里程" min-width="180" align="center" prop="lastRentBatCarOdo" :show-overflow-tooltip="true" />
            <el-table-column label="归还电池时车辆里程" min-width="150" align="center" prop="nowReturnBatCarOdo" :show-overflow-tooltip="true" />
            
            <el-table-column label="按ODO换电费" min-width="120" align="center" prop="odoAmount" :show-overflow-tooltip="true" />
            <el-table-column label="总充电量" min-width="120" align="center" prop="electAmount" :show-overflow-tooltip="true" />
            <el-table-column label="租借电池包仓位" min-width="120" align="center" prop="rentBatNo" :show-overflow-tooltip="true" />

            <el-table-column label="租用电池包编码" min-width="120" align="center" prop="rentBatCode" :show-overflow-tooltip="true" />
            <el-table-column label="租用电池包SOC" min-width="120" align="center" prop="rentBatSoc" :show-overflow-tooltip="true" />
            <el-table-column label="归还电池包编码" min-width="120" align="center" prop="returnBatCode" :show-overflow-tooltip="true" />
            
            <el-table-column label="归还电池包仓位" min-width="120" align="center" prop="returnBatNo" :show-overflow-tooltip="true" />
            <el-table-column label="归还电池包SOC" min-width="120" align="center" prop="returnBatSoc" :show-overflow-tooltip="true" />
            <el-table-column label="归还电池租出时soc" min-width="150" align="center" prop="returnBatRentSoc" :show-overflow-tooltip="true" />

            <el-table-column label="归还电池租出的换电站" min-width="160" align="center" prop="returnBatRentStationName" :show-overflow-tooltip="true" />
            <el-table-column label="换电模式" min-width="120" align="center" prop="changeMode" :show-overflow-tooltip="true">
              <template #default="scope">
                <div v-if="scope.row.changeMode == 1">全自动</div>
                <div v-else-if="scope.row.changeMode == 2">半自动</div>
                <div v-else-if="scope.row.changeMode == 3">人工干预</div>
              </template>
            </el-table-column>
            <el-table-column label="换电车道" min-width="120" align="center" prop="changeLane" :show-overflow-tooltip="true">
              <template #default="scope">
                <div v-if="scope.row.changeMode == 1">A车道</div>
                <div v-else-if="scope.row.changeMode == 2">B车道</div>
                <div v-else-if="scope.row.changeMode == 3">人工干预</div>
              </template>
            </el-table-column>
            <el-table-column label="交易编码" min-width="120" align="center" prop="tradeNo" :show-overflow-tooltip="true" />
            <el-table-column label="操作" align="center" width="100" fixed="right">
              <template #default="scope">
                <!-- <el-button link type="primary" icon="Edit" @click="showpop(2,scope.row)">修改</el-button> -->
                <el-button link type="danger" icon="Delete" @click="handleDelete(scope.row)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
          <div v-if="total > 10" style="display: flex;justify-content: right;padding-top:20px;">
            <el-pagination
              v-model:current-page="queryParams.pageNo"
              v-model:page-size="queryParams.pageSize"
              :page-sizes="[10, 20, 30, 40]"
              background
              size="small"
              layout="total, sizes, prev, pager, next, jumper"
              :total="total"
              @size-change="handleSizeChange"
              @current-change="getyys"
            />
          </div>
      </div>
  
    
      <!-- 添加或修改配置对话框 -->
        <el-dialog 
          v-model="openpop" 
          :title="ystit" 
          width="850px" 
          append-to-body
          :close-on-click-modal="false"
        >
        
        <el-form ref="yysRef" :model="addata" :rules="rules" label-width="170px">
          <el-row>
            <el-col :span="12">
                <el-form-item label="订单类型" prop="orderType">
                    <el-select v-model="addata.orderType" placeholder="请选择类型">
                        <el-option label="换电" value="1" />
                        <el-option label="充电" value="2" />
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="车主" prop="userId">
                  <el-autocomplete
                    style="width: 100%"
                    v-model="wxuser"
                    :fetch-suggestions="querySearchAsync"
                    placeholder="请输入手机号查询"
                    clearable
                    @blur="autoblur"
                    @select="handleSelect"
                    @clear="autoclear"
                  />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="车牌号" prop="plateNum">
                    <el-input v-model="addata.plateNum" placeholder="请输入车牌号" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="订单时间" prop="orderTime">
                    <el-date-picker
                    v-model="addata.orderTime"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    style="width: 100%;" 
                    type="datetime"
                    placeholder="请选择时间"
                />
                </el-form-item>
            </el-col>  
            <el-col :span="12">
                <el-form-item label="换电站" prop="stationCode">
                    <el-select v-model="addata.stationCode" placeholder="请选择换电站">
                        <el-option 
                          v-for="n in yunList" 
                          :label="n.name" 
                          :value="n.code"
                          @click="getlabel(n.name)" 
                        />
                    </el-select>
                </el-form-item>
            </el-col>
            
            <el-col :span="12">
                <el-form-item label="金额账号" prop="accountCode">
                    <el-input v-model="addata.accountCode" placeholder="请输入金额账号" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="订单金额" prop="amount">
                    <el-input v-model="addata.amount" placeholder="请输入订单金额" clearable />
                </el-form-item>
            </el-col>

            <el-col :span="12">
                <el-form-item label="订单状态" prop="status">
                    <el-select v-model="addata.status" placeholder="请选择状态">
                        <el-option label="等待受理" value="1" />
                        <el-option label="换电中" value="2" />
                        <el-option label="换电完成" value="3" />
                        <el-option label="出现异常" value="4" />
                        <el-option label="未结算" value="5" />
                        <el-option label="订单取消" value="6" />
                        <el-option label="已结算" value="7" />
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="计费方式" prop="feeType">
                    <el-select v-model="addata.feeType" placeholder="请选择计费方式">
                        <el-option label="ODO" value="1" />
                        <el-option label="SOC" value="2" />
                        <el-option label="按电量" value="3" />
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="基础费用" prop="basicFee">
                    <el-input v-model="addata.basicFee" placeholder="请输入基础费用" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="服务开始时间" prop="serviceTimeBegin">
                    <el-date-picker
                    v-model="addata.serviceTimeBegin"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    style="width: 100%;" 
                    type="datetime"
                    placeholder="请选择时间"
                />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="服务结束时间" prop="serviceTimeEnd">
                    <el-date-picker
                    v-model="addata.serviceTimeEnd"
                    value-format="YYYY-MM-DD HH:mm:ss"
                    style="width: 100%;" 
                    type="datetime"
                    placeholder="请选择时间"
                />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="服务费" prop="serviceFee">
                    <el-input v-model="addata.serviceFee" placeholder="请输入服务费" clearable />
                </el-form-item>
            </el-col>

            <el-col :span="12">
                <el-form-item label="上次租赁电池时车辆里程" prop="lastRentBatCarOdo">
                    <el-input v-model="addata.lastRentBatCarOdo" placeholder="请输入里程" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="归还电池时车辆里程" prop="nowReturnBatCarOdo">
                    <el-input v-model="addata.nowReturnBatCarOdo" placeholder="请输入里程" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="按ODO换电费" prop="odoAmount">
                    <el-input v-model="addata.odoAmount" placeholder="请输入换电费" clearable />
                </el-form-item>
            </el-col>

            <el-col :span="12">
                <el-form-item label="总充电量" prop="electAmount">
                    <el-input v-model="addata.electAmount" placeholder="请输入总充电量" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="租借电池包仓位" prop="rentBatNo">
                    <el-input v-model="addata.rentBatNo" placeholder="请输入租借电池包仓位" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="租用电池包编码" prop="rentBatCode">
                    <el-input v-model="addata.rentBatCode" placeholder="请输入租用电池包编码" clearable />
                </el-form-item>
            </el-col>
            
            <el-col :span="12">
                <el-form-item label="租用电池包SOC" prop="rentBatSoc">
                    <el-input v-model="addata.rentBatSoc" placeholder="请输入租用电池包SOC" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="归还电池包编码" prop="returnBatCode">
                    <el-input v-model="addata.returnBatCode" placeholder="请输入归还电池包编码" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="归还电池包仓位" prop="returnBatNo">
                    <el-input v-model="addata.returnBatNo" placeholder="请输入归还电池包仓位" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="归还电池包SOC" prop="returnBatSoc">
                    <el-input v-model="addata.returnBatSoc" placeholder="请输入归还电池包SOC" clearable />
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="归还电池租出时soc" prop="returnBatRentSoc">
                    <el-input v-model="addata.returnBatRentSoc" placeholder="请输入归还电池租出时soc" clearable />
                </el-form-item>
            </el-col>
            <!-- <el-col :span="12">
                <el-form-item label="归还电池租出时soc" prop="returnBatRentSoc">
                    <el-input v-model="addata.returnBatRentSoc" placeholder="请输入归还电池租出时soc" clearable />
                </el-form-item>
            </el-col> -->
            <el-col :span="12">
                <el-form-item label="归还电池租出的换电站" prop="returnBatRentStationCode">
                    <el-select v-model="addata.returnBatRentStationCode" placeholder="请选择换电站">
                        <el-option 
                          v-for="n in yunList" 
                          :label="n.name" 
                          :value="n.code"
                          @click="getlabel(n.name,2)"  
                        />
                    </el-select>
                </el-form-item>
            </el-col>

            <el-col :span="12">
                <el-form-item label="换电模式" prop="changeMode">
                    <el-select v-model="addata.changeMode" placeholder="请选择换电模式">
                        <el-option label="全自动" value="1" />
                        <el-option label="半自动" value="2" />
                        <el-option label="人工干预" value="3" />
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="换电车道" prop="changeLane">
                    <el-select v-model="addata.changeLane" placeholder="请选择换电模式">
                        <el-option label="A车道" value="1" />
                        <el-option label="B车道" value="2" />
                    </el-select>
                </el-form-item>
            </el-col>
            <el-col :span="12">
                <el-form-item label="交易编码" prop="tradeNo">
                    <el-input v-model="addata.tradeNo" placeholder="请输入交易编码" clearable />
                </el-form-item>
            </el-col>
            
          </el-row>
        </el-form>
        <template #footer>
          <div class="dialog-footer">
            <el-button type="primary" @click="handleAdd">确 定</el-button>
            <el-button @click="cancel">取 消</el-button>
          </div>
        </template>
      </el-dialog>
    </div>
  </template>
  <script setup lang="ts" name="UserPage">
        import { 
            gethdzlist
        } from '@/api/swapstation/hdz'

        import { 
            getjqrlist, 
            addhdz, 
            update,
            delhdz
        } from '@/api/order/replabatt'
        import { carNum } from '@/utils/validate'
      //  import { 
      //   getdict
      //  } from '@/api/systemSet/dict'
      import { jsonp } from 'vue-jsonp'
      import { ref,reactive} from 'vue'
      import { ElMessage, ElMessageBox } from 'element-plus'


      let queryParams = reactive({
        pageSize:20,	          //每页条数
        pageNo:1,	              //页数
        orderNo:'',	            //订单编码
        plateNum:'',	          //车牌号
        orderTimeBegin:'',	    //订单时间开始,示例值(yyyy-MM-dd HH:mm:ss)
        orderTimeEnd:'',	      //订单时间结束
        stationCode:'',	        //换电站编码
        stationName:'',	        //换电站名称
        userId:'',	            //换电车主ID
        tradeNo:''              //交易编码
     })
      
      //查询
      let total = ref(0)
      let yysList = ref<any>([])
      function handBtnqu(){
        queryParams.pageNo = 1
        getyys()
      }
      
      //初始查询换电站
      let yunList = ref<any>([])
        gethdzlist({
          pageSize:20,	      //每页条数
          pageNo:1,	          //页数
          proxyId:'',	          //归属运营商ID
          name:'',	          //站点名称
          code:'',	          //站点编码
          status:'',	          //状态：1-正常营业，2-正常停运，3-故障停运，4-指令停运，9-其它
          type:'',	          //站点类型ID
        }).then(rps => {
            if(rps.data){
                let list = (rps.data as any).records
                yunList.value = list?list:[]
                //queryParams.stationCode = list[0].code
                //getyys()
            }
        })
        
      
      let wxuser = ref('')
      //获取微信用户 ?? 暂时调用qq地图接口做个示例
      async function querySearchAsync (queryString: string, cb:any) {
            if(queryString !== ''){
                const url = 'https://apis.map.qq.com/ws/place/v1/suggestion' // 关键字查询??
                    jsonp(url, {
                    key: '3WDBZ-HMUCX-NIE43-ZPLQ4-OOHAO-OKBES', //ZJABZ-FWV6G-F7ZQ2-QKQKL-KQ3I5-DNBT7
                    keyword: queryString,
                    output: 'jsonp',
                }).then((res) => {
                    console.log(res)
                if (res.status == 0) {
                    // mapList.value = res.data;
                    let listss
                    listss = res.data.map((domain:any) => {
                        return {
                            value: domain.title ?`手机号：${domain.title}--昵称：${domain.address}`:domain.address,
                            id: '123456'  //??
                        }
                    })
                    cb(listss)
                    //return listss
                    // callback(mapList.value);
                }else{
                    cb([])
                }
                }).catch(() => {
                    cb([])
                })
            }{
              cb([])
            }
            
        }

      function autoblur() {
        if(addata.userId === ''){
          wxuser.value = ''
        }
      }

      function autoclear() {
        addata.userId = ''
      }

      function handleSelect(v: any) {
        addata.userId = v.id
      }
      function getyys() {
        yysList.value.splice(0)
        getjqrlist(queryParams).then(rps => {
            if(rps.data){
              yysList.value = (rps.data as any).records
              total.value = (rps.data as any).total
            }
        })
      }

      function handleSizeChange(val:number) {
        queryParams.pageSize = val
        getyys()
      }
      
      //重置
      let querform = ref()
      function resetQuery() {
        querform.value?.resetFields()
      }

      
      //新增、修改
      let type = ref(1)
      let openpop = ref(false)
      let ystit = ref('添加电池')
      let yysRef = ref()
      let slecas = ref('')
      let addata = reactive({
        orderType:'',	                            //类型：1-换电，2-充电
        plateNum:'',	                            //车牌号
        orderTime:'',	                            //订单时间,示例值(yyyy-MM-dd HH:mm:ss)
        stationCode:'',	                          //换电站编码
        stationName:'',	                          //换电站名称
        accountCode:'',	                          //金额账号
        amount:'',	                              //订单金额
        status:'',	                              //订单状态：1-等待受理，2-换电中，3-换电完成，4-出现异常，5-未结算，6-订单取消，7-已结算
        feeType:'',	                              //计算费用方式：1-ODO，2-SOC，3-按电量
        basicFee:'',	                            //基础费用
        serviceTimeBegin:'',	                    //服务开始时间
        serviceTimeEnd:'',	                      //服务结束时间
        serviceFee:'',	                          //服务费
        lastRentBatCarOdo:'',	                    //上次租赁电池时车辆里程
        nowReturnBatCarOdo:'',	                  //归还电池时车辆里程
        odoAmount:'',	                            //按ODO换电费
        electAmount:'',	                          //总充电量
        rentBatNo:'',	                            //租借电池包仓位
        rentBatCode:'',	                          //租用电池包编码
        rentBatSoc:'',	                          //租用电池包SOC
        returnBatCode:'',	                        //归还电池包编码
        returnBatNo:'',	                          //归还电池包仓位
        returnBatSoc:'',	                        //归还电池包SOC
        returnBatRentSoc:'',	                    //归还电池租出时soc
        returnBatRentStationCode:'',	            //归还电池租出的换电站编码
        returnBatRentStationName:'',	            //归还电池租出的换电站
        changeMode:'',	                          //换电模式：1-全自动，2-半自动，3-人工干预
        changeLane:'',	                          //换电车道 1-A 车道;2-B 车道
        userId:'123',	                            //换电车主ID
        tradeNo:''	                              //交易编码
      })
      const rules = ref({
        orderType:[
            { required: true, message: "请选择订单类型", trigger: "blur" }
        ],
        // userId:[
        //   { required: true, message: "请选择车主", trigger: "blur" }
        // ],
        plateNum:[
          // { required: true, message: "请输入车牌号", trigger: "blur" },
          { validator:carNum, trigger: "blur"}
        ]
      })

      //获取换电站名称
      function getlabel(n:string,type:number = 1){
        if(type == 1){
          addata.stationName = n
        }else{
          addata.returnBatRentStationCode = n
        }        
      }

      function showpop(num:any,row?:any){
        type.value = num
        openpop.value = true
        ystit.value = num == 1?'添加订单':'修改订单'
        yysRef.value?.resetFields()
        if(row){
          addata.orderType = row.orderType
          addata.plateNum = row.plateNum
          addata.orderTime = row.orderTime
          addata.stationCode = row.stationCode
          addata.stationName = row.stationName
          addata.accountCode = row.accountCode
          addata.amount = row.amount
          addata.status = row.status
          addata.feeType = row.feeType
          addata.basicFee = row.basicFee
          addata.serviceTimeBegin = row.serviceTimeBegin
          addata.serviceTimeEnd = row.serviceTimeEnd
          addata.serviceFee = row.serviceFee
          addata.lastRentBatCarOdo = row.lastRentBatCarOdo
          addata.nowReturnBatCarOdo = row.nowReturnBatCarOdo
          addata.odoAmount = row.odoAmount
          addata.electAmount = row.electAmount
          addata.rentBatNo = row.rentBatNo
          addata.rentBatCode = row.rentBatCode
          addata.rentBatSoc = row.rentBatSoc
          addata.returnBatCode = row.returnBatCode
          addata.returnBatNo = row.returnBatNo
          addata.returnBatSoc = row.returnBatSoc
          addata.returnBatRentSoc = row.returnBatRentSoc
          addata.returnBatRentStationCode = row.returnBatRentStationCode
          addata.returnBatRentStationName = row.returnBatRentStationName
          addata.changeMode = row.changeMode
          addata.changeLane = row.changeLane
          addata.userId = row.userId
          addata.tradeNo= row.tradeNo                    
           
        }else{
          addata.orderType = ''
          addata.plateNum = ''
          addata.orderTime = ''
          addata.stationCode = ''
          addata.stationName = ''
          addata.accountCode = ''
          addata.amount = ''
          addata.status = ''
          addata.feeType = ''
          addata.basicFee = ''
          addata.serviceTimeBegin = ''
          addata.serviceTimeEnd = ''
          addata.serviceFee = ''
          addata.lastRentBatCarOdo = ''
          addata.nowReturnBatCarOdo = ''
          addata.odoAmount = ''
          addata.electAmount = ''
          addata.rentBatNo = ''
          addata.rentBatCode = ''
          addata.rentBatSoc = ''
          addata.returnBatCode = ''
          addata.returnBatNo = ''
          addata.returnBatSoc = ''
          addata.returnBatRentSoc = ''
          addata.returnBatRentStationCode = ''
          addata.returnBatRentStationName = ''
          addata.changeMode = ''
          addata.changeLane = ''
          addata.userId = '123' //??
          addata.tradeNo = ''                  
        }
      }
      function savehand() {
        if(type.value == 1){
            return addhdz(addata)
        }
        return update(addata)
        
      }
      //保存
      function handleAdd() {
        yysRef.value?.validate((valid:Boolean) => {
            if (valid) {
                savehand().then(() => {
                ElMessage({
                    type: 'success',
                    message: type.value == 1?'添加成功':'修改成功'
                })
                setTimeout(()=> {
                    openpop.value = false
                    getyys()
                },600)
            })
            }
        })
      }

    //取消
    function cancel() {
      openpop.value = false
    }

      //删除
    function handleDelete(row:any) {
      ElMessageBox.confirm(
        `确定删除订单：${row.batCode}`,
        '温馨提示',
        {
            // confirmButtonText: '',
            // cancelButtonText: 'Cancel',
            type: 'warning',
        }
      ).then(() => {
        delhdz(row.pkId).then(() => {
            ElMessage({
                type: 'success',
                message: '删除成功'
            })
            getyys()
          })
      })
    }

    getyys()
  </script>
  <style scoped>
  .el-divider--horizontal{
    border-color:#5b98cd;
  }
  </style>