<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>
          <van-cell>
            <Mtextarea v-model="process.remark" placeholder="请认真填写做这件事的关键过程" :text_max="100"></Mtextarea>
          </van-cell>
        </van-cell-group>
        <div style="padding:0.32rem;">
          <van-button size="large" @click="data_verify" type="info">完成</van-button>
        </div>
      </scroller>
    </div>
  </div>
</template>
<script>
import request from '@/utils/request'
import Mtextarea from '@/components/common/Mtextarea'
import moment from 'moment'
export default {
  name: 'remberOne',
  components: {
    Mtextarea
  },
  data () {
    return {
      data: {
        work_id: 0,
        process: []
      },
      process: {
        recorder_id: this.$store.getters.user_info.id,
        recorder: this.$store.getters.user_info.name,
        remark: '',
        point: 0,
        img_url: this.$store.getters.user_info.img_url,
        time: moment().format('YYYY-MM-DD HH:mm')
      },
      send_loading: false
    }
  },
  methods: {

    data_verify () {
      let self = this
      self.$validator.validateAll().then(result => {
        if (!result) {
          self.$notify({ type: 'danger', message: self.$validator.errors.items[0].msg })
        } else {
          self.send()
        }
      })
    },
    send () {
      let self = this
      self.send_loading = true
      self.$toast.loading({
        message: '正在处理'
      })
      let _data = []
      let data = JSON.parse(localStorage.getItem('task_process_array'))
      _data.push(this.process)

      for (let i in data) {
        _data.push(data[i])
      }
      self.data.process = _data
      request('post','/api/integral/work', 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('update_task_detail', self.data)
          setTimeout(() => {
            self.$route_back()
          }, 500)
        } else {
          self.$toast(res.data.msg)
        }
      }).catch(e => {
        self.send_loading = false
        self.$toast.clear()
      })
    }
  },
  created () {
    if (this.$route.query.work_id) {
      this.data.work_id = this.$route.query.work_id
    }
  }
}
</script>
<style scoped>
  .body_com{height: calc(100% - 0.92rem); position: relative;}
</style>
