PurchaseDemandPlanListSelectModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1000"
  5. :visible="visible"
  6. v-drag-modal
  7. :confirmLoading="confirmLoading"
  8. class="ant-modal2"
  9. @cancel="handleCancel"
  10. >
  11. <a-card :bordered="false">
  12. <div class="table-page-search-wrapper">
  13. <a-form layout="inline">
  14. <a-row :gutter="48">
  15. <a-col :md="8" :sm="24">
  16. <a-form-item label="类型">
  17. <a-tree-select
  18. style="width: 100%"
  19. :dropdownStyle="{ maxHeight: '400px', overflow: 'auto' }"
  20. :treeData="spareTypeTreeData"
  21. :treeNodeFilterProp="'title'"
  22. :showSearch="true"
  23. v-model="queryParam.type"
  24. placeholder="请选择"
  25. >
  26. </a-tree-select>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="8" :sm="24">
  30. <a-form-item label="关键字">
  31. <a-input v-model="queryParam.keyword" placeholder="请输入名称/编号"/>
  32. </a-form-item>
  33. </a-col>
  34. <a-col :md="8 || 24" :sm="24">
  35. <span class="table-page-search-submitButtons">
  36. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  37. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  38. </span>
  39. </a-col>
  40. </a-row>
  41. </a-form>
  42. </div>
  43. <div class="table-operator" style="margin-bottom: 8px;">
  44. </div>
  45. <s-table
  46. ref="table"
  47. size="small"
  48. rowKey="goodsId"
  49. :columns="columns"
  50. :data="loadData"
  51. :scroll="{x: 1, y: BaseTool.Constant.scrollY }"
  52. :alert="options.alert"
  53. :customRow="options.customRow"
  54. :pagination="options.pagination"
  55. :rowSelection="options.rowSelection"
  56. showPagination="auto"
  57. >
  58. </s-table>
  59. <detail ref="detailModal"/>
  60. </a-card>
  61. <template slot="footer">
  62. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  63. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  64. </template>
  65. </a-modal>
  66. </template>
  67. <script>
  68. import { STable, Ellipsis } from '@/components'
  69. import Detail from './Detail'
  70. import { getPurchaseDemandPlanListPage, fetchPurchaseDemandPlanList } from '@/api/purchase/purchase-demand-plan-list'
  71. import { fetchSpareTypeTree } from '@/api/sqarepartmanage/sparetype'
  72. export default {
  73. name: 'PurchaseDemandPlanListSelectModal',
  74. components: {
  75. STable,
  76. Ellipsis,
  77. Detail
  78. },
  79. props: {
  80. type: {
  81. type: String,
  82. default: 'radio'
  83. },
  84. selectedRowKey: {
  85. type: Array,
  86. default: () => {
  87. return []
  88. }
  89. },
  90. selectedRow: {
  91. type: Array,
  92. default: () => {
  93. return []
  94. }
  95. }
  96. },
  97. data () {
  98. return {
  99. confirmLoading: false,
  100. mdl: {},
  101. modalTitle: null,
  102. visible: false,
  103. spareTypeTreeData: [],
  104. record: null,
  105. // 查询参数
  106. queryParam: {
  107. },
  108. extraQueryParam: {
  109. },
  110. // 表头
  111. columns: [
  112. {
  113. title: '序号',
  114. dataIndex: 'index',
  115. width: 70,
  116. customRender: (text, record, index) => {
  117. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  118. }
  119. },
  120. {
  121. title: '编号',
  122. dataIndex: 'no',
  123. checked: true,
  124. width: 180
  125. },
  126. {
  127. title: '名称',
  128. dataIndex: 'name',
  129. checked: true,
  130. width: 120
  131. },
  132. {
  133. title: '规格',
  134. dataIndex: 'specs',
  135. checked: true,
  136. width: 90
  137. },
  138. {
  139. title: '单位',
  140. dataIndex: 'unit',
  141. checked: true,
  142. width: 90
  143. },
  144. {
  145. title: '单价',
  146. dataIndex: 'price',
  147. checked: true,
  148. width: 100,
  149. customRender: (text, record, index) => {
  150. return this.BaseTool.Amount.formatter(text)
  151. }
  152. },
  153. {
  154. title: '数量',
  155. dataIndex: 'quantity',
  156. checked: true,
  157. width: 90,
  158. customRender: (text, record, index) => {
  159. return this.BaseTool.Amount.formatter(text)
  160. }
  161. },
  162. {
  163. title: '超支数量',
  164. dataIndex: 'overQuantity',
  165. checked: true,
  166. width: 90,
  167. customRender: (text, record, index) => {
  168. return this.BaseTool.Amount.formatter(text)
  169. }
  170. },
  171. {
  172. title: '总价',
  173. dataIndex: 'totalMoney',
  174. checked: true,
  175. width: 100,
  176. customRender: (text, record, index) => {
  177. return this.BaseTool.Amount.formatter(text)
  178. }
  179. },
  180. {
  181. title: '控制金额',
  182. dataIndex: 'controlMoney',
  183. checked: true,
  184. width: 100,
  185. customRender: (text, record, index) => {
  186. return this.BaseTool.Amount.formatter(text)
  187. }
  188. },
  189. {
  190. title: '合同项目名称',
  191. dataIndex: 'contractName',
  192. width: 120
  193. },
  194. {
  195. title: '合同项目数量',
  196. dataIndex: 'contractQuantity',
  197. width: 90,
  198. customRender: (text, record, index) => {
  199. return this.BaseTool.Amount.formatter(text)
  200. }
  201. },
  202. {
  203. title: '合同总金额',
  204. dataIndex: 'contractMoney',
  205. width: 100,
  206. customRender: (text, record, index) => {
  207. return this.BaseTool.Amount.formatter(text)
  208. }
  209. },
  210. {
  211. title: '合同项目单位',
  212. dataIndex: 'contractProjectUnit',
  213. width: 90,
  214. customRender: (text, record, index) => {
  215. return this.BaseTool.Table.getMapText(this.contractProjectUnitMap, text)
  216. }
  217. },
  218. {
  219. title: '项目单位',
  220. dataIndex: 'projectUnit',
  221. width: 90,
  222. customRender: (text, record, index) => {
  223. return this.BaseTool.Table.getMapText(this.projectUnitMap, text)
  224. }
  225. },
  226. {
  227. title: '已购数量',
  228. dataIndex: 'boughtQuantity',
  229. width: 90,
  230. customRender: (text, record, index) => {
  231. return this.BaseTool.Amount.formatter(text)
  232. }
  233. },
  234. {
  235. title: '已用金额',
  236. dataIndex: 'usedMoney',
  237. width: 90,
  238. customRender: (text, record, index) => {
  239. return this.BaseTool.Amount.formatter(text)
  240. }
  241. },
  242. {
  243. title: '备注',
  244. dataIndex: 'remark',
  245. width: 100
  246. },
  247. {
  248. title: '创建人名称',
  249. dataIndex: 'createdUserName',
  250. width: 100
  251. },
  252. {
  253. title: '创建时间',
  254. dataIndex: 'createdTime',
  255. width: 100
  256. }
  257. ],
  258. // 下拉框map
  259. unitMap: {},
  260. contractProjectUnitMap: {},
  261. projectUnitMap: {},
  262. // 加载数据方法 必须为 Promise 对象
  263. loadData: parameter => {
  264. parameter = {
  265. ...parameter,
  266. ...this.queryParam,
  267. ...this.extraQueryParam,
  268. dataScope: {
  269. sortBy: 'asc',
  270. sortName: 'no'
  271. }
  272. }
  273. return getPurchaseDemandPlanListPage(Object.assign(parameter, this.queryParam))
  274. .then(res => {
  275. return res.data
  276. })
  277. },
  278. selectedRowKeys: [],
  279. selectedRows: [],
  280. options: {
  281. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  282. rowSelection: {
  283. selectedRowKeys: this.selectedRowKeys,
  284. onChange: this.onSelectChange
  285. }
  286. },
  287. optionAlertShow: false,
  288. isCreated: false
  289. }
  290. },
  291. created () {
  292. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  293. this.contractProjectUnitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CONTRACT_PROJECT_UNIT)
  294. this.projectUnitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PROJECT_UNIT)
  295. },
  296. methods: {
  297. tableOption () {
  298. this.setTree()
  299. if (!this.optionAlertShow) {
  300. this.options = {
  301. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  302. rowSelection: {
  303. selectedRowKeys: this.selectedRowKeys,
  304. onChange: this.onSelectChange,
  305. // onSelect: this.onSelect,
  306. type: this.type,
  307. getCheckboxProps: record => ({
  308. props: {
  309. disabled: false,
  310. name: record.goodsId
  311. }
  312. })
  313. },
  314. customRow: (record) => {
  315. return {
  316. on: { // 事件
  317. click: (event) => { // 点击行
  318. // 选择对象
  319. this.mySelect([record.goodsId], [record])
  320. },
  321. dblclick: (event) => {
  322. this.mySelect([record.goodsId], [record])
  323. this.handleSelect()
  324. }
  325. }
  326. }
  327. },
  328. pagination: {
  329. onChange: (pages, pageSize) => {
  330. console.log(11111)
  331. }
  332. }
  333. }
  334. this.optionAlertShow = true
  335. } else {
  336. this.options = {
  337. alert: false,
  338. rowSelection: null
  339. }
  340. this.optionAlertShow = false
  341. }
  342. },
  343. handleView (record) {
  344. fetchPurchaseDemandPlanList({ id: record.id }).then(res => {
  345. const modal = this.$refs.detailModal
  346. modal.base(res.data)
  347. })
  348. },
  349. onSelect (record, selected, selectedRows) {
  350. if (selected) {
  351. this.selectedRows.push(record)
  352. }
  353. if (!selected) {
  354. const delIndex = this.selectedRows.findIndex(val => {
  355. return val.goodsId === record.goodsId
  356. })
  357. this.selectedRows.splice(delIndex, 1)
  358. }
  359. },
  360. handleOk () {
  361. this.$refs.table.refresh()
  362. },
  363. onSelectChange (selectedRowKeys, selectedRows) {
  364. this.selectedRowKeys = selectedRowKeys
  365. this.selectedRows = selectedRows
  366. },
  367. resetSearchForm () {
  368. this.queryParam = {
  369. ...this.extraQueryParam
  370. }
  371. this.$refs.table.refresh(true)
  372. },
  373. base (record, queryParam = {}) {
  374. this.visible = true
  375. this.modalTitle = '选择信息'
  376. this.extraQueryParam = queryParam
  377. this.record = record
  378. if (this.isCreated) {
  379. this.$refs.table.clearSelected()
  380. this.options.rowSelection.type = this.type
  381. this.handleOk()
  382. } else {
  383. this.tableOption()
  384. this.isCreated = true
  385. }
  386. const checkedRows = this.$store.getters.checkedRows
  387. console.log(checkedRows)
  388. const checkedRowKeys = checkedRows.map((item) => {
  389. return item.goodsId
  390. })
  391. this.$nextTick(() => {
  392. this.mySelect(checkedRowKeys, checkedRows)
  393. })
  394. },
  395. handleCancel () {
  396. this.visible = false
  397. this.confirmLoading = false
  398. },
  399. handleSelect () {
  400. if (this.selectedRowKeys.length === 0) {
  401. this.$message.warn('请至少选择一项信息')
  402. } else {
  403. this.confirmLoading = true
  404. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  405. this.confirmLoading = false
  406. this.visible = false
  407. }
  408. },
  409. mySelect (selectedRowKeys, selectedRows) {
  410. if (this.type === 'radio') {
  411. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  412. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  413. } else {
  414. let mySelectedRowKeys
  415. let mySelectedRows = this.selectedRows.filter(item => item.goodsId !== selectedRowKeys[0])
  416. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  417. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  418. } else {
  419. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  420. mySelectedRows = [...mySelectedRows, ...selectedRows]
  421. }
  422. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  423. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  424. }
  425. },
  426. /**
  427. * 设置备件类别树
  428. */
  429. setTree (record = {}) {
  430. fetchSpareTypeTree({}).then(res => {
  431. this.spareTypeTreeData = res.data
  432. })
  433. }
  434. }
  435. }
  436. </script>