  <template>
  <div class="list-contain"
       style="padding-bottom:50px">
    <top-nav title="任务详情"
             :showQuery="false"
             :back-func="handleClose"></top-nav>
    <div class="data-list"
         style="padding: 0 0 50px 0">
      <div class="contain-wrap"
           style="margin-top: 0;">
        <div class="ls-row">
          <div class="row-header title">
            <span class="icon iconfont icon-jichuxinxi"></span>
            <span>基础信息</span>
          </div>
          <div class="row-content right">
            <!-- 重用程度-->
            <div class="status">{{ taskInfo.emergencyDegreeKey }}</div>
          </div>
        </div>
        <div class="ls-row">
          <span class="row-header">任务ID</span>
          <span class="row-content">{{ taskInfo.taskId }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">客户名称</span>
          <span class="row-content">{{ taskInfo.customerName }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">状态</span>
          <span class="row-content c008C">{{ taskInfo.statusKey }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">协同人员</span>
          <span class="row-content">{{ taskInfo.userNamesStr }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">事项类型</span>
          <span class="row-content">{{ taskInfo.itemTypeKey }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">任务来源</span>
          <span class="row-content">{{ taskInfo.taskSourceKey }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">截止时间</span>
          <span class="row-content">{{ taskInfo.taskRequestDateFormat }}</span>
        </div>
        <div class="ls-row">
          <span class="row-header">任务描述</span>
          <span class="row-content">{{ taskInfo.taskContent }}</span>
        </div>
        <div class="tc p20 fc8CEE">
          <span class=""
                @click="handleExtend">查看更多</span>
          <van-icon :name=" isExtend?'arrow-up':'arrow-down'" />
        </div>

        <div v-if="isExtend">
          <div class="ls-row">
            <span class="row-header">创建时间</span>
            <span class="row-content">{{ taskInfo.createTimeFormat }}</span>
          </div>
          <div class="ls-row">
            <span class="row-header">关联项目</span>
            <span class="row-content">{{ taskInfo.projectCode }}</span>
          </div>
          <div class="ls-row">
            <span class="row-header">关联拜访报告</span>
            <span class="row-content">{{ taskInfo.visitReportCode }}</span>
          </div>
          <div class="ls-row">
            <span class="row-header">处理信息</span>
            <span class="row-content">{{ taskInfo.reviewerInfoStr }}</span>
          </div>
        </div>
      </div>

      <!-- 审批操作 -->
      <ls-apploval ref="operReviewer"
                   @send="getChildParam"
                   v-show="button"></ls-apploval>
      <ls-comment ref="detailInfo"
                  :handle="button"></ls-comment>
      <!-- 附件/日志-->
      <more-data ref="applovalLog"></more-data>

      <div class="btn-wrap-piyue"
           v-show="button">
        <van-button type="info"
                    class="submit"
                    @click="saveReviewer">提交</van-button>
      </div>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
import approveReback from '../../common/approveReback'
export default {
  name: 'task-detail',
  mixins: [approveReback],
  data () {
    return {
      ddUrl:false,
      isExtend: false,
      taskId: '',
      busId: '',
      button: false,
      handle: false,
      isShow: false,
      reviewerInfo: {
        resultName: '',
        creater: '',
        createTime: '',
        content: ''
      },
      detailInfo: {
        status: '',
        busId: '',
        moduleId: 3104,
        msgBoard: false,
        superiorName: ''
      },
      taskInfo: {},
      operateParam: {
        busId: '',
        moduleId: '3104'
      },
      orderId: '',
      textarea: '同意提交通过',
      radio: '',
      order: {
        head: {},
        rows: []
      },
      lastAndLastRoute: ['/visitList', '/workList', '/newWork'], // 上两级路由
      lastRoute: ['/taskList', '/newWork', '/home'] // 上级路由
    }
  },
  created(){
   this.ddUrl = this.$common.getUrlParams('ddUrl') || this.$common.getTopUrlParams('ddUrl');
  },
  mounted () {
    this.$nextTick(() => {
      if (this.$route.query.rowId != null && this.$route.query.rowId !== '') {
        this.getRowInfo()
      }
    })
    this.getSaleUserInfo()
  },
  methods: {
    getRowInfo () {
      this.operateParam.busId = this.$route.query.rowId
      this.getTaskDetails()
    },
    // 接收子组件的参数
    getChildParam (param) {
      // 控制提交按钮是否显示
      this.button = param.buttion
      this.handle = param.handle
    },
    // 根据任务ID获取其详情数据
    getTaskDetails () {
      this.$axios.post({
        domain: 'crmUrl',
        url: 'task.getTaskDetails',
        data: { id: this.operateParam.busId },
        requestType: 'body',
        showLoad: false,
        success: function (res) {
          if (res.errorCode === 200) {
            debugger
            this.taskInfo = res.data
            this.operateParam.busId = this.taskInfo.id
            this.detailInfo.busId = this.taskInfo.id
            this.detailInfo.status = this.taskInfo.status
            this.busId = this.taskInfo.id
            this.$refs.operReviewer.getOperReviewer(this.detailInfo)
            this.$refs.detailInfo.getComment(this.detailInfo)
            this.$refs.applovalLog.initParam({
              busId: this.busId,
              modelId: 3104
            })
          }
        }.bind(this),
        error: function (res) {
          Toast.fail(res.msg)
        }
      })
    },
    // 查询当前登录人员信息
    getSaleUserInfo () {
      this.$axios.post({
        domain: 'crmUrl',
        url: 'visit.getSaleUserInfo',
        data: {},
        requestType: 'body',
        showLoad: false,
        success: function (res) {
          if (res.errorCode === 200) {
            let data = res.data
            this.detailInfo.superiorName = data.userName
          }
        }.bind(this),
        error: function (res) {
          Toast.fail(res.body.msg || res.msg)
        }
      })
    },
    // 是否展开基础信息
    handleExtend () {
      this.isExtend = !this.isExtend
    },

    // 校验数据
    checkData (data) {
      let flag = true
      if (data.result === '' || data.result === undefined) {
        this.$toast('请选择批阅动作！')
        flag = false
      } else {
        if (data.result === 'adjust_cancel' || data.result === 'cancel' || data.result === 'unpass' || data.result === 'change' || data.result === 'adjust' || data.result === 'recall') {
          if (data.content === '' || data.content === undefined) {
            this.$toast('审批说明为空，无法提交！')
            flag = false
          }
        }
      }
      if (data.result === 'change') {
        if (data.taskUserId === '' || data.taskUserId === undefined) {
          this.$toast('请选择转办人！')
          flag = false
        }
      }
      return flag
    },
    // 返回上一页
    // handleClose (data) {
    //   let path = this.$route.path
    //   if (path === '/taskDetail') {
    //     this.clearCache()
    //     this.$router.back(-1)
    //   } else {
    //     this.$emit('taskData', data)
    //   }
    // },
    // 添加审批数据
    saveReviewer () {
      let th=this;
      let operReviewer = this.$refs['operReviewer'].param
      operReviewer.reviewerType = 3104
      let flag = this.checkData(operReviewer)
      if (flag) {
        this.$axios.post({
          domain: 'crmUrl',
          url: 'reviewer.saveReviewer',
          data: operReviewer,
          isShow:true,
          success: function (res) {
            if (res.errorCode === 200) {
              Toast.success('处理成功')
              if(this.ddUrl){
                th.getRowInfo();
              }else{
                th.handleClose()
              }
            } else {
              Toast.fail(res.msg)
            }
          }.bind(this)
        })
      }
    }
  }
}
</script>
<style lang="scss">
.contain-wrap {
  background-color: #fff;
  margin: 20px 0;
}
.btn-wrap-piyue {
  z-index: 1000;
  width: 100%;
  position: absolute;
  bottom: 0px;
  background: #fff;
  padding: 20px;
  .van-button.submit {
    height: 80px;
    width: 100%;
    background: #008cee;
    border-radius: 10px;
    color: 32px;
  }
}
</style>
