<template>
	<view>
		<u-modal :show-cancel-button="true" confirmColor="#5064eb"  @confirm="opinionConfirm" title="审核意见" :mask-close-able="true" v-model="opinionShow" >
			<view class="slot-content" style="margin: 20rpx;">
				<u-form label-width="150"  ref="uForm">
					<u-form-item :border-bottom="false"><u-input height="150"  placeholder="请输入审核意见(选填)" v-model="auditOpinion" /></u-form-item>
				</u-form>
			</view>
		</u-modal>
		<view class="bg-white" >
			<u-dropdown ref="uDropdown" @open="open" @close="close" active-color="#5064eb" duration="20">
				<u-dropdown-item @change="filterChange" v-model="auditFilterValue" title="审核状态" :options="auditFilterList"></u-dropdown-item>
				<u-dropdown-item @change="filterChange" v-model="carTypeFilterValue" title="车辆类型" :options="carTypeFilterList"></u-dropdown-item>
				<u-dropdown-item title="其他筛选">
					<view class="bg-white" style="padding: 20rpx 30rpx;">
						<u-form  label-width="200" :model="params" ref="uForm">
							<u-form-item label="车牌号码"><u-input placeholder="请输入车牌号码" v-model="params.number" /></u-form-item>
							<u-form-item label="车主姓名"><u-input placeholder="请输入车主姓名" v-model="params.personName" /></u-form-item>
							<u-form-item label="手机号码"><u-input placeholder="请输入手机号码" type="number" maxlength="11" v-model="params.personPhone" /></u-form-item>
						</u-form>
						<view class="flex justify-around " style="margin: 30rpx 0;">
							<view class="cu-btn bg-red radius" @click="reset" style="width: 42%;padding: 37rpx;">
								重置
							</view>
							<view class="cu-btn bg-blue radius" @click="filterChange();closeDropdown()" style="width: 42%;padding: 37rpx;">
								筛选
							</view>
						</view>
					</view>
				</u-dropdown-item>	
			</u-dropdown>
		</view>
		
		
		<mescroll-body ref="mescrollRef" @init="mescrollInit" @down="downCallback" @up="upCallback" :down="downOption" :up="upOption">
			<car-manager-card  @pass="pass" @fail="fail" :list="list"></car-manager-card>
		</mescroll-body>
		
		<!-- <wm-list-add bgColor="#7fc6ac"  ref="add" @clickAdd="add"/> -->
	</view>
</template>

<script>
	import wmListAdd from '@/components/wm-list-add/wm-list-add';
	import MescrollMixin from "@/components/mescroll-body/mescroll-mixins.js";
	import carManagerCard from "./comps/car-manager-card.vue"
	var that;
	export default {
		mixins: [MescrollMixin], // 使用mixin
		components:{
			carManagerCard,wmListAdd
		},
		data() {
			return {
				list:[],
				loginType:'',
				
				//审核意见
				operaId:'',//操作id
				opinionShow:false,
				auditOpinion:'',
				
				//筛选
				auditFilterValue: -2,
				carTypeFilterValue: -1,
				params:{
					number:'',
					personName:'',
					personPhone:''
				},
				
				auditFilterList: [{
						label: '全部',
						value: -2,
					},
					{
						label: '待审核',
						value: 0,
					},
					{
						label: '审核通过',
						value: 1,
					},
					{
						label: '审核不通过',
						value: -1,
					}
				],
				carTypeFilterList: [],
				other:[]
			
			}
		},
		onLoad() {
			that=this
			this.getCarTypeFilterList()
		},
		onShow() {
			//刷新mescroll数据
			// this.$util.reload(this.mescroll)
		},
		methods: {
			async getCarTypeFilterList(){
				let dict=this.$cache.get('dict')
				if (dict) {
					//缓存中有字典值
					this.carTypeFilterList=dict.carTypeList
					this.carTypeFilterList.unshift({
						label:'全部',
						value:'-1'
					})
					return
				}
				//车辆类型
				let res=await this.$api.dict('car_type')
			
				res.data.forEach((item)=>{
					let tmp={
						value:item.dictKey,
						label:item.dictValue
					}
					this.carTypeFilterList.push(tmp)
				})
				this.carTypeFilterList.unshift({
					label:'全部',
					value:'-1'
				})
				console.log(this.carTypeFilterList,12);
			},
			add(){
				uni.navigateTo({
					url:"./add"
				})
			},
			pass(item){
				let params={
					id:item.id,
					auditStatus:1
				}
				this.$dialog.showModal('确定要审核通过此记录吗？').then(res=>{
					this.$api.carManage.audit(params).then(res=>{
						if (res.code==200) {
							this.$u.toast('操作成功')
							this.mescroll.resetUpScroll();
						}
					})
				})
			},
			opinionConfirm(){
				let params={
					id:this.operaId,
					auditOpinion:this.auditOpinion|| '',
					auditStatus:-1
				}
				this.$api.carManage.audit(params).then(res=>{
					if (res.code==200) {
						this.$u.toast('操作成功')
						this.mescroll.resetUpScroll();
					}
				})
			},
			fail(item){
				this.operaId=item.id
				this.opinionShow=true
			},
			//筛选
			open(index) {
				this.$refs.uDropdown.highlight();
			},
			close(index) {
				this.$refs.uDropdown.highlight(index);
			},
			closeDropdown() {
				this.$refs.uDropdown.close();
			},
			filterChange(e){
				this.mescroll.resetUpScroll();
			},
			reset(){
				this.params={}
				this.mescroll.resetUpScroll();
				this.closeDropdown()
			},
			downCallback(){
				setTimeout(()=>{
					this.mescroll.resetUpScroll();
				},1200)
			},
			upCallback(mescroll){
				let params={
					current:mescroll.num,
					size:mescroll.size
				}
				if (this.auditFilterValue!=-2) {
					//不是筛选全部审核状态
					params.auditStatus=this.auditFilterValue
				}
				if (this.carTypeFilterValue!=-1) {
					//不是筛选全部车辆类型
					params.type=this.carTypeFilterValue
				}
				if (!this.$isEmpty(this.params.number)) {
					//车牌号
					params.number=this.params.number
				}
				if (!this.$isEmpty(this.params.personName)) {
					//姓名
					params.personName=this.params.personName
				}
				if (!this.$isEmpty(this.params.personPhone)) {
					//手机号
					params.personPhone=this.params.personPhone
				}
				try{
					this.$api.carManage.page(params).then(res=>{
						let data=res.data.records
						let total=res.data.total
						mescroll.endBySize(data.length,total);
						if(mescroll.num == 1) that.list = []; //如果是第一页需手动制空列表
						that.list=that.list.concat(data); //追加新数据
					})
				}catch(e){
					this.mescroll.endErr()
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	
</style>
