workshop-dailog.vue 4.2 KB

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