workshop-dailog.vue 4.2 KB

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