PurchaseOrderListSelectModal.vue 12 KB

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