<!--
 * @Author: liuzhenlin 461480418@qq.ocm
 * @Date: 2023-01-12 11:57:48
 * @LastEditors: liuzhenlin
 * @LastEditTime: 2023-02-15 18:21:43
 * @Description: file content
 * @FilePath: \oms\pages\customer\details.vue
-->
<template>
  <view class="home">
    <view class="nav">
      <view :style="{ paddingTop }">
        <view class="title" :style="[{ height }, { lineHeight: height }]">
          <view class="back" @click="goBack()">
            <u-icon name="arrow-left" color="#ffffff" size="22"></u-icon>
          </view>
          <text>客户详情</text>
        </view>
      </view>
    </view>
    <view class="main">
      <view class="main-top">
        <view class="customer-box">
          <view class="header flex1">
            <view class="name flex_l">
              <image class="img" src="../../static/images/menu1.png" mode="scaleToFill" />
              <text>{{ customerData.custName }}</text>
            </view>
            <view class="date">{{ parseTime(customerData.createdTime, '{y}-{m}-{d}') }}</view>
          </view>
          <view class="info">
            <view class="info-item">
              <u-row>
                <u-col span="7">
                  <view class="flex_l">
                    <view class="info-label">客户编码：</view>
                    <text class="info-txt">{{ customerData.custCode }}</text>
                  </view>
                </u-col>
                <u-col span="5">
                  <view class="flex_l">
                    <view class="info-label">客户行业：</view>
                    <text class="info-txt">{{ customerData.custIndustry }}</text>
                  </view>
                </u-col>
              </u-row>
            </view>
            <view class="info-item">
              <u-row justify="space-between">
                <u-col span="7">
                  <view class="flex_l">
                    <view class="info-label">所在位置：</view>
                    <text class="info-txt">{{ customerData.custProvince + '' + customerData.custCity }}</text>
                  </view>
                </u-col>
                <u-col span="5">
                  <view class="flex_l">
                    <view class="info-label">客户状态：</view>
                    <text class="info-txt">{{ custStatus[customerData.custStatus] }}</text>
                  </view>
                </u-col>
              </u-row>
            </view>
          </view>
        </view>
        <view class="tabs">
          <u-tabs
            @change="changeTabs"
            :current="curTabIndex"
            :scrollable="false"
            :list="list"
            :activeStyle="{
              color: '#3E7EF8',
              fontWeight: 'bold',
            }"
            :inactiveStyle="{
              color: '#969696',
            }"></u-tabs>
        </view>
      </view>
      <view class="data-list">
        <!-- 跟进记录 -->
        <follow-records v-if="curTabIndex == 0" ref="follow" :customerId="customerId"></follow-records>
        <!-- 详情 -->
        <customer-detail v-if="curTabIndex == 1" :detail="customerData" :abstract="abstractDetail"></customer-detail>
        <!-- 联系人 -->
        <contacts v-if="curTabIndex == 2" :customerId="customerId"></contacts>
      </view>
    </view>
    <!-- 新增按钮 -->
    <view class="fixed-btn-group" v-if="!isPublic" :style="{ width: openBtnWidth ? '480rpx' : '90rpx' }">
      <view class="flex1" v-if="openBtnWidth">
        <view class="btn center" @click="linkToConcat()">联</view>
        <view class="btn center" @click="linkToProject()">项</view>
        <view class="btn center" @click="linkToTransfer()">转</view>
        <view class="btn center" @click="$refs.moveCust.open(customerId)">公</view>
        <view class="btn center" @click="openFollow()">跟</view>
      </view>
      <view class="btn center" @click="openBtnWidth = !openBtnWidth">
        <u-icon name="plus" color="#fff" size="20"></u-icon>
      </view>
    </view>
    <view v-else class="fixed-btn-group">
      <view class="btn center" @click.stop="$refs.collection.open(customerId)">领</view>
    </view>
    <!-- 移入公海 -->
    <move-in-open-sea ref="moveCust" @fetchList="goBack()"></move-in-open-sea>
    <!-- 领用 -->
    <collection-customer ref="collection" @fetchList="goBack()"></collection-customer>
  </view>
