InspectLineModalAdd.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="width"
  5. :visible="visible"
  6. @ok="handleOk"
  7. @cancel="handleCancel"
  8. cancelText="关闭">
  9. <a-table
  10. ref="table"
  11. size="middle"
  12. :scroll="{x:true}"
  13. bordered
  14. rowKey="id"
  15. :columns="columns"
  16. :dataSource="dataSource"
  17. :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}"
  18. :pagination="false"
  19. class="j-table-force-nowrap">
  20. </a-table>
  21. </j-modal>
  22. </template>
  23. <script>
  24. import { httpAction, getAction } from '@/api/manage'
  25. export default {
  26. name: 'InspectLineModalAdd',
  27. components: {
  28. },
  29. props: {
  30. //表单禁用
  31. equipmentId: {
  32. type: String,
  33. default: ''
  34. },
  35. selectData: {
  36. type: Array,
  37. default: function(){
  38. return [] // 使用工厂函数返回默认值
  39. }
  40. },
  41. },
  42. data () {
  43. return {
  44. title:'',
  45. width: 1000,
  46. visible: false,
  47. type: '',
  48. /* table选中keys*/
  49. selectedRowKeys: [],
  50. /* table选中records*/
  51. selectionRows: [],
  52. columns: [
  53. // {
  54. // title: '',
  55. // dataIndex: '',
  56. // key:'rowIndex',
  57. // width:60,
  58. // align:"center",
  59. // customRender:function (t,r,index) {
  60. // return parseInt(index)+1;
  61. // }
  62. // },
  63. {
  64. title:'巡检项ID',
  65. align:"center",
  66. dataIndex: 'id'
  67. },
  68. {
  69. title:'巡检项编号',
  70. align:"center",
  71. dataIndex: 'itemcode'
  72. },
  73. {
  74. title:'巡检项名称',
  75. align:"center",
  76. dataIndex: 'itemname'
  77. },
  78. {
  79. title:'标准',
  80. align:"center",
  81. dataIndex: 'inspectionstandards',
  82. },
  83. {
  84. title:'备注',
  85. align:"center",
  86. dataIndex: 'remark'
  87. }
  88. ],
  89. dataSource: [],
  90. url: {
  91. getList: "/cmmsInspectItem/cmmsInspectItem/getItemByEqId",
  92. itemList: "/cmmsInspectItem/cmmsInspectItem/list",
  93. },
  94. }
  95. },
  96. methods: {
  97. add () {
  98. this.visible = true;
  99. if(this.type === '1'){
  100. getAction(this.url.getList, {eqid: this.equipmentId}).then((res) => {
  101. this.dataSource = res.result
  102. })
  103. } else {
  104. getAction(this.url.itemList, {classification: this.type}).then((res) => {
  105. this.dataSource = res.result.records
  106. })
  107. }
  108. this.selectList()
  109. },
  110. // 将以选中的值重新在列表中选中
  111. selectList() {
  112. this.selectionRows = this.selectData
  113. console.log(this.selectData)
  114. this.selectedRowKeys = this.selectData.map((res) => {
  115. return res.id
  116. })
  117. },
  118. close () {
  119. this.$emit('close');
  120. this.visible = false;
  121. this.onClearSelected()
  122. this.selectionRows = this.selectData
  123. this.selectedRowKeys = this.selectData.map((res) => {
  124. return res.id
  125. })
  126. this.dataSource = []
  127. },
  128. handleOk () {
  129. console.log(this.selectionRows)
  130. this.$emit('ok', this.selectionRows);
  131. this.visible = false;
  132. },
  133. handleCancel () {
  134. this.close()
  135. },
  136. onSelectChange(selectedRowKeys, selectionRows) {
  137. this.selectedRowKeys = selectedRowKeys;
  138. this.selectionRows = selectionRows;
  139. console.log(this.selectedRowKeys,this.selectionRows)
  140. },
  141. onClearSelected() {
  142. this.selectedRowKeys = [];
  143. this.selectionRows = [];
  144. },
  145. }
  146. }
  147. </script>