<template>
  <div class="wrapper">
    <div>
      <el-form
        :model="dataForm"
        ref="dataForm"
        @keyup.enter.native="dataFormSubmitHandle()"
        :label-width="$i18n.locale === 'en-US' ? '120px' : 'auto'"
      >
        <el-tooltip placement="bottom" :content="dataForm.comment">
          <template #title>
            <span>{{ dataForm.comment }}</span>
          </template>
          <el-form-item label="评论内容">
            <el-input
              type="textarea"
              v-model="dataForm.comment"
              :disabled="fieldDisabled"
              placeholder="评论内容"
            ></el-input>
          </el-form-item>
        </el-tooltip>
      </el-form>
    </div>
    <!--  流程综合组件   -->
    <!-- <ren-process-multiple
      v-if="processVisible"
      updateInstanceIdUrl="/processForm/tabilityapplication/updateInstanceId"
      saveFormUrl="/processForm/tabilityapplication"
      dataFormName="dataForm"
      ref="renProcessMultiple"
    ></ren-process-multiple> -->
    <!-- 审批 -->
    <div class="agreeOr" v-if="taskId">
      <div class="approvalOperation">
        <!-- <el-button type="primary" @click="showDialog('同意')">同意</el-button>
        <el-button type="danger" plain @click="showDialog('拒绝')"
          >驳回</el-button
        > -->
         <div class="contentOperation">
          <el-input v-model="input" placeholder="请输入审批意见"></el-input>
          <el-button class="agreeButton" @click="agreeOrNot($store.state.contentTabsActiveName,'同意')">同意</el-button>
          <el-button class="rejectButton"  @click="agreeOrNot($store.state.contentTabsActiveName,'拒绝')">驳回</el-button>
        </div>
      </div>
    </div>
    <!-- 审批弹窗 -->
     <el-dialog
      title="审批意见"
      :close-on-click-modal="false"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-input v-model="input" placeholder="请输入审批意见"></el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="handleClose2">取 消</el-button>
        <el-button
          type="primary"
          @click.native="agreeOrNot($store.state.contentTabsActiveName)"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import processModule from '@/mixins/process-module'
import qs from 'qs'
import debounce from 'lodash/debounce'
import bus from '@/views/bus.js'

