PartInfoSelectModal.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1000"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. class="ant-modal2"
  8. @cancel="handleCancel"
  9. >
  10. <a-card :bordered="false">
  11. <div class="table-page-search-wrapper">
  12. <a-form layout="inline">
  13. <a-row :gutter="48">
  14. <a-col :md="8" :sm="24">
  15. <a-form-item label="关键字">
  16. <a-input v-model.trim="queryParam.keyword" placeholder="请输入名称/编码"/>
  17. </a-form-item>
  18. </a-col>
  19. <a-col :md="8 || 24" :sm="24">
  20. <span class="table-page-search-submitButtons">
  21. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  22. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  23. </span>
  24. </a-col>
  25. </a-row>
  26. </a-form>
  27. </div>
  28. <div class="table-operator" style="margin-bottom: 8px;">
  29. </div>
  30. <s-table
  31. ref="table"
  32. size="default"
  33. rowKey="id"
  34. :columns="columns"
  35. :data="loadData"
  36. :alert="options.alert"
  37. :customRow="options.customRow"
  38. :rowSelection="options.rowSelection"
  39. showPagination="auto"
  40. :scroll="{ x: 1000, y: BaseTool.Constant.scrollY }"
  41. >
  42. <span slot="action" slot-scope="record">
  43. <template>
  44. <a @click="handleView(record)">查看</a>
  45. </template>
  46. </span>
  47. <span slot="status" slot-scope="text">
  48. <badge
  49. :status="DictCache.COLOR.PART_STATUS[text]"
  50. :text="statusMap[text]" />
  51. </span>
  52. </s-table>
  53. <detail ref="detailModal"/>
  54. </a-card>
  55. <template slot="footer">
  56. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  57. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  58. </template>
  59. </a-modal>
  60. </template>
  61. <script>
  62. import { STable, Ellipsis } from '@/components'
  63. import Detail from './Detail'
  64. import { getPartInfoPage, fetchPartInfo } from '@/api/part/info'
  65. export default {
  66. name: 'PartInfoSelectModal',
  67. components: {
  68. STable,
  69. Ellipsis,
  70. Detail
  71. },
  72. props: {
  73. type: {
  74. type: String,
  75. default: 'radio'
  76. },
  77. selectedRowKey: {
  78. type: Array,
  79. default: () => {
  80. return []
  81. }
  82. },
  83. selectedRow: {
  84. type: Array,
  85. default: () => {
  86. return []
  87. }
  88. }
  89. },
  90. data () {
  91. return {
  92. confirmLoading: false,
  93. mdl: {},
  94. modalTitle: null,
  95. visible: false,
  96. // 查询参数
  97. queryParam: {
  98. },
  99. statusMap: {},
  100. unitMap: {},
  101. levelMap: {},
  102. sourceTypeMap: {},
  103. // 表头
  104. columns: [
  105. // {
  106. // title: '序号',
  107. // dataIndex: 'index',
  108. // width: 50,
  109. // customRender: (text, record, index) => {
  110. // return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  111. // }
  112. // },
  113. {
  114. title: '部件编号',
  115. dataIndex: 'no',
  116. width: 300
  117. },
  118. {
  119. title: '部件名称',
  120. dataIndex: 'name',
  121. width: 300
  122. },
  123. {
  124. title: '部件类别',
  125. dataIndex: 'typeId',
  126. width: 300,
  127. customRender: (text, record, index) => {
  128. return record.typeName
  129. }
  130. },
  131. {
  132. title: '部件等级',
  133. dataIndex: 'level',
  134. width: 300,
  135. customRender: (text, record, index) => {
  136. return this.BaseTool.Object.getField(this.levelMap, text)
  137. }
  138. },
  139. {
  140. title: '所属设备',
  141. dataIndex: 'sbId',
  142. width: 300,
  143. customRender: (text, record, index) => {
  144. return record.sbName
  145. }
  146. },
  147. {
  148. title: '操作',
  149. key: 'action',
  150. width: '200px',
  151. align: 'center',
  152. fixed: 'right',
  153. scopedSlots: { customRender: 'action' }
  154. }
  155. ],
  156. // 加载数据方法 必须为 Promise 对象
  157. loadData: parameter => {
  158. parameter = {
  159. ...parameter,
  160. ...this.queryParam,
  161. dataScope: {
  162. sortBy: 'desc',
  163. sortName: 'update_time'
  164. }
  165. }
  166. return getPartInfoPage(Object.assign(parameter, this.queryParam))
  167. .then(res => {
  168. return res.data
  169. })
  170. },
  171. selectedRowKeys: this.selectedRowKey,
  172. selectedRows: this.selectedRow,
  173. options: {
  174. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  175. rowSelection: {
  176. selectedRowKeys: this.selectedRowKeys,
  177. onChange: this.onSelectChange
  178. }
  179. },
  180. optionAlertShow: false,
  181. isCreated: false
  182. }
  183. },
  184. created () {
  185. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PART_STATUS)
  186. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  187. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PART_LEVEL)
  188. this.sourceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_SOURCETYPE)
  189. },
  190. methods: {
  191. tableOption () {
  192. if (!this.optionAlertShow) {
  193. this.options = {
  194. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  195. rowSelection: {
  196. selectedRowKeys: this.selectedRowKeys,
  197. onChange: this.onSelectChange,
  198. type: this.type,
  199. getCheckboxProps: record => ({
  200. props: {
  201. disabled: false,
  202. name: record.id
  203. }
  204. })
  205. },
  206. customRow: (record) => {
  207. return {
  208. on: { // 事件
  209. click: (event) => { // 点击行
  210. // 选择对象
  211. this.mySelect([record.id], [record])
  212. },
  213. dblclick: (event) => {
  214. this.mySelect([record.id], [record])
  215. this.handleSelect()
  216. }
  217. }
  218. }
  219. }
  220. }
  221. this.optionAlertShow = true
  222. } else {
  223. this.options = {
  224. alert: false,
  225. rowSelection: null
  226. }
  227. this.optionAlertShow = false
  228. }
  229. },
  230. handleView (record) {
  231. fetchPartInfo({ id: record.id }).then(res => {
  232. const modal = this.$refs.detailModal
  233. modal.base(res.data)
  234. })
  235. },
  236. handleOk () {
  237. this.$refs.table.refresh()
  238. },
  239. onSelectChange (selectedRowKeys, selectedRows) {
  240. this.selectedRowKeys = selectedRowKeys
  241. this.selectedRows = selectedRows
  242. },
  243. resetSearchForm () {
  244. this.queryParam = {
  245. }
  246. this.$refs.table.refresh(true)
  247. },
  248. base (queryParam = {}) {
  249. this.visible = true
  250. this.modalTitle = '选择部件'
  251. this.queryParam = queryParam
  252. if (this.isCreated) {
  253. this.$refs.table.clearSelected()
  254. this.options.rowSelection.type = this.type
  255. this.handleOk()
  256. } else {
  257. this.tableOption()
  258. this.isCreated = true
  259. }
  260. // this.mySelect(this.selectedRowKeys, this.selectedRows)
  261. },
  262. handleCancel () {
  263. this.visible = false
  264. this.confirmLoading = false
  265. },
  266. handleSelect () {
  267. if (this.selectedRowKeys.length === 0) {
  268. this.$message.warn('请至少选择一项信息')
  269. } else {
  270. this.confirmLoading = true
  271. this.$emit('selected', this.selectedRowKeys, this.selectedRows)
  272. this.confirmLoading = false
  273. this.visible = false
  274. }
  275. },
  276. mySelect (selectedRowKeys, selectedRows) {
  277. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  278. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  279. }
  280. }
  281. }
  282. </script>