123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301 |
- <template>
- <div class="dialog-edit-record-item">
- <el-dialog
- v-model="dialogVisible"
- width="1000px"
- :title="editMode === 1 ? 'New line' : 'Edit'"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- :before-close="handleClose"
- >
- <el-form
- ref="mainForm"
- :rules="formRule"
- :model="form"
- label-width="185px"
- >
- <div class="flex items-start form-box">
- <div class="flex-auto">
- <el-form-item
- label="Reference"
- prop="Reference"
- >
- <el-input
- v-model="form.Reference"
- placeholder=""
- />
- </el-form-item>
- <el-form-item
- label="Tracking Number"
- prop="Tracking_Number"
- >
- <el-input v-model="form.Tracking_Number" />
- </el-form-item>
- <el-form-item
- label="CBM Or Chargable Weight"
- prop="CBM_Or_Chargable_Weight"
- >
- <el-input v-model="form.CBM_Or_Chargable_Weight" />
- </el-form-item>
- </div>
- <div class="flex-auto">
- <el-form-item
- label="Currency"
- prop="currency"
- >
- <el-select
- v-model="form.currency"
- :disabled="disableFlag"
- style="width: 100%"
- >
- <el-option
- v-for="option in currencyList as IOptionItem[]"
- :key="option.value"
- :label="option.label"
- :value="option.value"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- label="Statement Name"
- prop="statement_name"
- >
- <el-select
- v-model="form.statement_name"
- style="width: 100%"
- >
- <el-option
- v-for="(option, index) in statementList as IOptionItem[]"
- :key="index"
- :label="option.label"
- :value="option.label"
- ></el-option>
- </el-select>
- </el-form-item>
- <el-form-item
- label="Payment Type"
- prop="payment_type"
- >
- <el-select
- v-model="form.payment_type"
- disabled
- >
- <el-option
- v-for="option in paymentOption"
- :key="option.value"
- :label="option.label"
- :value="option.value"
- ></el-option>
- </el-select>
- </el-form-item>
- </div>
- </div>
- <br />
- <div class="flex justify-center">
- <el-button
- type="primary"
- @click="save(mainForm)"
- >
- Save
- </el-button>
- </div>
- </el-form>
- </el-dialog>
- </div>
- </template>
- <script lang="ts">
- import { defineComponent } from 'vue'
- export default defineComponent({
- name: 'EditIPoItem',
- })
- </script>
- <script lang="ts" setup>
- import { ref, watchEffect } from 'vue'
- import {
- ElMessage,
- ElDialog,
- ElForm,
- ElFormItem,
- ElSelect,
- ElOption,
- ElInput,
- ElButton,
- } from 'element-plus'
- import type { FormInstance, FormRules } from 'element-plus'
- import {
- // IPoItem,
- IOptionItem,
- } from '../inteface'
- const props = defineProps({
- visible: {
- type: Boolean,
- default: false,
- },
- disableFlag: {
- type: Boolean,
- default: false,
- },
- lockedCurrency: {
- type: String,
- default: '',
- },
- currentEditRow: {
- type: Object,
- default: () => {
- return {}
- },
- },
- currencyList: {
- type: Array,
- default: () => {
- return []
- },
- },
- statementList: {
- type: Array,
- default: () => {
- return [] as string[]
- },
- },
- editMode: {
- type: Number,
- default: 1,
- },
- })
- const paymentOption = [
- {
- label: '国际运费',
- value: '国际运费',
- },
- ]
- const dialogVisible = ref(false)
- const mainForm = ref<FormInstance>()
- const form: any = ref({})
- const formRule = ref<FormRules>({
- PO_Number: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- statement_name: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- Total: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- unit_price: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- Billable_Weight: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- Tracking_Number: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- payment_type: {
- required: true,
- message: '必填项',
- trigger: 'blur',
- },
- })
- watchEffect(() => {
- dialogVisible.value = props.visible
- form.value = Object.assign(
- {
- currency: 'CNY',
- statement_name: '',
- payment_type: '国际运费',
- },
- JSON.parse(JSON.stringify(props.currentEditRow)),
- )
- if (props.disableFlag) {
- form.value.currency = props.lockedCurrency
- }
- })
- const emit = defineEmits(['update:visible', 'edit', 'add'])
- const handleClose = function (done: any) {
- emit('update:visible', false)
- if (typeof done === 'function') {
- done()
- }
- }
- const save = function (formEl: FormInstance | undefined) {
- console.log('run', formEl)
- if (!formEl) return
- formEl.validate((valid, fields) => {
- console.log(valid)
- if (valid) {
- if (props.editMode === 1) {
- emit('add', form.value)
- } else if (props.editMode === 2) {
- emit('edit', form.value)
- }
- } else {
- console.log('check form has not pass!', fields)
- ElMessage.error('请检查表单必填项')
- }
- })
- }
- </script>
- <style lang="scss">
- .dialog-edit-record-item {
- input[type='number'] {
- -moz-appearance: textfield;
- appearance: textfield;
- &:hover {
- -moz-appearance: textfield;
- appearance: textfield;
- &::-webkit-inner-spin-button,
- &::-webkit-outer-spin-button {
- -webkit-appearance: none;
- margin: 0;
- }
- }
- &::-webkit-inner-spin-button,
- &::-webkit-outer-spin-button {
- -webkit-appearance: none;
- margin: 0;
- }
- }
- }
- </style>
- <style lang="scss" scoped>
- .form-box {
- .flex-auto {
- &:first-of-type {
- padding-right: 12px;
- }
- & + .flex-auto {
- padding-left: 12px;
- }
- }
- }
- </style>
|