ToolLogSelectModal.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  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="6" :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="6 || 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. <a @click="()=>{ this.advanced = !this.advanced}" style="margin-left: 8px">
  24. {{ advanced ? '收起' : '展开' }}
  25. <a-icon :type="advanced ? 'up' : 'down'"/>
  26. </a>
  27. </span>
  28. </a-col>
  29. </a-row>
  30. </a-form>
  31. </div>
  32. <div class="table-operator">
  33. </div>
  34. <s-table
  35. ref="table"
  36. size="default"
  37. rowKey="id"
  38. :columns="columns"
  39. :data="loadData"
  40. :alert="options.alert"
  41. :customRow="options.customRow"
  42. :rowSelection="options.rowSelection"
  43. showPagination="auto"
  44. >
  45. <span slot="action" slot-scope="record1">
  46. <template>
  47. <a @click="handleView(record1)">查看</a>
  48. </template>
  49. </span>
  50. </s-table>
  51. <detail ref="detailModal"/>
  52. </a-card>
  53. <template slot="footer">
  54. <a-button :loading="confirmLoading" type="primary" @click="handleCancel()">取消</a-button>
  55. <a-button :loading="confirmLoading" type="primary" @click="handleSelect()">确定</a-button>
  56. </template>
  57. </a-modal>
  58. </template>
  59. <script>
  60. import { STable, Ellipsis } from '@/components'
  61. import Detail from './Detail'
  62. import { getToolLogPage, fetchToolLog } from '@/api/tool/tool-log'
  63. export default {
  64. name: 'ToolLogSelectModal',
  65. components: {
  66. STable,
  67. Ellipsis,
  68. Detail
  69. },
  70. props: {
  71. type: {
  72. type: String,
  73. default: 'radio'
  74. },
  75. selectedRowKey: {
  76. type: Array,
  77. default: () => {
  78. return []
  79. }
  80. },
  81. selectedRow: {
  82. type: Array,
  83. default: () => {
  84. return []
  85. }
  86. }
  87. },
  88. data () {
  89. return {
  90. advanced: false,
  91. confirmLoading: false,
  92. mdl: {},
  93. modalTitle: null,
  94. visible: false,
  95. record: null,
  96. // 查询参数
  97. queryParam: {
  98. },
  99. extraQueryParam: {
  100. },
  101. // 表头
  102. columns: [
  103. {
  104. title: '序号',
  105. dataIndex: 'index',
  106. customRender: (text, record, index) => {
  107. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  108. }
  109. },
  110. {
  111. title: '检验人',
  112. dataIndex: 'checkUserId'
  113. },
  114. {
  115. title: '检验说明',
  116. dataIndex: 'requirement'
  117. },
  118. {
  119. title: '备注',
  120. dataIndex: 'remark'
  121. },
  122. {
  123. title: '创建人名称',
  124. dataIndex: 'createdUserName'
  125. },
  126. {
  127. title: '创建时间',
  128. dataIndex: 'createdTime'
  129. },
  130. {
  131. title: '工器具id',
  132. dataIndex: 'toolId'
  133. },
  134. {
  135. title: '检测日期',
  136. dataIndex: 'checkDate'
  137. },
  138. {
  139. title: '检定图片路径',
  140. dataIndex: 'imgPath'
  141. },
  142. {
  143. title: '检定文件路径',
  144. dataIndex: 'filePath'
  145. },
  146. {
  147. title: '操作',
  148. key: 'action',
  149. width: '200px',
  150. align: 'center',
  151. scopedSlots: { customRender: 'action' }
  152. }
  153. ],
  154. // 下拉框map
  155. // 加载数据方法 必须为 Promise 对象
  156. loadData: parameter => {
  157. parameter = {
  158. ...parameter,
  159. ...this.queryParam,
  160. ...this.extraQueryParam,
  161. dataScope: {
  162. sortBy: 'desc',
  163. sortName: 'update_time'
  164. }
  165. }
  166. return getToolLogPage(Object.assign(parameter, this.queryParam))
  167. .then(res => {
  168. return res.data
  169. })
  170. },
  171. selectedRowKeys: [],
  172. selectedRows: [],
  173. options: {
  174. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  175. rowSelection: {
  176. selectedRowKeys: this.selectedRowKeys,
  177. onChange: this.onSelectChange
  178. }
  179. },
  180. optionAlertShow: false,
  181. isCreated: false
  182. }
  183. },
  184. created () {
  185. // 下拉框map
  186. },
  187. methods: {
  188. tableOption () {
  189. if (!this.optionAlertShow) {
  190. this.options = {
  191. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  192. rowSelection: {
  193. selectedRowKeys: this.selectedRowKeys,
  194. onChange: this.onSelectChange,
  195. type: this.type,
  196. getCheckboxProps: record => ({
  197. props: {
  198. disabled: false,
  199. name: record.id
  200. }
  201. })
  202. },
  203. customRow: (record) => {
  204. return {
  205. on: { // 事件
  206. click: (event) => { // 点击行
  207. // 选择对象
  208. this.mySelect([record.id], [record])
  209. },
  210. dblclick: (event) => {
  211. this.mySelect([record.id], [record])
  212. this.handleSelect()
  213. }
  214. }
  215. }
  216. }
  217. }
  218. this.optionAlertShow = true
  219. } else {
  220. this.options = {
  221. alert: false,
  222. rowSelection: null
  223. }
  224. this.optionAlertShow = false
  225. }
  226. },
  227. handleView (record) {
  228. fetchToolLog({ id: record.id }).then(res => {
  229. const modal = this.$refs.detailModal
  230. modal.base(res.data)
  231. })
  232. },
  233. handleOk () {
  234. this.$refs.table.refresh()
  235. },
  236. onSelectChange (selectedRowKeys, selectedRows) {
  237. this.selectedRowKeys = selectedRowKeys
  238. this.selectedRows = selectedRows
  239. },
  240. resetSearchForm () {
  241. this.queryParam = {
  242. }
  243. this.$refs.table.refresh(true)
  244. },
  245. base (record, queryParam = {}) {
  246. this.visible = true
  247. this.modalTitle = '选择信息'
  248. this.extraQueryParam = queryParam
  249. this.record = record
  250. if (this.isCreated) {
  251. this.$refs.table.clearSelected()
  252. this.options.rowSelection.type = this.type
  253. this.handleOk()
  254. } else {
  255. this.tableOption()
  256. this.isCreated = true
  257. }
  258. },
  259. handleCancel () {
  260. this.visible = false
  261. this.confirmLoading = false
  262. },
  263. handleSelect () {
  264. if (this.selectedRowKeys.length === 0) {
  265. this.$message.warn('请至少选择一项信息')
  266. } else {
  267. this.confirmLoading = true
  268. this.$emit('selected', this.record, this.selectedRowKeys, this.selectedRows)
  269. this.confirmLoading = false
  270. this.visible = false
  271. }
  272. },
  273. mySelect(selectedRowKeys, selectedRows) {
  274. if (this.type === 'radio') {
  275. this.$refs.table.updateSelect(selectedRowKeys, selectedRows)
  276. this.$refs.table.rowSelection.onChange(selectedRowKeys, selectedRows)
  277. } else {
  278. let mySelectedRowKeys
  279. let mySelectedRows = this.selectedRows.filter(item => item.id !== selectedRowKeys[0])
  280. if (this.selectedRowKeys.includes(selectedRowKeys[0])) {
  281. mySelectedRowKeys = this.selectedRowKeys.filter(item => item !== selectedRowKeys[0])
  282. } else {
  283. mySelectedRowKeys = [...selectedRowKeys, ...this.selectedRowKeys]
  284. mySelectedRows = [...mySelectedRows, ...selectedRows]
  285. }
  286. this.$refs.table.updateSelect(mySelectedRowKeys, mySelectedRows)
  287. this.$refs.table.rowSelection.onChange(mySelectedRowKeys, mySelectedRows)
  288. }
  289. }
  290. }
  291. }
  292. </script>