processComponent.vue 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. <template>
  2. <div
  3. class="mainContentBox"
  4. style="padding: 0; box-shadow: 0px 2px 4px 0px rgba(0, 0, 0, 0.1)"
  5. >
  6. <div class="header">
  7. <div class="title">绑定工序</div>
  8. <el-space>
  9. <el-button :icon="Back" size="small" @click="back">返回</el-button>
  10. <el-button type="primary" :icon="Document" size="small" @click="save"
  11. >保存</el-button
  12. >
  13. </el-space>
  14. </div>
  15. <div class="types">
  16. <el-dropdown @command="handleCommand">
  17. <div class="typeBox addBtn">
  18. <el-icon class="icon"><CirclePlus /></el-icon>
  19. <div class="name">添加组件</div>
  20. </div>
  21. <template #dropdown>
  22. <el-dropdown-menu>
  23. <el-dropdown-item
  24. v-for="(com, index) in comTypes"
  25. :key="index"
  26. :command="com"
  27. >
  28. {{ com.compentName }}</el-dropdown-item
  29. >
  30. </el-dropdown-menu>
  31. </template>
  32. </el-dropdown>
  33. <VueDraggable
  34. v-model="selectProComs"
  35. :animation="150"
  36. ghostClass="ghost"
  37. @update="onUpdate"
  38. style="display: flex"
  39. >
  40. <div
  41. class="typeContainer"
  42. v-for="(item, index) in selectProComs"
  43. :key="index"
  44. @click="clickToolCom(item, index)"
  45. >
  46. <div class="typeBox others" :class="getNameClass(index)">
  47. <svg-icon :icon-class="item.compentType" size="30" />
  48. <div class="name">{{ item.compentName }}</div>
  49. </div>
  50. <Delete class="delete" @click.stop="clickDelete(index)" />
  51. </div>
  52. </VueDraggable>
  53. </div>
  54. <div class="binContainer">
  55. <div v-if="isChanged || selectIndex === -1">
  56. <el-empty
  57. :image-size="200"
  58. description="请先保存组件,然后再进行操作"
  59. />
  60. </div>
  61. <div v-else>
  62. <div class="tipTitle">{{ tipTitle }}</div>
  63. <el-button
  64. type="primary"
  65. @click="creatNewData"
  66. style="margin-bottom: 15px"
  67. >新增</el-button
  68. >
  69. <el-button
  70. type="primary"
  71. @click="saveSortData"
  72. style="margin-bottom: 15px"
  73. >保存顺序</el-button
  74. >
  75. <BottomTable ref="bottomTableRef" :tableType="tableType" />
  76. </div>
  77. </div>
  78. </div>
  79. </template>
  80. <script setup>
  81. import { Back, Document, CirclePlus, Delete } from "@element-plus/icons-vue";
  82. import { VueDraggable } from "vue-draggable-plus";
  83. import BottomTable from "@/views/base/craftManagement/route/components/bottomTable.vue";
  84. import { comTypes } from "@/views/base/craftManagement/route/components/configs";
  85. import { saveCompoents, getCompoentsList } from "@/api/craft/process/index";
  86. import { useCommonStoreHook, useDictionaryStoreHook } from "@/store";
  87. import {
  88. processesByRouteId,
  89. saveProcessInRoute,
  90. } from "@/api/craft/route/index";
  91. const router = useRouter();
  92. const route = useRoute();
  93. //组件是否已经改变,如果改变了需要点击保存,才能展示下面的table
  94. const isChanged = ref(true);
  95. const loadTopList = () => {
  96. getCompoentsList(route.params.id).then((res) => {
  97. selectProComs.value = res.data || [];
  98. selectIndex.value = -1;
  99. isChanged.value = false;
  100. });
  101. };
  102. onMounted(async () => {
  103. await loadTopList();
  104. isChanged.value = false;
  105. });
  106. // 顶部====================
  107. const back = () => {};
  108. const save = async () => {
  109. for (let i = 0; i < selectProComs.value.length; i++) {
  110. selectProComs.value[i].operationId = route.params.id;
  111. selectProComs.value[i].sortNum = i;
  112. }
  113. let p = {
  114. operationId: route.params.id,
  115. dtos: selectProComs.value,
  116. };
  117. let res = await saveCompoents(p);
  118. // Elmessage.success("保存成功");
  119. loadTopList();
  120. };
  121. // Tools顶部组件 ==================
  122. // 已经存在的工序组件
  123. const selectProComs = ref([]);
  124. const selectIndex = ref(-1);
  125. const currentCom = ref({});
  126. const handleCommand = (itme) => {
  127. console.log(itme);
  128. selectProComs.value.push(itme);
  129. isChanged.value = true;
  130. };
  131. // 点击某一个改变下面的table
  132. const clickToolCom = (com, index) => {
  133. selectIndex.value = index;
  134. currentCom.value = com;
  135. tableType.value = com.compentType;
  136. };
  137. const onUpdate = () => {
  138. console.log("update");
  139. isChanged.value = true;
  140. };
  141. const clickDelete = (index) => {
  142. selectProComs.value.splice(index, 1);
  143. selectIndex.value = -1;
  144. isChanged.value = true;
  145. };
  146. const getNameClass = (index) => {
  147. return index === selectIndex.value ? "selected" : "normal";
  148. };
  149. // 底部table ===============
  150. const tipTitle = ref("编辑物料采集");
  151. const bottomTableRef = ref({});
  152. const tableType = ref("MARTERIAL");
  153. const creatNewData = () => {
  154. bottomTableRef.value && bottomTableRef.value.startCreat();
  155. };
  156. const saveSortData = () => {
  157. bottomTableRef.value && bottomTableRef.value.saveSortData();
  158. };
  159. </script>
  160. <style lang="scss" scoped>
  161. .header {
  162. height: 50px;
  163. display: flex;
  164. background-color: #f5f7f9;
  165. justify-content: space-between;
  166. align-items: center;
  167. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  168. }
  169. .types {
  170. width: 100%;
  171. height: 116px;
  172. border-bottom: 1px solid rgba(0, 0, 0, 0.1);
  173. padding: 12px 20px;
  174. display: flex;
  175. .typeContainer {
  176. }
  177. .typeBox {
  178. height: 80px;
  179. width: 80px;
  180. border-radius: 4px 4px 4px 4px;
  181. display: flex;
  182. flex-direction: column;
  183. justify-content: center;
  184. align-items: center;
  185. .icon {
  186. height: 32px;
  187. width: 32px;
  188. }
  189. .name {
  190. width: 56px;
  191. height: 16px;
  192. font-weight: 500;
  193. font-size: 14px;
  194. line-height: 16px;
  195. text-align: center;
  196. font-style: normal;
  197. text-transform: none;
  198. }
  199. }
  200. .addBtn {
  201. border: 1px solid #0a59f7;
  202. color: #0a59f7;
  203. }
  204. .others {
  205. color: rgba(0, 0, 0, 0.9);
  206. border: 1px solid rgba(0, 0, 0, 0.9);
  207. margin-left: 20px;
  208. position: relative;
  209. }
  210. .delete {
  211. //position: absolute;
  212. //bottom: -20px;
  213. //left: 0;
  214. margin-left: 50px;
  215. width: 1em;
  216. height: 1em;
  217. color: red;
  218. visibility: hidden;
  219. }
  220. .typeContainer:hover {
  221. .delete {
  222. visibility: visible;
  223. }
  224. }
  225. .normal {
  226. background: #ffffff;
  227. border: 1px solid rgba(35, 32, 50, 0.1);
  228. }
  229. .selected {
  230. background: rgba(10, 89, 247, 0.2);
  231. border: 1px solid #0a59f7;
  232. }
  233. }
  234. .title {
  235. line-height: 44px;
  236. color: #6f7991;
  237. font-size: 14px;
  238. font-weight: bold;
  239. text-align: left;
  240. margin-left: 20px;
  241. }
  242. .binContainer {
  243. height: calc(100vh - 165px);
  244. width: 100%;
  245. background-color: #f5f7f9;
  246. overflow-y: auto;
  247. background-color: white;
  248. //margin-top: 16px;
  249. //margin-left: 20px;
  250. padding: 16px 20px;
  251. }
  252. .tipTitle {
  253. width: 84px;
  254. height: 16px;
  255. font-weight: 500;
  256. font-size: 14px;
  257. color: rgba(0, 0, 0, 0.9);
  258. line-height: 16px;
  259. text-align: left;
  260. font-style: normal;
  261. text-transform: none;
  262. margin-bottom: 16px;
  263. }
  264. </style>