123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <template>
- <div>
- <div class="my-title">{{ !id ? "新增" : "修改" }}</div>
- <el-form
- :model="dataForm"
- :rules="dataRule"
- ref="dataForm"
- @keyup.enter.native="dataFormSubmit()"
- label-width="100px"
- >
- <el-row class="my-row">
- <el-col :span="8">
- <el-form-item label="方案编码" prop="optionCode">
- <el-input
- v-model="dataForm.optionCode"
- placeholder="方案编码"
- :disabled="isEdit"
- ></el-input>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="物料名称" prop="productId">
- <el-select
- v-model="dataForm.productId"
- placeholder="请选择"
- filterable
- remote
- clearable
- >
- <el-option
- v-for="item in materialList"
- :key="item.materialId"
- :label="item.materialName"
- :value="item.materialId"
- >
- </el-option>
- </el-select>
- </el-form-item>
- </el-col>
- <el-col :span="8">
- <el-form-item label="方案名称" prop="optionName">
- <el-input
- v-model="dataForm.optionName"
- placeholder="方案名称"
- :disabled="isEdit"
- ></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row class="my-row">
- <el-col :span="12">
- <el-form-item label="备注说明" prop="remark">
- <el-input
- type="textarea"
- v-model="dataForm.remark"
- placeholder="备注"
- :disabled="isEdit"
- ></el-input>
- </el-form-item>
- </el-col>
- </el-row>
- <el-row class="my-row">
- <upload-component
- :title="'工艺方案附件'"
- :accept="'*'"
- :file-obj-list="fileList"
- @uploadSuccess="uploadSuccess"
- />
- </el-row>
- </el-form>
- <span slot="footer" class="dialog-footer">
- <el-button @click="onChose">取消</el-button>
- <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
- </span>
- </div>
- </template>
- <script>
- import UploadComponent from "../common/upload-component";
- import { getMaterialList, getMaterialTechDetail } from "@/api/material";
- export default {
- name: "material-tech-add-or-update",
- components: { UploadComponent },
- data() {
- return {
- id: 0,
- isEdit: false,
- dataForm: {
- optionCode: "",
- productId: "",
- optionName: "",
- remark: "",
- },
- fileList: [],
- materialList: [],
- dataRule: {
- optionCode: [
- { required: true, message: "请输入方案编码", trigger: "blur" },
- ],
- materialName: [
- { required: true, message: "请输入物料名称", trigger: "blur" },
- ],
- optionName: [
- { required: true, message: "请输入方案名称", trigger: "blur" },
- ],
- },
- };
- },
- created() {},
- methods: {
- onChose() {
- this.$emit("onChose");
- },
- async init(id, display) {
- this.id = id || 0;
- this.fileList = [];
- this.$refs["dataForm"].resetFields();
- this.materialList = [];
- await this.getMaterialList();
- if (!id) return;
- await getMaterialTechDetail(id).then(({ data }) => {
- if (data && data.code === "200") {
- this.dataForm.optionId = id;
- this.dataForm.productId = data.data.productId;
- this.dataForm.optionCode = data.data.optionCode;
- this.dataForm.optionName = data.data.optionName;
- this.dataForm.remark = data.data.remark;
-
- // 附件
- if (data.data.attachList) {
- data.data.attachList.forEach((item) => {
- this.fileList.push({
- name: item.fileName,
- url: item.url,
- id: item.url,
- });
- });
- }
- }
- });
- },
- uploadSuccess(fileList) {
- this.fileList = fileList;
- },
- async getMaterialList() {
- await getMaterialList().then(({ data }) => {
- if (data && data.code === "200") {
- this.materialList = data.data.records;
- }
- });
- },
- dataFormSubmit() {
- this.$refs["dataForm"].validate((valid) => {
- if (valid) {
- // 产品技术文件
- let fList = this.fileList;
- if (fList.length > 0) {
- this.dataForm.attachList = [];
- for (let i = 0; i < fList.length; i++) {
- this.dataForm.attachList.push({
- fileName: fList[i].name,
- url: fList[i].url,
- });
- }
- } else {
- this.$message.error("请上传工艺方案附件");
- return;
- }
- this.$http({
- url: !this.id
- ? this.$http.adornUrl(`/biz-service/pro-technology-option/save`)
- : this.$http.adornUrl(
- `/biz-service/pro-technology-option/update`
- ),
- method: "post",
- data: this.$http.adornData({ ...this.dataForm, orgId: this.orgId }),
- }).then(({ data }) => {
- if (data && data.code === "200") {
- this.$message({
- message: "操作成功",
- type: "success",
- duration: 1500,
- onClose: () => {
- this.onChose();
- this.$emit("refreshDataList");
- },
- });
- } else {
- this.$message.error(data.msg);
- }
- });
- }
- });
- },
- },
- };
- </script>
- <style scoped></style>
|