</template>
<script>
  import customerApi from '../../api/customer'
  import to from 'await-to-js'
  import customerDetail from './components/customerDetail'
  import followRecords from './components/followRecords'
  import MoveInOpenSea from './components/moveInOpenSea'
  import CollectionCustomer from '../openSeaCustomer/components/collectionCustomer'
  import Contacts from 'pages/customer/components/contacts'
  export default {
    name: 'omsIndex',
    components: { customerDetail, followRecords, MoveInOpenSea, CollectionCustomer, Contacts },
    data() {
      return {
        openBtnWidth: false,
        curTabIndex: 0,
        fllowList: [], //跟进数据
        list: [
          {
            name: '跟进记录',
            index: 0,
          },
          {
            name: '详细信息',
            index: 1,
          },
          {
            name: '联系人',
            index: 2,
          },
        ],
        height: '',
        paddingTop: '',
        customerData: {},
        abstractDetail: null,
        custStatus: {
          10: '正常',
          20: '异常',
        },
        customerId: 0, //客户id
        isPublic: false,
      }
    },
    onLoad(option) {
      this.customerId = parseInt(option.id)
      this.isPublic = option.type == 'public'
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    onShow() {
      this.curTabIndex = 0
      this.openBtnWidth = false
      this.getCustomerDetail()
      this.getAbstractDetail()
    },
    methods: {
      async getCustomerDetail() {
        const [err, res] = await to(customerApi.getDetail({ ids: [this.customerId] }))
        if (err) return
        if (res && res.code == 200) {
          // console.log(res)
          this.customerData = res.data.list[0]
        }
      },
      async getAbstractDetail() {
        const [err, res] = await to(customerApi.getAbstract({ id: this.customerId }))
        if (err) return
        if (res && res.code == 200) {
          this.abstractDetail = res.data.list
          this.$refs.follow.getRecords()
        }
      },
      // 改变tab
      changeTabs(data) {
        // console.log(data)
        this.curTabIndex = data.index
      },
      // 打开转移
      openFollow() {
        this.$store.commit('setDetails', this.customerData)
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/publicPages/follow?targetType=10&id=' + this.customerData.id,
        })
      },
      // 跳转到转移客户
      linkToTransfer() {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/customer/transfer?id=' + this.customerId,
        })
      },
      // 跳转到创建项目
      linkToProject() {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/project/create?id=' + this.customerId,
        })
      },
      linkToConcat() {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/publicPages/concatCreate?id=' + this.customerId + '&name=' + this.customerData.custName,
        })
      },
      goBack() {
        uni.navigateBack({
          //关闭当前页面，返回上一页面或多级页面。
          delta: 1,
        })
      },
    },
  }
</script>
<style>
  page {
    background: #f2f3f5;
  }
</style>
<style lang="scss" scoped>
  .home {
    padding-top: 200rpx;

    .nav {
      position: absolute;
      left: 0;
      top: 0;
      width: 100%;
      height: 356rpx;
      background: #3e7ef8;
      border-radius: 0 0 31rpx 31rpx;
      .title {
        position: relative;
        text-align: center;
        font-size: 32rpx;
        font-weight: bold;
        color: #ffffff;
        .back {
          position: absolute;
          top: 0;
          bottom: 0;
          margin: auto;
          left: 70rpx;
          display: flex;
        }
      }
    }

    .main {
      position: absolute;
      width: 100%;
      height: calc(100vh - 200rpx);
      overflow: hidden;
      padding-bottom: 64rpx;
      .main-top {
        padding: 0 32rpx;
      }
      .customer-box {
        width: 100%;
        background: #ffffff;
        box-shadow: 0 6rpx 19rpx 2rpx rgba(0, 45, 132, 0.15);
        border-radius: 32rpx;
        padding: 22rpx 38rpx 68rpx 40rpx;
        .header {
          .name {
            .img {
              width: 46rpx;
              height: 46rpx;
              border-radius: 50%;
              margin-right: 8rpx;
            }
            text {
              font-size: 28rpx;
              font-weight: bold;
              color: #323232;
            }
          }
          .date {
            font-size: 24rpx;
            color: #3e7ef8;
          }
        }
        .info {
          .info-item {
            margin-top: 18rpx;
            .info-label {
              width: 116rpx;
              text-align: left;
              font-size: 24rpx;
              color: #646464;
            }
            .info-txt {
              flex: 1;
              font-size: 24rpx;
              color: #323232;
            }
          }
        }
      }
      .data-list {
        margin-top: 16rpx;
        width: 100%;
        height: calc(100vh - 532rpx);
        background: #ffffff;
        padding: 32rpx;
        overflow: auto;
        padding-bottom: 145rpx;
        .status1 {
          color: #4096fb;
          background: rgba(64, 150, 251, 0.2);
        }
        .status2 {
          background: rgba(255, 184, 60, 0.2);
          color: #ffb83c;
        }
        .status3 {
          color: #fe6936;
          background: rgba(254, 105, 54, 0.2);
        }
      }
    }
    .fixed-btn-group {
      position: fixed;
      display: flex;
      justify-content: space-around;
      align-items: center;
      width: 90rpx;
      height: 90rpx;
      bottom: 50rpx;
      right: 50rpx;
      box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
      border-radius: 20px;
      transition: all 0.2s;
      background: #fff;
      .btn {
        width: 60rpx;
        height: 60rpx;
        background: #3e7ef8;
        border-radius: 50%;
        margin: 10rpx;
        font-size: 26rpx;
        font-weight: bold;
        color: #ffffff;
      }
    }
  }
</style>
