material-tech-add-or-update.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. <template>
  2. <div>
  3. <div class="my-title">{{ !id ? "新增" : "修改" }}</div>
  4. <el-form
  5. :model="dataForm"
  6. :rules="dataRule"
  7. ref="dataForm"
  8. @keyup.enter.native="dataFormSubmit()"
  9. label-width="100px"
  10. >
  11. <el-row class="my-row">
  12. <el-col :span="8">
  13. <el-form-item label="方案编码" prop="optionCode">
  14. <el-input
  15. v-model="dataForm.optionCode"
  16. placeholder="方案编码"
  17. :disabled="isEdit"
  18. ></el-input>
  19. </el-form-item>
  20. </el-col>
  21. <el-col :span="8">
  22. <el-form-item label="物料名称" prop="productId">
  23. <el-select
  24. v-model="dataForm.productId"
  25. placeholder="请选择"
  26. filterable
  27. remote
  28. clearable
  29. >
  30. <el-option
  31. v-for="item in materialList"
  32. :key="item.materialId"
  33. :label="item.materialName"
  34. :value="item.materialId"
  35. >
  36. </el-option>
  37. </el-select>
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="8">
  41. <el-form-item label="方案名称" prop="optionName">
  42. <el-input
  43. v-model="dataForm.optionName"
  44. placeholder="方案名称"
  45. :disabled="isEdit"
  46. ></el-input>
  47. </el-form-item>
  48. </el-col>
  49. </el-row>
  50. <el-row class="my-row">
  51. <el-col :span="12">
  52. <el-form-item label="备注说明" prop="remark">
  53. <el-input
  54. type="textarea"
  55. v-model="dataForm.remark"
  56. placeholder="备注"
  57. :disabled="isEdit"
  58. ></el-input>
  59. </el-form-item>
  60. </el-col>
  61. </el-row>
  62. <el-row class="my-row">
  63. <upload-component
  64. :title="'工艺方案附件'"
  65. :accept="'*'"
  66. :file-obj-list="fileList"
  67. @uploadSuccess="uploadSuccess"
  68. />
  69. </el-row>
  70. </el-form>
  71. <span slot="footer" class="dialog-footer">
  72. <el-button @click="onChose">取消</el-button>
  73. <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
  74. </span>
  75. </div>
  76. </template>
  77. <script>
  78. import UploadComponent from "../common/upload-component";
  79. import { getMaterialList, getMaterialTechDetail } from "@/api/material";
  80. export default {
  81. name: "material-tech-add-or-update",
  82. components: { UploadComponent },
  83. data() {
  84. return {
  85. id: 0,
  86. isEdit: false,
  87. dataForm: {
  88. optionCode: "",
  89. productId: "",
  90. optionName: "",
  91. remark: "",
  92. },
  93. fileList: [],
  94. materialList: [],
  95. dataRule: {
  96. optionCode: [
  97. { required: true, message: "请输入方案编码", trigger: "blur" },
  98. ],
  99. materialName: [
  100. { required: true, message: "请输入物料名称", trigger: "blur" },
  101. ],
  102. optionName: [
  103. { required: true, message: "请输入方案名称", trigger: "blur" },
  104. ],
  105. },
  106. };
  107. },
  108. created() {},
  109. methods: {
  110. onChose() {
  111. this.$emit("onChose");
  112. },
  113. async init(id, display) {
  114. this.id = id || 0;
  115. this.fileList = [];
  116. this.$refs["dataForm"].resetFields();
  117. this.materialList = [];
  118. await this.getMaterialList();
  119. if (!id) return;
  120. await getMaterialTechDetail(id).then(({ data }) => {
  121. if (data && data.code === "200") {
  122. this.dataForm.optionId = id;
  123. this.dataForm.productId = data.data.productId;
  124. this.dataForm.optionCode = data.data.optionCode;
  125. this.dataForm.optionName = data.data.optionName;
  126. this.dataForm.remark = data.data.remark;
  127. // 附件
  128. if (data.data.attachList) {
  129. data.data.attachList.forEach((item) => {
  130. this.fileList.push({
  131. name: item.fileName,
  132. url: item.url,
  133. id: item.url,
  134. });
  135. });
  136. }
  137. }
  138. });
  139. },
  140. uploadSuccess(fileList) {
  141. this.fileList = fileList;
  142. },
  143. async getMaterialList() {
  144. await getMaterialList().then(({ data }) => {
  145. if (data && data.code === "200") {
  146. this.materialList = data.data.records;
  147. }
  148. });
  149. },
  150. dataFormSubmit() {
  151. this.$refs["dataForm"].validate((valid) => {
  152. if (valid) {
  153. // 产品技术文件
  154. let fList = this.fileList;
  155. if (fList.length > 0) {
  156. this.dataForm.attachList = [];
  157. for (let i = 0; i < fList.length; i++) {
  158. this.dataForm.attachList.push({
  159. fileName: fList[i].name,
  160. url: fList[i].url,
  161. });
  162. }
  163. } else {
  164. this.$message.error("请上传工艺方案附件");
  165. return;
  166. }
  167. this.$http({
  168. url: !this.id
  169. ? this.$http.adornUrl(`/biz-service/pro-technology-option/save`)
  170. : this.$http.adornUrl(
  171. `/biz-service/pro-technology-option/update`
  172. ),
  173. method: "post",
  174. data: this.$http.adornData({ ...this.dataForm, orgId: this.orgId }),
  175. }).then(({ data }) => {
  176. if (data && data.code === "200") {
  177. this.$message({
  178. message: "操作成功",
  179. type: "success",
  180. duration: 1500,
  181. onClose: () => {
  182. this.onChose();
  183. this.$emit("refreshDataList");
  184. },
  185. });
  186. } else {
  187. this.$message.error(data.msg);
  188. }
  189. });
  190. }
  191. });
  192. },
  193. },
  194. };
  195. </script>
  196. <style scoped></style>