PurchaseApplyListSelectModal.vue 12 KB

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