addOrEditDialog.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374
  1. <template>
  2. <ele-modal
  3. custom-class="ele-dialog-form long-dialog-form"
  4. :centered="true"
  5. :visible.sync="addOrEditDialogFlag"
  6. :title="title"
  7. :append-to-body="false"
  8. :close-on-click-modal="false"
  9. width="60%"
  10. :before-close="cancel"
  11. :maxable="true"
  12. :resizable="true"
  13. >
  14. <el-form
  15. ref="form"
  16. :model="form"
  17. :rules="rules"
  18. label-width="120px"
  19. class="el-form-box"
  20. :disabled="title == '详情'"
  21. >
  22. <headerTitle title="产品信息"> </headerTitle>
  23. <el-row>
  24. <el-col :span="12">
  25. <el-form-item label="编码" prop="code">
  26. <el-input
  27. clearable
  28. readonly
  29. v-model="form.code"
  30. @click.native="$refs.produceRef.open()"
  31. placeholder="请选择"
  32. />
  33. </el-form-item>
  34. </el-col>
  35. <el-col :span="12">
  36. <el-form-item label="名称" prop="name">
  37. <el-input clearable disabled v-model="form.name" placeholder=" " />
  38. </el-form-item>
  39. </el-col>
  40. <el-col :span="12">
  41. <el-form-item label="工厂名称:" prop="factoriesId">
  42. <el-select
  43. style="width: 100%"
  44. clearable
  45. v-model="form.factoriesId"
  46. placeholder="请选择所属工厂"
  47. >
  48. <el-option
  49. v-for="item in factoryList"
  50. :label="item.name"
  51. :value="item.id"
  52. :key="item.id"
  53. @click.native="change_factoryId(item)"
  54. ></el-option>
  55. </el-select>
  56. </el-form-item>
  57. </el-col>
  58. </el-row>
  59. <headerTitle title="产线节拍"> </headerTitle>
  60. <ele-pro-table
  61. :columns="columns"
  62. :datasource="form.list"
  63. ref="table"
  64. height="400px"
  65. full-height="calc(100vh - 116px)"
  66. :needPage="false"
  67. :selection.sync="selection"
  68. >
  69. <template v-slot:toolbar v-if="title != '详情'">
  70. <el-button
  71. size="small"
  72. type="primary"
  73. icon="el-icon-plus"
  74. class="ele-btn-icon"
  75. @click="handParent()"
  76. >
  77. 新增
  78. </el-button>
  79. <el-popconfirm
  80. class="ele-action"
  81. title="确定要删除选中的信息吗?"
  82. @confirm="remove()"
  83. >
  84. <template v-slot:reference>
  85. <el-button
  86. type="danger"
  87. :underline="false"
  88. icon="el-icon-delete"
  89. :disabled="selection?.length === 0"
  90. >
  91. 删除
  92. </el-button>
  93. </template>
  94. </el-popconfirm>
  95. </template>
  96. <template v-slot:taktTime="{ row, $index }">
  97. <el-form-item
  98. label-width="0"
  99. :prop="'list.' + $index + '.taktTime'"
  100. :rules="[{ required: true, message: '请输入', trigger: 'blur' }]"
  101. >
  102. <el-input
  103. clearable
  104. v-model.number="row.taktTime"
  105. placeholder="请输入"
  106. />
  107. </el-form-item>
  108. </template>
  109. <template v-slot:priority="{ row, $index }">
  110. <el-form-item
  111. label-width="0"
  112. :prop="'list.' + $index + '.priority'"
  113. :rules="[{ required: true, message: '请输入', trigger: 'blur' }]"
  114. >
  115. <el-input
  116. clearable
  117. v-model.number="row.priority"
  118. placeholder="请输入"
  119. />
  120. </el-form-item>
  121. </template>
  122. <template v-slot:productionLineId="{ row, $index }">
  123. <el-form-item
  124. label-width="0"
  125. :prop="'list.' + $index + '.productionLineId'"
  126. :rules="[{ required: true, message: '请选择', trigger: 'blur' }]"
  127. >
  128. <el-select
  129. style="width: 100%"
  130. clearable
  131. v-model="row.productionLineId"
  132. placeholder="请选择"
  133. >
  134. <el-option
  135. v-for="item in productionLineList"
  136. :label="item.name"
  137. :value="item.id"
  138. :key="item.id"
  139. @click.native="change_productionLineId(item, $index)"
  140. ></el-option>
  141. </el-select>
  142. </el-form-item>
  143. </template>
  144. <template v-slot:remark="{ row }">
  145. <el-input clearable v-model="row.remark" placeholder="请输入" />
  146. </template>
  147. <template v-slot:columnRequired="{ column }">
  148. <span class="is-required">{{ column.label }}</span>
  149. </template>
  150. </ele-pro-table>
  151. </el-form>
  152. <div slot="footer">
  153. <el-button
  154. type="primary"
  155. @click="save()"
  156. v-lodading="loading"
  157. v-if="title != '详情'"
  158. >保存</el-button
  159. >
  160. <el-button @click="cancel">返回</el-button>
  161. </div>
  162. <ProductModal
  163. ref="produceRef"
  164. @changeParent="produceConfirm"
  165. ></ProductModal>
  166. </ele-modal>
  167. </template>
  168. <script>
  169. const defForm = {
  170. code: '', //编码
  171. name: '', //名称
  172. productId: '', //物品id
  173. factoriesId: '', //工厂id
  174. factoriesName: '', //工厂名称
  175. list: [] //表格数据
  176. };
  177. import {
  178. getFactoryarea,
  179. listFactoryLineByFactoryId
  180. } from '@/api/factoryModel';
  181. import ProductModal from '@/components/productList/product-list.vue';
  182. import {
  183. saveOrUpdate,
  184. getById
  185. } from '@/api/productionScheduling/productionLineBeat';
  186. export default {
  187. components: { ProductModal },
  188. computed: {},
  189. data() {
  190. return {
  191. lodading: false,
  192. title: '',
  193. addOrEditDialogFlag: false,
  194. form: { ...defForm },
  195. rules: {
  196. name: [
  197. { required: true, message: '名称不能为空', trigger: 'change' }
  198. ],
  199. factoriesId: [
  200. { required: true, message: '请选择工厂', trigger: 'change' }
  201. ],
  202. code: [{ required: true, message: '编码不能为空', trigger: 'change' }]
  203. },
  204. factoryList: [],
  205. selection: [],
  206. productionLineList: [],
  207. columns: [
  208. {
  209. width: 45,
  210. type: 'selection',
  211. columnKey: 'selection',
  212. fixed: 'left',
  213. align: 'center'
  214. },
  215. {
  216. width: 60,
  217. type: 'index',
  218. columnKey: 'index',
  219. label: '序号',
  220. align: 'center',
  221. fixed: 'left'
  222. },
  223. {
  224. prop: 'productionLineName',
  225. slot: 'productionLineId',
  226. headerSlot: 'columnRequired',
  227. label: '产线名称',
  228. align: 'center',
  229. showOverflowTooltip: true,
  230. minWidth: 180
  231. },
  232. {
  233. prop: 'taktTime',
  234. slot: 'taktTime',
  235. headerSlot: 'columnRequired',
  236. label: '产线节拍(分钟)',
  237. align: 'center',
  238. showOverflowTooltip: true,
  239. minWidth: 180
  240. },
  241. {
  242. prop: 'priority',
  243. slot: 'priority',
  244. headerSlot: 'columnRequired',
  245. label: '优先顺序',
  246. align: 'center',
  247. showOverflowTooltip: true,
  248. minWidth: 120
  249. },
  250. {
  251. prop: 'remark',
  252. slot: 'remark',
  253. label: '备注',
  254. align: 'center',
  255. showOverflowTooltip: true,
  256. minWidth: 200
  257. }
  258. ],
  259. loading: false
  260. };
  261. },
  262. mounted() {},
  263. created() {
  264. this.getFactoryList();
  265. },
  266. methods: {
  267. //初始化
  268. async open(row = {}, type) {
  269. this.addOrEditDialogFlag = true;
  270. this.title = type == 'add' ? '新增' : type == 'edit' ? '修改' : '详情';
  271. if (type !== 'add') {
  272. this.form = await getById(row.id);
  273. this.form.list.forEach((item, index) => {
  274. item.key = index;
  275. });
  276. if (this.form.factoriesId) {
  277. this.change_factoryId({ id: this.form.factoriesId });
  278. }
  279. }
  280. },
  281. handParent() {
  282. this.form.list.push({
  283. productionLineName: '',
  284. productionLineId: '',
  285. taktTime: '',
  286. remark: '',
  287. key: this.form.list?.length || 0
  288. });
  289. },
  290. async getFactoryList() {
  291. const { list } = await getFactoryarea({
  292. pageNum: 1,
  293. size: 999,
  294. type: 1,
  295. enable: 1
  296. });
  297. this.factoryList = list || [];
  298. },
  299. /* 获取产线 */
  300. async change_factoryId(item) {
  301. this.productionLineList = await listFactoryLineByFactoryId([
  302. this.form.factoriesId
  303. ]);
  304. this.form.factoriesName = item.name;
  305. },
  306. change_productionLineId(item, index) {
  307. this.$set(this.form.list[index], 'productionLineName', item.name);
  308. },
  309. produceConfirm(data) {
  310. this.form.name = data[0].name;
  311. this.form.code = data[0].code;
  312. this.form.productId = data[0].id;
  313. this.form.brandNo = data[0].brandNum;
  314. this.form.modelType = data[0].modelType;
  315. this.form.specification = data[0].specification;
  316. },
  317. remove() {
  318. let keys = this.selection.map((item) => item.key);
  319. this.form.list = this.form.list.filter(
  320. (item) => !keys.includes(item.key)
  321. );
  322. this.selection = [];
  323. },
  324. save() {
  325. this.$refs.form.validate((valid) => {
  326. if (!this.form.list?.length) {
  327. this.$message.error('节拍信息不能为空');
  328. return;
  329. }
  330. if (valid) {
  331. let priorityList = this.form.list.map((item) => item.priority);
  332. if (new Set(priorityList).size !== priorityList.length) {
  333. this.$message.error('优先顺序不能重复');
  334. return;
  335. }
  336. this.loading = true;
  337. saveOrUpdate(this.form)
  338. .then((res) => {
  339. this.$message.success('操作成功');
  340. this.cancel();
  341. this.$emit('done');
  342. })
  343. .finally(() => {
  344. this.loading = false;
  345. });
  346. }
  347. });
  348. },
  349. //关闭弹窗
  350. cancel() {
  351. this.addOrEditDialogFlag = false;
  352. this.form = {
  353. ...defForm
  354. };
  355. this.form.list = [];
  356. }
  357. }
  358. };
  359. </script>
  360. <style scoped lang="scss">
  361. // :deep(.el-form-item--medium) {
  362. // display: none;
  363. // }
  364. </style>