<template>
  <view class="container" @touchmove.stop.prevent v-if="pageData.pageRouter === 'default'">
    <view class="container_form">
      <view class="category">
        <text class="name">状态</text>
        <text class="value">
					<uni-data-picker @change="categoryChange" v-model="searchData.category" :clear-icon="false" :localdata="pageData.categoryList" popup-title="请选择状态">
						
					</uni-data-picker>
				</text>
      </view>
		<!-- 	<view class="category">
				<label class="uni-list-cell uni-list-cell-pd">
					<text class="name">待评价</text>
					<checkbox value="1" color="#49b856" :checked="searchData.evaluate" />
				</label>
			</view> -->
    </view>
    <view class="container_foot">
      <view class="clear" @click="clear">清除选项</view>
      <view class="foot_btns">
        <view class="cancel" @click="cancel">取消</view>
        <view class="confirm" @click="confirm">确认</view>
      </view>
    </view>
  </view>
  <view class="mask" @touchmove.stop.prevent></view>
  <view class="line" @touchmove.stop.prevent></view>
  
</template>

<script setup>
  import { defineEmits, ref, reactive, defineProps } from 'vue'
  import { onLoad } from '@dcloudio/uni-app'
  import { useLoginUserStore } from '@/stores/loginUser'
	import { repositoryListSearchStore } from '@/stores/repositorySearch'
  import { api_area, api_incidentcategory } from "@/http/api.js"
  import { transform } from '@/utils/index.js'
		
  const emit = defineEmits(['cancelEmit', 'confirmEmit']);
  const loginUserStore = useLoginUserStore();
	const repositorySearchStore = repositoryListSearchStore();
  
  // 页面数据
  const pageData = reactive({
    pageRouter: 'default',
    areaList: [],
    categoryList: [
			{text: '全部', value: 0},
			{text: '待受理', value: 'accept,storage'},
			{text: '处理中', value: 'pending,handler,reassign'},
			{text: '待评价', value: 'close0', hasWxdegree: 0},
			{text: '已关闭', value: 'close1', hasWxdegree: 1},
			{text: '不受理', value: 'reject'},
			{text: '撤销', value: 'cancel'},
		],
  });
	
  const searchData = reactive({
		evaluate:false,
    hospital: {},
    selected: 'todoingAll',
    area: {id: 0, area: '全部'},
    category: 0,
    acceptDate: [],
		categoryChangeData:[]
  })
  
  // 清空
  function clear(){
    searchData.category = {};
    searchData.acceptDate = [];
		searchData.evaluate = false;
		searchData.categoryChangeData = [];
		repositorySearchStore.clearRepositoryListSearchData()
  }
  
  // 取消
  function cancel(){
    emit('cancelEmit')
  }
  
  // 确认
  function confirm(){
		repositorySearchStore.setRepositoryListSearchData(searchData)
    emit('confirmEmit', searchData);
  }

  function categoryChange(val){
		searchData.categoryChangeData = val.detail.value
	}
	
  function getCategoryList(){
   //  uni.showLoading({
   //    title: "加载中",
   //    mask: true,
   //  });
    
   //  let postData = {
   //    idx: 0,
   //    sum: 9999,
   //    incidentcategory: {

			// },
   //  }
   //  if(loginUserStore.loginUser.user.duty){
   //    postData.incidentcategory.duty = loginUserStore.loginUser.user.duty.id;
   //  }else if(loginUserStore.loginUser.user.branch){
   //    postData.incidentcategory.branch = loginUserStore.loginUser.user.branch.id;
   //  }
    
   //  api_incidentcategory(postData).then(res => {
   //    uni.hideLoading();
   //    if(res.status == 200){
   //      let list = res.list || [];
			// 	list = list.map(i=> ({...i, parentid: i.parent?.id}))
			// 	pageData.categoryList = transform(list, 'id', 'parentid')
   //    }else{
   //      uni.showToast({
   //        icon: 'none',
   //        title: res.msg || '请求数据失败！'
   //      });
   //    }
   //  })
  }
	
  // 页面路由跳转
  function clickPageRouter(type){
    pageData.pageRouter = type;
    switch(type){
      case 'category':
        getCategoryList('one');
      break;
    }
  }
	
  onLoad((option) => {
		// getCategoryList()
		let data = repositorySearchStore.repositorySearch.data
    searchData.category = data && data.category;
		searchData.title = data && data.title;
		searchData.categoryChangeData = data && data.categoryChangeData
		searchData.evaluate = data && data.evaluate
  })
