CheckStandardSelectModal.vue 8.8 KB

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