<template>
	<view class="container">
		<z-paging ref="paging" v-model="dataList" @query="queryList"  :auto="false">
		<template #top>
			<tui-tabs :tabs="tabsList" :currentTab="currentTab" :height="90" :padding="10" bold :scale="1.1" @change="change"></tui-tabs>
		</template>
		<view class="ul fs-p20">
			<view class="li fs-bg__white fs-p30 fs-size__h4 fs-radius__sm fs-mt20" v-for="(item, index) in dataList">
				<view @click="toDetails(item.problemNo)">
					<view class="fs-flex__between">
						<view>问题单号：{{item.problemNo}}</view>
						<view>紧急程度：
							<tui-text v-if="item.pressingType == 1" type="primary" text="特急"></tui-text>
							<tui-text v-else-if="item.pressingType == 2" type="primary" text="紧急"></tui-text>
							<tui-text v-else-if="item.pressingType == 3" type="primary" text="一般"></tui-text>
						</view>
					</view>
					<view class="fs-flex__between fs-mt16"> 
						<view>
							指派状态：
							<tui-text v-if="item.distributeStatus == 2" text="已指派" type="success"></tui-text>
							<tui-text v-else text="待指派" type="danger"></tui-text>
						</view>
						<view>
							领导确认：
							<tui-text v-if="item.leaderConfrimStatus == 1" text="待确认" type="warning"></tui-text>
							<tui-text v-else-if="item.leaderConfrimStatus == 2" text="已确认" type="success"></tui-text>
							<tui-text v-else-if="item.leaderConfrimStatus == 3" text="已拒绝" type="danger"></tui-text>
						</view>
					</view>
					<view class="fs-mt16">道路名称：{{item.roadName}}</view>
					<view class="fs-mt16 fs-ellipsis__2">问题描述：{{item.remark}}</view>
					<view class="fs-mt16">提交日期：{{item.createTime}}</view>
				</view>
				<view class="fs-mt16 fs-align__right">
					<tui-tag type="primary" padding="12rpx 30rpx" shape="circle" plain @click="toStep(item.problemNo)">处理进度</tui-tag>
					<block v-if="item.leaderConfrimStatus == 2">
						<tui-tag type="primary" padding="12rpx 30rpx" shape="circle" plain margin="0 0 0 20rpx" @click="toCase(item.problemNo)">处理详情</tui-tag>
						<tui-tag v-if="item.userConfrimStatus == 1" type="green" padding="12rpx 30rpx" shape="circle" plain margin="0 0 0 20rpx" @click="openModal(item.problemNo)">确认</tui-tag>
					</block>
				</view>
			</view>
		</view>
		</z-paging>
		<tui-modal :show="showModal" @click="confirm" @cancel="hideModal" content="您确定要完成吗？"></tui-modal>
	</view>
</template>

<script>
import { apiCaseRecord, apiCaseconfirm } from '@/api/work'
export default {
	data() {
		return {
			tabsList: [
				{name: "全部", sign: ""},
				{name: "待确认", sign: 1},
				{name: "已确认", sign: 2},
				{name: "已驳回", sign: 3}
			],
			currentTab: 0,
			dataList: [],
			showModal: false,
			problemNo: ''
		}
	},
	onLoad() {

	},
  onShow(){
    if (this.$refs.paging) {
      this.$refs.paging.refresh() // 重置到第一页并触发query事件
    }
  },
	methods: {
		// 获取记录列表
		queryList(pageNo, pageSize) {
			const params = {
				pageReq: {isAsc: 'desc', orderByColumn: 'id', pageNum: pageNo, pageSize: pageSize},
				userConfrimStatus: this.tabsList[this.currentTab].sign
			}
			apiCaseRecord({data:params}).then(res => {
				this.$refs.paging.complete(res.rows)
			})
		},
		// 切换菜单
		change(e) {
			this.currentTab = e.index
			this.$refs.paging.reload()
		},
		// 打开确认
		openModal(problemNo) {
			this.problemNo = problemNo
			this.showModal = true
		},
		// 取消确认
		hideModal() {
			this.showModal = false
		},
		// 确认提交
		confirm(e) {
			this.hideModal()
			if (e.index == 1) {
				apiCaseconfirm({data:{problemNo:this.problemNo, userConfrimRemark:'OK'}}).then(res => {
					this.$refs.paging.refresh()
				})
			}
		},
		// 问题详情
		toDetails(problemNo) {
			uni.$tui.href(`/pages/work/daily/details?problem_no=${problemNo}`)
		},
		// 处理详情
		toCase(problemNo) {
			uni.$tui.href(`/pages/work/case/result?problem_no=${problemNo}`)
		},
		// 进度详情
		toStep(problemNo) {
			uni.$tui.href(`/pages/work/daily/step?problem_no=${problemNo}`)
		}
	}
}
</script>

<style lang="scss" scoped>
.ul .li:first-child {
	margin-top: 0;
}
</style>
