<template>
  <div class="">
    <el-dialog
      v-model="show"
      class="custom-export-indent-quote-dialog"
      title="导出"
      width="500px"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      :append-to-body="true"
      :before-close="close"
    >
      <el-form
        label-width="120px"
        :model="form"
      >
        <el-form-item label="Saleperson">
          <el-select
            v-model="form.saleperson"
            filterable
          >
            <el-option
              v-for="item in creatorOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="Export PDF City">
          <el-select
            v-model="form.pdf_city"
            filterable
            allow-create
          >
            <el-option
              v-for="item in cityList"
              :key="item"
              :label="item"
              :value="item"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item
          v-for="item in step3FormList"
          :key="item.tabLabel"
          :label="item.tabLabel"
        >
          <div class="flex items-center">
            <el-input v-model="form[`zdy_date_${item.typeNumber}_${item.number}`]"></el-input>
            &nbsp;
            <el-select v-model="form[`cycle_name_${item.typeNumber}_${item.number}`]">
              <el-option value="weeks">weeks</el-option>
              <el-option value="business days">business days</el-option>
            </el-select>
          </div>
        </el-form-item>
        <el-form-item label="Exchange">
          <el-input v-model="form.exchange"></el-input>
        </el-form-item>
        <el-form-item label="报价有效期">
          <el-input v-model="form.days">
            <template #append>Days</template>
          </el-input>
        </el-form-item>
        <el-form-item label="NOTES">
          <el-input
            v-model="form.notes"
            :rows="4"
            type="textarea"
          ></el-input>
        </el-form-item>
        <el-form-item label="备注">
          <el-input
            v-model="form.other_notes"
            :rows="4"
            type="textarea"
          ></el-input>
        </el-form-item>
        <el-form-item label="商品及服务税">
          <el-select v-model="form.gst_name">
            <el-option value=""></el-option>
            <el-option value="+GST">+GST</el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div class="flex justify-center items-center">
        <el-button
          size="small"
          type="primary"
          @click="save"
        >
          确定
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script lang="ts" setup>
import { defineComponent, ref, watch } from 'vue'
import { ElButton, ElForm, ElFormItem, ElInput, ElSelect, ElDialog, ElOption } from 'element-plus'
import cloneDeep from 'lodash.clonedeep'
defineComponent({
  name: 'ComponentIndentExportForm',
})
const {
  visible = false,
  formData = {} as any,
  creatorOptions = [],
  step3FormList = [],
  cityList = [],
} = defineProps<{
  visible: boolean
  formData: object
  creatorOptions: any[]
  step3FormList: any[]
  cityList?: any[]
}>()
const $emit = defineEmits(['update:visible', 'save'])
const show = ref(false)
const form = ref({} as any)
watch(
  () => visible,
  () => {
    show.value = visible
    if (show.value) {
      form.value = cloneDeep(formData)
    }
  },
)
const save = () => {
  $emit('save', form.value)
  close()
}
const close = (done = {} as any) => {
  $emit('update:visible', false)
  if (typeof done === 'function') done()
}
</script>
<style lang="scss">
.custom-export-indent-quote-dialog {
  .el-dialog__body {
    min-height: 60vh;
    max-height: 80vh;
    overflow-y: scroll;
    overflow-x: auto;
    padding-top: 8px;
    padding-bottom: 8px;
  }
}
</style>
