equipment-dailog.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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="name"></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. :needPage="false"
  20. :initLoad="false"
  21. :selection.sync="selectionList"
  22. :datasource="datasourceShow"
  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 { getDeviceList, getPlanDeviceList } from '@/api/aps/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. name: '',
  58. selectionList: [],
  59. memoList: [],
  60. datasource: [],
  61. isSingle: false,
  62. callback: null,
  63. radio: ''
  64. };
  65. },
  66. computed: {
  67. columns () {
  68. const list = [
  69. {
  70. label: '设备编码',
  71. prop: 'code'
  72. },
  73. {
  74. label: '设备名称',
  75. prop: 'name'
  76. },
  77. // {
  78. // label: '生产状态',
  79. // prop: 'status'
  80. // },
  81. {
  82. label: '未完成工单数',
  83. prop: 'incompleteOrderNum'
  84. },
  85. {
  86. label: '预计完成时间',
  87. prop: 'planCompleteDate'
  88. },
  89. {
  90. label: '产能',
  91. prop: 'capacityNum',
  92. width: 200,
  93. formatter: (row) =>
  94. row.capacityNum + ' ' + row.capacityUnit + '/' + row.capacityTime
  95. },
  96. {
  97. label: '末单牌号',
  98. prop: 'lastOrderGrade'
  99. }
  100. ];
  101. if (!this.isSingle) {
  102. list.push({
  103. slot: 'select',
  104. prop: 'select',
  105. label: '选择',
  106. align: 'center'
  107. });
  108. }
  109. return list;
  110. },
  111. datasourceShow () {
  112. return this.datasource?.filter((item) => {
  113. if (this.name) {
  114. return item.name.includes(this.name);
  115. }
  116. return true;
  117. });
  118. }
  119. },
  120. methods: {
  121. open (list = []) {
  122. this.memoList = list;
  123. this.isSingle = false;
  124. this.visible = true;
  125. this._getList();
  126. },
  127. openSingle (list = [], callback) {
  128. this.memoList = list;
  129. this.callback = callback;
  130. this.isSingle = true;
  131. this.visible = true;
  132. this._getList();
  133. },
  134. handleDone ({ data }) {
  135. if (this.memoList.length) {
  136. this.$nextTick(() => {
  137. if (this.isSingle) {
  138. this.$refs.table.setCurrentRow(
  139. data.find((item) => item.id == this.memoList[0].deviceId)
  140. );
  141. } else {
  142. this.memoList.length &&
  143. this.$refs.table.setSelectedRowKeys(
  144. this.memoList.map((i) => i.deviceId)
  145. );
  146. }
  147. });
  148. }
  149. },
  150. async _getList () {
  151. const fn = this.isPlan ? getPlanDeviceList : getDeviceList;
  152. const data = await fn({
  153. name: this.name,
  154. productionId: this.produceVersionId
  155. });
  156. this.datasource = data || [];
  157. },
  158. confirm () {
  159. if (this.isSingle) {
  160. if (!this.current) return this.$message.error('请选择数据');
  161. this.callback && this.callback(this.current);
  162. } else {
  163. if (!this.current) return this.$message.error('请选择数据');
  164. this.$emit('success', [this.current]);
  165. }
  166. this.cancel();
  167. },
  168. cancel () {
  169. this.$refs.table.clearSelection();
  170. this.radio = '';
  171. this.current = null;
  172. this.visible = false;
  173. },
  174. // 单击获取id
  175. choose (row) {
  176. this.current = row;
  177. this.radio = row.id;
  178. }
  179. }
  180. };
  181. </script>
  182. <style lang="scss" scoped>
  183. .search-box {
  184. display: flex;
  185. justify-content: flex-start;
  186. align-items: center;
  187. margin-bottom: 20px;
  188. .el-input {
  189. width: 220px;
  190. margin: 0 32px;
  191. }
  192. }
  193. </style>