edit.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301
  1. <template>
  2. <div class="dialog-edit-record-item">
  3. <el-dialog
  4. v-model="dialogVisible"
  5. width="1000px"
  6. :title="editMode === 1 ? 'New line' : 'Edit'"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. :before-close="handleClose"
  10. >
  11. <el-form
  12. ref="mainForm"
  13. :rules="formRule"
  14. :model="form"
  15. label-width="185px"
  16. >
  17. <div class="flex items-start form-box">
  18. <div class="flex-auto">
  19. <el-form-item
  20. label="Reference"
  21. prop="Reference"
  22. >
  23. <el-input
  24. v-model="form.Reference"
  25. placeholder=""
  26. />
  27. </el-form-item>
  28. <el-form-item
  29. label="Tracking Number"
  30. prop="Tracking_Number"
  31. >
  32. <el-input v-model="form.Tracking_Number" />
  33. </el-form-item>
  34. <el-form-item
  35. label="CBM Or Chargable Weight"
  36. prop="CBM_Or_Chargable_Weight"
  37. >
  38. <el-input v-model="form.CBM_Or_Chargable_Weight" />
  39. </el-form-item>
  40. </div>
  41. <div class="flex-auto">
  42. <el-form-item
  43. label="Currency"
  44. prop="currency"
  45. >
  46. <el-select
  47. v-model="form.currency"
  48. :disabled="disableFlag"
  49. style="width: 100%"
  50. >
  51. <el-option
  52. v-for="option in currencyList as IOptionItem[]"
  53. :key="option.value"
  54. :label="option.label"
  55. :value="option.value"
  56. ></el-option>
  57. </el-select>
  58. </el-form-item>
  59. <el-form-item
  60. label="Statement Name"
  61. prop="statement_name"
  62. >
  63. <el-select
  64. v-model="form.statement_name"
  65. style="width: 100%"
  66. >
  67. <el-option
  68. v-for="(option, index) in statementList as IOptionItem[]"
  69. :key="index"
  70. :label="option.label"
  71. :value="option.label"
  72. ></el-option>
  73. </el-select>
  74. </el-form-item>
  75. <el-form-item
  76. label="Payment Type"
  77. prop="payment_type"
  78. >
  79. <el-select
  80. v-model="form.payment_type"
  81. disabled
  82. >
  83. <el-option
  84. v-for="option in paymentOption"
  85. :key="option.value"
  86. :label="option.label"
  87. :value="option.value"
  88. ></el-option>
  89. </el-select>
  90. </el-form-item>
  91. </div>
  92. </div>
  93. <br />
  94. <div class="flex justify-center">
  95. <el-button
  96. type="primary"
  97. @click="save(mainForm)"
  98. >
  99. Save
  100. </el-button>
  101. </div>
  102. </el-form>
  103. </el-dialog>
  104. </div>
  105. </template>
  106. <script lang="ts">
  107. import { defineComponent } from 'vue'
  108. export default defineComponent({
  109. name: 'EditIPoItem',
  110. })
  111. </script>
  112. <script lang="ts" setup>
  113. import { ref, watchEffect } from 'vue'
  114. import {
  115. ElMessage,
  116. ElDialog,
  117. ElForm,
  118. ElFormItem,
  119. ElSelect,
  120. ElOption,
  121. ElInput,
  122. ElButton,
  123. } from 'element-plus'
  124. import type { FormInstance, FormRules } from 'element-plus'
  125. import {
  126. // IPoItem,
  127. IOptionItem,
  128. } from '../inteface'
  129. const props = defineProps({
  130. visible: {
  131. type: Boolean,
  132. default: false,
  133. },
  134. disableFlag: {
  135. type: Boolean,
  136. default: false,
  137. },
  138. lockedCurrency: {
  139. type: String,
  140. default: '',
  141. },
  142. currentEditRow: {
  143. type: Object,
  144. default: () => {
  145. return {}
  146. },
  147. },
  148. currencyList: {
  149. type: Array,
  150. default: () => {
  151. return []
  152. },
  153. },
  154. statementList: {
  155. type: Array,
  156. default: () => {
  157. return [] as string[]
  158. },
  159. },
  160. editMode: {
  161. type: Number,
  162. default: 1,
  163. },
  164. })
  165. const paymentOption = [
  166. {
  167. label: '国际运费',
  168. value: '国际运费',
  169. },
  170. ]
  171. const dialogVisible = ref(false)
  172. const mainForm = ref<FormInstance>()
  173. const form: any = ref({})
  174. const formRule = ref<FormRules>({
  175. PO_Number: {
  176. required: true,
  177. message: '必填项',
  178. trigger: 'blur',
  179. },
  180. statement_name: {
  181. required: true,
  182. message: '必填项',
  183. trigger: 'blur',
  184. },
  185. Total: {
  186. required: true,
  187. message: '必填项',
  188. trigger: 'blur',
  189. },
  190. unit_price: {
  191. required: true,
  192. message: '必填项',
  193. trigger: 'blur',
  194. },
  195. Billable_Weight: {
  196. required: true,
  197. message: '必填项',
  198. trigger: 'blur',
  199. },
  200. Tracking_Number: {
  201. required: true,
  202. message: '必填项',
  203. trigger: 'blur',
  204. },
  205. payment_type: {
  206. required: true,
  207. message: '必填项',
  208. trigger: 'blur',
  209. },
  210. })
  211. watchEffect(() => {
  212. dialogVisible.value = props.visible
  213. form.value = Object.assign(
  214. {
  215. currency: 'CNY',
  216. statement_name: '',
  217. payment_type: '国际运费',
  218. },
  219. JSON.parse(JSON.stringify(props.currentEditRow)),
  220. )
  221. if (props.disableFlag) {
  222. form.value.currency = props.lockedCurrency
  223. }
  224. })
  225. const emit = defineEmits(['update:visible', 'edit', 'add'])
  226. const handleClose = function (done: any) {
  227. emit('update:visible', false)
  228. if (typeof done === 'function') {
  229. done()
  230. }
  231. }
  232. const save = function (formEl: FormInstance | undefined) {
  233. console.log('run', formEl)
  234. if (!formEl) return
  235. formEl.validate((valid, fields) => {
  236. console.log(valid)
  237. if (valid) {
  238. if (props.editMode === 1) {
  239. emit('add', form.value)
  240. } else if (props.editMode === 2) {
  241. emit('edit', form.value)
  242. }
  243. } else {
  244. console.log('check form has not pass!', fields)
  245. ElMessage.error('请检查表单必填项')
  246. }
  247. })
  248. }
  249. </script>
  250. <style lang="scss">
  251. .dialog-edit-record-item {
  252. input[type='number'] {
  253. -moz-appearance: textfield;
  254. appearance: textfield;
  255. &:hover {
  256. -moz-appearance: textfield;
  257. appearance: textfield;
  258. &::-webkit-inner-spin-button,
  259. &::-webkit-outer-spin-button {
  260. -webkit-appearance: none;
  261. margin: 0;
  262. }
  263. }
  264. &::-webkit-inner-spin-button,
  265. &::-webkit-outer-spin-button {
  266. -webkit-appearance: none;
  267. margin: 0;
  268. }
  269. }
  270. }
  271. </style>
  272. <style lang="scss" scoped>
  273. .form-box {
  274. .flex-auto {
  275. &:first-of-type {
  276. padding-right: 12px;
  277. }
  278. & + .flex-auto {
  279. padding-left: 12px;
  280. }
  281. }
  282. }
  283. </style>