processComponent.vue 7.9 KB

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