<template>
  <view class="wrapper">
    <uni-nav-bar left-icon="back" @clickLeft="back" statusBar fixed title="跟进记录"></uni-nav-bar>
    <scroll-list ref="list" :option="option" @load="upCallback" @refresh="downCallback" style="background-color: #ffffff">
      <timeline>
        <timelineItem v-for="(item, index) in list" :key="index">
          <view class="time">
            {{ item.createTime }}
          </view>
          <view class="tripItem">
            <view class="row">
              <view class="title">跟进人：</view>
              <view class="value">{{ item.visitorName }}</view>
            </view>
            <view class="row">
              <view class="title">拜访对象：</view>
              <view class="value">{{ item.respondent }}</view>
            </view>
            <view class="row">
              <view class="title">沟通内容：</view>
              <view class="value">{{ item.content }}</view>
            </view>
            <view class="row">
              <view class="title">备注信息：</view>
              <view class="value">{{ item.remark }}</view>
            </view>
            <view class="row">
              <view class="title"></view>
              <view class="value">
                <image class="icon" src="/static/imgs/client-detail/address-icon.png"></image>
                <text class="location">{{ item.address }}</text>
              </view>
            </view>
          </view>
        </timelineItem>
      </timeline>
    </scroll-list>
    <qn-footer fixed height="120rpx">
      <view class="button-area">
        <view class="button button__submit" @click="addTap">
          <text class="text" style="color: white">新增跟进</text>
        </view>
      </view>
    </qn-footer>
  </view>
</template>

<script>
import timeline from './timeLine.vue'
import timelineItem from './timelineItem.vue'
import qnFooter from '@/components/qn-footer/qn-footer.vue'
import { go2, back } from '@/utils/hook.js'
import { getVisitRecordList } from '@/apis/followUpRecords.js'
export default {
  components: {
    timeline,
    timelineItem,
    qnFooter
  },
  data() {
    return {
      option: {
        size: 10,
        auto: true,
        height: 0,
        emptyText: '暂无数据~',
        background: '#F7F8FA',
        disabled: false,
        emptyImage: '/static/imgs/order/order-empty.png'
      },
      params: {
        asc: '',
        desc: '',
        customerEnterpriseId: null,
        mallSupplierId: this.$store.state.supplierInfo.supplierId || null
      },
      pagination: {
        pageNum: 0, // 初始会执行一次下拉加载
        pageSize: 10
      },
      list: []
    }
  },
  created() {
    let that = this
    uni.getSystemInfo({
      success: function (res) {
        that.option.height = res.windowHeight * (750 / res.windowWidth) - 120
      }
    })
  },
  onShow() {
    this.downCallback()
  },
  onLoad(option) {
    if (option.customerEnterpriseId) {
      this.params.customerEnterpriseId = option.customerEnterpriseId
    }
  },
  methods: {
    back,
    getList() {
      return new Promise((resolve, reject) => {
        getVisitRecordList({ ...this.params, ...this.pagination })
          .then((res) => {
            if (res) {
              if (res.current == 1) {
                this.list = res.records
              } else {
                this.list = this.list.concat(res.records)
              }
              resolve({ list: this.list, total: res.total })
            } else {
              reject()
            }
          })
          .catch((err) => {
            reject(err)
          })
      })
    },
    addTap() {
      go2('add-record', { customerEnterpriseId: this.params.customerEnterpriseId })
    },
    downCallback() {
      this.pagination.pageNum = 1
      this.getList()
        .then(({ list, total }) => {
          this.$refs.list.refreshSuccess({ list, total })
        })
        .catch(() => {
          this.$refs.list.refreshFail()
        })
    },
    upCallback() {
      this.pagination.pageNum++
      this.getList()
        .then(({ list, total }) => {
          this.$refs.list.loadSuccess({ list, total })
        })
        .catch(() => {
          this.$refs.list.loadFail()
        })
    }
  }
}
</script>

<style lang="scss">
.wrapper {
  background-color: #ffffff;
  .time {
    font-size: 26rpx;
    color: #000000;
    letter-spacing: 0;
    font-weight: 400;
  }
  .tripItem {
    margin-top: 20rpx;
    // height: 140rpx;
    padding: 20rpx 30rpx;
    // height: 376rpx;
    background: #f7f8fa;
    border-radius: 8rpx;
    .row {
      display: flex;
      flex-direction: row;
      padding: 16rpx 0rpx;
      .title {
        flex: 0 0 140rpx;
        font-size: 28rpx;
        color: #888888;
        letter-spacing: 0;
        font-weight: 400;
      }
      .value {
        display: flex;
        align-items: center;
        flex: 1;
        font-size: 28rpx;
        color: #333333;
        letter-spacing: 0;
        font-weight: 400;
        line-height: 1.3;
      }
      .icon {
        width: 32rpx;
        height: 32rpx;
      }
      .location {
        font-size: 26rpx;
        color: #888888;
        letter-spacing: 0;
        text-align: left;
        line-height: 32rpx;
        font-weight: 400;
        padding-left: 10rpx;
      }
    }
  }
  .see-more {
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    padding-top: 20rpx;
    background: #ffffff;
    // border-top: 2rpx solid rgba(221,221,221,0.5);
    // padding: 0rpx 32rpx;
    font-size: 28rpx;
    color: #007aff;
    letter-spacing: 0;
    text-align: center;
    font-weight: 400;
    .icon {
      width: 24rpx;
      height: 24rpx;
    }
  }
  .button-area {
    width: 750rpx;
    padding: 0 32rpx;
    display: flex;
    flex-direction: row;
    align-items: center;
    // justify-content: space-between;
    .button {
      flex-grow: 0;
      flex-shrink: 0;
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 10rpx;
      .text {
        font-size: 30rpx;
        font-weight: 500;
        text-align: center;
      }
    }
    .button__cancel {
      width: 270rpx;
      height: 88rpx;
      border: 2rpx solid #979797;
    }
    .button__submit {
      width: 100%;
      height: 88rpx;
      background: #007aff;
    }
  }
}
</style>
