<template>
  <div>
    <van-nav-bar :title="title" left-text="返回" @click-left="$route_back" left-arrow></van-nav-bar>
    <div class="body_com has_header">
      <scroller>
        <van-panel class="update-process-box" style="margin: 0.2rem 0;" title="任务进度" v-if="init_process != 100">
          <div slot="default" class="process-box">
            <van-slider v-model="value" active-color="#1989fa" @drag-start="show_tip = true" @drag-end="show_tip = false">
              <template slot="button">
                <div class="custom-button">
                  <div class="drag-tip" v-show="show_tip">{{value}}</div>
                  <div class="drag-tip-corner" v-show="show_tip"></div>
                  {{ value }}
                </div>
              </template>
            </van-slider>
            <div style="font-size:0.28rem;padding-top:0.32rem;">已完成{{value}}%</div>
          </div>
        </van-panel>

        <van-cell-group v-else>
          <van-cell>
            <Mtextarea v-model="remark" placeholder="请输入备注（选填）" :text_max="30" :imgs_max="3" images :imgs.sync="files"></Mtextarea>
          </van-cell>
        </van-cell-group>
        <div style="padding:0.32rem;">
          <van-button size="large" v-if="init_process != 100" @click="send" type="info">完成</van-button>
          <van-button size="large" v-else @click="send" type="info">提交</van-button>
        </div>
      </scroller>
    </div>
  </div>
</template>
<script>
import request from '@/utils/request'
import Vue from 'vue'
import { Panel, Slider } from 'vant'
import Mtextarea from '@/components/common/Mtextarea'
Vue.use(Panel).use(Slider)
export default {
  components: {Mtextarea},
  // 数据
  data () {
    return {
      show_tip: false,
      value: 0,
      title: '更新进度',
      init_process: 0,
      remark: '',
      files: []
    }
  },
  watch: {
    // value(val){
    //   if(val == 100){
    //     // this.init_process = val
    //     this.$dialog({ message: '进度100%代表任务完成，将不能再对任务进行更改！' , confirmButtonText: '我知道了'});
    //   }
    // }
  },
  methods: {
    send () {
      let self = this
      self.send_loading = true
      self.$toast.loading({
        message: '正在处理'
      })
      let data = {}
      if (this.init_process != 100) {
        data = {
          work_id: self.$route.query.work_id,
          progress: self.value
        }
      } else {
        data = {
          work_id: self.$route.query.work_id,
          state: '1',
          remark: self.remark,
          files: this.files
        }
      }
      request('post', '/api/integral/work', data).then(res => {
        if (res.data.code == 1) {
          self.send_loading = false
          self.$toast.clear()
          self.$toast.success(res.data.msg)
          if (data.progress) {
            // 通知详情更新进度
            self.$keep_alive_update('update_task_progress', self.value)
          }
          if (data.state) {
            // 更新列表
            self.$keep_alive_update('update_efficiency_detail', data)
            self.$keep_alive_update('update_integral_approval_performance', data)
            self.$keep_alive_update('update_task_message', 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.progress) {
      this.value = this.$route.query.progress
      this.init_process = this.$route.query.progress
    }
  },
  activated () {
    if (this.$route.query.progress === 100) {
      this.value = this.$route.query.progress
      this.title = '完成任务'
      // this.$dialog({ message: '进度100%代表任务完成，将不能再对任务进行更改！' , confirmButtonText: '我知道了'});
    }
    this.init_process = this.$route.query.progress
    this.remark = ''
  }
}
</script>
<style rel="stylesheet/less" lang="less" scoped>

  .custom-button {
    width: 32px;
    color: #fff;
    font-size: 10px;
    line-height: 24px;
    text-align: center;
    background-color: #1989fa;
    border-radius: 100px;
    position: relative;
  }
  .body_com{height: calc(100% - 0.92rem); position: relative;}
  .add_btn{
    background-color: #26A2FF;
    border-radius: 50%;
    width: 1.12rem;
    height: 1.12rem;
    position: fixed;
    right: .48rema;
    bottom: 1.04rem;
    text-align: center;
    .van-icon{
      line-height: 1.12rem;
    }
  }
  .update-process-box .van-cell__value{
    text-align: right;
  }
  .time {
    color: #909399;
  }
  .timeExactly {
    color: #303133;
    padding-left:0.16rem;
  }
  .date {
    color: #303133;
    font-size: 18px;
  }
  .van-panel__header-value {
    color: #26A2FF;
  }
  .van-progress {
    width: 90%;
    margin: 0 auto;
  }
  .van-tabs__line {
    color: #26A2FF;
  }
  .changsize {
    font-size: 0.32rem;
    color: #303133;
  }
  .rember {
    height: 0.88rem;
    line-height:0.88rem;
    color:#26A2FF;
    float:right;
    padding-right:0.32rem;
  }
  .process-box{
    padding:0.32rem;
    padding-left:0.42rem;
    padding-right:0.42rem;
  }
  .drag-tip{
    position: absolute;
    top: -0.7rem;
    color: #eef6ff;
    background-color: #86c2ff;
    height: 0.6rem;
    line-height: 0.6rem;
    text-align: center;
    border-radius: 0.32rem;
    width:0.6rem;
    left:50%;
    margin-left:-0.3rem;
  }
  .drag-tip-corner {
    border:0.1rem solid transparent;
    border-top-color: #86c2ff;
    position: absolute;
    top: -0.12rem;
    left:50%;
    margin-left:-0.1rem;
  }
</style>
