PurchaseContractMainListSelectModal.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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 { getPurchaseContractMainListPage, fetchPurchaseContractMainList } from '@/api/purchase/purchase-contract-main-list'
  59. export default {
  60. name: 'PurchaseContractMainListSelectModal',
  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: '名称',
  127. dataIndex: 'name'
  128. },
  129. {
  130. title: '型号',
  131. dataIndex: 'model'
  132. },
  133. {
  134. title: '整机编号',
  135. dataIndex: 'machineNo'
  136. },
  137. {
  138. title: '发动机型号',
  139. dataIndex: 'engineModel'
  140. },
  141. {
  142. title: '发动机编号',
  143. dataIndex: 'engineNo'
  144. },
  145. {
  146. title: '数量',
  147. dataIndex: 'quantity',
  148. customRender: (text, record, index) => {
  149. return this.BaseTool.Amount.formatter(text)
  150. } ,
  151. },
  152. {
  153. title: '单位',
  154. dataIndex: 'unit',
  155. customRender: (text, record, index) => {
  156. return this.BaseTool.Object.getField(this.unitMap, text)
  157. } ,
  158. },
  159. {
  160. title: '单价',
  161. dataIndex: 'price',
  162. customRender: (text, record, index) => {
  163. return this.BaseTool.Amount.formatter(text)
  164. } ,
  165. },
  166. {
  167. title: '总价',
  168. dataIndex: 'totalMoney',
  169. customRender: (text, record, index) => {
  170. return this.BaseTool.Amount.formatter(text)
  171. } ,
  172. },
  173. {
  174. title: '备注',
  175. dataIndex: 'remark'
  176. },
  177. {
  178. title: '删除标志',
  179. dataIndex: 'delFlag'
  180. },
  181. {
  182. title: '创建人名称',
  183. dataIndex: 'createdUserName'
  184. },
  185. {
  186. title: '创建时间',
  187. dataIndex: 'createdTime'
  188. },
  189. {
  190. title: '操作',
  191. key: 'action',
  192. width: '200px',
  193. align: 'center',
  194. scopedSlots: { customRender: 'action' }
  195. }
  196. ],
  197. // 下拉框map
  198. unitMap: {},
  199. // 加载数据方法 必须为 Promise 对象
  200. loadData: parameter => {
  201. parameter = {
  202. ...parameter,
  203. ...this.queryParam,
  204. ...this.extraQueryParam,
  205. dataScope: {
  206. sortBy: 'desc',
  207. sortName: 'update_time'
  208. }
  209. }
  210. return getPurchaseContractMainListPage(Object.assign(parameter, this.queryParam))
  211. .then(res => {
  212. return res.data
  213. })
  214. },
  215. selectedRowKeys: [],
  216. selectedRows: [],
  217. options: {
  218. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  219. rowSelection: {
  220. selectedRowKeys: this.selectedRowKeys,
  221. onChange: this.onSelectChange
  222. }
  223. },
  224. optionAlertShow: false,
  225. isCreated: false
  226. }
  227. },
  228. created () {
  229. // 下拉框map
  230. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.PURCHASE_CONTRACT_MAIN_LIST_UNIT)
  231. },
  232. methods: {
  233. tableOption () {
  234. if (!this.optionAlertShow) {
  235. this.options = {
  236. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  237. rowSelection: {
  238. selectedRowKeys: this.selectedRowKeys,
  239. onChange: this.onSelectChange,
  240. type: this.type,
  241. getCheckboxProps: record => ({
  242. props: {
  243. disabled: false,
  244. name: record.id
  245. }
  246. })
  247. },
  248. customRow: (record) => {
  249. return {
  250. on: { // 事件
  251. click: (event) => { // 点击行
  252. // 选择对象
  253. this.mySelect([record.id], [record])
  254. },
  255. dblclick: (event) => {
  256. this.mySelect([record.id], [record])
  257. this.handleSelect()
  258. }
  259. }
  260. }
  261. }
  262. }
  263. this.optionAlertShow = true
  264. } else {
  265. this.options = {
  266. alert: false,
  267. rowSelection: null
  268. }
  269. this.optionAlertShow = false
  270. }
  271. },
  272. handleView (record) {
  273. fetchPurchaseContractMainList({ id: record.id }).then(res => {
  274. const modal = this.$refs.detailModal
  275. modal.base(res.data)
  276. })
  277. },
  278. handleOk () {
  279. this.$refs.table.refresh()
  280. },
  281. onSelectChange (selectedRowKeys, selectedRows) {
  282. this.selectedRowKeys = selectedRowKeys
  283. this.selectedRows = selectedRows
  284. },
  285. resetSearchForm () {
  286. this.queryParam = {
  287. }
  288. this.$refs.table.refresh(true)
  289. },
  290. base (record, queryParam = {}) {
  291. this.visible = true
  292. this.modalTitle = '选择信息'
  293. this.extraQueryParam = queryParam
  294. this.record = record
  295. if (this.isCreated) {
  296. this.$refs.table.clearSelected()
  297. this.options.rowSelection.type = this.type
  298. this.handleOk()
  299. } else {
  300. this.tableOption()
  301. this.isCreated = true
  302. }
  303. },
  304. handleCancel () {
  305. this.visible = false
  306. this.confirmLoading = false
  307. },
  308. handleSelect () {
  309. if (this.selectedRowKeys.length === 0) {
  310. this.$message.warn('请至少选择一项信息')
  311. } else {
  312. this.confirmLoading = true
  313. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  314. this.confirmLoading = false
  315. this.visible = false
  316. }
  317. },
  318. mySelect(selectedRowKeys, selectedRows) {
  319. if (this.type === 'radio') {
  320. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  321. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  322. } else {
  323. let mySelectedRowKeys
  324. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  325. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  326. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  327. } else {
  328. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  329. mySelectedRows = [...mySelectedRows, ...selectedRows]
  330. }
  331. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  332. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  333. }
  334. }
  335. }
  336. }
  337. </script>