<template>
	<scroll-view style="flex:1">
		<view class="tableTop">
			<u-subsection bg-color="rgb(215,224,233)" button-color="rgb(0,99,208)" active-color="white" :list="list" @change="subChange"></u-subsection>
	<!-- 		<view class="operation">
				<uni-easyinput placeholder="请输入编号"></uni-easyinput>
				<u-button type="primary" size="medium" ripple>查询</u-button>
				<u-button size="medium" ripple @click="getTableList()">刷新</u-button>
			</view> -->
		</view>
		<u-line length="95%" margin="auto" color="#000"/>
		<myTable 
			:column="column" 
			:tableData="tableData"
			:pageCurrent="pageCurrent"
			:pageSize="pageSize"
			:total="total"
			blUrl="/pages/information/information?url=/pages/handleMeeting/handleMeeting"
		>
			<template #action="{row, blUrl}">
				<button class="uni-button" size="mini" type="primary" @click="handleBL(row, blUrl)">办理</button>
				<!-- <button class="uni-button" size="mini" type="warn" @click="handleDel(row)">删除</button> -->
			</template>
		</myTable>
	</scroll-view>
</template>

<script setup>
	import { ref } from 'vue';
	import { onReady, onShow } from"@dcloudio/uni-app"
	import { ApiRequest } from "@/utils/request.js"

	const list = ref([{name: '待办'}, {name: '已办'}, {name: '办结'}])
	const s4 = new SM4Util()
	const currentUrl = ref('')
	const pageCurrent = ref(1)
	const pageSize = ref(15)
	const total = ref(0)
	const jjcdList = ref([])
	const column = ref([])
	const column1 = ref([
		{
			title:"紧急程度",
			key:"FW_WFH.JJCDCAPTION"
		},
		{
			title:"公文种类",
			key:"FLOWNAME"
		},
		{
			title:"标题",
			key:"FW_WFH.BT"
		},
		{
			title:"发文字号",
			key:"FW_WFH.FWZH"
		},
		{
			title:"主办处室",
			key:"FW_WFH.ZS"
		},
		{
			title:"是否已阅",
			key:"FW_WFH.SFXYJDCAPTION"
		},
		{
			title:"操作",
			key:"action"
		}
	])
	const column2 = ref([
		{
			title:"紧急程度",
			key:"JJCD",
			formatter: (val)=>{
				for(let i=0; i<jjcdList.value.length; i++){
					if(jjcdList.value[i].CODE === val){
						return jjcdList.value[i].CNAME
					}
				}
			}
		},
		{
			title:"公文种类",
			key:"FLOWNAME"
		},
		{
			title:"标题",
			key:"TITLE"
		},
		{
			title:"发文字号",
			key:"FWZH"
		},
		{
			title:"主办处室",
			key:"NGRBM"
		},
		{
			title:"上一节点转办时间",
			key:"RECEIVEDATE"
		},
		{
			title:"操作",
			key:"action"
		}
	])
	const column3 = ref([
		{
			title:"紧急程度",
			key:"JJCD"
		},
		{
			title:"公文种类",
			key:"FLOWNAME"
		},
		{
			title:"标题",
			key:"TITLE"
		},
		{
			title:"发文字号",
			key:"FWZH"
		},
		{
			title:"主办处室",
			key:"NGRBM"
		},
		{
			title:"上一节点转办时间",
			key:"RECEIVEDATE"
		},
		{
			title:"操作",
			key:"action"
		}
	])
	const tableData = ref([])
	
	//切换页签
	function subChange(e){
		pageCurrent.value = 1 //重置当前页码
		switch (e){
			case 0: //待办
				column.value = column1.value
				currentUrl.value = '/g2work/routeinfo/queryDataTodoWithPage'
				getTableList()
				break;
			case 1: //已办
				column.value = column2.value
				currentUrl.value = '/g2work/routeinfo/queryDataDoneWithPage'
				getTableList()
				break;
			case 2: //办结
				column.value = column3.value
				currentUrl.value = '/g2work/routeinfo/queryDataFinishWithPage'
				getTableList()
				break;
		}
	}
	
	function getTableList(pageno){
		ApiRequest({
			url: currentUrl.value,
			method: 'POST',
			data:{
				pageno: pageno || pageCurrent.value,
				pagesize: pageSize.value,
				userid: uni.getStorageSync('GlWorkPlatform-userid'),
				querycondition: "[]",
				ordercondition:  "",
				flowid: "AA20|AA03|AA10|AA55|AA56|AA57|AA08|AA23|AA77|AA06",
				columnscondition: '[{"COLID":"JJCD","COLUMNS":"FW_ZSWSXW.JJCD|FW_ZSWPXXW.JJCD|FW_ZB.JJCD|FW_GFXWJXGMRBM.JJCD|FW_WFH.JJCD|FW_SPJ.JJCD|FW_ZRBGHYJY.JJCD|FW_HYJY.JJCD"},{"COLID":"GWZL","COLUMNS":"FW_ZSWSXW.GWZL|FW_ZSWPXXW.GWZL|FW_ZB.GWZL|FW_GWHBGSFW.FWZL|FW_GWHFWGZ.FWZL|FW_GFXWJXGMRBM.GWZL|FW_WFH.GWZL|FW_SPJ.GWZL|FW_ZRBGHYJY.GWZL|FW_HYJY.GWZL"},{"COLID":"FWZH","COLUMNS":"FW_ZSWSXW.FWZH|FW_ZSWPXXW.FWZH|FW_ZB.FWZH|FW_GFXWJXGMRBM.FWZH|FW_WFH.FWZH|FW_SPJ.FWZH|FW_ZRBGHYJY.FWZH|FW_HYJY.FWZH"},{"COLID":"NGRBM","COLUMNS":"FW_ZSWSXW.NGRBM|FW_ZSWPXXW.NGRBM|FW_ZB.NGRBM|FW_GWHBGSFW.NGRBM|FW_GWHFWGZ.NGRBM|FW_GFXWJXGMRBM.NGRBM|FW_WFH.NGRBM|FW_SPJ.NGRBM|FW_ZRBGHYJY.NGRBM|FW_HYJY.NGRBM"},{"COLID":"NGR","COLUMNS":"FW_ZSWSXW.NGR|FW_ZSWPXXW.NGR|FW_ZB.NGR|FW_GWHBGSFW.NGR|FW_GWHFWGZ.NGR|FW_GFXWJXGMRBM.NGR|FW_WFH.NGR|FW_SPJ.NGR|FW_ZRBGHYJY.NGR|FW_HYJY.NGR"}]'
			}
		}).then(res=>{
			if(res.code === 0 && res.success){
				tableData.value = res.data
				total.value = res.meta.totalCount
			}
		})
	}
	
	//更改页码
	function pageChange(val){
		pageCurrent.value = val
		getTableList(val)
	}
	
	function handleBL(row, blUrl){
		console.log(row);
		uni.reLaunch({
			url: blUrl + '&name=' + row.name
		})
	}
	
	function handleDel(row){
		uni.showModal({
			title: "提示",
			content: "再次确认是否删除",
			confirmColor: "#ff1919",
			success: (e)=>{
				if(e.confirm){
					console.log(row);
				}
			}
		})
	}
	
	//获取紧急程度列表
	function getJJCD(){
		ApiRequest({
			url: '/g2app/abase/queryDataCode',
			method: 'POST',
			data: {
				data: s4.encryptData_CBC(JSON.stringify({ckey: "CODE_EMERGENCY", routeinfoid: '0'}))
			}
		}).then(obj=>{
			let res = strToJson(s4.decryptData_CBC(obj.data))
			if(res.code === 0 && res.success){
				jjcdList.value = res.data.CODE_EMERGENCY
			}
		})
	}
	
	onReady(()=>{
		getJJCD() //获取紧急程度列表
		subChange(0) //获取表格
	})
</script>

<style lang="scss" scoped>
	::v-deep .uni-table-scroll{
		margin: 0 50rpx !important;
		width: calc(100vw - 100rpx) !important;
	}
</style>
