<template>
  <view class="content">
    <view class="logo_bg">
      <view class="logo-content">
        <image :src="src1" model="aspectFit "></image>
        <view class="user_name">
          <view>{{ userInfo.name  }}</view>
          <view>{{ userInfo.groupName }}</view>
        </view>
        <uni-icons
          class="tuichu"
          type="gear"
          @click="goSystemSettings"
          size="38"
          color="#fff"
        ></uni-icons>
      </view>
    </view>
    <view class="bg_content">
      <view class="tab-data">
        <label class="tab-lable">我的任务</label>
        <view class="tab-content">
			  <!-- @click="onDataOrderTab(index)" -->
          <label
            :class="{ 'data-action': DataOrderType == index }"
          
            v-for="(item, index) in taskList"
            >{{ item.name }}</label
          >
        </view>
      </view>
      <view class="tab">
        <view class="tab-content">
          <view class="tab-content-title">
            <label>{{ taskList[DataOrderType].workNum }}</label
            ><label>总工单(次)</label></view
          >
          <view class="tab-content-title">
            <label>{{ taskList[DataOrderType].manHour }}</label
            ><label>总工时(小时)</label></view
          >
        </view>
        <label class="tab-check-lable" @click="gomiss">查看详情</label>
      </view>
      <view class="options">
        <image src="../../static/sop.jpg" model="aspectFit "></image>
      </view>
      <view class="notice" @click="goAbout">
        <image class="icon" src="@/static/u79.svg" model="aspectFit "></image>
        <text class="text1">关于株洲硬质合金集团型材分公司</text>
        <text class="iconfont icon-youjiantou icos"></text>
      </view>
    </view>
  </view>
</template>

<script>
import { postJ } from '@/utils/api.js'
import dayjs from 'dayjs'
export default {
  data () {
    return {
      src1: 'https://cdn.uviewui.com/uview/album/1.jpg',
      userInfo: null,
      DataOrderType: 0,
      taskList: [
        {
          name: '今天',
          type: 'day',
          list: [],
          workNum: '',
          manHour: ''
        },
        {
          name: '本周',
          type: 'week',
          list: [],
          workNum: '',
          manHour: ''
        },
        {
          name: '本月',
          type: 'month',
          list: [],
          workNum: '',
          manHour: ''
        }
      ]
    }
  },
  onLoad () {
    this.userInfo = uni.getStorageSync('userInfo')
    console.log(this.userInfo)
    // this.getdata()
  },
  methods: {
    click (name) {
      console.log('click', name)
    },
    onDataOrderTab (index) {
      this.DataOrderType = index
      this.getdata()
    },
    getdata () {
      let par = {
        endTime: '',
        startTime: ''
      }
      let type = this.taskList[this.DataOrderType].type
      switch (type) {
        case 'day':
          par.startTime = dayjs().startOf('day').format('YYYY-MM-DD')
          par.endTime = dayjs().endOf('day').format('YYYY-MM-DD')
          break
        case 'week':
          par.startTime = dayjs().startOf('week').format('YYYY-MM-DD')
          par.endTime = dayjs().endOf('week').format('YYYY-MM-DD')
          break
        case 'month':
          par.startTime = dayjs().startOf('month').format('YYYY-MM-DD')
          par.endTime = dayjs().endOf('month').format('YYYY-MM-DD')
          break
        default:
          break
      }
      postJ(this.apiUrl + '/workOrder/getMyTaskStatistics', par).then(res => {
        if (res.success) {
          this.taskList[this.DataOrderType].workNum = res.data.num
          this.taskList[this.DataOrderType].manHour = res.data.workingHours
        }
      })
    },
    goAbout () {
      // uni.navigateTo({
      //   url: './about/about'
      // })
    },
    gomiss () {
      uni.navigateTo({
        url: '/pages/home/work/work'
      })
    },

    goSystemSettings () {
      uni.navigateTo({
        url: '/pages/systemSettings/index'
      })
    }
  }
}
</script>

<style lang="scss" scoped>
@import 'center.scss';
</style>
