program-add-or-update.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317
  1. <template>
  2. <div>
  3. <div class="my-title">{{ type === 1 ? "处理" : "修改" }}</div>
  4. <e-desc title="基本信息" column="3">
  5. <e-desc-item label="项目名称">{{ dataForm.projectName }}</e-desc-item>
  6. <e-desc-item label="任务号">{{ dataForm.orderCode }}</e-desc-item>
  7. <e-desc-item label="图号">{{ dataForm.mapNumber }}</e-desc-item>
  8. <e-desc-item label="物料名称">{{ dataForm.productName }}</e-desc-item>
  9. <e-desc-item label="数量">{{ dataForm.planCnt }}</e-desc-item>
  10. <e-desc-item label="状态">{{
  11. dataForm.state
  12. ? optionsStates.find((item) => item.value === dataForm.state).label
  13. : ""
  14. }}</e-desc-item>
  15. <e-desc-item label="合同交期">{{ dataForm.deliveryDate }}</e-desc-item>
  16. <e-desc-item label="责任人">{{
  17. dataForm.responsibilityPerson
  18. }}</e-desc-item>
  19. </e-desc>
  20. <e-desc title="技术协议">
  21. <e-desc-item v-if="dataForm.attachList1" label="技术协议" span="3">
  22. <div v-for="(item, index) in dataForm.attachList1" style="display: inline">
  23. <span v-if="index > 0">,</span>
  24. <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{
  25. item.fileName }}</a>
  26. </div>
  27. </e-desc-item>
  28. </e-desc>
  29. <e-desc title="技术文件">
  30. <e-desc-item v-if="dataForm.attachList2" label="技术文件" span="3">
  31. <div v-for="(item, index) in dataForm.attachList2" style="display: inline">
  32. <span v-if="index > 0">,</span>
  33. <a :key="item.fileName + index" type="primary" href="#" @click="previewFile(item.fileName, item.url)">{{
  34. item.fileName }}</a>
  35. </div>
  36. </e-desc-item>
  37. </e-desc>
  38. <e-desc title="工艺路线">
  39. <el-table :data="dataForm.proTechnologyStepNodeList" :row-style="tableRowStyle" border style="width: 100%">
  40. <el-table-column label="序号" type="index" width="50" align="center">
  41. </el-table-column>
  42. <el-table-column prop="nodeName" header-align="center" align="center" min-width="80"
  43. :show-tooltip-when-overflow="true" label="工种">
  44. </el-table-column>
  45. <el-table-column prop="require" header-align="center" align="center" min-width="400"
  46. :show-tooltip-when-overflow="true" label="工序要求">
  47. </el-table-column>
  48. </el-table>
  49. </e-desc>
  50. <e-desc title="编程列表">
  51. <el-form :model="dataForm" :rules="dataRule" ref="dataForm" style="width: 100%">
  52. <!-- 编程列表 -->
  53. <el-table :data="dataForm.proProgramDetailsList || []" border style="width: 100%">
  54. <el-table-column label="序号" type="index" width="50" align="center">
  55. </el-table-column>
  56. <el-table-column prop="nodeName" header-align="center" align="center" min-width="80" label="节点名称">
  57. </el-table-column>
  58. <el-table-column prop="require" header-align="center" align="center" min-width="240" label="节点内容">
  59. </el-table-column>
  60. <el-table-column prop="preTaskTime" header-align="center" align="center" min-width="100" label="程序时间">
  61. </el-table-column>
  62. <el-table-column prop="num" header-align="center" align="center" min-width="100" label="程序数量">
  63. </el-table-column>
  64. <el-table-column prop="attachList" header-align="center" align="center" label="程序文件">
  65. <template slot-scope="scope">
  66. <el-button :disabled="!scope.row.attachList || scope.row.attachList.length === 0
  67. " type="text" size="small" @click="attachDetails(scope.row.attachList)">查看</el-button>
  68. </template>
  69. </el-table-column>
  70. <!-- Add dialog for row operations -->
  71. <el-table-column header-align="center" align="center" width="120" label="操作">
  72. <template slot-scope="scope">
  73. <el-button v-if="type === 2" type="text" size="small"
  74. @click="handleEdit(scope.row, scope.$index)">编辑</el-button>
  75. <el-button v-if="type === 1" type="text" size="small" style="color: red"
  76. @click="deleteRow(scope.$index)">删除</el-button>
  77. </template>
  78. </el-table-column>
  79. </el-table>
  80. <!-- Add/Edit dialog -->
  81. <el-dialog :title="dialogTitle" :visible.sync="dialogVisible" width="500px">
  82. <el-form :model="rowForm" ref="rowForm" label-width="100px">
  83. <el-form-item label="节点名称">
  84. <el-input v-model="rowForm.nodeName" placeholder="请输入节点名称"></el-input>
  85. </el-form-item>
  86. <el-form-item label="节点内容">
  87. <el-input v-model="rowForm.require" placeholder="请输入节点内容"></el-input>
  88. </el-form-item>
  89. <el-form-item label="预估工时">
  90. <el-input-number v-model="rowForm.preTaskTime" :min="1" placeholder="请输入预估工时"></el-input-number>
  91. </el-form-item>
  92. <el-form-item label="程序数量">
  93. <el-input-number v-model="rowForm.num" :min="1" placeholder="请输入程序数量"></el-input-number>
  94. </el-form-item>
  95. <el-form-item label="程序文件">
  96. <upload-component :display-title="false" :displayStar="false" :accept="'*'"
  97. :file-obj-list="rowForm.attachList" @uploadSuccess="handleUploadSuccess" />
  98. </el-form-item>
  99. </el-form>
  100. <span slot="footer">
  101. <el-button @click="dialogVisible = false">取 消</el-button>
  102. <el-button type="primary" @click="saveRow">确 定</el-button>
  103. </span>
  104. </el-dialog>
  105. <el-row v-if="type === 1" style="text-align: center; margin-top: 10px">
  106. <el-button type="primary" icon="el-icon-plus" @click="handleAdd"></el-button>
  107. </el-row> </el-form>
  108. </e-desc>
  109. <span slot="footer" class="dialog-footer">
  110. <el-button @click="onChose">取消</el-button>
  111. <el-button type="primary" @click="dataFormSubmit()" v-reClick>确定</el-button>
  112. </span>
  113. <preview-component ref="preview" v-if="previewVisible" @onChose="previewVisible = false" />
  114. <attach-detail-dialog ref="attachDetail" />
  115. </div>
  116. </template>
  117. <script>
  118. import EDesc from "../common/e-desc";
  119. import EDescItem from "../common/e-desc-item";
  120. import { getDetail } from "@/api/program";
  121. import uploadComponent from "../common/upload-component";
  122. import AttachDetailDialog from '../common/attach-detail-dialog'
  123. import PreviewComponent from '@/views/modules/common/preview-component'
  124. export default {
  125. name: "program-add-or-update",
  126. components: { EDesc, EDescItem, uploadComponent, AttachDetailDialog, PreviewComponent },
  127. data() {
  128. return {
  129. id: 0,
  130. type: 1,
  131. dataForm: {
  132. attachList1: [],
  133. attachList2: [],
  134. proTechnologyStepNodeList: [],
  135. proProgramDetailsList: [],
  136. },
  137. // 状态列表数据
  138. optionsStates: [
  139. { value: "1", label: "待处理" },
  140. { value: "2", label: "已处理" },
  141. ],
  142. previewVisible: false,
  143. dataRule: {},
  144. dialogVisible: false,
  145. dialogTitle: '',
  146. rowForm: {
  147. nodeName: '',
  148. require: '',
  149. preTaskTime: 0,
  150. num: 1,
  151. attachList: []
  152. },
  153. editIndex: -1
  154. };
  155. },
  156. created() { },
  157. methods: {
  158. init(id, type) {
  159. this.type = type;
  160. this.id = id || 0;
  161. // this.getMaterialList()
  162. this.getDetail();
  163. },
  164. onChose() {
  165. this.$emit("onChose");
  166. },
  167. getDetail() {
  168. getDetail(this.id).then(({ data }) => {
  169. if (data && data.code === "200") {
  170. this.dataForm = data.data;
  171. if (!this.dataForm.proProgramDetailsList) {
  172. this.dataForm.proProgramDetailsList = [];
  173. }
  174. if (!this.dataForm.proTechnologyStepNodeList) {
  175. this.dataForm.proTechnologyStepNodeList = [];
  176. }
  177. this.fileList1 = data.data.attachList1 || [];
  178. this.fileList2 = data.data.attachList2 || [];
  179. } else {
  180. this.$message.error(data.msg);
  181. }
  182. });
  183. },
  184. dataFormSubmit() {
  185. this.$refs["dataForm"].validate((valid) => {
  186. if (valid) {
  187. // 检查proProgramDetailsList是否为空
  188. if (
  189. !this.dataForm.proProgramDetailsList ||
  190. this.dataForm.proProgramDetailsList.length === 0
  191. ) {
  192. this.$message.error("编程列表不能为空");
  193. return;
  194. }
  195. // proProgramDetailsList 中附件字段name转为fileName
  196. if (this.type === 1 && this.dataForm.proProgramDetailsList) {
  197. this.dataForm.proProgramDetailsList.forEach((item) => {
  198. item.attachList.forEach((attach) => {
  199. attach.fileName = attach.name;
  200. });
  201. });
  202. } else if (this.rowForm.attachList) {
  203. this.rowForm.attachList.forEach((attach) => {
  204. attach.fileName = attach.name;
  205. });
  206. }
  207. // console.log(this.rowForm)
  208. // return
  209. this.$http({
  210. url: this.type === 1
  211. ? this.$http.adornUrl(`/biz-service/proProgram/updateProcessing`)
  212. : this.$http.adornUrl(`/biz-service/proProgram/update`),
  213. method: "post",
  214. data: this.type === 1 ? this.$http.adornData({ ...this.dataForm, orgId: this.orgId }) : this.$http.adornData(this.rowForm),
  215. }).then(({ data }) => {
  216. if (data && data.code === "200") {
  217. this.$message({
  218. message: "操作成功",
  219. type: "success",
  220. duration: 1500,
  221. onClose: () => {
  222. this.onChose();
  223. this.$emit("refreshDataList");
  224. },
  225. });
  226. } else {
  227. this.$message.error(data.msg);
  228. }
  229. });
  230. }
  231. });
  232. },
  233. // 编程列表相关方法
  234. addRow() {
  235. if (!this.dataForm.proProgramDetailsList) {
  236. this.dataForm.proProgramDetailsList = [];
  237. }
  238. this.dataForm.proProgramDetailsList.push({
  239. nodeName: "",
  240. require: "",
  241. num: 1,
  242. preTaskTime: 1,
  243. attachList: [],
  244. });
  245. },
  246. deleteRow(index) {
  247. this.dataForm.proProgramDetailsList.splice(index, 1);
  248. },
  249. uploadProgramSuccess(fileList, index) {
  250. this.dataForm.proProgramDetailsList[index].attachList = fileList;
  251. },
  252. tableRowStyle({ row }) {
  253. return row.id === this.dataForm.nodeId
  254. ? { backgroundColor: "#ffcccc" }
  255. : {};
  256. },
  257. handleAdd() {
  258. this.dialogTitle = '新增编程项目'
  259. this.editIndex = -1
  260. this.rowForm = {
  261. nodeName: '',
  262. require: '',
  263. preTaskTime: 1,
  264. num: 1,
  265. attachList: []
  266. }
  267. this.dialogVisible = true
  268. },
  269. handleEdit(row, index) {
  270. this.dialogTitle = '编辑编程项目'
  271. this.editIndex = index
  272. console.log(row)
  273. this.rowForm = {
  274. ...row,
  275. attachList: row.attachList ? row.attachList.map(item => ({
  276. ...item,
  277. name: item.fileName,
  278. id: item.url
  279. })) : []
  280. }
  281. this.dialogVisible = true
  282. },
  283. saveRow() {
  284. if (this.editIndex === -1) {
  285. this.dataForm.proProgramDetailsList.push({ ...this.rowForm })
  286. } else {
  287. this.$set(this.dataForm.proProgramDetailsList, this.editIndex, { ...this.rowForm })
  288. }
  289. this.dialogVisible = false
  290. },
  291. handleUploadSuccess(fileList) {
  292. this.rowForm.attachList = fileList
  293. },
  294. attachDetails(attachList) {
  295. // 转换数据结构以匹配组件期望的格式
  296. const formattedList = attachList.map(item => ({
  297. fileName: item.fileName || item.name || item.originalName,
  298. url: item.url || item.path || item.src
  299. }))
  300. this.$refs.attachDetail.init(formattedList)
  301. },
  302. // 预览
  303. previewFile(fileName, url) {
  304. this.previewVisible = true
  305. this.$nextTick(() => {
  306. this.$refs.preview.init(fileName, url)
  307. })
  308. }
  309. },
  310. };
  311. </script>
  312. <style></style>