checkAdd.vue 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <template>
  2. <ele-modal
  3. :title="title"
  4. :visible.sync="visible"
  5. :close-on-click-modal="false"
  6. @close="handleClose"
  7. resizable
  8. maxable
  9. width="500px"
  10. >
  11. <el-form ref="formRef" :model="form" :rules="rules" label-width="130px">
  12. <el-form-item label="放行类型" prop="checklistType">
  13. <DictSelection
  14. dictName="放行类型"
  15. clearable
  16. v-model="form.checklistType"
  17. @change="checklistTypeChange"
  18. >
  19. </DictSelection>
  20. </el-form-item>
  21. <el-form-item label="放行单模板名称" prop="templateId">
  22. <el-select
  23. style="width: 100%"
  24. v-model="form.templateId"
  25. placeholder="请选择,来源于放行单模板。"
  26. filterable
  27. remote
  28. :remote-method="remoteMethod"
  29. @change="handleTemplateChange"
  30. >
  31. <el-option
  32. v-for="item in templateIdList"
  33. :key="item.id"
  34. :label="item.templateName"
  35. :value="item.id"
  36. >
  37. </el-option>
  38. </el-select>
  39. </el-form-item>
  40. </el-form>
  41. <template v-slot:footer>
  42. <el-button type="primary" @click="submit">提 交</el-button>
  43. <el-button @click="handleClose">取 消</el-button>
  44. </template>
  45. </ele-modal>
  46. </template>
  47. <script>
  48. import dictMixins from '@/mixins/dictMixins';
  49. import { checklisttemplatePage } from '@/api/checklisttemplate/index';
  50. export default {
  51. mixins: [dictMixins],
  52. components: {},
  53. data() {
  54. const formBaseData = {
  55. // 放行单类型,1-成品放行,2-商品放行,3-物料放行
  56. checklistType: '',
  57. templateId: null,
  58. templateName: ''
  59. };
  60. return {
  61. visible: false,
  62. title: '新增放行单',
  63. formBaseData,
  64. form: JSON.parse(JSON.stringify(formBaseData)),
  65. rules: {
  66. checklistType: [
  67. { required: true, message: '请选择放行类型', trigger: 'blur' },
  68. { required: true, message: '请选择放行类型', trigger: 'change' }
  69. ],
  70. templateId: [
  71. { required: true, message: '请选择放行单模板', trigger: 'blur' },
  72. { required: true, message: '请选择放行单模板', trigger: 'change' }
  73. ]
  74. },
  75. //模板列表
  76. templateIdList: [],
  77. };
  78. },
  79. created() {},
  80. methods: {
  81. // 外部调用,打开弹窗
  82. open(type, data) {
  83. console.log('data type', type, data);
  84. if (type == 'add') {
  85. this.title = '新增放行单';
  86. } else {
  87. this.title = '编辑放行单';
  88. }
  89. this.visible = true;
  90. },
  91. // 关闭时清理表单
  92. handleClose() {
  93. this.visible = false;
  94. this.form = JSON.parse(JSON.stringify(this.formBaseData));
  95. this.$refs.formRef && this.$refs.formRef.resetFields();
  96. },
  97. // 提交
  98. submit() {
  99. this.$refs.formRef.validate((valid) => {
  100. if (valid) {
  101. this.$emit('submit', this.form);
  102. // 下一步 放行单申请
  103. this.$emit('confirm', this.form);
  104. this.handleClose();
  105. }
  106. });
  107. },
  108. // 远程搜索
  109. remoteMethod(query) {
  110. if (query !== '') {
  111. this.fetchTemplateList(query);
  112. } else {
  113. this.fetchTemplateList();
  114. }
  115. },
  116. // 查询模板列表
  117. async fetchTemplateList(templateName = '') {
  118. if (this.form.checklistType == '') {
  119. this.templateIdList = [];
  120. return;
  121. }
  122. const data = await checklisttemplatePage({
  123. pageNum: 1,
  124. size: 99,
  125. templateName: templateName,
  126. checklistType: this.form.checklistType
  127. });
  128. this.templateIdList = data.list;
  129. console.log('data', data);
  130. },
  131. // 选择模板
  132. handleTemplateChange(id) {
  133. const selected = this.templateIdList.find((item) => item.id === id);
  134. if (selected) {
  135. this.form.templateName = selected.templateName;
  136. } else {
  137. this.form.templateName = '';
  138. }
  139. },
  140. // 选择放行单类型
  141. checklistTypeChange() {
  142. this.fetchTemplateList();
  143. this.form.templateId = null;
  144. this.form.templateName = '';
  145. }
  146. }
  147. };
  148. </script>
  149. <style scoped lang="scss"></style>