<template>
  <view class="content">
	<picker class="picker" mode="date" :value="date" fields="month" @change="bindDateChange">
		<view class="date-screen">{{ date }}</view>
	</picker>
	<uni-card class="view-title" title="实发工资">
	  <text class="uni-body view-content">{{salarylist.actuallyPayMoney}}</text>
	</uni-card>
	<view class="wagt">
		<text class="strip">
			工资明细
		</text>
	</view>
	<view class="content-section">
		<view class="menu-list">
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>部门</view>
					<view class="text-right">{{salarylist.deptName}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>姓名</view>
					<view class="text-right">{{user.nickName}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>基本工资</view>
					<view class="text-right">{{salarylist.basicSalary}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>实际出勤天数</view>
					<view class="text-right">{{salarylist.actuallyDays}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>实际出勤小时数</view>
					<view class="text-right">{{salarylist.actuallyHours}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>出勤工时</view>
					<view class="text-right">{{salarylist.dayWorkHours}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>包活工时</view>
					<view class="text-right">{{salarylist.workOrderHours}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>加班工时</view>
					<view class="text-right">{{salarylist.overtimeWorkHours}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>日工帮工工时</view>
					<view class="text-right">{{salarylist.rigongHelpHours}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>日工工资</view>
					<view class="text-right">{{salarylist.dayWorkPay}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>包活工资</view>
					<view class="text-right">{{salarylist.workOrderPay}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>加班工资</view>
					<view class="text-right">{{salarylist.overtime}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>帮工工资</view>
					<view class="text-right">{{salarylist.banggongPay}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow" v-for="(item, index) in salarylist.allButieData" v-if="item.type === '1'" :key="index">
				<view class="menu-item-box">
					<view>{{item.buTieName}}</view>
					<view class="text-right">{{item.money}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>应付工资</view>
					<view class="text-right">{{salarylist.shoudPayMoney}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow"  v-for="(item, index) in salarylist.allButieData" v-if="item.type === '0'" :key="index">
				<view class="menu-item-box">
					<view>{{item.buTieName}}</view>
					<view class="text-right">{{item.money}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>实发工资</view>
					<view class="text-right">{{salarylist.actuallyPayMoney}}</view>
				</view>
			</view>
			<view class="list-cell list-cell-arrow">
				<view class="menu-item-box">
					<view>备注</view>
					<view class="text-right">{{salarylist.note}}</view>
				</view>
			</view>
		</view>
	</view>
  </view>
</template>

<script>
	import { getUserProfile } from "@/api/system/user"
	import { getSalary} from "@/api/system/salary"
	function getDate(type) {
		const date = new Date();
		let year = date.getFullYear();
		let month = date.getMonth();
		let day = date.getDate();
		if (type === 'start') {
			year = year - 10;
		} else if (type === 'end') {
			year = year + 10;
		}
		month = month > 9 ? month : '0' + month;
		day = day > 9 ? day : '0' + day;
		return `${year}-${month}`;
	}
  export default {
	data() {
		return {
			user: {},
			date: getDate({
				format: true
			}),
			startDate: getDate('start'),
			endDate: getDate('end'),
			salarylist: {},
			queryParams: {
				employeeName: ''
			}
		}
	},
	methods: {
		// 查询用户
		getUser() {
			getUserProfile().then(response => {
				this.user = response.data
				this.queryParams.employeeName = this.user.nickName
				this.queryParams.year = new Date(this.date).toISOString().slice(0,4)
				this.queryParams.month = new Date(this.date).toISOString().slice(5,7)
				this.getSalarylist()
			})
		},
		// 日期选择
		bindDateChange: function(e) {
			this.date = e.detail.value;
			this.user = {}
			this.queryParams.employeeName = ''
			this.queryParams.year = ''
			this.queryParams.month = ''
			this.salarylist = []
			this.getUser()
		},
		// 查询工资
		getSalarylist() {
			getSalary(this.queryParams).then(response => {
				this.salarylist = response.rows[0]
				this.salarylist.allButieData = JSON.parse(this.salarylist.allButieData)
			})
		}
	},
    onLoad: function() {
		this.getUser()
    }
  }
</script>

<style lang="scss" scoped>
  .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
  }
  
  .picker {
	  width: 55px;
	  height: 25px;
	  background-color: #5383FF;
	  border-radius: 5px;
	  text-align: center;
	  margin-top: 5px;
  }
  
  .date-screen {
	  line-height: 25px;
	  font-size: 11px;
	  color: #ffffff;
  }
  
  .wagt {
	  width: 90%;
	  border-left: 3px solid #5959C1;
  }
  
  .strip {
	  margin: 5px;
	  font-weight: bold;
	  font-size: 30rpx;
  }
  
  .view-title {
    font-weight: bold;
	width: 100%;
	text-align: center;
  }
  
  ::v-deep .uni-card {
	  background-color: #5383FF;
  }
  
  ::v-deep .uni-card .uni-card__header .uni-card__header-content .uni-card__header-content-title {
	  color: #ffffff;
  }
  
  .view-content {
    font-size: 35rpx;
    padding: 12px 5px 0;
    color: #ffffff;
    line-height: 24px;
    font-weight: bold;
  }
  
  .content-section {
	  width: 100%;
  }
</style>
