SpareLongYanSelectModal.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1050"
  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="24">
  13. <div class="table-page-search-wrapper">
  14. <a-form layout="inline">
  15. <a-row :gutter="48">
  16. <a-col :md="8" :sm="24">
  17. <a-form-item label="备件名称">
  18. <a-input v-model.trim="queryParam.spareName" placeholder="请输入备件名称"/>
  19. </a-form-item>
  20. </a-col>
  21. <a-col :md="8" :sm="24">
  22. <a-form-item label="备件编码">
  23. <a-input v-model.trim="queryParam.spareNo" placeholder="请输入备件编码"/>
  24. </a-form-item>
  25. </a-col>
  26. <a-col :md="8" :sm="24">
  27. <a-form-item label="规格型号">
  28. <a-input v-model="queryParam.ggxh" placeholder="请输入规格型号"/>
  29. </a-form-item>
  30. </a-col>
  31. <!-- <a-col :md="8" :sm="24">
  32. <a-form-item label="原厂编号">
  33. <a-input v-model="queryParam.initNo" placeholder="模糊查询"/>
  34. </a-form-item>
  35. </a-col>
  36. <a-col :md="8" :sm="24">
  37. <a-form-item label="关联设备">
  38. <a-input v-model="queryParam.model" placeholder="新号/旧号/名称/规格"/>
  39. </a-form-item>
  40. </a-col>
  41. <a-col :md="8" :sm="24">
  42. <a-form-item
  43. label="仓库"
  44. :labelCol="BaseTool.Constant.labelCol"
  45. :wrapperCol="BaseTool.Constant.wrapperCol"
  46. >
  47. <a-tree-select
  48. style="width: 100%"
  49. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  50. :treeData="storeTreeDate"
  51. :treeNodeFilterProp="'title'"
  52. :showSearch="true"
  53. v-model="queryParam.storeId"
  54. placeholder="请选择"
  55. >
  56. </a-tree-select>
  57. </a-form-item>
  58. </a-col>-->
  59. <a-col :md="8 || 24" :sm="24">
  60. <span class="table-page-search-submitButtons">
  61. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  62. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  63. </span>
  64. </a-col>
  65. </a-row>
  66. </a-form>
  67. </div>
  68. <div class="table-operator" style="margin-bottom: 8px;">
  69. </div>
  70. <s-table
  71. ref="table"
  72. size="default"
  73. rowKey="id"
  74. :columns="columns"
  75. :data="loadData"
  76. :alert="options.alert"
  77. :customRow="options.customRow"
  78. :rowSelection="options.rowSelection"
  79. showPagination="auto"
  80. >
  81. <span slot="action" slot-scope="record1">
  82. <template>
  83. <a @click="handleView(record1)">查看</a>
  84. </template>
  85. </span>
  86. </s-table>
  87. </a-col>
  88. </a-row>
  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 { getSpareLongYanPage, fetchSpareStore } from '@/api/store/sparestore'
  100. export default {
  101. name: 'SpareLongYanSelectModal',
  102. components: {
  103. STable,
  104. Ellipsis,
  105. Detail
  106. },
  107. props: {
  108. type: {
  109. type: String,
  110. default: 'checkbox'
  111. },
  112. selectedRowKey: {
  113. type: Array,
  114. default: () => {
  115. return []
  116. }
  117. },
  118. selectedRow: {
  119. type: Array,
  120. default: () => {
  121. return []
  122. }
  123. }
  124. },
  125. data () {
  126. return {
  127. confirmLoading: false,
  128. mdl: {},
  129. modalTitle: null,
  130. visible: false,
  131. record: null,
  132. expandedKeys: [],
  133. selectedKeys: [],
  134. isSpecial: null,
  135. // 查询参数
  136. queryParam: {
  137. },
  138. // 表头
  139. columns: [
  140. {
  141. title: '序号',
  142. dataIndex: 'index',
  143. customRender: (text, record, index) => {
  144. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  145. }
  146. },
  147. {
  148. title: '备件名称',
  149. dataIndex: 'spareName'
  150. },
  151. {
  152. title: '备件编码',
  153. dataIndex: 'no'
  154. },
  155. {
  156. title: '规格型号',
  157. dataIndex: 'ggxh'
  158. }
  159. ],
  160. // 下拉框map
  161. delFlagMap: {},
  162. // 加载数据方法 必须为 Promise 对象
  163. loadData: parameter => {
  164. parameter = {
  165. ...parameter,
  166. ...this.queryParam,
  167. dataScope: {
  168. sortBy: 'desc',
  169. sortName: 'update_time'
  170. }
  171. }
  172. return getSpareLongYanPage(Object.assign(parameter, this.queryParam)).then(res => {
  173. if (res.data.rows === null) {
  174. const data = { total: 0, rows: [], pageNum: 1, pageSize: 10, pages: 1 }
  175. return data
  176. } else {
  177. return res.data
  178. }
  179. })
  180. },
  181. selectedRowKeys: [],
  182. selectedRows: [],
  183. options: {
  184. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  185. rowSelection: {
  186. selectedRowKeys: this.selectedRowKeys,
  187. onChange: this.onSelectChange
  188. }
  189. },
  190. optionAlertShow: false,
  191. isCreated: false
  192. }
  193. },
  194. created () {
  195. // 下拉框map
  196. this.delFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.DELFLAG)
  197. },
  198. methods: {
  199. tableOption () {
  200. if (!this.optionAlertShow) {
  201. this.options = {
  202. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  203. rowSelection: {
  204. selectedRowKeys: this.selectedRowKeys,
  205. onChange: this.onSelectChange,
  206. type: this.type,
  207. getCheckboxProps: record => ({
  208. props: {
  209. disabled: false,
  210. name: record.id
  211. }
  212. })
  213. },
  214. customRow: (record) => {
  215. return {
  216. on: { // 事件
  217. click: (event) => { // 点击行
  218. // 选择对象
  219. this.mySelect([record.id], [record])
  220. },
  221. dblclick: (event) => {
  222. this.mySelect([record.id], [record])
  223. this.handleSelect()
  224. }
  225. }
  226. }
  227. }
  228. }
  229. this.optionAlertShow = true
  230. } else {
  231. this.options = {
  232. alert: false,
  233. rowSelection: null
  234. }
  235. this.optionAlertShow = false
  236. }
  237. },
  238. handleView (record) {
  239. fetchSpareStore({ id: record.id }).then(res => {
  240. const modal = this.$refs.detailModal
  241. modal.base(res.data)
  242. })
  243. },
  244. handleOk () {
  245. this.$refs.table.refresh()
  246. },
  247. onSelectChange (selectedRowKeys, selectedRows) {
  248. this.selectedRowKeys = selectedRowKeys
  249. this.selectedRows = selectedRows
  250. },
  251. resetSearchForm () {
  252. this.queryParam.keyword = null
  253. this.queryParam.typeId = null
  254. this.queryParam.model = null
  255. this.queryParam.storeId = null
  256. this.$refs.table.refresh(true)
  257. },
  258. base (record, queryParam = {}) {
  259. this.visible = true
  260. this.modalTitle = '选择信息'
  261. this.queryParam = queryParam
  262. if (queryParam.isSpecial !== undefined) {
  263. this.isSpecial = queryParam.isSpecial
  264. this.record = record
  265. }
  266. if (this.isCreated) {
  267. this.$refs.table.clearSelected()
  268. // this.options.rowSelection.type = this.type
  269. this.handleOk()
  270. } else {
  271. this.tableOption()
  272. this.isCreated = true
  273. }
  274. },
  275. handleCancel () {
  276. this.visible = false
  277. this.confirmLoading = false
  278. },
  279. handleSelect () {
  280. if (this.selectedRowKeys.length === 0) {
  281. this.$message.warn('请至少选择一项信息')
  282. } else {
  283. this.confirmLoading = true
  284. if (this.record !== null) {
  285. this.record.isSpecial = this.isSpecial
  286. }
  287. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  288. this.confirmLoading = false
  289. this.visible = false
  290. }
  291. },
  292. mySelect (selectedRowKeys, selectedRows) {
  293. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  294. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  295. },
  296. onSelect: function (selectedKeys, info) {
  297. this.selectedKeys = selectedKeys
  298. this.queryParam.typeId = selectedKeys.length > 0 ? selectedKeys[0] : ''
  299. this.$refs.table.refresh(true)
  300. },
  301. onExpand (expandedKeys) {
  302. this.expandedKeys = expandedKeys
  303. this.autoExpandParent = false
  304. }
  305. }
  306. }
  307. </script>