SpotcheckContentModalAdd.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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: 'SpotcheckContentModalAdd',
  27. components: {
  28. },
  29. props: {
  30. modelForm: {
  31. type: Object,
  32. default: function(){
  33. return {} // 使用工厂函数返回默认值
  34. }
  35. },
  36. dataList: {
  37. type: Array,
  38. default: function(){
  39. return [] // 使用工厂函数返回默认值
  40. }
  41. },
  42. },
  43. data () {
  44. return {
  45. title:'',
  46. width:1000,
  47. visible: false,
  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: 'conditions',
  82. },
  83. {
  84. title:'备注',
  85. align:"center",
  86. dataIndex: 'remark'
  87. }
  88. ],
  89. dataSource: [],
  90. url: {
  91. getList: "/cmmsSpotcheckItem/cmmsSpotcheckItem/listbyequipmentid/{equipmentid}"
  92. },
  93. }
  94. },
  95. methods: {
  96. add () {
  97. this.visible = true;
  98. getAction(`/cmmsSpotcheckItem/cmmsSpotcheckItem/listbyequipmentid/${this.modelForm.equipmentid}`).then((res) => {
  99. this.dataSource = res.result
  100. })
  101. this.selectList()
  102. },
  103. // 将以选中的值重新在列表中选中
  104. selectList() {
  105. console.log(111,this.dataList)
  106. this.selectionRows = this.dataList
  107. this.selectedRowKeys = this.dataList.map((res) => {
  108. return res.id
  109. })
  110. },
  111. close () {
  112. this.$emit('close');
  113. this.visible = false;
  114. this.onClearSelected()
  115. this.selectionRows = this.dataList
  116. this.selectedRowKeys = this.dataList.map((res) => {
  117. return res.id
  118. })
  119. },
  120. handleOk () {
  121. console.log(this.selectionRows)
  122. this.$emit('customEvent', this.selectionRows);
  123. this.visible = false;
  124. },
  125. submitCallback(){
  126. this.$emit('ok');
  127. this.visible = false;
  128. },
  129. handleCancel () {
  130. this.close()
  131. },
  132. onSelectChange(selectedRowKeys, selectionRows) {
  133. this.selectedRowKeys = selectedRowKeys;
  134. this.selectionRows = selectionRows;
  135. console.log(this.selectedRowKeys,this.selectionRows)
  136. },
  137. onClearSelected() {
  138. this.selectedRowKeys = [];
  139. this.selectionRows = [];
  140. },
  141. }
  142. }
  143. </script>