</script>

<style lang="scss" scoped>
.uni-checkbox-input:hover{
	border-color:#49b856;
}
.mask{
  position: fixed;
  left: 0;
  top: 0;
  right: 0;
  bottom: 0;
  background-color: rgba(0, 0, 0, 0.4);
  z-index: 999;
}
.line{
  content: '';
  position: fixed;
  top: 0;
  left: 0;
  z-index: 9999;
  height: 8rpx;
  width: 100%;
  background-color: #EBEBEB;
}
.container{
  position: fixed;
  left: 125rpx;
  top: 0;
  right: 0;
  bottom: 0;
  z-index: 9999;
  background-color: #F7F7F7;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  
  .container_form{
    height: 100%;
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
		.item{
			padding: 32rpx;
		}
  }
  
  .hospital{
    display: flex;
		align-items: center;
    padding: 32rpx 24rpx 24rpx;
    background-color: #fff;
    .name{
      font-size: 28rpx;
      flex-shrink: 0;
      margin-right: 24rpx;
    }
    .value{
			width: 100%;
      font-size: 22rpx;
			.uni-input{
				font-size: 26rpx;
			}
    }
  }
  
  .areas{
    flex: 1;
    min-height: 0;
    margin-top: 16rpx;
    background-color: #fff;
    .areas_item{
      padding: 24rpx;
      border-bottom: 1rpx solid #DEDEDE;
    }
  }
  
  .categorys{
    flex: 1;
    min-height: 0;
    margin-top: 16rpx;
    background-color: #fff;
    .categorys_item{
      padding: 24rpx;
      border-bottom: 1rpx solid #DEDEDE;
    }
  }
  
  .tabs{
    margin-top: 16rpx;
    background-color: #FBFBFB;
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: 16rpx 0;
    padding: 24rpx 16rpx;
    .tab{
      width: 180rpx;
      height: 60rpx;
      display: flex;
      justify-content: center;
      align-items: center;
      background-color: #F7F7F7;
      font-size: 28rpx;
      position: relative;
      .newicon-xuanzejiaobiao{
        opacity: 0;
        position: absolute;
        right: 0;
        bottom: 0;
        font-size: 38rpx;
        color: #53B9BB;
      }
      &.active{
        background-color: rgba(149, 220, 231, 0.30);
        .newicon-xuanzejiaobiao{
          opacity: 1;
        }
      }
    }
  }
  
  .area,
  .category,
  .acceptDate{
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 24rpx;
    background-color: #fff;
    margin-top: 24rpx;
    .name{
      font-size: 28rpx;
      flex-shrink: 0;
      margin-right: 24rpx;
    }
		.value{
			flex:1;
		}
  }
  
  .container_foot{
    .clear{
      padding: 24rpx;
      font-size: 28rpx;
      background-color: #fff;
      margin: 0 16rpx;
      display: flex;
      align-items: center;
      justify-content: center;
    }
    .foot_btns{
      margin-top: 24rpx;
      display: flex;
      border-top: 1rpx solid #BFBFBF;
      .cancel{
        flex: 1;
        background-color: #fff;
        font-size: 32rpx;
        padding: 24rpx;
        display: flex;
        justify-content: center;
      }
      .confirm{
        flex: 1;
        font-size: 32rpx;
        padding: 24rpx;
        background-color: $uni-primary;
        display: flex;
        justify-content: center;
        color: #fff;
      }
    }
  }
}
</style>