| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226 |
- <template>
- <el-dialog
- :title="title"
- v-if="visible"
- :visible.sync="visible"
- :before-close="handleClose"
- :close-on-click-modal="false"
- :close-on-press-escape="false"
- append-to-body
- width="700px"
- >
- <el-form
- ref="form"
- label-width="100px"
- :rules="rules"
- :inline="true"
- :model="formData"
- >
- <el-form-item label="BOM编码:" prop="code">
- <el-input
- size="mini"
- placeholder="BOM编码"
- v-model="formData.code"
- ></el-input>
- </el-form-item>
- <el-form-item label="BOM名称:" prop="name">
- <el-input
- size="mini"
- placeholder="BOM名称"
- v-model="formData.name"
- ></el-input>
- </el-form-item>
- <el-form-item label="版本号:" prop="versions">
- <el-input
- size="mini"
- disabled
- placeholder="版本号"
- v-model="formData.versions"
- ></el-input>
- </el-form-item>
- <el-form-item label="状态:" prop="status">
- <el-select
- size="mini"
- style="width: 100%"
- disabled
- v-model="formData.status"
- placeholder="请选择"
- >
- <el-option
- v-for="item in statusOptions"
- :label="item.label"
- :value="item.value"
- :key="item.value"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-form>
- <div slot="footer" class="dialog-footer">
- <el-button size="small" @click="handleClose">关 闭</el-button>
- <el-button size="small" type="primary" @click="handleSave"
- >确 认</el-button
- >
- </div>
- </el-dialog>
- </template>
- <script>
- import {
- saveBomTreeList,
- bomCategoryUpdate,
- hasNewVersion
- } from '@/api/material/BOM.js';
- import { getCode } from '@/api/codeManagement/index.js';
- export default {
- data() {
- return {
- visible: true,
- statusOptions: [
- {
- label: '已停用',
- value: '2'
- },
- {
- label: '已发布',
- value: '1'
- },
- {
- label: '草稿',
- value: '0'
- }
- ],
- formData: {
- code: '',
- name: '',
- versions: '',
- status: '0'
- },
- title: '新建BOM',
- rules: {
- name: [
- {
- required: true,
- message: '请输入BOM名称',
- trigger: 'blur'
- }
- ],
- code: [
- {
- required: true,
- message: '请输入BOM编码',
- trigger: 'blur'
- }
- ]
- }
- };
- },
- props: {
- categoryObj: {
- type: Object,
- default() {
- return {};
- }
- },
- categoryId: {
- type: String,
- default: ''
- },
- categoryName: {
- type: String,
- default: ''
- },
- isEdit: {
- type: Boolean,
- default: false
- }
- },
- async created() {
- if (this.isEdit) {
- this.title = '编辑BOM';
- this.formData = {
- code: this.categoryObj.code,
- name: this.categoryObj.name,
- versions: 'V' + this.categoryObj.versions + '.0',
- status: this.categoryObj.status,
- id: this.categoryObj.id
- };
- } else {
- this.title = '新建BOM';
- this.formData = {
- code: await getCode('bom_add_code'),
- name: this.categoryName || '',
- versions: '',
- status: '0'
- };
- }
- },
- methods: {
- handleClose() {
- this.$emit('close');
- },
- handleSave() {
- this.$refs.form.validate(async (valid) => {
- if (valid) {
- if (!this.isEdit) {
- let isHas = await this.hasVersionFn();
- if (!isHas) return;
- }
- let param = {
- ...this.formData,
- categoryId: this.categoryId,
- bomType: this.categoryObj.bomType
- };
- let URL = this.isEdit ? bomCategoryUpdate : saveBomTreeList;
- URL(param).then((res) => {
- this.$message.success(this.isEdit ? '修改成功' : '保存成功');
- this.$emit('close', this.formData);
- // this.handleClose();
- });
- } else {
- return false;
- }
- });
- },
- hasVersionFn() {
- return new Promise((resolve) => {
- let param = {
- categoryId: this.categoryId,
- bomType: this.categoryObj.bomType
- };
- hasNewVersion(param).then((res) => {
- if (res.data == 1) {
- this.$confirm('已经草稿版本存在,是否覆盖?', '提示', {
- confirmButtonText: '覆盖',
- cancelButtonText: '取消',
- type: 'warning'
- })
- .then(() => {
- resolve(true);
- })
- .catch(() => {
- resolve(false);
- });
- } else {
- resolve(true);
- }
- });
- });
- }
- }
- };
- </script>
- <style lang="scss" scoped></style>
|