InspectContentModalAdd.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. <template>
  2. <j-modal
  3. :title="title"
  4. :width="width"
  5. :visible="visible"
  6. @ok="handleOk"
  7. @cancel="handleCancel"
  8. cancelText="关闭">
  9. <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
  10. <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
  11. <a style="margin-left: 24px" @click="onClearSelected">清空</a>
  12. </div>
  13. <a-table
  14. ref="table"
  15. size="middle"
  16. :scroll="{x:true}"
  17. bordered
  18. rowKey="id"
  19. :columns="columns"
  20. :dataSource="dataSource"
  21. :rowSelection="{selectedRowKeys: selectedRowKeys, onChange: onSelectChange, onSelect: onSelect}"
  22. :pagination="ipagination"
  23. @change="handleTableChange"
  24. class="j-table-force-nowrap">
  25. </a-table>
  26. </j-modal>
  27. </template>
  28. <script>
  29. import { httpAction, getAction } from '@/api/manage'
  30. import { mixinDevice } from '@/utils/mixin'
  31. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  32. export default {
  33. name: 'SpotcheckContentModalAdd',
  34. mixins:[JeecgListMixin, mixinDevice],
  35. props: {
  36. //表单禁用
  37. equipmentId: {
  38. type: String,
  39. default: ''
  40. },
  41. selectData: {
  42. type: Array,
  43. default: function(){
  44. return [] // 使用工厂函数返回默认值
  45. }
  46. },
  47. },
  48. data () {
  49. return {
  50. title:'',
  51. width: 1000,
  52. visible: false,
  53. type: '',
  54. /* table选中keys*/
  55. selectedRowKeys: [],
  56. /* table选中records*/
  57. selectionRows: [],
  58. columns: [
  59. // {
  60. // title: '',
  61. // dataIndex: '',
  62. // key:'rowIndex',
  63. // width:60,
  64. // align:"center",
  65. // customRender:function (t,r,index) {
  66. // return parseInt(index)+1;
  67. // }
  68. // },
  69. // {
  70. // title:'巡检标准ID',
  71. // align:"center",
  72. // dataIndex: 'id'
  73. // },
  74. {
  75. title:'巡检标准编号',
  76. align:"center",
  77. dataIndex: 'itemcode'
  78. },
  79. {
  80. title:'巡检标准名称',
  81. align:"center",
  82. dataIndex: 'itemname'
  83. },
  84. {
  85. title:'标准',
  86. align:"center",
  87. dataIndex: 'inspectionstandards',
  88. },
  89. {
  90. title:'备注',
  91. align:"center",
  92. dataIndex: 'remark'
  93. }
  94. ],
  95. dataSource: [],
  96. chooseData: [],
  97. url: {
  98. getList: "/cmmsInspectItem/cmmsInspectItem/getItemByEqId",
  99. itemList: "/cmmsInspectItem/cmmsInspectItem/list",
  100. },
  101. }
  102. },
  103. watch: {
  104. selectData: {
  105. handler(newV, oldV){
  106. console.log(newV, oldV)
  107. if(newV.length > 0){
  108. this.selectList()
  109. }
  110. },
  111. }
  112. },
  113. methods: {
  114. add(){
  115. this.visible = true;
  116. this.loadData()
  117. },
  118. loadData () {
  119. // console.log(this.type)
  120. var params = this.getQueryParams();//查询条件
  121. this.loading = true;
  122. if(this.type === '1'){
  123. params.eqid = this.equipmentId
  124. getAction(this.url.getList, params).then((res) => {
  125. if (res.success) {
  126. this.dataSource = res.result.records||res.result;
  127. if(res.result.total)
  128. {
  129. this.ipagination.total = res.result.total;
  130. }else{
  131. this.ipagination.total = 0;
  132. }
  133. // this.selectList()
  134. }else{
  135. this.$message.warning(res.message)
  136. }
  137. }).finally(() => {
  138. this.loading = false
  139. })
  140. } else {
  141. params.classification = this.type
  142. getAction(this.url.itemList, params).then((res) => {
  143. if (res.success) {
  144. this.dataSource = res.result.records||res.result;
  145. if(res.result.total)
  146. {
  147. this.ipagination.total = res.result.total;
  148. }else{
  149. this.ipagination.total = 0;
  150. }
  151. // this.selectList()
  152. }else{
  153. this.$message.warning(res.message)
  154. }
  155. }).finally(() => {
  156. this.loading = false
  157. })
  158. }
  159. },
  160. // 将以选中的值重新在列表中选中
  161. selectList() {
  162. this.chooseData = [...this.selectData]
  163. console.log('chooseData', this.chooseData)
  164. this.selectedRowKeys = this.chooseData.map((res) => {
  165. return res.id
  166. })
  167. console.log(this.selectedRowKeys)
  168. },
  169. close () {
  170. this.visible = false;
  171. },
  172. handleOk () {
  173. this.$emit('ok', this.chooseData);
  174. console.log(this.chooseData)
  175. this.visible = false;
  176. },
  177. handleCancel () {
  178. this.close()
  179. },
  180. onSelect(selectedRow, selected){
  181. // console.log(selectedRow, selected)
  182. if(selected){
  183. // 新增
  184. this.chooseData.push(selectedRow)
  185. } else {
  186. // 删除(过滤)
  187. var index = this.chooseData.findIndex(item => item.id === selectedRow.id)
  188. this.chooseData.splice(index, 1)
  189. }
  190. },
  191. }
  192. }
  193. </script>