<template>
  <el-row class="main">
    <el-row class="send-container">
      <el-row class="panel send-panel send-panel1">
        <el-row class="send-container">
          <el-button class="send-btn">寄</el-button>
          <el-row>
            <el-button>地址簿</el-button>
            <el-button>智能填写</el-button>
          </el-row>
        </el-row>
        <el-form label-width="auto" class="form">
          <el-form-item>
            <template #label>
              <span class="required">*</span>姓名
            </template>
            <el-input placeholder="请填写发件人姓名" v-model="formRef.senderName"></el-input>
          </el-form-item>
        </el-form>
        <el-form label-width="auto" class="form">
          <el-form-item>
            <template #label>
              <span class="required">*</span>省市区
            </template>
            <el-input placeholder="请输入目前省市区" v-model="formRef.senderCity"></el-input>
          </el-form-item>
        </el-form>
        <el-form label-width="auto" class="form">
          <el-form-item label="公司名称">
            <el-input placeholder="请填写公司名称" v-model="senderCompanyRef"></el-input>
          </el-form-item>
        </el-form>
      </el-row>

      <el-image src="/arrow.png"></el-image>

      <el-row class="panel send-panel send-panel1">
        <el-row class="send-container">
          <el-button class="send-btn receiver-btn">收</el-button>
          <el-row>
            <el-button>地址簿</el-button>
            <el-button>智能填写</el-button>
          </el-row>
        </el-row>
        <el-form label-width="auto" class="form">
          <el-form-item>
            <template #label>
              <span class="required">*</span>姓名
            </template>
            <el-input placeholder="请填写收件人姓名" v-model="formRef.receiverName"></el-input>
          </el-form-item>
        </el-form>

        <el-form label-width="auto" class="form">
          <el-form-item>
            <template #label>
              <span class="required">*</span>收件的省市区
            </template>
            <el-input placeholder="请输入收件城市" v-model="formRef.receiverCity"></el-input>
          </el-form-item>
        </el-form>

        <el-form label-width="auto" class="form">
          <el-form-item label="公司名称">
            <el-input placeholder="请填写公司名称" v-model="receiverCompanyRef"></el-input>
          </el-form-item>
        </el-form>
      </el-row>

    </el-row>

    <el-row class="panel send-panel">
      <el-text class="send-label">寄件方式</el-text>
      <el-radio-group v-model="sendType">
        <el-radio value="0" size="large">预约上门取件</el-radio>
        <el-radio value="1" size="large">自行联系快递员</el-radio>
      </el-radio-group>
    </el-row>

    <el-row class="panel send-panel">
      <el-button class="confirm-btn" @click="handleExpressSender">下单</el-button>
    </el-row>

  </el-row>
</template>

<script setup>
import { ref } from 'vue';
import { getExpressForm } from '../../utils/tools';
import { useExpressStore } from '../../store';
import { ElMessage } from 'element-plus'
const expressStore = useExpressStore()

const formRef = ref(getExpressForm())
const senderCompanyRef = ref("")
const receiverCompanyRef = ref("")
const sendType = ref("0");
function handleExpressSender() {
  let { senderName, receiverName, senderCity, receiverCity } = formRef.value
  if (senderCompanyRef.value) {
    senderName = senderCompanyRef.value + " " + senderName
    senderCompanyRef.value = ""
  }
  if (receiverCompanyRef.value) {
    receiverName = receiverCompanyRef.value + " " + receiverName
    receiverCompanyRef.value = ""
  }
  if (!senderName || !receiverName || !senderCity || !receiverCity) {
    ElMessage({
      message: '请填写完必填信息',
      type: 'error',
      plain: true,
    })
    return
  }
  expressStore.addExpress(formRef.value)
  formRef.value = getExpressForm()
  ElMessage({
    message: '下单成功',
    type: 'success',
    plain: true,
  })
}
</script>

<style>
.send-container {
  display: flex;
  width: 100%;
  flex-direction: row;
  justify-content: space-between;
  align-items: center;
}

.panel {
  display: flex;
  flex-direction: column;
  background-color: white;
  justify-content: center;
  align-items: flex-start;
  width: 100%;
}

.send-panel {
  padding: 10px;
  margin-top: 10px;
  line-height: 40px;
}

.send-panel1 {
  width: 40%;
  align-items: center;
}

.send-btn {
  background-color: black;
  color: white;
  border-radius: 100%;
  padding: 10px;
}

.receiver-btn {
  background-color: red;
}

.form {
  margin-top: 10px;
  width: 80%;
}

.send-label {
  font-weight: 600;
  align-self: flex-start;
}

.confirm-btn {
  background-color: red;
  color: white;
}

.required {
  color: red;
}
</style>
