user-setting.vue 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="1060px"
  5. :visible="visible"
  6. :append-to-body="true"
  7. :close-on-click-modal="true"
  8. custom-class="ele-dialog-form"
  9. :title="`给工序【${this.data?.code}${this.data?.name}】配置参数`"
  10. @update:visible="updateVisible"
  11. >
  12. <div class="ele-body">
  13. <ele-pro-table
  14. ref="table"
  15. :needPage="false"
  16. :columns="columns"
  17. :datasource="datasource"
  18. >
  19. <!-- 表头工具栏 -->
  20. <template v-slot:toolbar>
  21. <el-button
  22. size="small"
  23. type="primary"
  24. icon="el-icon-plus"
  25. class="ele-btn-icon"
  26. @click="showAddLog"
  27. >
  28. 添加参数
  29. </el-button>
  30. </template>
  31. <!-- 描述 -->
  32. <template v-slot:description="{ row }">
  33. <el-input v-model="row.description" placeholder="请输入"></el-input>
  34. </template>
  35. <!-- 单位 -->
  36. <template v-slot:unitName="{ row }">
  37. <el-input v-model="row.unitName" placeholder="请输入"></el-input>
  38. </template>
  39. <!-- 上限 -->
  40. <template v-slot:maxValue="{ row }">
  41. <el-input v-model="row.maxValue" placeholder="请输入"></el-input>
  42. </template>
  43. <!-- 下限 -->
  44. <template v-slot:minValue="{ row }">
  45. <el-input v-model="row.minValue" placeholder="请输入"></el-input>
  46. </template>
  47. <!-- 默认值 -->
  48. <template v-slot:defaultValue="{ row }">
  49. <el-input v-model="row.defaultValue" placeholder="请输入"></el-input>
  50. </template>
  51. <!-- 默认值 -->
  52. <template v-slot:notNull="{ row }">
  53. <el-select v-model="row.notNull" placeholder="请选择">
  54. <el-option
  55. v-for="item in timeType"
  56. :key="item.value"
  57. :label="item.label"
  58. :value="item.value"
  59. >
  60. </el-option>
  61. </el-select>
  62. </template>
  63. <!-- 状态列 -->
  64. <!-- 操作列 -->
  65. <template v-slot:action="{ row }">
  66. <el-popconfirm
  67. class="ele-action"
  68. title="确定要删除当前工序吗?"
  69. @confirm="remove(row)"
  70. >
  71. <template v-slot:reference>
  72. <el-link type="danger" :underline="false" icon="el-icon-delete">
  73. 删除
  74. </el-link>
  75. </template>
  76. </el-popconfirm>
  77. </template>
  78. </ele-pro-table>
  79. </div>
  80. <template v-slot:footer>
  81. <el-button @click="updateVisible(false)">取消</el-button>
  82. <el-button type="primary" :loading="loading" @click="save">
  83. 保存
  84. </el-button>
  85. </template>
  86. <ele-modal
  87. width="1720px"
  88. :visible="addDialog"
  89. :append-to-body="true"
  90. :close-on-click-modal="true"
  91. @update:visible="closeAdd"
  92. custom-class="ele-dialog-form"
  93. >
  94. <Paramrter :data="tableData" ref="Paramrter" />
  95. <template v-slot:footer>
  96. <el-button @click="closeAdd">取消</el-button>
  97. <el-button type="primary" :loading="loading" @click="addParamrter">
  98. 添加
  99. </el-button>
  100. </template>
  101. </ele-modal>
  102. </ele-modal>
  103. </template>
  104. <script>
  105. import producetask from '@/api/technology/production';
  106. import parameter from '@/api/technology/parameter';
  107. import Paramrter from './parameter';
  108. import { deepClone } from '@/components/FormGenerator/utils/index';
  109. export default {
  110. components: { Paramrter },
  111. props: {
  112. // 弹窗是否打开
  113. visible: Boolean,
  114. // 修改回显的数据
  115. data: Object
  116. },
  117. data() {
  118. return {
  119. timeType: [
  120. { value: 1, label: '是' },
  121. { value: 0, label: '否' }
  122. ],
  123. // 表格列配置
  124. columns: [
  125. {
  126. prop: 'paramName',
  127. label: '参数名称',
  128. showOverflowTooltip: true,
  129. align: 'center',
  130. minWidth: 110
  131. },
  132. {
  133. align: 'center',
  134. slot: 'description',
  135. prop: 'description',
  136. label: '文本描述',
  137. showOverflowTooltip: true,
  138. minWidth: 110
  139. },
  140. {
  141. prop: 'unitName',
  142. slot: 'unitName',
  143. label: '参数单位',
  144. align: 'center',
  145. showOverflowTooltip: true
  146. },
  147. {
  148. prop: 'maxValue',
  149. slot: 'maxValue',
  150. label: '参数上限',
  151. align: 'center',
  152. // showOverflowTooltip: true
  153. },
  154. {
  155. prop: 'minValue',
  156. slot: 'minValue',
  157. label: '参数下限',
  158. align: 'center',
  159. // showOverflowTooltip: true
  160. },
  161. {
  162. prop: 'defaultValue',
  163. slot: 'defaultValue',
  164. label: '默认值',
  165. align: 'center',
  166. // showOverflowTooltip: true
  167. },
  168. {
  169. prop: 'notNull',
  170. slot: 'notNull',
  171. label: '是否必填',
  172. align: 'center',
  173. showOverflowTooltip: true
  174. },
  175. {
  176. columnKey: 'action',
  177. label: '操作',
  178. align: 'center',
  179. resizable: false,
  180. slot: 'action',
  181. showOverflowTooltip: true
  182. }
  183. ],
  184. loading: false,
  185. addDialog: false,
  186. removeList: [],
  187. tableData: []
  188. };
  189. },
  190. methods: {
  191. addParamrter() {
  192. let arr = deepClone(this.$refs.Paramrter.selection)
  193. arr.forEach((element) => {
  194. this.$set(element, 'paramId', element.id);
  195. this.$set(element, 'paramName', element.name);
  196. delete element.id;
  197. delete element.name;
  198. });
  199. this.$refs.table.setData([...arr, ...this.$refs.table.getData()]);
  200. this.closeAdd();
  201. },
  202. showAddLog() {
  203. this.tableData = this.$refs.table.getData()
  204. this.addDialog = true;
  205. },
  206. /*关闭选择参数*/
  207. closeAdd() {
  208. this.$refs.Paramrter.$refs.tableParameter.setSelectedRows([]);
  209. this.addDialog = false;
  210. },
  211. /* 刷新表格 */
  212. reload() {
  213. this.$refs.table.reload();
  214. },
  215. remove(row) {
  216. const data = this.$refs.table.getData() ?? [];
  217. if (row.id) {
  218. this.removeList.push(row.id);
  219. this.$refs.table.setData(data.filter((d) => d.id !== row.id));
  220. } else {
  221. this.$refs.table.setData(
  222. data.filter((d) => d.paramId !== row.paramId)
  223. );
  224. }
  225. },
  226. /* 表格数据源 */
  227. async datasource({ page, limit, where }) {
  228. if (this.data?.id) {
  229. console.log(22222);
  230. const res = await producetask.paramList({
  231. taskId: this.data.id,
  232. pageNum: 1,
  233. size: -1
  234. });
  235. return res;
  236. }
  237. },
  238. /* 保存编辑 */
  239. save() {
  240. let arr = this.$refs.table.getData();
  241. arr.forEach((it) => {
  242. if (!it.taskId) {
  243. this.$set(it, 'taskId', this.data.id);
  244. }
  245. });
  246. if(!arr.length){
  247. return this.$message.warning('参数不能为空')
  248. }
  249. let canSave = true
  250. for(var i=0;i<arr.length;i++){
  251. const defaultValue = Number(arr[i].defaultValue)
  252. const maxValue = Number(arr[i].maxValue)
  253. const minValue = Number(arr[i].minValue)
  254. if(defaultValue!=''&maxValue!=''){
  255. if(defaultValue>maxValue||defaultValue==maxValue){
  256. this.$message.warning('默认值应小于参数上限')
  257. canSave = false
  258. break
  259. }
  260. }
  261. if(defaultValue!=''&minValue!=''){
  262. if(defaultValue<minValue||defaultValue==minValue){
  263. this.$message.warning('默认值应大于参数下限')
  264. canSave = false
  265. break
  266. }
  267. }
  268. if(maxValue!=''&minValue!=''){
  269. if(maxValue<minValue||maxValue==minValue){
  270. this.$message.warning('参数上限应大于参数下限')
  271. canSave = false
  272. break
  273. }
  274. }
  275. }
  276. if(canSave){
  277. producetask
  278. .paramSave({
  279. removeList: this.removeList,
  280. saveList: arr
  281. })
  282. .then((msg) => {
  283. if(msg){
  284. this.$message.success(msg);
  285. this.updateVisible(false);
  286. }
  287. });
  288. }
  289. // this.$refs.form.validate((valid) => {
  290. // if (!valid) {
  291. // return false;
  292. // }
  293. // if (!this.isUpdate) {
  294. // delete this.form.id;
  295. // }
  296. // this.form.workBeat.beatTimes = this.totalTime;
  297. // this.loading = true;
  298. // producetask
  299. // .save(this.form)
  300. // .then((msg) => {
  301. // this.form = {};
  302. // this.loading = false;
  303. // this.$message.success(msg);
  304. // this.updateVisible(false);
  305. // this.$emit('done');
  306. // })
  307. // .catch((e) => {
  308. // this.loading = false;
  309. // // this.$message.error(e.message);
  310. // });
  311. // });
  312. },
  313. /* 更新visible */
  314. updateVisible(value) {
  315. this.removeList = [];
  316. this.$emit('update:visible', value);
  317. }
  318. },
  319. watch: {
  320. visible(visible) {
  321. if (visible) {
  322. this.$nextTick(() => {
  323. this.reload();
  324. });
  325. }
  326. }
  327. }
  328. };
  329. </script>