<template>
  <div>
    <van-nav-bar title="绩效审批" left-text="返回" @click-left="$route_back" left-arrow></van-nav-bar>
    <div class="body_com has_header">
      <scroller>

        <van-cell-group>
          <div slot="title" class="red">绩效与工资挂钩，建议在月绩效评审会最终确认后提交此项分值</div>
          <van-field label="月平衡分" v-model="base_point" placeholder="请输入月平衡分"  disabled/>
          <van-field label="积分" v-model="data.point" placeholder="请输入积分" required />
        </van-cell-group>

        <van-cell-group>
          <van-cell>
            <Mtextarea v-model="data.remark" :text_max="100" placeholder="填写意见（必填）"></Mtextarea>
          </van-cell>
        </van-cell-group>

        <div style="padding:0.32rem;">
          <van-button size="large" @click="send" type="info">提交</van-button>
        </div>
      </scroller>
    </div>
  </div>
</template>

<script>
import Mtextarea from '@/components/common/Mtextarea'
import EmployeeSelectorCell from '@/components/common/EmployeeSelectorCell'
import request from '@/utils/request'
import Vue from 'vue'
import { Collapse, CollapseItem, Image} from 'vant'

Vue.use(Image)
Vue.use(Collapse)
Vue.use(CollapseItem)
export default {
  name: 'performance',
  components: {
    Mtextarea, EmployeeSelectorCell
  },
  data () {
    return {
      data: {
        package_id: 0,
        point: 0,
        remark: ''
      },
      employee_id: 0,
      month: '',
      base_point: ''
    }
  },
  methods: {
    get_data () {
      let self = this
      self.$toast.loading({
        message: '正在加载'
      })
      request('get', '/api/integral/performance/info', {employee_id: this.employee_id, month: this.month}).then(res => {
        self.$toast.clear()
        self.base_point = res.data.data.base_point
        self.data.package_id = res.data.data.id
      }).catch(e => {

      })
    },
    send () {
      let self = this
      if (this.data.point == '') {
        this.$toast('请输入积分')
        return false
      } else if (this.data.remark == '') {
        this.$toast('请填写意见')
        return false
      }
      self.send_loading = true
      self.$toast.loading({
        message: '正在处理'
      })
      request('put', '/api/integral/performance', self.data).then(res => {
        if (res.data.code == 1) {
          self.send_loading = false
          self.$toast.clear()
          self.$toast.success(res.data.msg)
          self.$keep_alive_update('efficiency_detail_update', self.data)
          setTimeout(() => {
            self.$route_back()
          }, 500)
        } else {
          self.$toast.fail(res.data.msg)
        }
      }).catch(e => {
        self.send_loading = false
        self.$toast.clear()
      })
    }
  },
  created () {
    if (this.$route.query.employee_id) {
      this.employee_id = this.$route.query.employee_id
      this.month = this.$route.query.month
      this.data.point = this.$route.query.review_point
    }
    this.get_data()
  }
}
</script>

<style scoped>
  .body_com {
    height: calc(100% - 0.92rem);
    position: relative;
  }
  .red{color:#F56C6C;}
</style>
