<template>
  <uni-swipe-action v-if="openSlider">
    <uni-swipe-action-item>
      <view class="list-item" @click="handleToDetail">
        <view class="list-item-main">
          <text class="left">
            {{ itemData.leadsName }}
          </text>
        </view>
        <view class="list-item-desc">
          <text class="left">
            最后跟进时间：{{ itemData.lastTime || '--' }}
          </text>
          <text class="right">
            {{ itemData.ownerUserName }}
          </text>
        </view>
      </view>
      <template v-slot:right>
        <view class="delete" @click="setFollow">
          跟进
        </view>
      </template>
    </uni-swipe-action-item>
  </uni-swipe-action>

  <view v-else class="list-item" @click="handleToDetail">
    <view class="list-item-main">
      <text class="left">
        {{ itemData.leadsName }}
      </text>
    </view>
    <view class="list-item-desc">
      <text class="left">
        最后跟进时间：{{ itemData.lastTime || '--' }}
      </text>
      <text class="right">
        {{ itemData.ownerUserName }}
      </text>
    </view>
  </view>
</template>

<script>
  import {LeadsSetFollow} from 'API/crm/message'

  export default {
    name: 'DetailLeadsItem',
    props: {
      itemData: {
        type: Object,
        required: true
      },
      openSlider: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        rightOptions: [
          {
            text: '跟进',
            style: {
              backgroundColor: '#3c80f7',
              width: 50
            }
          }
        ]
      }
    },
    methods: {
      handleToDetail() {
        console.log('to detail')
        this.$Router.navigateTo({
          url: '/pages_crm/leads/detail',
          query: {
            id: this.itemData.leadsId
          }
        })
      },
      setFollow() {
        LeadsSetFollow([
          this.itemData.leadsId
        ]).then(() => {
          this.$toast('跟进成功')
          this.$emit('refresh')
        }).catch()
      },
    }
  }
</script>

<style scoped lang="scss">
  @import "detailItem";

  .delete {
    width: 170rpx;
    height: 100%;
    color: white;
    font-size: 28rpx;
    background-color: $theme-color;
    @include center;
  }
</style>
