InspectLineModalAdd.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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:'巡检点编号',
  65. align:"center",
  66. dataIndex: 'contentcode'
  67. },
  68. {
  69. title:'巡检点名称',
  70. align:"center",
  71. dataIndex: 'contentname'
  72. },
  73. {
  74. title:'备注',
  75. align:"center",
  76. dataIndex: 'remark'
  77. },
  78. ],
  79. dataSource: [],
  80. url: {
  81. getList: "/cmmsInspectItem/cmmsInspectItem/getItemByEqId",
  82. spotList: "/cmmsInspectSpot/cmmsInspectSpot/listDetails",
  83. },
  84. }
  85. },
  86. methods: {
  87. add () {
  88. this.visible = true;
  89. // {status: '0'}
  90. getAction(this.url.spotList).then((res) => {
  91. this.dataSource = res.result.records
  92. })
  93. this.selectList()
  94. },
  95. // 将以选中的值重新在列表中选中
  96. selectList() {
  97. this.selectionRows = this.selectData
  98. console.log(this.selectData)
  99. this.selectedRowKeys = this.selectData.map((res) => {
  100. return res.id
  101. })
  102. },
  103. close () {
  104. this.$emit('close');
  105. this.visible = false;
  106. this.onClearSelected()
  107. this.selectionRows = this.selectData
  108. this.selectedRowKeys = this.selectData.map((res) => {
  109. return res.id
  110. })
  111. this.dataSource = []
  112. },
  113. handleOk () {
  114. console.log(this.selectionRows)
  115. this.$emit('ok', this.selectionRows);
  116. this.visible = false;
  117. },
  118. handleCancel () {
  119. this.close()
  120. },
  121. onSelectChange(selectedRowKeys, selectionRows) {
  122. this.selectedRowKeys = selectedRowKeys;
  123. this.selectionRows = selectionRows;
  124. console.log(this.selectedRowKeys,this.selectionRows)
  125. },
  126. onClearSelected() {
  127. this.selectedRowKeys = [];
  128. this.selectionRows = [];
  129. },
  130. }
  131. }
  132. </script>