<template>
  <view class="warpper">
    <qnHeader class="header">
      <view class="header-title">跟进记录</view>
      <view class="right-title" @click="saveClick">保存</view>
    </qnHeader>
    <view class="paper-price">
      <view class="">
        <view class="paper-price-image-title">
          <text class="add-paper-start"><uni-icons custom-prefix="iconfont" type="icon-required" size="14" color="#F5222D"></uni-icons></text>
          <text class="add-paper-title">拜访对象</text>
        </view>
        <view class="paper-price-image">
          <qn-easyinput
            class="paper-price-textArea bf-height"
            :maxlength="200"
            :styles="{ disableColor: '#F7F8FA' }"
            v-model="form.respondent"
            :inputBorder="false"
            type="textarea"
            placeholder="请输入拜访对象"
          ></qn-easyinput>
        </view>
      </view>
      <view class="">
        <view class="paper-price-image-title">
          <text class="add-paper-start"><uni-icons custom-prefix="iconfont" type="icon-required" size="14" color="#F5222D"></uni-icons></text>
          <text class="add-paper-title">沟通记录</text>
        </view>
        <view class="paper-price-image">
          <qn-easyinput
            class="paper-price-textArea gt-height"
            :maxlength="500"
            :styles="{ disableColor: '#F7F8FA' }"
            v-model="form.content"
            :inputBorder="false"
            type="textarea"
            placeholder="请输入与客户的沟通记录"
          ></qn-easyinput>
        </view>
      </view>
      <view class="">
        <view class="paper-price-image-title">
          <!-- <text class="add-paper-start"><uni-icons custom-prefix="iconfont" type="icon-required" size="14" color="#F5222D"></uni-icons></text> -->
          <text class="add-paper-title">备注信息</text>
        </view>
        <view class="paper-price-image">
          <qn-easyinput
            class="paper-price-textArea bf-height"
            :maxlength="200"
            :styles="{ disableColor: '#F7F8FA' }"
            v-model="form.remark"
            :inputBorder="false"
            type="textarea"
            placeholder="请输入备注"
          ></qn-easyinput>
          <view class="location">
            <image class="icon" src="/static/imgs/client-detail/address-icon.png"></image>
            <text class="text">{{ form.address }}</text>
            <!-- <uni-icons size="16" type="bottom"></uni-icons> -->
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
import wgs84togcj02 from '@/utils/locationTransform.js'
import { back, uploadImage } from '@/utils/hook.js'
import qnHeader from '@/components/qn-header/qn-header.vue'
import { createVisitRecord } from '@/apis/followUpRecords.js'
const validateFields = ['content', 'respondent']
export default {
  components: { qnHeader },
  data() {
    return {
      form: {
        address: '',
        content: '',
        customerEnterpriseId: this.$store.state.supplierInfo.id || null,
        remark: '',
        respondent: ''
      }
    }
  },
  onLoad() {
    this.locatePosition()
  },
  methods: {
    locatePosition() {
      uni.getLocation({
        type: 'gcj02',
        geocode: true,
        // type: 'wgs84',
        success: (res) => {
          console.log('location success', res)
          if (res.address) {
            this.form.address = res.address.province + res.address.city + res.address.district + res.address.street
          }
          // const { lat, lon } = wgs84togcj02(res.latitude, res.longitude)
        },
        fail: (err) => {
          uni.showToast({
            icon: 'error',
            title: '定位失败:' + err.code
          })
        }
      })
    },
    // 保存
    saveClick() {
      for (let i = 0; i < validateFields.length; i++) {
        if (this.form[validateFields[i]] === null || this.form[validateFields[i]] === '') {
          uni.showToast({
            title: '请完善信息',
            icon: 'none'
          })
          return
        }
      }
      createVisitRecord(this.form).then((res) => {
        if (res) {
          uni.showToast({
            title: '添加成功',
            icon: 'success'
          })
          setTimeout(() => {
            back()
          }, 1000)
        }
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.warpper {
  background-color: #ffffff;
  height: 100%;
  .header {
    justify-content: space-between;
  }
  .header-title {
    font-size: 36rpx;
    color: #000000;
    letter-spacing: 0;
    text-align: center;
    font-weight: 500;
  }

  .right-title {
    font-size: 28rpx;
    color: #007aff;
    text-align: center;
    line-height: 40rpx;
    font-weight: 500;
  }
  .add-paper-start {
    font-size: 28rpx;
    color: #f5222d;
    letter-spacing: 0;
    font-weight: 400;
  }
  .add-paper-title {
    font-size: 28rpx;
    color: #000000;
    letter-spacing: 0;
    font-weight: 500;
  }
  .paper-price {
    background-color: #ffffff;
    padding: 20rpx 0rpx;

    .paper-price-form {
      background: #f7f8fa;
      border-radius: 8rpx;
      margin: 22rpx 32rpx;
      padding: 22rpx 32rpx;
      line-height: 60rpx;
      margin-bottom: 30rpx;
    }
    .paper-price-item {
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      .flex {
        display: flex;
        margin-left: 4px;
        align-items: center;
      }
    }
    .delete-text {
      font-size: 28rpx;
      color: #f5222d;
      letter-spacing: 0;
      font-weight: 400;
    }
    .paper-price-main {
      padding: 22rpx 32rpx;
      height: 88rpx;
      align-items: center;
      border-bottom: 2rpx solid rgba(221, 221, 221, 0.5);
    }
    .paper-price-image-title {
      padding: 0rpx 32rpx;
      align-items: center;
    }
    .paper-price-image {
      padding: 16rpx 32rpx;
    }
    .paper-price-textArea {
      background: #f7f8fa;
      border-radius: 20rpx;
      padding: 10rpx;
    }
    .paper-price-title {
      font-size: 28rpx;
      color: #000000;
      letter-spacing: 0;
      font-weight: 600;
    }
    .paper-price-subtitle {
      font-size: 24rpx;
      color: #888888;
      font-weight: 400;
    }
    .dian {
      background: #adbac9;
      width: 10rpx;
      height: 10rpx;
      border-radius: 50%;
      // margin-top: 28rpx;
      margin-right: 10rpx;
    }
    .label_text {
      font-size: 28rpx;
      color: #888888;
      letter-spacing: 0;
      font-weight: 400;
    }
    .label_value {
      padding-bottom: 5rpx;
      border-bottom: 2rpx solid #d8d8d8;
      width: 65%;
      text-align: right;
    }
    .label-select {
      display: flex;
      align-items: center;
      justify-content: flex-end;
    }
    .text-left {
      margin-left: 10rpx;
    }
    .text-right {
      margin-right: 10rpx;
    }
  }
  .bf-height {
    height: 155rpx;
  }
  .gt-height {
    height: 210rpx;
  }
  .location {
    display: flex;
    flex-direction: row;
    align-items: center;
    padding-top: 20rpx;
    .icon {
      width: 32rpx;
      height: 32rpx;
    }
    .text {
      font-size: 26rpx;
      color: #888888;
      letter-spacing: 0;
      text-align: left;
      font-weight: 400;
      padding-left: 10rpx;
    }
  }
}
</style>
