PurchasePlanListSelectModal.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436
  1. <template>
  2. <a-modal
  3. :title="modalTitle"
  4. :width="1000"
  5. :visible="visible"
  6. :confirmLoading="confirmLoading"
  7. v-drag-modal
  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.trim="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="id"
  49. :columns="columns"
  50. :data="loadData"
  51. :scroll="{x: 1, y: BaseTool.Constant.scrollY }"
  52. :alert="options.alert"
  53. :customRow="options.customRow"
  54. :rowSelection="options.rowSelection"
  55. showPagination="auto"
  56. >
  57. </s-table>
  58. <detail ref="detailModal"/>
  59. </a-card>
  60. <template slot="footer">
  61. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  62. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  63. </template>
  64. </a-modal>
  65. </template>
  66. <script>
  67. import { STable, Ellipsis } from '@/components'
  68. import Detail from './Detail'
  69. import { getPurchasePlanListPage, fetchPurchasePlanList } from '@/api/purchase/purchase-plan-list'
  70. import { fetchSpareTypeTree } from '@/api/sqarepartmanage/sparetype'
  71. export default {
  72. name: 'PurchasePlanListSelectModal',
  73. components: {
  74. STable,
  75. Ellipsis,
  76. Detail
  77. },
  78. props: {
  79. type: {
  80. type: String,
  81. default: 'radio'
  82. },
  83. selectedRowKey: {
  84. type: Array,
  85. default: () => {
  86. return []
  87. }
  88. },
  89. selectedRow: {
  90. type: Array,
  91. default: () => {
  92. return []
  93. }
  94. }
  95. },
  96. data () {
  97. return {
  98. confirmLoading: false,
  99. mdl: {},
  100. spareTypeTreeData: [],
  101. modalTitle: null,
  102. visible: false,
  103. record: null,
  104. // 查询参数
  105. queryParam: {
  106. },
  107. extraQueryParam: {
  108. },
  109. // 表头
  110. columns: [
  111. {
  112. title: '序号',
  113. dataIndex: 'index',
  114. width: 70,
  115. customRender: (text, record, index) => {
  116. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  117. }
  118. },
  119. {
  120. title: '编号',
  121. dataIndex: 'no',
  122. checked: true,
  123. width: 180
  124. },
  125. {
  126. title: '名称',
  127. dataIndex: 'name',
  128. checked: true,
  129. width: 120
  130. },
  131. {
  132. title: '规格',
  133. dataIndex: 'specs',
  134. checked: true,
  135. width: 90
  136. },
  137. {
  138. title: '单位',
  139. dataIndex: 'unit',
  140. checked: true,
  141. width: 90
  142. },
  143. {
  144. title: '单价',
  145. dataIndex: 'price',
  146. checked: true,
  147. width: 100,
  148. customRender: (text, record, index) => {
  149. return this.BaseTool.Amount.formatter(text)
  150. }
  151. },
  152. {
  153. title: '数量',
  154. dataIndex: 'quantity',
  155. checked: true,
  156. width: 90,
  157. customRender: (text, record, index) => {
  158. return this.BaseTool.Amount.formatter(text)
  159. }
  160. },
  161. {
  162. title: '总价',
  163. dataIndex: 'totalMoney',
  164. checked: true,
  165. width: 100,
  166. customRender: (text, record, index) => {
  167. return this.BaseTool.Amount.formatter(text)
  168. }
  169. },
  170. {
  171. title: '品牌',
  172. dataIndex: 'brand',
  173. checked: true,
  174. width: 120
  175. },
  176. {
  177. title: '适用车型',
  178. dataIndex: 'suitableModel',
  179. checked: true,
  180. width: 120
  181. },
  182. {
  183. title: '车架号',
  184. dataIndex: 'vin',
  185. width: 150
  186. },
  187. {
  188. title: '发动机号',
  189. dataIndex: 'engineNum',
  190. width: 150
  191. },
  192. {
  193. title: '已购数量',
  194. dataIndex: 'boughtQuantity',
  195. width: 90,
  196. customRender: (text, record, index) => {
  197. return this.BaseTool.Amount.formatter(text)
  198. }
  199. },
  200. {
  201. title: '已到数量',
  202. dataIndex: 'arrivedQuantity',
  203. width: 90,
  204. customRender: (text, record, index) => {
  205. return this.BaseTool.Amount.formatter(text)
  206. }
  207. },
  208. {
  209. title: '未到数量',
  210. dataIndex: 'notArriveQuantity',
  211. width: 90,
  212. customRender: (text, record, index) => {
  213. return this.BaseTool.Amount.formatter(text)
  214. }
  215. },
  216. {
  217. title: '已用金额',
  218. dataIndex: 'usedMoney',
  219. width: 90,
  220. customRender: (text, record, index) => {
  221. return this.BaseTool.Amount.formatter(text)
  222. }
  223. },
  224. {
  225. title: '产地',
  226. dataIndex: 'producePlace',
  227. width: 90,
  228. customRender: (text, record, index) => {
  229. return this.BaseTool.Table.getMapText(this.areaMap, text)
  230. }
  231. },
  232. {
  233. title: '重量',
  234. dataIndex: 'weight',
  235. width: 90,
  236. customRender: (text, record, index) => {
  237. return this.BaseTool.Amount.formatter(text)
  238. }
  239. },
  240. {
  241. title: '体积',
  242. dataIndex: 'volume',
  243. width: 90,
  244. customRender: (text, record, index) => {
  245. return this.BaseTool.Amount.formatter(text)
  246. }
  247. },
  248. {
  249. title: '外形尺寸',
  250. dataIndex: 'dimension',
  251. width: 90
  252. },
  253. {
  254. title: '备注',
  255. dataIndex: 'remark',
  256. width: 90
  257. }
  258. ],
  259. // 下拉框map
  260. unitMap: {},
  261. areaMap: {},
  262. statusMap: {},
  263. // 加载数据方法 必须为 Promise 对象
  264. loadData: parameter => {
  265. parameter = {
  266. ...parameter,
  267. ...this.queryParam,
  268. ...this.extraQueryParam,
  269. dataScope: {
  270. sortBy: 'desc',
  271. sortName: 'update_time'
  272. }
  273. }
  274. return getPurchasePlanListPage(Object.assign(parameter, this.queryParam))
  275. .then(res => {
  276. return res.data
  277. })
  278. },
  279. selectedRowKeys: [],
  280. selectedRows: [],
  281. options: {
  282. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  283. rowSelection: {
  284. selectedRowKeys: this.selectedRowKeys,
  285. onChange: this.onSelectChange
  286. }
  287. },
  288. optionAlertShow: false,
  289. isCreated: false
  290. }
  291. },
  292. created () {
  293. // 下拉框map
  294. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  295. this.areaMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PRODUCER_AREA)
  296. },
  297. methods: {
  298. tableOption () {
  299. this.setTree()
  300. if (!this.optionAlertShow) {
  301. this.options = {
  302. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  303. rowSelection: {
  304. selectedRowKeys: this.selectedRowKeys,
  305. onChange: this.onSelectChange,
  306. // onSelect: this.onSelect,
  307. type: this.type,
  308. getCheckboxProps: record => ({
  309. props: {
  310. disabled: false,
  311. name: record.goodsId
  312. }
  313. })
  314. },
  315. customRow: (record) => {
  316. return {
  317. on: { // 事件
  318. click: (event) => { // 点击行
  319. // 选择对象
  320. this.mySelect([record.goodsId], [record])
  321. },
  322. dblclick: (event) => {
  323. this.mySelect([record.goodsId], [record])
  324. this.handleSelect()
  325. }
  326. }
  327. }
  328. }
  329. }
  330. this.optionAlertShow = true
  331. } else {
  332. this.options = {
  333. alert: false,
  334. rowSelection: null
  335. }
  336. this.optionAlertShow = false
  337. }
  338. },
  339. handleView (record) {
  340. fetchPurchasePlanList({ id: record.id }).then(res => {
  341. const modal = this.$refs.detailModal
  342. modal.base(res.data)
  343. })
  344. },
  345. handleOk () {
  346. this.$refs.table.refresh()
  347. },
  348. onSelectChange (selectedRowKeys, selectedRows) {
  349. this.selectedRowKeys = selectedRowKeys
  350. this.selectedRows = selectedRows
  351. },
  352. onSelect (record, selected, selectedRows) {
  353. if (selected) {
  354. this.selectedRows.push(record)
  355. }
  356. if (!selected) {
  357. const delIndex = this.selectedRows.findIndex(val => {
  358. return val.goodsId === record.goodsId
  359. })
  360. this.selectedRows.splice(delIndex, 1)
  361. }
  362. },
  363. resetSearchForm () {
  364. this.queryParam = {
  365. ...this.extraQueryParam
  366. }
  367. this.$refs.table.refresh(true)
  368. },
  369. base (record, queryParam = {}) {
  370. this.visible = true
  371. this.modalTitle = '选择信息'
  372. this.extraQueryParam = queryParam
  373. this.record = record
  374. if (this.isCreated) {
  375. this.$refs.table.clearSelected()
  376. this.options.rowSelection.type = this.type
  377. this.handleOk()
  378. } else {
  379. this.tableOption()
  380. this.isCreated = true
  381. }
  382. const checkedRows = this.$store.getters.checkedRows
  383. const checkedRowKeys = checkedRows.map((item) => {
  384. return item.goodsId
  385. })
  386. this.$nextTick(() => {
  387. this.mySelect(checkedRowKeys, checkedRows)
  388. })
  389. },
  390. handleCancel () {
  391. this.visible = false
  392. this.confirmLoading = false
  393. },
  394. handleSelect () {
  395. if (this.selectedRowKeys.length === 0) {
  396. this.$message.warn('请至少选择一项信息')
  397. } else {
  398. this.confirmLoading = true
  399. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  400. this.confirmLoading = false
  401. this.visible = false
  402. }
  403. },
  404. mySelect (selectedRowKeys, selectedRows) {
  405. if (this.type === 'radio') {
  406. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  407. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  408. } else {
  409. let mySelectedRowKeys
  410. let mySelectedRows = this.selectedRows.filter(item => item.goodsId !== selectedRowKeys[0])
  411. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  412. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  413. } else {
  414. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  415. mySelectedRows = [...mySelectedRows, ...selectedRows]
  416. }
  417. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  418. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  419. }
  420. },
  421. /**
  422. * 设置备件类别树
  423. */
  424. setTree (record = {}) {
  425. fetchSpareTypeTree({}).then(res => {
  426. this.spareTypeTreeData = res.data
  427. })
  428. }
  429. }
  430. }
  431. </script>