<template>
  <div slot="title">
    <div class="task_state">
      <div
        class="task_urgent"
        v-if="item.urgentStateValue"
        :style="{
          background:
            item.urgentStateValue == 1
              ? '#e55555'
              : item.urgentStateValue == 2
              ? '#FFAE44'
              : '#409eff',
        }"
      >
        <i class="icon-jinjizhuangtai"></i>
      </div>
      <div
        v-if="tagType[item.status]"
        :class="tagType[item.status]"
        class="task_status"
        type="success"
      >
        <span>{{ statusTag[item.status] }}</span>
      </div>
      <div class="task_list_name" v-html="hightLight(searchValue,item.subject)">
      </div>
    </div>
    <div v-if="item.status == 'draft'" class="draft-class">
        <div class="task_list_procDefName">
            <i class="icon-liucheng"></i>
            {{ item.procDefName }}
        </div>
          <van-button
            type="default"
            @click.stop="$emit('deleteDraft', item.id)"
            :disabled="item.supportMobile != 1"
            size="small"
            style="width: 78px; border-radius: 8px"
          >
            删除
          </van-button>
    </div>
    <div class="task_list_word" v-else>
      <div class="task_list_flowname">
        <div class="task_list_flex">
          <div class="task_list_time">
            <i class="icon-time-circle"></i>
            {{ item.createTime }}
          </div>
          <div class="task_list_procDefName" style="margin-left: 20px">
            <i class="icon-liucheng"></i>
            {{ item.procDefName }}
          </div>
        </div>
        <div>
          <i class="icon-liuchengbianhao"></i>
          <span v-html="hightLight(searchValue,item.id)"></span>
          <i
            class="icon-fuzhi"
            style="color: #409eff"
            @click.stop="(event) => clipboard(item.id, event)"
          ></i>
        </div>
      </div>
      <div class="task_list_user_box">
        <div class="task_list_user">
          <div class="left-img-box">
            <img v-if="item.imgSrc" class="image" :src="item.imgSrc" />
            <span v-else class="text">
              {{ item.creator.replace(/,/g, '/').substr(0, 1) }}
            </span>
          </div>
          <span>{{ item.creator }}</span>
        </div>
        <div class="task_list_procDefName">
          <span v-if="item.status == 'end'" class="task_list_status_end">
            <i class="icon-wancheng1"></i>
            已归档
          </span>
          <span
            v-else-if="item.status == 'manualend'"
            class="task_list_status_manualend"
          >
            <i class="icon-jieshu"></i>
            人工结束
          </span>
          <div v-else>
            <div
              class="task_list_procDefName"
              v-if="extraField[item.id] && extraField[item.id].nodeName"
            >
              <i class="icon-dangqianjiedian"></i>
              <span
                v-for="(name, index) in extraField[item.id].nodeName"
                :key="`node-name_${item.id}_${index}`"
                class="flowlist-node-name"
              >
                {{ name }}
              </span>
            </div>
          </div>
        </div>
      </div>
      <div
        class="task_list_operation"
        v-if="
          (isShowOperation(item) && isShowDelBtn(item)) ||
          (isShowOperation(item) && isTerminationBtn(item))
        "
      >
        <van-button
          type="default"
          v-if="isShowDelBtn(item)"
          @click.stop="$emit('delete', item.id)"
          :disabled="item.supportMobile != 1"
          size="small"
         
        >
          删除
        </van-button>
        <van-button
          type="info"
          v-if="isTerminationBtn(item)"
          :disabled="item.supportMobile != 1"
          @click.stop="$emit('termination', item.id)"
          size="small"
          style="margin-left: 12px"
        >
          终止
        </van-button>
      </div>
    </div>
  </div>
