SparePartInfoSelectModal.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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. <a-row :gutter="8">
  12. <a-col :span="5">
  13. <a-tree
  14. @expand="onExpand"
  15. :expandedKeys="expandedKeys"
  16. :autoExpandParent="true"
  17. @select="onSelect"
  18. :selectedKeys="selectedKeys"
  19. :treeData="spareTypeTreeData"
  20. />
  21. </a-col>
  22. <a-col :span="19">
  23. <div class="table-page-search-wrapper">
  24. <a-form layout="inline">
  25. <a-row :gutter="48">
  26. <a-col :md="6 || 24" :sm="24">
  27. <a-form-item label="">
  28. <a-input v-model="queryParam.keyword" placeholder="名称/编码"/>
  29. </a-form-item>
  30. </a-col>
  31. <a-col :md="6 || 24" :sm="24">
  32. <a-form-item label="">
  33. <a-input v-model="queryParam.ggxh" placeholder="规格型号"/>
  34. </a-form-item>
  35. </a-col>
  36. <a-col :md="6 || 24" :sm="24">
  37. <a-form-item label="">
  38. <a-input v-model="queryParam.initNo" placeholder="原厂编号"/>
  39. </a-form-item>
  40. </a-col>
  41. <a-col :md="6 || 24" :sm="24">
  42. <a-form-item label="">
  43. <a-select v-model="queryParam.isSpecial" placeholder="请选择">
  44. <a-select-option
  45. v-for="(label,value) in specialMap"
  46. :key="value"
  47. :label="label"
  48. :value="parseInt(value)">{{ label }}
  49. </a-select-option>
  50. </a-select>
  51. </a-form-item>
  52. </a-col>
  53. <a-col :md="8" :sm="24">
  54. <a-form-item label="关联设备">
  55. <a-input v-model="queryParam.model" placeholder="新号/旧号/名称/规格"/>
  56. </a-form-item>
  57. </a-col>
  58. <a-col :md="6 || 24" :sm="24">
  59. <span class="table-page-search-submitButtons">
  60. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  61. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  62. </span>
  63. </a-col>
  64. </a-row>
  65. </a-form>
  66. </div>
  67. <div class="table-operator">
  68. </div>
  69. <s-table
  70. ref="table"
  71. size="default"
  72. rowKey="id"
  73. :columns="columns"
  74. :data="loadData"
  75. :alert="options.alert"
  76. :customRow="options.customRow"
  77. :rowSelection="options.rowSelection"
  78. showPagination="auto"
  79. >
  80. <span slot="action" slot-scope="record">
  81. <template>
  82. <a @click="handleView(record)">查看</a>
  83. </template>
  84. </span>
  85. </s-table>
  86. </a-col>
  87. </a-row>
  88. <detail ref="detailModal"/>
  89. </a-card>
  90. <template slot="footer">
  91. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  92. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  93. </template>
  94. </a-modal>
  95. </template>
  96. <script>
  97. import { STable, Ellipsis } from '@/components'
  98. import Detail from './Detail'
  99. import { getSparePartInfoPage, fetchSparePartInfo } from '@/api/sqarepartmanage/sparepartinfo'
  100. import { fetchSpareTypeTree } from '@/api/sqarepartmanage/sparetype'
  101. export default {
  102. name: 'SparePartInfoSelectModal',
  103. components: {
  104. STable,
  105. Ellipsis,
  106. Detail
  107. },
  108. props: {
  109. type: {
  110. type: String,
  111. default: 'radio'
  112. },
  113. typeName: {
  114. type: String,
  115. default: ''
  116. },
  117. selectedRowKey: {
  118. type: Array,
  119. default: () => {
  120. return []
  121. }
  122. },
  123. selectedRow: {
  124. type: Array,
  125. default: () => {
  126. return []
  127. }
  128. }
  129. },
  130. data () {
  131. return {
  132. confirmLoading: false,
  133. mdl: {},
  134. modalTitle: null,
  135. specialMap: {},
  136. visible: false,
  137. record: null,
  138. spareTypeTreeData: [],
  139. expandedKeys: [],
  140. selectedKeys: [],
  141. // 查询参数
  142. queryParam: {
  143. },
  144. extraQueryParam: {
  145. },
  146. // 表头
  147. columns: [
  148. {
  149. title: '序号',
  150. dataIndex: 'index',
  151. customRender: (text, record, index) => {
  152. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  153. }
  154. },
  155. {
  156. title: '编号',
  157. dataIndex: 'no'
  158. },
  159. {
  160. title: '名称',
  161. dataIndex: 'name'
  162. },
  163. {
  164. title: '规格型号',
  165. dataIndex: 'ggxh'
  166. },
  167. {
  168. title: '备件价值',
  169. dataIndex: 'initialValue',
  170. customRender: (text, record, index) => {
  171. return this.BaseTool.Amount.formatter(text)
  172. }
  173. },
  174. {
  175. title: '计量单位',
  176. dataIndex: 'unit'
  177. },
  178. {
  179. title: '操作',
  180. key: 'action',
  181. align: 'center',
  182. scopedSlots: { customRender: 'action' }
  183. }
  184. ],
  185. // 加载数据方法 必须为 Promise 对象
  186. loadData: parameter => {
  187. parameter = {
  188. ...parameter,
  189. ...this.queryParam,
  190. ...this.extraQueryParam,
  191. dataScope: {
  192. sortBy: 'desc',
  193. sortName: 'name'
  194. }
  195. }
  196. return getSparePartInfoPage(Object.assign(parameter, this.queryParam))
  197. .then(res => {
  198. return res.data
  199. })
  200. },
  201. selectedRowKeys: [],
  202. selectedRows: [],
  203. options: {
  204. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  205. rowSelection: {
  206. selectedRowKeys: this.selectedRowKeys,
  207. onChange: this.onSelectChange
  208. }
  209. },
  210. optionAlertShow: false,
  211. isCreated: false
  212. }
  213. },
  214. created () {
  215. // 下拉框map
  216. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SPARE_PART_INFO_LEVEL)
  217. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  218. this.specialMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  219. },
  220. methods: {
  221. tableOption () {
  222. if (!this.optionAlertShow) {
  223. this.options = {
  224. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  225. rowSelection: {
  226. selectedRowKeys: this.selectedRowKeys,
  227. onChange: this.onSelectChange,
  228. type: this.type,
  229. getCheckboxProps: record => ({
  230. props: {
  231. disabled: false,
  232. name: record.id
  233. }
  234. })
  235. },
  236. customRow: (record) => {
  237. return {
  238. on: { // 事件
  239. click: (event) => { // 点击行
  240. // 选择对象
  241. this.mySelect([record.id], [record])
  242. },
  243. dblclick: (event) => {
  244. this.mySelect([record.id], [record])
  245. this.handleSelect()
  246. }
  247. }
  248. }
  249. }
  250. }
  251. this.optionAlertShow = true
  252. } else {
  253. this.options = {
  254. alert: false,
  255. rowSelection: null
  256. }
  257. this.optionAlertShow = false
  258. }
  259. },
  260. handleView (record) {
  261. fetchSparePartInfo({ id: record.id }).then(res => {
  262. const modal = this.$refs.detailModal
  263. modal.base(res.data)
  264. })
  265. },
  266. handleOk () {
  267. this.$refs.table.refresh()
  268. },
  269. onSelectChange (selectedRowKeys, selectedRows) {
  270. this.selectedRowKeys = selectedRowKeys
  271. this.selectedRows = selectedRows
  272. },
  273. resetSearchForm () {
  274. this.queryParam = {
  275. }
  276. this.$refs.table.refresh(true)
  277. },
  278. base (record, queryParam = {}) {
  279. this.visible = true
  280. this.modalTitle = '选择信息'
  281. this.queryParam = queryParam
  282. this.record = record
  283. if (!this.BaseTool.Object.isBlank(queryParam.typeName)) {
  284. fetchSpareTypeTree({ name: queryParam.typeName }).then(res => {
  285. this.spareTypeTreeData = res.data
  286. })
  287. } else {
  288. fetchSpareTypeTree().then(res => {
  289. this.spareTypeTreeData = res.data
  290. })
  291. }
  292. if (this.isCreated) {
  293. this.$refs.table.clearSelected()
  294. this.options.rowSelection.type = this.type
  295. this.handleOk()
  296. } else {
  297. this.tableOption()
  298. this.isCreated = true
  299. }
  300. },
  301. handleCancel () {
  302. this.visible = false
  303. this.confirmLoading = false
  304. },
  305. handleSelect () {
  306. if (this.selectedRowKeys.length === 0) {
  307. this.$message.warn('请至少选择一项信息')
  308. } else {
  309. this.confirmLoading = true
  310. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  311. this.confirmLoading = false
  312. this.visible = false
  313. }
  314. },
  315. mySelect (selectedRowKeys, selectedRows) {
  316. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  317. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  318. },
  319. onSelect: function (selectedKeys, info) {
  320. this.selectedKeys = selectedKeys
  321. this.queryParam.typeId = selectedKeys.length > 0 ? selectedKeys[0] : ''
  322. this.queryParam.typeName = ''
  323. this.$refs.table.refresh(true)
  324. },
  325. onExpand (expandedKeys) {
  326. this.expandedKeys = expandedKeys
  327. this.autoExpandParent = false
  328. }
  329. }
  330. }
  331. </script>