<template>
  <div class="sub-detail">
    <div class="card">
      <header>
        <em>[子任务]</em>
        {{detail.taskTitle}}
      </header>
      <u-gap height="16"></u-gap>
      <u-row>
        <span>任务类型：</span>
        <span>{{$dict.getLabel("workTaskType",detail.type)}}</span>
      </u-row>
      <u-gap height="8"></u-gap>
      <u-row>
        <span>开始时间：</span>
        <span>{{detail.createTime}}</span>
      </u-row>
      <u-gap height="8"></u-gap>
      <u-row>
        <span>截止时间：</span>
        <span>{{detail.lastTime}}</span>
      </u-row>
      <u-gap height="8"></u-gap>
      <u-row>
        <span>剩余时间：</span>
        <span style="color:#1365DD">{{detail.overTimeStatus}}</span>
      </u-row>
      <u-gap height="8"></u-gap>
      <u-row>
        <span>任务状态：</span>
        <span style="color:#1365DD">{{$dict.getLabel("workTaskDoStatus",detail.status)}}</span>
      </u-row>
      <u-gap height="16"></u-gap>
    </div>
    <div class="card" style="padding-top: 0">
      <div class="label">任务说明</div>
      <u-read-more close-text="展开" color="#999999" show-height="300">
        <span>{{detail.taskDescription}}</span>
      </u-read-more>
    </div>

    <div class="card">
      <div class="label">当前进度</div>
      <text>已完成{{detail.percent}}%</text>
      <div class="progress">
        <div class="pro-active" :style="{width:detail.percent + '%'}"></div>
      </div>
    </div>

    <div class="card" style="padding-top: 0" v-if="detail.userInfoList && detail.userInfoList.length">
      <div class="label title">任务完成进度(<i>{{count}}</i>/{{detail.userInfoList.length}})</div>
      <u-row justify="between" v-for="(item,index) in detail.userInfoList" :key="index" @click="finishDetail(item)">
        <div>{{item.userName && item.userName.substr(-2)}}</div>
        <u-row justify="between" class="item">
          <text class="name">{{item.userName}}</text>
          <label class="right">
            <span>已完成{{item.percent}}%</span>
            <label class="arrow"></label>
          </label>
        </u-row>
      </u-row>
    </div>

    <div class="footer" v-if="detail.status==0">
      <div>
        <img :src="$cdn + 'common/gb.png'" alt="" @click="show=true,content='确定是否要关闭任务？',idx=0">关闭任务
      </div>
      <div>
        <img :src="$cdn + 'common/tx.png'" alt="" @click="show=true,content='该操作会向所有执行人发送提醒，您确定发送吗？',idx=1">一键催办
      </div>
    </div>
    <u-modal v-model="show" :content="content" @confirm="confirm"></u-modal>
    <ai-back></ai-back>
  </div>
</template>

<script>

  export default {
    name: "subDetail",
    data() {
      return {
        id: null,
        detail: {},
        show: false,
        content: "",
        idx: null,
        count: 0,
      }
    },
    onLoad(opt) {
      this.id = opt.id
      this.$dict.load("workTaskType", "workTaskDoStatus").then(_ => this.getDetail())
    },
    methods: {
      finishDetail({id}){
        uni.navigateTo({
          url:"./finishDetail?id=" + id
        })
      },
      confirm() {
        this.$http.post(this.idx == 0 ? "/app/appworktaskinfo/stopOrFinish" : "/app/appworktaskuserinfo/sendMesage", null, {
          params: {
            id: this.id,
            status: this.idx == 0 ? 2 : null
          }
        }).then(res => {
          if (res.code == 0) {
            this.$u.toast(this.idx == 0 ? "关闭成功" : "催办成功")
            this.getDetail()
          }
        })
      },
      getDetail() {
        this.$http.post("/app/appworktaskinfo/queryDetailById", null, {
          params: {
            id: this.id
          }
        }).then(res => {
          if (res && res.data) {
            this.detail = res.data
            this.count = res.data?.userInfoList?.reduce((pre,cur)=>{
              return pre + (cur.percent==100 ? 1 : 0)
            },0)
          }
        })
      }
    },
  }
</script>

<style lang="scss" scoped>
  .sub-detail {
    min-height: 100%;
    overflow-x: hidden;
    background-color: #F5F5F5;
    padding-bottom: 140px;

    .card {
      background-color: #FFFFFF;
      margin-bottom: 8px;
      box-sizing: border-box;
      padding: 16px 32px;

      header {
        font-size: 40px;
        font-weight: 600;
        color: #333333;
        line-height: 64px;
        letter-spacing: 1px;

        & > em {
          font-style: normal;
          color: #1365DD;
          font-size: 40px;
        }
      }

      .u-row {
        flex: 1;
        margin-left: 16px;
        position: relative;


        .item {
          height: 112px;

          &:after {
            width: 622px;
            height: 2px;
            content: "";
            position: absolute;
            left: 0;
            bottom: 0;
            background-color: rgba(216, 221, 230, 0.5);
          }
        }

        & > div {
          width: 80px;
          height: 80px;
          background-color: #4E8EEE;
          border-radius: 50%;
          text-align: center;
          font-size: 28px;
          font-weight: bold;
          color: #FFFFFF;
          display: flex;
          align-items: center;
          justify-content: center;
        }

        & > span:first-child {
          font-size: 30px;
          color: #999999;;
          line-height: 48px;
        }

        & > span:last-child {
          font-size: 30px;
          color: #343D65;
          margin-left: 16px;
          line-height: 48px;
        }

        .name {
          font-size: 32px;
          font-weight: 400;
          color: #333333;
        }

        .title {
          width: 490px;
          height: 112px;
          display: flex;
          align-items: center;
          font-size: 32px;
          color: #333333;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        .right {
          font-size: 28px;
          color: #1365DD;
          display: flex;
          align-items: center;

          .arrow {
            width: 16px;
            height: 16px;
            border-top: 3px solid #CCCCCC;
            border-right: 3px solid #CCCCCC;
            transform: rotate(45deg);
          }
        }
      }

      & > text {
        width: 100%;
        display: inline-block;
        font-size: 30px;
        color: #649EFD;
        text-align: center;
      }

      .progress {
        height: 12px;
        background: #F2F4FC;
        border-radius: 12px;
        position: relative;
        margin: 16px 0 80px 0;

        .pro-active {
          height: 12px;
          background: #639EFD;
          border-radius: 12px;
          position: absolute;
          left: 0;
          top: 0;
        }

      }

      & > span {
        font-size: 32px;
        color: #333333;
        line-height: 48px;
        letter-spacing: 1px;
        display: inline-block;
      }

      .label {
        height: 80px;
        font-size: 32px;
        color: #333333;
        display: flex;
        align-items: center;
        margin-bottom: 16px;

        & > em {
          font-style: normal;
          font-size: 32px;
          color: #1365DD;
        }

        & > i {
          font-style: normal;
          font-size: 32px;
          color: #2EA222;
        }
      }

      .title {
        font-weight: bold;
        height: 96px;
        border-bottom: 1px solid rgba(216, 221, 230, 0.5);
      }

    }

    .footer {
      height: 112px;
      width: 100%;
      position: fixed;
      left: 0;
      bottom: 0;
      background: #FFFFFF;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 36px;
      color: #FFFFFF;

      img {
        width: 48px;
        height: 48px;
        margin-right: 8px;
      }

      & > div:first-child, div:last-child {
        width: 50%;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
      }

      & > div:first-child {
        color: #666666;
      }

      & > div:last-child {
        background: #1365DD;
      }
    }
  }
</style>
