<!--
 * @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>{{ detail.contractName }}</text>
            </view>
            <view class="date">{{ parseTime(detail.createdTime, '{y}-{m}-{d} {h}:{i}') }}</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">{{ detail.custName }}</text>
                  </view>
                </u-col>
                <u-col span="5">
                  <view class="flex_l">
                    <view class="info-label">负责人：</view>
                    <text class="info-txt">{{ detail.inchargeName }}</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">{{ formatPrice(detail.contractAmount) }}</text>
                  </view>
                </u-col>
                <u-col span="5">
                  <view class="flex_l">
                    <view class="info-label">回款金额：</view>
                    <text class="info-txt">{{ formatPrice(detail.collectedAmount) }}</text>
                  </view>
                </u-col>
              </u-row>
            </view>
          </view>
        </view>
        <view class="tabs">
          <u-tabs @change="changeTabs" lineWidth="8" :current="curTabIndex" lineHeight="8" :scrollable="false"
            :list="list" :lineColor="`url(${lineBg}) 100% 100%`" :activeStyle="{
              color: '#3E7EF8',
              fontWeight: 'bold',
            }" :inactiveStyle="{
              color: '#969696',
            }" itemStyle="height: 90rpx;"></u-tabs>
        </view>
      </view>
      <view class="data-list">
        <!-- 产品 -->
        <contract-product v-if="curTabIndex == 0" :list="product"></contract-product>
        <!-- 回款记录 -->
        <contract-collection v-else-if="curTabIndex == 1" :contractId="contractId"></contract-collection>
        <!-- 详情 -->
        <contract-detail v-else-if="curTabIndex == 2" :detail="detail">
        </contract-detail>
        <!-- 发票 -->
        <contract-invoice v-else-if="curTabIndex == 3" :contractId="contractId"></contract-invoice>
        <!-- 活动 -->
        <contract-dynamics v-else-if="curTabIndex == 4" :contractId="contractId"></contract-dynamics>
      </view>
    </view>
    <!-- 新增按钮 -->
    <view class="fixed-btn-group" :style="{ width: openBtnWidth ? '320rpx' : '90rpx' }">
      <view class="flex1" v-if="openBtnWidth">
        <view class="btn center" @click="linkToCollection()">回</view>
        <view class="btn center" @click="linkToInvoice()">发</view>
      </view>
      <view class="btn center" @click="openBtnWidth = !openBtnWidth">
        <u-icon name="plus" color="#fff" size="20"></u-icon>
      </view>
    </view>
  </view>
</template>
<script>
  import customerApi from '../../api/customer'
  import contApi from '../../api/contract'
  import ContractDetail from './components/contractDetail'
  import ContractCollection from './components/contractCollection'
  import ContractInvoice from './components/contractInvoice'
  import ContractProduct from './components/contractProduct'
  import ContractDynamics from './components/contractDynamics'
  import to from 'await-to-js'
  export default {
    name: 'omsIndex',
    components: {
      ContractDetail,
      ContractCollection,
      ContractInvoice,
      ContractProduct,
      ContractDynamics
    },
    data() {
      return {
        openBtnWidth: false,
        lineBg: require('../../static/images/up.png'),
        curTabIndex: 0,
        fllowList: [], //跟进数据
        list: [{
            name: '产品',
            index: 0,
          },
          {
            name: '回款',
            index: 1,
          },
          {
            name: '详情',
            index: 2,
          },
          {
            name: '发票',
            index: 3,
          },
          {
            name: '活动',
            index: 4,
          },
        ],
        height: '',
        paddingTop: '',
        detail: {},
        abstractDetail: null,
        custStatus: {
          10: '正常',
          20: '异常',
        },
        contractId: 0, //客户id
        product:[]
      }
    },
    onLoad(option) {
      this.contractId = parseInt(option.id)
    },
    created() {
      const navData = uni.getMenuButtonBoundingClientRect()
      this.height = navData.height + 'px'
      this.paddingTop = navData.top + 'px'
    },
    onShow() {
      this.getCustomerDetail()
    },
    methods: {
      async getCustomerDetail() {
        const [err, res] = await to(contApi.getDetails({
          id: this.contractId
        }))
        if (err) return
        if (res && res.code == 200) {
          let {
            product,
            ...data
          } = res.data
          this.product = product
          this.detail = data
        }
      },
      // 改变tab
      changeTabs(data) {
        console.log(data)
        this.curTabIndex = data.index
      },
      // 打开转移
      openFollow() {
        this.$store.commit('setDetails', this.detail)
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/publicPages/follow?targetType=10',
        })
      },
      // 跳转到新建回款
      linkToInvoice() {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/contract/invoice?id=' + this.contractId + '&code=' + this.detail.contractCode,
        })
      },
      linkToCollection() {
        uni.navigateTo({
          //保留当前页面，跳转到应用内的某个页面
          url: '/pages/contract/collection?id=' + this.contractId + '&code=' + this.detail.contractCode,
        })
      },
      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 {
              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;

      .btn {
        width: 60rpx;
        height: 60rpx;
        background: #3e7ef8;
        border-radius: 50%;
        margin: 10rpx;
        font-size: 26rpx;
        font-weight: bold;
        color: #ffffff;
      }
    }
  }
</style>
