<template>
  <div class="position-com __box-shadow">
    <CusTab :tabs="[
          {name: '度', value: 'd'},
          {name: '度分', value: 'df'},
          {name: '度分秒', value: 'dfm'},
      ]"  v-model:param="cusTransfer.tab" style="padding-left: 12px;"/>
    <div class="content">
      <div class="item">
        <div class="input">
          <div class="label">经度：</div>
          <template v-if="cusTransfer.tab === 'd'">
            <CusFormColumn
                link="number"
                :decimal="8"
                v-model:param="cusTransfer.format.d.lon1"/>
            <div class="unit">°</div>
          </template>
          <template v-else-if="cusTransfer.tab === 'df'">
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.df.lon1"/>
            <div class="unit">°</div>
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.df.lon2"/>
            <div class="unit">‘</div>
          </template>
          <template v-else-if="cusTransfer.tab === 'dfm'">
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.dfm.lon1"/>
            <div class="unit">°</div>
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.dfm.lon2"/>
            <div class="unit">‘</div>
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.dfm.lon3"/>
            <div class="unit">"</div>
          </template>
        </div>
        <div class="switch __hover" @click="cusTransfer.format.isEast = !cusTransfer.format.isEast">
          <div class="switch-item" :class="{active: cusTransfer.format.isEast}">E</div>
          <div class="switch-item" :class="{active: !cusTransfer.format.isEast}">W</div>
        </div>
      </div>
      <div class="item">
        <div class="input">
          <div class="label">纬度：</div>
          <template v-if="cusTransfer.tab === 'd'">
            <CusFormColumn
                link="number"
                :decimal="8"
                v-model:param="cusTransfer.format.d.lat1"/>
            <div class="unit">°</div>
          </template>
          <template v-else-if="cusTransfer.tab === 'df'">
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.df.lat1"/>
            <div class="unit">°</div>
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.df.lat2"/>
            <div class="unit">‘</div>
          </template>
          <template v-else-if="cusTransfer.tab === 'dfm'">
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.dfm.lat1"/>
            <div class="unit">°</div>
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.dfm.lat2"/>
            <div class="unit">‘</div>
            <CusFormColumn
                link="number"
                v-model:param="cusTransfer.format.dfm.lat3"/>
            <div class="unit">"</div>
          </template>
        </div>
        <div class="switch __hover" @click="cusTransfer.format.isSouth = !cusTransfer.format.isSouth">
          <div class="switch-item" :class="{active: cusTransfer.format.isSouth}">S</div>
          <div class="switch-item" :class="{active: !cusTransfer.format.isSouth}">N</div>
        </div>
      </div>
    </div>
    <div class="buttons">
      <div class="__hover">确定</div>
      <div class="__hover cancel">取消</div>
    </div>
  </div>
</template>

<script lang="ts">
import {
  defineComponent,
  computed,
  onMounted,
  ref,
  reactive,
  watch,
  getCurrentInstance,
  ComponentInternalInstance,
  toRefs,
  nextTick
} from 'vue'
import {useStore} from 'vuex'
import {useRouter, useRoute} from 'vue-router'
import {ElMessage, ElMessageBox} from "element-plus";

export default defineComponent({
  name: '',
  components: {},
  props: {
    map: {
      required: true
    },
    mapFunc: {
      required: true
    },
    transfer: {}
  },
  setup(props, {emit}) {
    const store = useStore();
    const router = useRouter();
    const route = useRoute();
    const that = (getCurrentInstance() as ComponentInternalInstance).appContext.config.globalProperties
    const state = reactive({
      transfer: <any>props.transfer,
      cusTransfer: <any>{
        tab: 'd',
        format: {
          d: {
            lon1: null,
            lat1: null,
          },
          df: {
            lon1: null,
            lon2: null,
            lat1: null,
            lat2: null,
          },
          dfm: {
            lon1: null,
            lon2: null,
            lon3: null,
            lat1: null,
            lat2: null,
            lat3: null,
          },
          isEast: true,
          isSouth: false,
        },
      }
    })
    onMounted(() => {
      if (props.transfer) {
        state.cusTransfer = props.transfer
      } else {
        emit('update:transfer', state.cusTransfer)
      }
    })
    return {
      ...toRefs(state),
    }
  },
})
</script>

<style scoped lang="scss">
.position-com {
  width: 100%;
  background-color: #FFFFFF;
  padding-bottom: 12px;
  .content {
    display: flex;
    flex-direction: column;
    padding: 0 12px;
    margin-top: 12px;
    .item {
      width: 100%;
      display: flex;
      align-items: center;
      &:not(:last-child) {
        margin-bottom: 8px;
      }
      .input {
        display: flex;
        align-items: center;
        flex: 1;
        .label {
          width: 44px;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #434343;
        }
        :deep(.cus-form-column) {
          flex: 1;
          height: 36px;
          max-width: unset;
        }
        .unit {
          margin-left: 7px;
          margin-right: 12px;
          align-self: flex-start;
          margin-top: 3px;
        }
      }
      .switch {
        width: 50px;
        height: 28px;
        display: flex;
        align-items: center;
        justify-content: center;
        border: 2px solid #108DF3;
        border-radius: 4px;
        .switch-item {
          width: 16px;
          height: 16px;
          font-size: 14px;
          font-family: Microsoft YaHei;
          font-weight: 400;
          color: #108DF3;
          border-radius: 2px;
          display: flex;
          align-items: center;
          justify-content: center;
          margin: 0 3px;
          &.active {
            font-size: 12px;
            color: #FFFFFF;
            background-color: #108DF3;
          }
        }
      }
    }
  }
  .buttons {
    margin-top: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    >div {
      width: 80px;
      height: 36px;
      background-color: #1280F1;
      border: 1px solid #1270DA;
      border-radius: 2px;
      display: flex;
      align-items: center;
      justify-content: center;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #FFFFFF;
      &:not(:last-child) {
        margin-right: 10px;
      }
    }
    .cancel {
      background-color: #FFFFFF;
      border-color: #1270DA;
      color: #108DF3;
    }
  }
}
</style>