</template>
<script>
  import clipboard from '@/utils/clipboard'
  import hightLight from '@/mixins/hightLight.js'
  export default {
    components: {},
    props: ['item', 'extraField','searchValue'],
    mixins: [hightLight],
    data() {
      return {
        statusTag: {
          running: '运行中',
          end: '结束',
          manualend: '人工结束',
          revoke: '撤回',
          revokeToStart: '撤回',
          backToStart: '驳回',
          back: '驳回',
          draft: '草稿',
        },
        tagType: {
          running: 'theme-bgcolor',
          end: 'light-gray-bgcolor',
          manualend: 'light-gray-bgcolor',
          revoke: 'yellow-bgcolor',
          revokeToStart: 'yellow-bgcolor',
          backToStart: 'red-bgcolor',
          back: 'red-bgcolor',
          draft: 'purple-blue-bgcolor',
        },
      }
    },
    computed: {
      isShowOperation() {
        return (item) => {
          const statusList = [
            'draft',
            'manualend',
            'revokeToStart',
            'backToStart',
            'revokeToStart',
          ]
          return (
            (item.status === 'back' && item.backToStart) ||
            statusList.includes(item.status)
          )
        }
      },
      isShowDelBtn() {
        return (item) => {
          const { status, backToStart } = item
          const hasStatus = [
            'revokeToStart',
            'manualend',
            'backToStart',
          ].includes(status)
          return hasStatus || (status === 'back' && backToStart)
        }
      },
      isTerminationBtn() {
        return (item) => {
          const { status, backToStart } = item
          const hasStatus = ['revokeToStart', 'backToStart'].includes(status)
          return hasStatus || (status === 'back' && backToStart)
        }
      },
    },
    methods: { clipboard },
  }
</script>
<style lang="scss" scoped>
  .task_state {
    display: flex;
    align-items: center;
    justify-self: start;
    white-space: nowrap;
    .task_urgent {
      border-radius: 5px;
      padding: 0 5px;
      height: 18px;
      line-height: 18px;
      transform: skew(345deg, 0deg);
      margin-right: 8px;
      .icon-jinjizhuangtai {
        font-size: $base-font-size-big;
        transform: skew(-345deg, 0deg);
        color: #fff;
      }
    }
    .task_status {
      margin-right: 8px;
      margin-left: 4px;
      color: $base-white-color;
      font-size: 10px;
      border-radius: 5px;
      padding: 0 5px;
      transform: skew(345deg, 0deg);
      height: 18px;
      line-height: 18px;
      span {
        display: block;
        transform: skew(-345deg, 0deg);
      }
    }
    .task_list_name {
      word-break: break-all;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      font-size: $base-font-size-big;
      font-weight: bold;
      color: $base-text-color;
    }
  }
  .task_list_word {
    font-size: $base-font-size-small;
    i {
      font-size: $base-font-size-big;
    }
    .task_list_flowname {
      padding: 7px 0;
      color: $base-gray-text-color;
      border-bottom: 1px solid $base-gray-line-color;
      .task_list_flex {
        display: flex;
        .icon-time-circle,.icon-liucheng{
          font-size: 16px
        }
      }
    }
    .task_list_user_box {
      display: flex;
      align-items: center;
      justify-content: space-between;
      white-space: nowrap;
      padding-top: 12px;
      color: $base-text-color;
      .task_list_user {
        display: flex;
        align-items: center;
        .left-img-box {
          width: 30px;
          height: 30px;
          line-height: 30px;
          text-align: center;
          border-radius: 50%;
          margin-right: 4px;
          background: $--color-primary;
          .text {
            color: $base-white-color;
          }
          .span {
            color: $base-text-color;
          }
          .image {
            width: 30px;
            height: 30px;
            border-radius: 50%;
          }
        }
      }
    }
    .task_list_operation {
      float: right;
      margin-top: 16px;
      .van-button--small {
        width: 78px;
        border-radius: 8px;
      }
    }
    .task_list_procDefName {
      word-break: break-all;
      white-space: nowrap;
      text-overflow: ellipsis;
      overflow: hidden;
      max-width: 140px;
      .task_list_status_end,
      .task_list_status_manualend {
        color: #8c8c8c;
      }
    }
  }
  .draft-class{
    display: flex;
    justify-content:space-between;
    align-items: center;
    margin-top: 10px;
  }
</style>
