FirmProducerSelectModal.vue 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  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. <a-divider type="vertical" />
  45. </template>
  46. </span>
  47. </s-table>
  48. <detail ref="detailModal"/>
  49. </a-card>
  50. <template slot="footer">
  51. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  52. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">选择</a-button>
  53. </template>
  54. </a-modal>
  55. </template>
  56. <script>
  57. import { STable, Ellipsis } from '@/components'
  58. import Detail from './Detail'
  59. import { getFirmProducerPage, fetchFirmProducer } from '@/api/firm/producer'
  60. export default {
  61. name: 'FirmProducerSelectModal',
  62. components: {
  63. STable,
  64. Ellipsis,
  65. Detail
  66. },
  67. props: {
  68. type: {
  69. type: String,
  70. default: 'radio'
  71. },
  72. selectedRowKey: {
  73. type: Array,
  74. default: () => {
  75. return []
  76. }
  77. },
  78. producerType: {
  79. type: Number,
  80. default: 1
  81. },
  82. selectedRow: {
  83. type: Array,
  84. default: () => {
  85. return []
  86. }
  87. }
  88. },
  89. data () {
  90. return {
  91. confirmLoading: false,
  92. mdl: {},
  93. supplyTypeMap: {},
  94. modalTitle: null,
  95. visible: false,
  96. record: null,
  97. // 查询参数
  98. queryParam: {
  99. },
  100. extraQueryParam: {
  101. },
  102. levelMap: {},
  103. typeMap: {},
  104. delFlagMap: {},
  105. // 表头
  106. columns: [
  107. {
  108. title: '序号',
  109. checked: true,
  110. dataIndex: 'index',
  111. customRender: (text, record, index) => {
  112. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  113. }
  114. },
  115. /* {
  116. title: '编码',
  117. checked: true,
  118. dataIndex: 'account'
  119. },*/
  120. {
  121. title: '名称',
  122. checked: true,
  123. dataIndex: 'name'
  124. },
  125. {
  126. title: '品牌',
  127. checked: true,
  128. dataIndex: 'pp'
  129. },
  130. // {
  131. // title: '等级',
  132. // checked: true,
  133. // dataIndex: 'level',
  134. // customRender: (text, record, index) => {
  135. // return this.BaseTool.Object.getField(this.levelMap, text)
  136. // }
  137. // },
  138. {
  139. title: '类型',
  140. dataIndex: 'supplyType',
  141. customRender: (text, record, index) => {
  142. return this.BaseTool.Table.customRenderMultiDictValue(this, text, record, this.supplyTypeMap)
  143. }
  144. },
  145. {
  146. title: '联系人',
  147. checked: true,
  148. dataIndex: 'contactPerson'
  149. },
  150. {
  151. title: '联系电话',
  152. dataIndex: 'phone'
  153. },
  154. {
  155. title: '联系地址',
  156. dataIndex: 'registerAddress'
  157. },
  158. {
  159. title: '排序',
  160. dataIndex: 'sort'
  161. },
  162. {
  163. title: '操作',
  164. checked: true,
  165. key: 'action',
  166. width: '200px',
  167. align: 'center',
  168. scopedSlots: { customRender: 'action' }
  169. }
  170. ],
  171. // 加载数据方法 必须为 Promise 对象
  172. loadData: parameter => {
  173. parameter = {
  174. ...parameter,
  175. supplyType: this.producerType,
  176. statusList: [2, 3],
  177. ...this.queryParam,
  178. ...this.extraQueryParam,
  179. dataScope: {
  180. sortBy: 'desc',
  181. sortName: 'update_time'
  182. },
  183. type: null
  184. }
  185. return getFirmProducerPage(parameter)
  186. .then(res => {
  187. return res.data
  188. })
  189. },
  190. selectedRowKeys: [],
  191. selectedRows: [],
  192. options: {
  193. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  194. rowSelection: {
  195. selectedRowKeys: this.selectedRowKeys,
  196. onChange: this.onSelectChange
  197. }
  198. },
  199. optionAlertShow: false,
  200. isCreated: false
  201. }
  202. },
  203. created () {
  204. this.delFlagMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.DELFLAG)
  205. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.FIRM_PRODUCER_LEVEL)
  206. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.FIRM_PRODUCER_TYPE)
  207. this.supplyTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SUPPLIER_SUPPLY_TYPE)
  208. },
  209. methods: {
  210. tableOption () {
  211. if (!this.optionAlertShow) {
  212. this.options = {
  213. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  214. rowSelection: {
  215. selectedRowKeys: this.selectedRowKeys,
  216. onChange: this.onSelectChange,
  217. type: this.type,
  218. getCheckboxProps: record => ({
  219. props: {
  220. disabled: false,
  221. name: record.id
  222. }
  223. })
  224. },
  225. customRow: (record) => {
  226. return {
  227. on: { // 事件
  228. click: (event) => { // 点击行
  229. // 选择对象
  230. this.mySelect([record.id], [record])
  231. },
  232. dblclick: (event) => {
  233. this.mySelect([record.id], [record])
  234. this.handleSelect()
  235. }
  236. }
  237. }
  238. }
  239. }
  240. this.optionAlertShow = true
  241. } else {
  242. this.options = {
  243. alert: false,
  244. rowSelection: null
  245. }
  246. this.optionAlertShow = false
  247. }
  248. },
  249. handleView (record) {
  250. fetchFirmProducer({ id: record.id }).then(res => {
  251. const modal = this.$refs.detailModal
  252. modal.base(res.data)
  253. })
  254. },
  255. handleOk () {
  256. this.$refs.table.refresh()
  257. },
  258. onSelectChange (selectedRowKeys, selectedRows) {
  259. this.selectedRowKeys = selectedRowKeys
  260. this.selectedRows = selectedRows
  261. },
  262. resetSearchForm () {
  263. this.queryParam = {
  264. }
  265. this.$refs.table.refresh(true)
  266. },
  267. base (record, queryParam = {}) {
  268. this.visible = true
  269. this.modalTitle = '选择信息'
  270. this.queryParam = queryParam
  271. this.record = record
  272. if (this.isCreated) {
  273. this.$refs.table.clearSelected()
  274. this.options.rowSelection.type = this.type
  275. this.handleOk()
  276. } else {
  277. this.tableOption()
  278. this.isCreated = true
  279. }
  280. },
  281. handleCancel () {
  282. this.visible = false
  283. this.confirmLoading = false
  284. },
  285. handleSelect () {
  286. if (this.selectedRowKeys.length === 0) {
  287. this.$message.warn('请至少选择一项信息')
  288. } else {
  289. this.confirmLoading = true
  290. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  291. this.confirmLoading = false
  292. this.visible = false
  293. }
  294. },
  295. mySelect (selectedRowKeys, selectedRows) {
  296. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  297. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  298. }
  299. }
  300. }
  301. </script>