index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <template>
  2. <div class="brand">
  3. <el-table
  4. :data="tableData"
  5. stripe
  6. border
  7. row-key="sc_workorder_nodeid"
  8. size="small"
  9. :tree-props="{ children: 'children', hasChildren: 'hasChildren' }"
  10. >
  11. <el-table-column width="55"> </el-table-column>
  12. <el-table-column
  13. prop="workname"
  14. :label="$t(`工序内容`)"
  15. show-overflow-tooltip
  16. width="400"
  17. >
  18. <template slot-scope="scope">
  19. <span>{{ $t(scope.row.workname) }}</span>
  20. </template>
  21. </el-table-column>
  22. <el-table-column prop="status" :label="$t(`状态`)" width="70">
  23. <template slot-scope="scope">
  24. <div
  25. v-if="scope.row.parentid != 0"
  26. :style="{
  27. color:
  28. scope.row.status == 0
  29. ? tool.getStatusColor('未完成', true)
  30. : scope.row.status == 1
  31. ? tool.getStatusColor('已完成', true)
  32. : tool.getStatusColor('进行中', true),
  33. }"
  34. >
  35. {{
  36. scope.row.status == 0
  37. ? $t("未完成")
  38. : scope.row.status == 1
  39. ? $t("已完成")
  40. : $t("进行中")
  41. }}
  42. </div>
  43. <div v-else>--</div>
  44. </template>
  45. </el-table-column>
  46. <el-table-column
  47. prop="remarks"
  48. show-overflow-tooltip
  49. :label="$t(`操作说明`)"
  50. min-width="400"
  51. >
  52. <template slot-scope="scope">
  53. {{ scope.row.remarks ? $t(scope.row.remarks) : "--" }}
  54. </template>
  55. </el-table-column>
  56. <el-table-column
  57. prop="trainers"
  58. show-overflow-tooltip
  59. :label="$t(`操作人员`)"
  60. width="300"
  61. >
  62. <template slot-scope="scope">
  63. {{
  64. scope.row.trainers?.length
  65. ? scope.row.trainers.map((item) => $t(item.name)).join(",")
  66. : "--"
  67. }}
  68. </template>
  69. </el-table-column>
  70. <el-table-column
  71. prop="remarksBz"
  72. show-overflow-tooltip
  73. :label="$t(`备注说明`)"
  74. min-width="400"
  75. >
  76. <template slot-scope="scope">
  77. {{ scope.row.remarksBz ? $t(scope.row.remarksBz) : "--" }}
  78. </template>
  79. </el-table-column>
  80. <el-table-column :label="$t('操作')" width="110" fixed="right">
  81. <template slot-scope="scope">
  82. <el-button type="text" @click="goDetail(scope.row)" size="mini">
  83. {{ $t(`详情`) }}
  84. </el-button>
  85. </template>
  86. </el-table-column>
  87. </el-table>
  88. <detail
  89. :visible.sync="drawerVisible"
  90. :data="detailData"
  91. @close="drawerVisible = false"
  92. />
  93. </div>
  94. </template>
  95. <script>
  96. import detail from "./detail.vue";
  97. export default {
  98. props: ["data"],
  99. components: { detail },
  100. data() {
  101. return {
  102. tableData: [],
  103. drawerVisible: false,
  104. detailData: null,
  105. };
  106. },
  107. created() {},
  108. methods: {
  109. async department(callback) {
  110. this.tableData = this.sortBySequence(
  111. this.createTreeData(this.data.nodes)
  112. );
  113. console.log("this.tableData", this.tableData);
  114. },
  115. createTreeData(array) {
  116. var that = this;
  117. let arr = [];
  118. function convertToElementTree(node) {
  119. // 新节点
  120. var elNode = {
  121. parentid: node["parentid"],
  122. sc_workorder_nodeid: node["sc_workorder_nodeid"],
  123. sc_workorderid: node["sc_workorderid"],
  124. workname: node["workpresetjson"]?.workname,
  125. status: node["status"],
  126. parentid: node["parentid"],
  127. remarks: node["workpresetjson"]?.remarks,
  128. trainers: node["trainers"],
  129. remarksBz: node["remarks"],
  130. sequence: node["sequence"],
  131. children: [],
  132. };
  133. if (Array.isArray(node.child) && node.child.length > 0) {
  134. // 如果存在子节点
  135. for (var index = 0; index < node.child.length; index++) {
  136. // 遍历子节点, 把每个子节点看做一颗独立的树, 传入递归构造子树, 并把结果放回到新node的children中
  137. elNode.children.push(convertToElementTree(node.child[index]));
  138. }
  139. elNode.children = that.sortBySequence(elNode.children);
  140. }
  141. return elNode;
  142. }
  143. array.forEach((element) => {
  144. console.log("element-----------", element);
  145. arr.push(convertToElementTree(element));
  146. });
  147. console.log("arr-----------", arr);
  148. return arr;
  149. },
  150. sortBySequence(list) {
  151. return [...list].sort(
  152. (a, b) => (Number(a.sequence) || 0) - (Number(b.sequence) || 0)
  153. );
  154. },
  155. async goDetail(row) {
  156. const res = await this.$api.requested({
  157. id: 2026052615161102,
  158. content: {
  159. sc_workorderid: row.sc_workorderid,
  160. sc_workorder_nodeid: row.sc_workorder_nodeid,
  161. },
  162. });
  163. if (res.code === 1) {
  164. this.detailData = res.data;
  165. this.drawerVisible = true;
  166. }
  167. },
  168. handleSizeChange(val) {
  169. this.params.content.pageSize = val;
  170. this.department();
  171. },
  172. handleCurrentChange(val) {
  173. this.params.content.pageNumber = val;
  174. this.department();
  175. },
  176. },
  177. mounted() {
  178. this.department();
  179. },
  180. };
  181. </script>
  182. <style scoped>
  183. </style>