workshop-dailog.vue 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <template>
  2. <!-- title="添加工单-选择设备" -->
  3. <ele-modal
  4. :visible.sync="visible"
  5. title="选择干燥区域"
  6. width="65vw"
  7. append-to-body
  8. :maxable="true"
  9. >
  10. <div class="search-box">
  11. 工位编码:
  12. <el-input placeholder="请输入" v-model="searchKey"></el-input>
  13. </div>
  14. <!-- 数据表格 -->
  15. <!-- :highlight-current-row="isSingle" -->
  16. <ele-pro-table
  17. ref="table"
  18. :columns="columns"
  19. @done="handleDone"
  20. row-key="id"
  21. :selection.sync="selectionList"
  22. :datasource="datasource"
  23. :current.sync="current"
  24. highlight-current-row
  25. height="45vh"
  26. @row-click="choose"
  27. >
  28. <template v-slot:select="{ row }">
  29. <el-radio class="radio" v-model="radio" :label="row.id"
  30. ><i></i
  31. ></el-radio>
  32. </template>
  33. </ele-pro-table>
  34. <div class="footer" slot="footer">
  35. <el-button @click="cancel">取消</el-button>
  36. <el-button @click="confirm" type="primary">确定</el-button>
  37. </div>
  38. </ele-modal>
  39. </template>
  40. <script>
  41. import { factoryworkstation } from '@/api/mainData/index';
  42. export default {
  43. props: {
  44. produceVersionId: {
  45. type: String,
  46. default: ''
  47. },
  48. isPlan: {
  49. type: Boolean,
  50. default: false
  51. }
  52. },
  53. data() {
  54. return {
  55. visible: false,
  56. current: null,
  57. searchKey: '',
  58. selectionList: [],
  59. memoList: [],
  60. isSingle: false,
  61. callback: null,
  62. radio: ''
  63. };
  64. },
  65. computed: {
  66. columns() {
  67. const list = [
  68. {
  69. prop: 'code',
  70. label: '工位编码'
  71. },
  72. {
  73. label: '工位名称',
  74. prop: 'name'
  75. },
  76. {
  77. label: '责任人',
  78. prop: 'leaderName',
  79. slot: 'factory'
  80. },
  81. {
  82. label: '所属车间',
  83. prop: 'workshopName'
  84. },
  85. {
  86. label: '所属产线',
  87. prop: 'productionLineName'
  88. }
  89. ];
  90. if (!this.isSingle) {
  91. list.push({
  92. slot: 'select',
  93. prop: 'select',
  94. label: '选择',
  95. align: 'center'
  96. });
  97. }
  98. return list;
  99. }
  100. },
  101. methods: {
  102. open(list = []) {
  103. this.memoList = list;
  104. this.isSingle = false;
  105. this.visible = true;
  106. },
  107. openSingle(list = [], callback) {
  108. this.memoList = list;
  109. this.callback = callback;
  110. this.isSingle = true;
  111. this.visible = true;
  112. },
  113. handleDone({ data }) {
  114. if (this.memoList.length) {
  115. this.$nextTick(() => {
  116. if (this.isSingle) {
  117. this.$refs.table.setCurrentRow(
  118. data.find(
  119. (item) =>
  120. item.id ==
  121. (this.memoList[0].deviceId ||
  122. this.memoList[0].sourceInstanceId)
  123. )
  124. );
  125. } else {
  126. this.memoList.length &&
  127. this.$refs.table.setSelectedRowKeys(
  128. this.memoList.map((i) => i.deviceId)
  129. );
  130. }
  131. });
  132. }
  133. },
  134. datasource({ page, limit }) {
  135. return factoryworkstation({
  136. pageNum: page,
  137. size: limit,
  138. code: this.searchKey
  139. });
  140. },
  141. confirm() {
  142. if (this.isSingle) {
  143. if (!this.current) return this.$message.error('请选择数据');
  144. this.callback && this.callback(this.current);
  145. } else {
  146. if (!this.current) return this.$message.error('请选择数据');
  147. this.$emit('success', [this.current]);
  148. }
  149. this.cancel();
  150. },
  151. cancel() {
  152. this.$refs.table.setCurrentRow();
  153. this.$refs.table.clearSelection();
  154. this.radio = '';
  155. this.current = null;
  156. this.visible = false;
  157. },
  158. // 单击获取id
  159. choose(row) {
  160. this.current = row;
  161. this.radio = row.id;
  162. }
  163. }
  164. };
  165. </script>
  166. <style lang="scss" scoped>
  167. .search-box {
  168. display: flex;
  169. justify-content: flex-start;
  170. align-items: center;
  171. margin-bottom: 20px;
  172. .el-input {
  173. width: 220px;
  174. margin: 0 32px;
  175. }
  176. }
  177. </style>