SelectBatchNoDialog.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <template>
  2. <el-dialog
  3. :visible.sync="modalIsShow"
  4. title="选择批次号"
  5. top="10vh"
  6. width="400px"
  7. :close-on-click-modal="false"
  8. :close-on-press-escape="false"
  9. append-to-body
  10. @opened="dialogOpened"
  11. >
  12. <el-form
  13. ref="modalFormComp"
  14. :model="modalForm"
  15. :rules="rules"
  16. :key="modalForm.id"
  17. label-width="70px"
  18. >
  19. <el-form-item prop="sequence" label="批次号:">
  20. <el-input
  21. v-model.trim="modalForm.alphabet"
  22. placeholder="编码"
  23. disabled
  24. style="width: 80px"
  25. >
  26. </el-input>
  27. <el-input-number
  28. v-model="modalForm.sequence"
  29. placeholder="请输入"
  30. :min="1"
  31. :max="999999"
  32. :step="1"
  33. step-strictly
  34. :controls="false"
  35. ></el-input-number>
  36. </el-form-item>
  37. </el-form>
  38. <div slot="footer">
  39. <el-button type="primary" @click="confirm">确定</el-button>
  40. <el-button @click="cancel">取消</el-button>
  41. </div>
  42. </el-dialog>
  43. </template>
  44. <script>
  45. const initModalForm = { alphabet: "A", sequence: 1 };
  46. export default {
  47. name: "select-batch-no-dialog",
  48. data() {
  49. return {
  50. modalIsShow: false,
  51. modalForm: { ...initModalForm },
  52. rules: {
  53. sequence: [
  54. {
  55. required: true,
  56. message: "请输入批次号",
  57. trigger: "change",
  58. },
  59. ],
  60. },
  61. };
  62. },
  63. methods: {
  64. cancel() {
  65. this.modalIsShow = false;
  66. },
  67. open() {
  68. this.modalIsShow = true;
  69. },
  70. dialogOpened() {
  71. const batchInfo = this.$ls.get("batchInfo");
  72. if (batchInfo) {
  73. this.modalForm.alphabet = batchInfo.alphabet;
  74. this.modalForm.sequence = batchInfo.sequence + 1;
  75. } else {
  76. this.modalForm = { ...initModalForm };
  77. }
  78. this.$nextTick(() => {
  79. this.$refs.modalFormComp.clearValidate();
  80. });
  81. },
  82. async confirm() {
  83. const valid = await this.$refs.modalFormComp.validate().catch(() => {});
  84. if (!valid) return;
  85. const batchNo = `${this.modalForm.alphabet}${this.modalForm.sequence}`;
  86. this.$ls.set("batchInfo", {
  87. ...this.modalForm,
  88. batchNo,
  89. });
  90. this.$emit("confirm", batchNo);
  91. this.cancel();
  92. },
  93. },
  94. };
  95. </script>