user-setting.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  1. <!-- 用户编辑弹窗 -->
  2. <template>
  3. <ele-modal
  4. width="1060px"
  5. :visible="visible"
  6. :append-to-body="true"
  7. :close-on-click-modal="false"
  8. custom-class="ele-dialog-form"
  9. :title="`给工序配置参数`"
  10. @update:visible="updateVisible"
  11. :maxable="true"
  12. >
  13. <div class="ele-body">
  14. <ele-pro-table
  15. ref="table"
  16. :needPage="false"
  17. :columns="columns"
  18. :datasource="datasource"
  19. >
  20. <!-- 表头工具栏 -->
  21. <template v-slot:toolbar>
  22. <el-button
  23. size="small"
  24. type="primary"
  25. icon="el-icon-plus"
  26. class="ele-btn-icon"
  27. @click="showAddLog"
  28. >
  29. 添加参数
  30. </el-button>
  31. </template>
  32. <!-- 描述 -->
  33. <template v-slot:description="{ row }">
  34. <el-input v-model="row.description" placeholder="请输入"></el-input>
  35. </template>
  36. <!-- 单位 -->
  37. <template v-slot:unitName="{ row }">
  38. <el-input v-model="row.unitName" placeholder="请输入"></el-input>
  39. </template>
  40. <!-- 上限 -->
  41. <template v-slot:maxValue="{ row }">
  42. <el-input v-model="row.maxValue" placeholder="请输入"></el-input>
  43. </template>
  44. <!-- 下限 -->
  45. <template v-slot:minValue="{ row }">
  46. <el-input v-model="row.minValue" placeholder="请输入"></el-input>
  47. </template>
  48. <!-- 默认值 -->
  49. <template v-slot:defaultValue="{ row }">
  50. <el-input v-model="row.defaultValue" placeholder="请输入"></el-input>
  51. </template>
  52. <!-- 默认值 -->
  53. <template v-slot:notNull="{ row }">
  54. <el-select v-model="row.notNull" placeholder="请选择">
  55. <el-option
  56. v-for="item in timeType"
  57. :key="item.value"
  58. :label="item.label"
  59. :value="item.value"
  60. >
  61. </el-option>
  62. </el-select>
  63. </template>
  64. <!-- 状态列 -->
  65. <!-- 操作列 -->
  66. <template v-slot:action="{ row }">
  67. <el-popconfirm
  68. class="ele-action"
  69. title="确定要删除当前工序吗?"
  70. @confirm="remove(row)"
  71. >
  72. <template v-slot:reference>
  73. <el-link type="danger" :underline="false" icon="el-icon-delete">
  74. 删除
  75. </el-link>
  76. </template>
  77. </el-popconfirm>
  78. </template>
  79. </ele-pro-table>
  80. </div>
  81. <template v-slot:footer>
  82. <el-button @click="updateVisible(false)">取消</el-button>
  83. <el-button type="primary" :loading="loading" @click="save">
  84. 保存
  85. </el-button>
  86. </template>
  87. <ele-modal
  88. width="1720px"
  89. :visible="addDialog"
  90. :append-to-body="true"
  91. :close-on-click-modal="false"
  92. @update:visible="closeAdd"
  93. custom-class="ele-dialog-form"
  94. :maxable="true"
  95. >
  96. <Paramrter :data="tableData" ref="Paramrter" />
  97. <template v-slot:footer>
  98. <el-button @click="closeAdd">取消</el-button>
  99. <el-button type="primary" :loading="loading" @click="addParamrter">
  100. 添加
  101. </el-button>
  102. </template>
  103. </ele-modal>
  104. </ele-modal>
  105. </template>
  106. <script>
  107. import producetask from '@/api/technology/production';
  108. import Paramrter from './parameter';
  109. import { deepClone } from '@/components/FormGenerator/utils/index';
  110. export default {
  111. components: { Paramrter },
  112. props: {
  113. // 弹窗是否打开
  114. visible: Boolean,
  115. // 修改回显的数据
  116. data: Object
  117. },
  118. data() {
  119. return {
  120. timeType: [
  121. { value: 1, label: '是' },
  122. { value: 0, label: '否' }
  123. ],
  124. // 表格列配置
  125. columns: [
  126. {
  127. prop: 'paramName',
  128. label: '参数名称',
  129. showOverflowTooltip: true,
  130. align: 'center',
  131. minWidth: 110
  132. },
  133. {
  134. align: 'center',
  135. slot: 'description',
  136. prop: 'description',
  137. label: '文本描述',
  138. showOverflowTooltip: true,
  139. minWidth: 110
  140. },
  141. {
  142. prop: 'unitName',
  143. slot: 'unitName',
  144. label: '参数单位',
  145. align: 'center',
  146. showOverflowTooltip: true
  147. },
  148. {
  149. prop: 'maxValue',
  150. slot: 'maxValue',
  151. label: '参数上限',
  152. align: 'center',
  153. // showOverflowTooltip: true
  154. },
  155. {
  156. prop: 'minValue',
  157. slot: 'minValue',
  158. label: '参数下限',
  159. align: 'center',
  160. // showOverflowTooltip: true
  161. },
  162. {
  163. prop: 'defaultValue',
  164. slot: 'defaultValue',
  165. label: '默认值',
  166. align: 'center',
  167. // showOverflowTooltip: true
  168. },
  169. {
  170. prop: 'notNull',
  171. slot: 'notNull',
  172. label: '是否必填',
  173. align: 'center',
  174. showOverflowTooltip: true
  175. },
  176. {
  177. columnKey: 'action',
  178. label: '操作',
  179. align: 'center',
  180. resizable: false,
  181. slot: 'action',
  182. showOverflowTooltip: true
  183. }
  184. ],
  185. loading: false,
  186. addDialog: false,
  187. removeList: [],
  188. tableData: []
  189. };
  190. },
  191. methods: {
  192. addParamrter() {
  193. let arr = deepClone(this.$refs.Paramrter.selection)
  194. arr.forEach((element) => {
  195. this.$set(element, 'paramId', element.id);
  196. this.$set(element, 'paramName', element.name);
  197. delete element.id;
  198. delete element.name;
  199. });
  200. this.$refs.table.setData([...arr, ...this.$refs.table.getData()]);
  201. this.closeAdd();
  202. },
  203. showAddLog() {
  204. this.tableData = this.$refs.table.getData()
  205. this.addDialog = true;
  206. },
  207. /*关闭选择参数*/
  208. closeAdd() {
  209. this.$refs.Paramrter.$refs.tableParameter.setSelectedRows([]);
  210. this.addDialog = false;
  211. },
  212. /* 刷新表格 */
  213. reload() {
  214. this.$refs.table.reload();
  215. },
  216. remove(row) {
  217. const data = this.$refs.table.getData() ?? [];
  218. if (row.id) {
  219. this.removeList.push(row.id);
  220. this.$refs.table.setData(data.filter((d) => d.id !== row.id));
  221. } else {
  222. this.$refs.table.setData(
  223. data.filter((d) => d.paramId !== row.paramId)
  224. );
  225. }
  226. },
  227. /* 表格数据源 */
  228. async datasource({ page, limit, where }) {
  229. if (this.data?.id) {
  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>