<template>
  <div class="app-container">
	<!-- 已办待回访 -->

    <div>
      <HyForm v-bind="searchFormConfig" v-model="searchFormData">
        <template #footer>
          <div class="handle-btns">
            <el-button icon="Refresh" @click="closeSearchFormData"
              >重置</el-button
            >
            <el-button type="primary" icon="Search" @click="getListData"
              >搜索</el-button
            >
          </div>
        </template>
      </HyForm>
    </div>

    <div>
      <JyTable
	  	ref="table"
        :loading="loading"
        v-bind="contentTableConfig"
        :rowKey="''"
        :listCount="listCount"
        :listData="dataList"
        v-model:page="pageInfo"
        @update:page="getListData"
      >
        <template #headerHandler>
          <!-- <el-button type="primary" size="default" @click="openModal()">
            添加工单
          </el-button> -->
        </template>

        <template #workordercode="scope">
          <a style="color: blue" @click="openWorkHandle(scope.row)">{{ scope.row['workordercode'] }}</a>
        </template>

        <template #source="scope">
          <div>
            {{ `${scope.row['source']}（${scope.row['projectname']}）` }}
          </div>
        </template>

        <template #workorderstatename="scope">
          <!-- <div
            style="color: red"
            v-if="scope.row['workorderstatename'] !== '已完成'"
          >
            {{ scope.row['workorderstatename'] }}
          </div>
          <div style="color: green" v-else>
            {{ scope.row['workorderstatename'] }}
          </div> -->
          <el-tag
								v-if="scope.row.workorderstatename"
                effect="plain"
                :type="tagTypeFn(scope.row.workorderstatename)"
              >{{ scope.row.workorderstatename }}</el-tag>
        </template>

        <template #handler="scope">  
            <el-button type="primary" text size="small" @click="thDis = true">退回</el-button> 
        </template>
      </JyTable>
    </div>

    <!-- 弹出框 -->
    <div> 
		<reasonModal  
			v-model:dialogVisible="thDis" 
			@submit="thFn"
		></reasonModal>
    </div>
  </div>
</template>

<script setup name="WaitForReturnVisit">
import { ref, getCurrentInstance } from 'vue'

import HyForm from '@/base-ui/form'
import JyTable from '@/base-ui/table'
import JyForm from '@/base-ui/form'

import reasonModal from '@/components/workOrder/reasonModal'

import { searchFormConfig } from './config/search.config'
import { contentTableConfig } from './config/content.config'
import { modalConfig } from './config/modal.config'

import { Link, User, Search } from '@element-plus/icons-vue'

import { getToken } from '@/utils/auth'
import { tagTypeFn } from '@/utils/index'

import { useRouter } from 'vue-router'
const router = useRouter();
  
import {
  getPageListData,
  deletePageData,
  createPageData,
  editPageData
} from '@/api/main/system/system'

const { proxy } = getCurrentInstance() 

const table = ref('')

// 表格数据
const dataList = ref([])
// 表格loading
const loading = ref(false)

// 分页数据
const pageInfo = ref({ currentPage: 1, pageSize: 10 })
const listCount = ref(0)
  
// 搜索数据
const searchFormData = ref({}) 

const thDis = ref(false)





// 获取列表
const getListData = (() => {
	return (function fn(page) {
		dataList.value = []
		loading.value = true

		let params = {
			...searchFormData.value,
			pageNum: page?.currentPage || pageInfo.value.currentPage,
			pageSize: page?.pageSize || pageInfo.value.pageSize,
			listType : 4,
			// listType : 0,

		}
		getPageListData('/order/workorder', params).then(({ data, total }) => {
			dataList.value = data
			listCount.value = total
			loading.value = false
		})
		return fn
	})()
})()
 
// 重置搜索框
function closeSearchFormData() {
  searchFormData.value = {}
  getListData()
}
 
// 详情
function openWorkHandle(rowData) {  
 
	let query = {
		workordercode : rowData.workordercode,
		type : 'ybdhf'
	}

	sessionStorage.setItem('workQuery', JSON.stringify(query))

	router.push({ path : '/workHandle' }) 
}

// 退回
function thFn (data){
	let rowData = table.value.rowData

	createPageData(`/order/workorder/backtoaudit/${rowData.workorderId}` , data).then(data=>{
		proxy.$modal.msgSuccess(data.message);
		getListData()
	})
}
 
</script>

<style scoped lang="scss">
	.header {
		color: red;
	}

	.handle-btns {
		text-align: right;
		padding: 0 15px 20px 0;
	}

	.czButt {
		button {
			margin: 0;
		}
	}
</style>