export default {
  // 注入公共方法
  mixins: [processModule],
  components: {},
  props: {
    // fromList: {
    //   // type: Array,
    //   // default: () => {
    //   //   return []
    //   // }
    // }
  },
  data () {
    return {
      // processVisible: true,
      // visible: false,
      // 表单属性是否可编辑
      fieldDisabled: false,
      dataForm: [],
      id: '',
      shifoushizujian: true,
      // 审批
      dialogVisible: false,
      dialogType: '',
      input: '',
      visible: true,
      taskId: ''

    }
  },
  watch: {},
  computed: {},
  methods: {
    init () {
      this.visible = true
      // this.getInfo(this.$router.currentRoute.params.params.params.resourceDTO.id)
      // this.dataForm = this.$router.currentRoute.params.params.params.resourceDTO
      // this.id=this.$router.currentRoute
      this.$nextTick(() => {
        this.$refs.dataForm.resetFields()
        // if (this.dataForm.id) {
        // 如业务KEY已存在，不允许编辑
        this.fieldDisabled = true
        // this.id = this.$router.currentRoute.businessKey
        this.getInfo(this.$router.currentRoute.params.businessKey)
        console.log('id', this.$router.currentRoute.params.businessKey)
        // }
      })
    },
    getInfo (id) {
      this.$http.get('/demandComment/' + id).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.dataForm = res.data
        // this.dataForm = res.data.resourceDTO
        // if (this.dataForm.type != '应用资源') {
        //   this.shifoushizujian = false
        // } else {
        //   this.shifoushizujian = true
        // }
        console.log('this.dataForm', this.dataForm)
      })
    },
    // 审批
    showDialog (title) {
      this.dialogVisible = true
      this.dialogType = title
    },
    handleClose (done) {
      this.$confirm('确认关闭？')
        .then((_) => {
          this.input = ''
          done()
        })
        .catch((_) => {})
    },
    handleClose2 () {
      this.dialogVisible = false
      this.input = ''
    },
    // 同意与退回
    agreeOrNot: debounce(
      function (data, type) {
        this.dataForm.taskId = this.$route.params.taskId
        if (type === '同意') {
          // if (this.input !== '') {
          console.log('this.dataForm', this.dataForm)
          const params = qs.stringify({
            taskId: this.dataForm.taskId,
            comment: this.input || '同意'
          })
          console.log(params)
          this.$http
            .post('/act/task/complete?' + params)
            .then(({ data: res }) => {
              if (res.code !== 0) {
                this.$message.error(res.msg)
                if (this.callbacks.taskHandleErrorCallback) {
                  this.callbacks.taskHandleErrorCallback(res)
                }
                return
              }
              bus.$emit('commentInit')
              bus.$emit('workInit')
              this.$message({
                message: this.$t('prompt.success'),
                type: 'success',
                duration: 500,
                onClose: () => {
                  this.visible = false
                  this.dialogVisible = false
                  if (this.callbacks.taskHandleSuccessCallback) {
                    this.callbacks.taskHandleSuccessCallback(res)
                  }
                }
              })
            })
            .catch(() => {})
          this.tabRemoveHandle(data)
          // } else {
          //   this.$message.error('请输入审批意见！')
          // }
        } else if (type === '拒绝') {
          if (this.input !== '') {
            const params = qs.stringify({
              taskId: this.dataForm.taskId,
              comment: this.input
            })
            this.$http
              .post('/act/task/backToFirst?', params)
              .then(({ data: res }) => {
                if (res.code !== 0) {
                  this.$message.error(res.msg)
                  if (this.callbacks.taskHandleErrorCallback) {
                    this.callbacks.taskHandleErrorCallback(res)
                  }
                  return
                }
                bus.$emit('commentInit')
                bus.$emit('workInit')
                this.$message({
                  message: this.$t('prompt.success'),
                  type: 'success',
                  duration: 500,
                  onClose: () => {
                    this.visible = false
                    if (this.callbacks.taskHandleSuccessCallback) {
                      this.callbacks.taskHandleSuccessCallback(res)
                    }
                  }
                })
              })
            this.tabRemoveHandle(data)
          } else {
            this.$message.error('请输入审批意见！')
          }
        }
      },
      1000,
      { leading: true, trailing: false }
    ),
    tabRemoveHandle (tabName) {
      console.log(tabName, 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
      if (tabName === 'home') {
        return false
      }
      this.$store.state.contentTabs = this.$store.state.contentTabs.filter(
        (item) => item.name !== tabName
      )
      if (this.$store.state.contentTabs.length <= 0) {
        this.$store.state.sidebarMenuActiveName =
          this.$store.state.contentTabsActiveName = 'home'
        return false
      }
      // 当前选中tab被删除
      if (tabName === this.$store.state.contentTabsActiveName) {
        const tab =
          this.$store.state.contentTabs[
            this.$store.state.contentTabs.length - 1
          ]
        this.$router.push({
          name: /^iframe_.+/.test(tab.name) ? 'iframe' : tab.name,
          params: { ...tab.params },
          query: { ...tab.query }
        })
      }
    }
  },
  created () {
    this.init()
    this.taskId = this.$route.params.taskId
    this.dataForm.taskId = this.$route.params.taskId
  },
  mounted () {}
}
</script>
<style lang="scss" >
.kuandukuandukuandu {
  max-width: 1500px;
}
.agreeOr {
  & > div {
    // text-align: right;
    padding-right: 40px;
    margin: 20px 0;
  }
}
</style>
<style lang="scss" scoped>
::v-deep .el-textarea__inner {
  height: 100px;
  resize: none;
}
.approvalOperation{
  display: flex;
  flex-direction: column;
  .contentOperation{
    display: flex;
  flex-direction: row;
  margin-bottom: 10px;
  .el-input{
    margin-left: 0px;
    width: 500px;
    height: 32px;
    line-height: 32px;
    .el-input__inner{
         height: 32px;
         width: 500px;
          line-height: 32px;
    }
  }
  .agreeButton{
    display: inline-block;
    line-height: 8px;
    width:80px;
    height: 32px;
    white-space: nowrap;
    cursor: pointer;
    color: #ffffff;
    -webkit-appearance: none;
    text-align: center;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    outline: 0;
    margin-left: 10px;
    -webkit-transition: .1s;
    transition: .1s;
    font-weight: 500;
    //padding: 12px 20px;
    font-size: 14px;
    border-radius: 4px;
    background-color: #0058e1;
  }
  .agreeButton:hover{
    background: #65a5f9;
    border-color: #65a5f9;
    color: #FFF;
  }
  .rejectButton{
    display: inline-block;
    line-height: 8px;
    width:80px;
    height: 32px;
    white-space: nowrap;
    cursor: pointer;
    color: #F56C6C;
    -webkit-appearance: none;
    text-align: center;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    outline: 0;
    margin: 0;
    -webkit-transition: .1s;
    transition: .1s;
    font-weight: 500;
    //padding: 12px 20px;
    font-size: 14px;
    border-radius: 4px;
    border-color: #F56C6C;
    margin-left: 12px;
  }
 .rejectButton:hover{
    background-color: #F56C6C;
    border-color: #F56C6C;
    color: #ffffff;
  }
  .transferButton{
     display: inline-block;
    line-height: 8px;
    width:80px;
    height: 32px;
    white-space: nowrap;
    cursor: pointer;
    color: #0058e1;
    -webkit-appearance: none;
    text-align: center;
    -webkit-box-sizing: border-box;
    box-sizing: border-box;
    outline: 0;
    margin: 0;
    -webkit-transition: .1s;
    transition: .1s;
    font-weight: 500;
    //padding: 12px 20px;
    font-size: 14px;
    border-radius: 4px;
    border-color: #0058e1;
    margin-left: 12px;
  }
  }
}
</style>
