CheckStandardSelectModal.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  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" 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. <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. levelMap: {},
  104. actionTypeMap: {},
  105. record: null,
  106. // 查询参数
  107. queryParam: {
  108. type: this.checkType
  109. },
  110. extraQueryParam: {},
  111. // 表头
  112. columns: [
  113. {
  114. title: '序号',
  115. dataIndex: 'index',
  116. customRender: (text, record, index) => {
  117. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  118. }
  119. },
  120. {
  121. title: '设备新号',
  122. dataIndex: 'sbNo',
  123. checked: true,
  124. width: '100px'
  125. },
  126. {
  127. title: '设备名称',
  128. dataIndex: 'sbName',
  129. checked: true,
  130. width: '150px'
  131. },
  132. {
  133. title: '设备新号',
  134. dataIndex: 'sbNo',
  135. checked: true,
  136. width: '150px'
  137. },
  138. {
  139. title: '部位',
  140. dataIndex: 'partName',
  141. checked: true,
  142. width: '200px'
  143. },
  144. {
  145. title: '标准编码',
  146. dataIndex: 'no',
  147. checked: true,
  148. width: '120px'
  149. },
  150. {
  151. title: '维护等级',
  152. dataIndex: 'level',
  153. width: '100px',
  154. checked: true,
  155. customRender: (text, record, index) => {
  156. return this.BaseTool.Table.getMapText(this.levelMap, text)
  157. }
  158. },
  159. {
  160. title: '标准内容',
  161. dataIndex: 'requirement',
  162. checked: true,
  163. width: '250px',
  164. customRender: (text, record, index) => {
  165. if (text != null) {
  166. if (text.length > 40) {
  167. return text.slice(0, 40)
  168. } else {
  169. return text
  170. }
  171. } else {
  172. return text
  173. }
  174. }
  175. },
  176. {
  177. title: '计划周期',
  178. dataIndex: 'period',
  179. width: '100px',
  180. checked: true,
  181. customRender: (text, record, index) => {
  182. return text + this.BaseTool.Table.getMapText(this.periodTypeMap, record.periodType)
  183. }
  184. },
  185. {
  186. title: '预计下次执行日期',
  187. dataIndex: 'nextDate',
  188. checked: true,
  189. width: '200px'
  190. },
  191. {
  192. title: '上次执行日期',
  193. dataIndex: 'lastDate',
  194. fixed: 'right',
  195. checked: true,
  196. width: '200px'
  197. },
  198. {
  199. title: '操作',
  200. key: 'action',
  201. width: '250px',
  202. checked: true,
  203. fixed: 'right',
  204. align: 'center',
  205. scopedSlots: { customRender: 'action' }
  206. }
  207. ],
  208. // 下拉框map
  209. typeMap: {},
  210. enableMap: {},
  211. // 加载数据方法 必须为 Promise 对象
  212. loadData: parameter => {
  213. parameter = {
  214. ...parameter,
  215. ...this.queryParam,
  216. ...this.extraQueryParam,
  217. dataScope: {
  218. }
  219. }
  220. return getCheckStandardPage(Object.assign(parameter, this.queryParam))
  221. .then(res => {
  222. return res.data
  223. })
  224. },
  225. selectedRowKeys: [],
  226. selectedRows: [],
  227. options: {
  228. alert: {
  229. show: true,
  230. clear: () => {
  231. this.selectedRowKeys = []
  232. }
  233. },
  234. rowSelection: {
  235. selectedRowKeys: this.selectedRowKeys,
  236. onChange: this.onSelectChange
  237. }
  238. },
  239. optionAlertShow: false,
  240. isCreated: false
  241. }
  242. },
  243. created () {
  244. // 下拉框map
  245. this.typeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_STANDARD_TYPE)
  246. this.enableMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.YES_NO)
  247. this.periodTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_PERIOD_TYPE)
  248. this.actionTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_ACTION_TYPE)
  249. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.CHECK_PLAN_LEVEL)
  250. },
  251. methods: {
  252. tableOption () {
  253. if (!this.optionAlertShow) {
  254. this.options = {
  255. alert: {
  256. show: true,
  257. clear: () => {
  258. this.selectedRowKeys = []
  259. }
  260. },
  261. rowSelection: {
  262. selectedRowKeys: this.selectedRowKeys,
  263. onChange: this.onSelectChange,
  264. type: this.type,
  265. getCheckboxProps: record => ({
  266. props: {
  267. disabled: false,
  268. name: record.id
  269. }
  270. })
  271. },
  272. customRow: (record) => {
  273. return {
  274. on: { // 事件
  275. click: (event) => { // 点击行
  276. // 选择对象
  277. this.mySelect([record.id], [record])
  278. },
  279. dblclick: (event) => {
  280. this.mySelect([record.id], [record])
  281. this.handleSelect()
  282. }
  283. }
  284. }
  285. }
  286. }
  287. this.optionAlertShow = true
  288. } else {
  289. this.options = {
  290. alert: false,
  291. rowSelection: null
  292. }
  293. this.optionAlertShow = false
  294. }
  295. },
  296. handleView (record) {
  297. fetchCheckStandard({ id: record.id }).then(res => {
  298. const modal = this.$refs.detailModal
  299. modal.base(res.data)
  300. })
  301. },
  302. handleOk () {
  303. this.$refs.table.refresh()
  304. },
  305. onSelectChange (selectedRowKeys, selectedRows) {
  306. this.selectedRowKeys = selectedRowKeys
  307. this.selectedRows = selectedRows
  308. },
  309. resetSearchForm () {
  310. this.queryParam = {}
  311. this.$refs.table.refresh(true)
  312. },
  313. base (record, queryParam = {}) {
  314. this.visible = true
  315. this.modalTitle = '选择信息'
  316. this.extraQueryParam = queryParam
  317. this.record = record
  318. if (this.isCreated) {
  319. this.$refs.table.clearSelected()
  320. this.options.rowSelection.type = this.type
  321. this.handleOk()
  322. } else {
  323. this.tableOption()
  324. this.isCreated = true
  325. }
  326. },
  327. handleCancel () {
  328. this.visible = false
  329. this.confirmLoading = false
  330. },
  331. handleSelect () {
  332. if (this.selectedRowKeys.length === 0) {
  333. this.$message.warn('请至少选择一项信息')
  334. } else {
  335. this.confirmLoading = true
  336. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  337. this.confirmLoading = false
  338. this.visible = false
  339. }
  340. },
  341. mySelect (selectedRowKeys, selectedRows) {
  342. if (this.type === 'radio') {
  343. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  344. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  345. } else {
  346. let mySelectedRowKeys
  347. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  348. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  349. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  350. } else {
  351. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  352. mySelectedRows = [...mySelectedRows, ...selectedRows]
  353. }
  354. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  355. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  356. }
  357. }
  358. }
  359. }
  360. </script>