index.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. <template>
  2. <div class="ele-body">
  3. <el-card shadow="never">
  4. <search
  5. ref="search"
  6. @search="search"
  7. :options_groupId="dict.groupId"
  8. :options_factory="dict.factory"
  9. ></search>
  10. <ele-pro-table
  11. ref="table"
  12. :columns="columns"
  13. :datasource="datasource"
  14. cache-key="systemRoleTable5"
  15. >
  16. <!-- 表头工具栏 -->
  17. <template v-slot:toolbar>
  18. <el-button
  19. size="small"
  20. type="primary"
  21. icon="el-icon-plus"
  22. class="ele-btn-icon"
  23. @click="openEdit('add')"
  24. >
  25. 添加
  26. </el-button>
  27. </template>
  28. <template v-slot:groupId="{ row }">
  29. {{ showgroupName(row.groupId) }}
  30. </template>
  31. <template v-slot:parent="{ row }">
  32. {{ showgfactory(row, 2) }}
  33. </template>
  34. <template v-slot:factory="{ row }">
  35. <!-- {{ showgfactory(row, 1) }} -->
  36. {{ pathFn(row.pathName) }}
  37. </template>
  38. <!-- 操作列 -->
  39. <template v-slot:action="{ row }">
  40. <el-link
  41. type="primary"
  42. :underline="false"
  43. icon="el-icon-edit"
  44. @click="openEdit('edit', row)"
  45. >
  46. 修改
  47. </el-link>
  48. <el-popconfirm
  49. class="ele-action"
  50. title="确定要删除此角色吗?"
  51. @confirm="remove(row)"
  52. >
  53. <template v-slot:reference>
  54. <el-link type="danger" :underline="false" icon="el-icon-delete">
  55. 删除
  56. </el-link>
  57. </template>
  58. </el-popconfirm>
  59. </template>
  60. </ele-pro-table>
  61. </el-card>
  62. <edit
  63. ref="edit"
  64. @done="done"
  65. :options_groupId="dict.groupId"
  66. :options_factory="dict.factory"
  67. ></edit>
  68. </div>
  69. </template>
  70. <script>
  71. import search from './components/search.vue';
  72. import edit from './components/edit.vue';
  73. import { getFactoryarea, deletefactoryarea } from '@/api/factoryModel';
  74. import { listOrganizations } from '@/api/system/organization';
  75. export default {
  76. components: {
  77. search,
  78. edit
  79. },
  80. data () {
  81. return {
  82. columns: [
  83. {
  84. width: 45,
  85. type: 'index',
  86. columnKey: 'index',
  87. align: 'center'
  88. },
  89. {
  90. prop: 'code',
  91. label: '车间编码'
  92. },
  93. {
  94. label: '车间名称',
  95. prop: 'name'
  96. },
  97. {
  98. label: '所属公司',
  99. prop: 'groupId',
  100. slot: 'groupId'
  101. },
  102. {
  103. label: '工厂编码',
  104. prop: 'parentCode',
  105. slot: 'parent'
  106. },
  107. {
  108. label: '所属工厂 - 厂房',
  109. prop: 'parentId',
  110. slot: 'factory'
  111. },
  112. {
  113. label: '区域名',
  114. prop: 'areaName',
  115. },
  116. {
  117. label: '详细地址',
  118. prop: 'extInfo.location'
  119. },
  120. {
  121. columnKey: 'action',
  122. label: '操作',
  123. width: 220,
  124. align: 'center',
  125. resizable: false,
  126. slot: 'action',
  127. showOverflowTooltip: true
  128. }
  129. ],
  130. dict: {
  131. groupId: [],
  132. factory: []
  133. }
  134. };
  135. },
  136. created () {
  137. this.getGs();
  138. this.getFactoryarea();
  139. },
  140. methods: {
  141. datasource ({ page, where, limit }) {
  142. return getFactoryarea({
  143. ...where,
  144. pageNum: page,
  145. size: limit,
  146. type: 3
  147. });
  148. },
  149. search (where) {
  150. this.$refs.table.reload({
  151. where: where,
  152. page: 1
  153. });
  154. },
  155. openEdit (type, row) {
  156. this.$refs.edit.open(type, row);
  157. },
  158. // 获取公司数据
  159. getGs () {
  160. listOrganizations().then((list) => {
  161. console.log(list);
  162. this.dict.groupId = list;
  163. });
  164. },
  165. // 回显公司名称
  166. showgroupName (id) {
  167. let result = this.dict.groupId.find((n) => n.id == id);
  168. if (result) {
  169. return result.name;
  170. } else {
  171. return '';
  172. }
  173. },
  174. // 回显工厂名称
  175. showgfactory (row, type) {
  176. let result = row.parent.find((n) => n.id == row.parentId);
  177. if (result && type == 1) {
  178. return result.name;
  179. } else if(result && type == 2) {
  180. return result.code;
  181. }
  182. else {
  183. return '';
  184. }
  185. },
  186. pathFn(name) {
  187. let arr = name.split('-')
  188. return arr.slice(0,2).join('-')
  189. },
  190. // 获取工厂数据
  191. getFactoryarea () {
  192. let par = {
  193. type: 1,
  194. size: 9999,
  195. type: 2,
  196. };
  197. getFactoryarea(par).then((res) => {
  198. this.dict.factory = res.list;
  199. });
  200. },
  201. remove (row) {
  202. deletefactoryarea(row.id)
  203. .then((message) => {
  204. this.$message.success(message);
  205. this.done();
  206. })
  207. .catch((e) => {
  208. this.$message.error(e.message);
  209. });
  210. },
  211. done () {
  212. this.$refs.search.search();
  213. }
  214. }
  215. };
  216. </script>