PurchaseContractListSelectModal.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  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="default"
  33. rowKey="id"
  34. :columns="columns"
  35. :data="loadData"
  36. :alert="options.alert"
  37. :customRow="options.customRow"
  38. :rowSelection="options.rowSelection"
  39. showPagination="auto"
  40. >
  41. <span slot="action" slot-scope="record1">
  42. <template>
  43. <a @click="handleView(record1)">查看</a>
  44. </template>
  45. </span>
  46. </s-table>
  47. <detail ref="detailModal"/>
  48. </a-card>
  49. <template slot="footer">
  50. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  51. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  52. </template>
  53. </a-modal>
  54. </template>
  55. <script>
  56. import { STable, Ellipsis } from '@/components'
  57. import Detail from './Detail'
  58. import { getPurchaseContractListPage, fetchPurchaseContractList } from '@/api/purchase/purchase-contract-list'
  59. export default {
  60. name: 'PurchaseContractListSelectModal',
  61. components: {
  62. STable,
  63. Ellipsis,
  64. Detail
  65. },
  66. props: {
  67. type: {
  68. type: String,
  69. default: 'radio'
  70. },
  71. selectedRowKey: {
  72. type: Array,
  73. default: () => {
  74. return []
  75. }
  76. },
  77. selectedRow: {
  78. type: Array,
  79. default: () => {
  80. return []
  81. }
  82. }
  83. },
  84. data () {
  85. return {
  86. confirmLoading: false,
  87. mdl: {},
  88. modalTitle: null,
  89. visible: false,
  90. record: null,
  91. // 查询参数
  92. queryParam: {
  93. },
  94. extraQueryParam: {
  95. },
  96. // 表头
  97. columns: [
  98. {
  99. title: '序号',
  100. dataIndex: 'index',
  101. customRender: (text, record, index) => {
  102. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  103. }
  104. },
  105. {
  106. title: '总需求计划主键',
  107. dataIndex: 'demandPlanId'
  108. },
  109. {
  110. title: '采购计划主键',
  111. dataIndex: 'purchasePlanId'
  112. },
  113. {
  114. title: '采购申请ID',
  115. dataIndex: 'purchaseApplyId'
  116. },
  117. {
  118. title: '采购单ID',
  119. dataIndex: 'purchaseOrderId'
  120. },
  121. {
  122. title: '发运单ID',
  123. dataIndex: 'dispatchOrderId'
  124. },
  125. {
  126. title: '主清单ID',
  127. dataIndex: 'mainListId'
  128. },
  129. {
  130. title: '名称',
  131. dataIndex: 'name'
  132. },
  133. {
  134. title: '规格',
  135. dataIndex: 'specs'
  136. },
  137. {
  138. title: '数量',
  139. dataIndex: 'quantity',
  140. customRender: (text, record, index) => {
  141. return this.BaseTool.Amount.formatter(text)
  142. } ,
  143. },
  144. {
  145. title: '单位',
  146. dataIndex: 'unit',
  147. customRender: (text, record, index) => {
  148. return this.BaseTool.Object.getField(this.unitMap, text)
  149. } ,
  150. },
  151. {
  152. title: '单价',
  153. dataIndex: 'price',
  154. customRender: (text, record, index) => {
  155. return this.BaseTool.Amount.formatter(text)
  156. } ,
  157. },
  158. {
  159. title: '总价',
  160. dataIndex: 'totalMoney',
  161. customRender: (text, record, index) => {
  162. return this.BaseTool.Amount.formatter(text)
  163. } ,
  164. },
  165. {
  166. title: '备注',
  167. dataIndex: 'remark'
  168. },
  169. {
  170. title: '删除标志',
  171. dataIndex: 'delFlag'
  172. },
  173. {
  174. title: '创建人名称',
  175. dataIndex: 'createdUserName'
  176. },
  177. {
  178. title: '创建时间',
  179. dataIndex: 'createdTime'
  180. },
  181. {
  182. title: '操作',
  183. key: 'action',
  184. width: '200px',
  185. align: 'center',
  186. scopedSlots: { customRender: 'action' }
  187. }
  188. ],
  189. // 下拉框map
  190. unitMap: {},
  191. // 加载数据方法 必须为 Promise 对象
  192. loadData: parameter => {
  193. parameter = {
  194. ...parameter,
  195. ...this.queryParam,
  196. ...this.extraQueryParam,
  197. dataScope: {
  198. sortBy: 'desc',
  199. sortName: 'update_time'
  200. }
  201. }
  202. return getPurchaseContractListPage(Object.assign(parameter, this.queryParam))
  203. .then(res => {
  204. return res.data
  205. })
  206. },
  207. selectedRowKeys: [],
  208. selectedRows: [],
  209. options: {
  210. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  211. rowSelection: {
  212. selectedRowKeys: this.selectedRowKeys,
  213. onChange: this.onSelectChange
  214. }
  215. },
  216. optionAlertShow: false,
  217. isCreated: false
  218. }
  219. },
  220. created () {
  221. // 下拉框map
  222. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_CONTRACT_LIST_UNIT)
  223. },
  224. methods: {
  225. tableOption () {
  226. if (!this.optionAlertShow) {
  227. this.options = {
  228. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  229. rowSelection: {
  230. selectedRowKeys: this.selectedRowKeys,
  231. onChange: this.onSelectChange,
  232. type: this.type,
  233. getCheckboxProps: record => ({
  234. props: {
  235. disabled: false,
  236. name: record.id
  237. }
  238. })
  239. },
  240. customRow: (record) => {
  241. return {
  242. on: { // 事件
  243. click: (event) => { // 点击行
  244. // 选择对象
  245. this.mySelect([record.id], [record])
  246. },
  247. dblclick: (event) => {
  248. this.mySelect([record.id], [record])
  249. this.handleSelect()
  250. }
  251. }
  252. }
  253. }
  254. }
  255. this.optionAlertShow = true
  256. } else {
  257. this.options = {
  258. alert: false,
  259. rowSelection: null
  260. }
  261. this.optionAlertShow = false
  262. }
  263. },
  264. handleView (record) {
  265. fetchPurchaseContractList({ id: record.id }).then(res => {
  266. const modal = this.$refs.detailModal
  267. modal.base(res.data)
  268. })
  269. },
  270. handleOk () {
  271. this.$refs.table.refresh()
  272. },
  273. onSelectChange (selectedRowKeys, selectedRows) {
  274. this.selectedRowKeys = selectedRowKeys
  275. this.selectedRows = selectedRows
  276. },
  277. resetSearchForm () {
  278. this.queryParam = {
  279. }
  280. this.$refs.table.refresh(true)
  281. },
  282. base (record, queryParam = {}) {
  283. this.visible = true
  284. this.modalTitle = '选择信息'
  285. this.extraQueryParam = queryParam
  286. this.record = record
  287. if (this.isCreated) {
  288. this.$refs.table.clearSelected()
  289. this.options.rowSelection.type = this.type
  290. this.handleOk()
  291. } else {
  292. this.tableOption()
  293. this.isCreated = true
  294. }
  295. },
  296. handleCancel () {
  297. this.visible = false
  298. this.confirmLoading = false
  299. },
  300. handleSelect () {
  301. if (this.selectedRowKeys.length === 0) {
  302. this.$message.warn('请至少选择一项信息')
  303. } else {
  304. this.confirmLoading = true
  305. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  306. this.confirmLoading = false
  307. this.visible = false
  308. }
  309. },
  310. mySelect(selectedRowKeys, selectedRows) {
  311. if (this.type === 'radio') {
  312. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  313. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  314. } else {
  315. let mySelectedRowKeys
  316. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  317. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  318. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  319. } else {
  320. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  321. mySelectedRows = [...mySelectedRows, ...selectedRows]
  322. }
  323. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  324. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  325. }
  326. }
  327. }
  328. }
  329. </script>