<template>
	<view>
		<view class="date ddflex">
			<picker :range="dateList" range-key="label" @change="changeDate">
				<view>{{dateList[dateIndex].label}}</view>
				<image :src="picUrlss+'blue/yeji_rico.png'" class="rico"></image>
			</picker>
		</view>
		<view class="filter ddflex">
			<view class="li" @click="switchDefault()">默认</view>
			<view class="li ddflex" @click="switchSaleType()">业绩<image :src="picUrlss+'blue/'+ (saleSort == 1 ? 'down.png' : saleSort == 2 ? 'up.png':'sort.png')"></image></view>
			<view class="li ddflex" @click="switchCommissionType()">提成<image :src="picUrlss+'blue/'+ (commissionSort == 3 ? 'down.png' : commissionSort == 4 ? 'up.png':'sort.png')"></image></view>
		</view>
		<view class="list" v-if="pageList&&pageList.length>0">
			<view class="li" v-for="(item,index) in pageList" :key="index">
				<view class="tit">{{item.realName}}</view>
				<view class="datas ddflex">
					<view class="lis">
						<view>{{toDecimal(item.personal)}}</view>个人销售
					</view>
					<view class="lis spe">
						<view :class="toDecimal(item.bl)>=0?'green':''">{{toDecimal(item.bl)}}%</view>较上月增长
					</view>
					<view class="lis">
						<view>{{toDecimal(item.estimate)}}</view>提成
					</view>
				</view>
			</view>
		</view>
		<view class="nodata" v-else>
			<image :src="picUrlss+'empty_dd.png'"></image>
			<text>暂无业绩</text>
		</view>
	</view>
</template>

<script>
	const app = getApp();
	const req = require('../../../utils/request.js');
	const api = require('../../../utils/api.js');
	const util = require('../../../utils/util.js');
	export default {
		components: {
		},
		data() {
			return {
				picUrlss: req.public.picUrls,
				dateIndex: 2,
				dateList: [{
						label: '今天',
						value: 1
					},
					{
						label: '本周',
						value: 2
					},
					{
						label: '本月',
						value: 3
					},
					{
						label: '季度',
						value: 4
					},
					{
						label: '今年',
						value: 5
					}
				],
				form: {
					page: 1,
					limit: 10
				},
				pageList: [],
				isLoad: true,
				saleSort: '',
				commissionSort: '',
			}
		},
		onLoad(options) {
			this.deptId = options.deptId
			this.dateIndex = options.dateIndex
			uni.setNavigationBarTitle({
				title: options.deptName
			})
			this.getPageList()
		},
		onShow() {
		},
		onHide() {
		},
		onReachBottom() {
			this.form.page++
			this.getPageList()
		},
		methods: {
			changeDate(e){
				this.dateIndex = e.detail.value
				this.saleSort = ''
				this.commissionSort = ''
				this.form.page = 1
				this.isLoad = true
				this.getPageList();
			},
			switchDepartment(){
				this.isShowPop = true
			},
			hidePop(){
				this.isShowPop = false
			},
			switchTeam(item,index){
				if(this.teamIndex == index) return false
				this.teamIndex = index
				this.form.page = 1
				this.isLoad = true
				this.getPageList(item.id)
				this.hidePop()
			},
			confirmSwitchTeam(){
				this.hidePop()
			},
			switchSaleType(){
				this.commissionSort = ''
				console.log('saleSort==',this.saleSort)
				if(this.saleSort == '') this.saleSort = 1
				else if(this.saleSort == 1) this.saleSort = 2
				else this.saleSort = 1
				this.form.page = 1
				this.isLoad = true
				this.getPageList()
			},
			switchCommissionType(){
				this.saleSort = ''
				if(this.commissionSort == '') this.commissionSort = 3
				else if(this.commissionSort == 3) this.commissionSort = 4
				else this.commissionSort = 3
				this.form.page = 1
				this.isLoad = true
				this.getPageList()
			},
			switchDefault(){
				this.commissionSort = ''
				this.saleSort = ''
				this.form.page = 1
				this.isLoad = true
				this.getPageList()
			},
			toDecimal(num) {
				return util.toDecimal(num);
			},
			getPageList(){
				if (!this.isLoad) return false;
				this.isLoad = false;
				let that = this;
				let form = that.form
				form.dayType = that.dateList[that.dateIndex].value
				form.deptId = this.deptId
				if(this.saleSort) form.sort = this.saleSort
				if(this.commissionSort) form.sort  =this.commissionSort
				if(form.page == 1){
					uni.showLoading()
				}
				req.getRequest(api.team_personAchievementList,form,data=>{
					if (data && data.length >= 10) that.isLoad = true;
					if (that.form.page > 1) data = that.pageList.concat(data);
					that.pageList = data
					uni.hideLoading();
				})
			}
		}
	}
</script>

<style>
	@import "./index.css";
</style>
