SbModelBom.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <template>
  2. <a-card :bordered="false">
  3. <div v-show="visible">
  4. <a-row :gutter="8">
  5. <a-col :span="4">
  6. <a-tree
  7. @expand="onExpand"
  8. :expandedKeys="expandedKeys"
  9. :autoExpandParent="true"
  10. @select="onSelect"
  11. :selectedKeys="selectedKeys"
  12. :treeData="treeData"
  13. />
  14. </a-col>
  15. <a-col :span="20">
  16. <div class="table-page-search-wrapper" >
  17. <a-form layout="inline">
  18. <a-row :gutter="48">
  19. <a-col :md="8" :sm="24">
  20. <a-form-item label="关键字">
  21. <a-input v-model="queryParam.keyword" placeholder="请输入名称/编码"/>
  22. </a-form-item>
  23. </a-col>
  24. <a-col :md="8 || 24" :sm="24">
  25. <span class="table-page-search-submitButtons">
  26. <a-button type="primary" @click="$refs.table.refresh(true)">查询</a-button>
  27. <a-button style="margin-left: 8px" @click="resetSearchForm">重置</a-button>
  28. </span>
  29. </a-col>
  30. </a-row>
  31. </a-form>
  32. </div>
  33. <div class="table-operator">
  34. <a-button style="margin-left: 8px" v-if="$auth('sb-infos-export')" type="primary" icon="download" @click="doExport">导出</a-button>
  35. <a-dropdown v-action:edit v-if="selectedRowKeys.length > 0 && $auth('sb-infos-del')">
  36. <a-menu slot="overlay">
  37. <a-popconfirm title="是否要删除所选数据?" @confirm="batchDelete()">
  38. <a-menu-item key="1"><a-icon type="delete" /><a>删除</a></a-menu-item>
  39. </a-popconfirm>
  40. </a-menu>
  41. <a-button style="margin-left: 8px">
  42. 批量操作 <a-icon type="down" />
  43. </a-button>
  44. </a-dropdown>
  45. </div>
  46. <s-table
  47. ref="table"
  48. size="default"
  49. rowKey="id"
  50. :widthSpace="true"
  51. :columns="columns"
  52. :data="loadData"
  53. :alert="options.alert"
  54. :rowSelection="options.rowSelection"
  55. :scroll="{y: BaseTool.Constant.scrollY }"
  56. showPagination="auto"
  57. >
  58. <span slot="action" slot-scope="record">
  59. <template>
  60. <a @click="handleView(record)">BOM列表</a>
  61. <!--<a-divider type="vertical" />
  62. <a @click="handleCopy(record)">复制</a>-->
  63. </template>
  64. </span>
  65. <span slot="status" slot-scope="text">
  66. <badge
  67. :status="DictCache.COLOR.SB_INFO_STATUS[text]"
  68. :text="statusMap[text]" />
  69. </span>
  70. </s-table>
  71. </a-col>
  72. </a-row>
  73. </div>
  74. <base-form ref="baseModal" @ok="handleOk"/>
  75. <detail ref="detailModal" @ok="handleOk"/>
  76. <download-modal ref="downloadModal"/>
  77. <preview-modal ref="previewModal"/>
  78. </a-card>
  79. </template>
  80. <script>
  81. import { STable, Ellipsis } from '@/components'
  82. import BaseForm from './modules/BaseForm'
  83. import Detail from './modules/Detail'
  84. import DownloadModal from '@/views/download/DownloadModal'
  85. import PreviewModal from '@/views/preview/PreviewModal'
  86. import { getSbInfoPage, deleteSbInfos, fetchSbInfo, exportSbInfo } from '@/api/sb/info'
  87. import { selectSpareInfoListByModelId } from '@/api/sb/modelbom'
  88. import { fetchSbTypeTree } from '@/api/sb/type'
  89. import BaseTool from '../../../utils/tool'
  90. export default {
  91. name: 'SbModelList',
  92. components: {
  93. STable,
  94. Ellipsis,
  95. BaseForm,
  96. Detail,
  97. DownloadModal,
  98. PreviewModal
  99. },
  100. data () {
  101. return {
  102. // 查询参数
  103. queryParam: {
  104. },
  105. depreciationTypeMap: {},
  106. levelMap: {},
  107. statusMap: {},
  108. treeData: [],
  109. expandedKeys: [],
  110. selectedKeys: [],
  111. unitMap: {},
  112. sourceTypeMap: {},
  113. visible: true,
  114. // 表头
  115. columns: [
  116. {
  117. title: '序号',
  118. dataIndex: 'index',
  119. width: 80,
  120. checked: true,
  121. customRender: (text, record, index) => {
  122. return `${(this.$refs.table.localPagination.current - 1) * this.$refs.table.localPagination.pageSize + index + 1}`
  123. }
  124. },
  125. {
  126. title: '设备名称',
  127. checked: true,
  128. dataIndex: 'name'
  129. },
  130. {
  131. title: '设备型号',
  132. checked: true,
  133. dataIndex: 'model'
  134. },
  135. // {
  136. // title: '名称型号',
  137. // checked: true,
  138. // dataIndex: 'nameModel'
  139. // },
  140. {
  141. title: '设备类型',
  142. checked: true,
  143. dataIndex: 'type',
  144. customRender: (text, record, index) => {
  145. return record.typeName
  146. }
  147. },
  148. {
  149. title: '设备等级',
  150. checked: true,
  151. dataIndex: 'level',
  152. customRender: (text, record, index) => {
  153. return this.BaseTool.Object.getField(this.levelMap, text)
  154. }
  155. },
  156. {
  157. title: '生产商',
  158. dataIndex: 'producerId',
  159. customRender: (text, record, index) => {
  160. return record.producerName
  161. }
  162. },
  163. {
  164. title: '计量单位',
  165. dataIndex: 'unit',
  166. customRender: (text, record, index) => {
  167. return BaseTool.Object.getField(this.unitMap, text)
  168. }
  169. },
  170. {
  171. title: '状态',
  172. checked: true,
  173. dataIndex: 'status',
  174. scopedSlots: { customRender: 'status' }
  175. },
  176. {
  177. title: '操作',
  178. key: 'action',
  179. checked: true,
  180. width: 150,
  181. align: 'center',
  182. // fixed: 'right',
  183. scopedSlots: { width: 200, customRender: 'action' }
  184. }
  185. ],
  186. // 加载数据方法 必须为 Promise 对象
  187. loadData: parameter => {
  188. parameter = {
  189. ...parameter,
  190. ...this.queryParam,
  191. dataScope: {
  192. sortBy: 'desc',
  193. sortName: 'update_time'
  194. }
  195. }
  196. return getSbInfoPage(Object.assign(parameter, this.queryParam))
  197. .then(res => {
  198. return res.data
  199. })
  200. },
  201. selectedRowKeys: [],
  202. selectedRows: [],
  203. options: {
  204. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  205. rowSelection: {
  206. selectedRowKeys: this.selectedRowKeys,
  207. onChange: this.onSelectChange
  208. }
  209. },
  210. optionAlertShow: false
  211. }
  212. },
  213. created () {
  214. this.tableOption()
  215. this.depreciationTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_DEPRECIATIONTYPE)
  216. this.levelMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_LEVEL)
  217. this.statusMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SB_MODEL_RECOMMEND)
  218. this.unitMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBINFO_UNIT)
  219. this.sourceTypeMap = this.DictCache.getLabelByValueMapByType(this.DictCache.TYPE.SBTYPE_SOURCETYPE)
  220. fetchSbTypeTree().then(res => {
  221. this.treeData = res.data
  222. })
  223. },
  224. methods: {
  225. tableOption () {
  226. if (!this.optionAlertShow) {
  227. this.options = {
  228. alert: { show: true, clear: () => { this.selectedRowKeys = [] } },
  229. rowSelection: {
  230. selectedRowKeys: this.selectedRowKeys,
  231. onChange: this.onSelectChange,
  232. getCheckboxProps: record => ({
  233. props: {
  234. disabled: false,
  235. name: record.id
  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. batchDelete (id) {
  250. let ids = []
  251. if (this.BaseTool.String.isBlank(id)) {
  252. const length = this.selectedRows.length
  253. if (length === 0) {
  254. this.$message.info('请选择要删除的记录')
  255. return
  256. }
  257. ids = this.selectedRows.map(item => item.id)
  258. } else {
  259. ids = [id]
  260. }
  261. deleteSbInfos(ids).then(res => {
  262. this.$message.info('删除成功')
  263. this.handleOk()
  264. this.$refs.table.clearSelected()
  265. })
  266. },
  267. handleEdit (record) {
  268. selectSpareInfoListByModelId({ id: record.id }).then(res => {
  269. const modal = this.$refs.baseModal
  270. const data = { data: res.data, modelId: record.id }
  271. modal.base(data)
  272. })
  273. },
  274. handleView (record) {
  275. this.visible = false
  276. fetchSbInfo({ id: record.id }).then(res => {
  277. const modal = this.$refs.detailModal
  278. modal.base(res.data)
  279. })
  280. },
  281. handleCopy (record) {
  282. fetchSbInfo({ id: record.id }).then(res => {
  283. const modal = this.$refs.baseModal
  284. res.data.id = null
  285. modal.base(res.data)
  286. })
  287. },
  288. handleOk () {
  289. this.visible = true
  290. this.$refs.table.refresh()
  291. },
  292. onSelectChange (selectedRowKeys, selectedRows) {
  293. this.selectedRowKeys = selectedRowKeys
  294. this.selectedRows = selectedRows
  295. },
  296. resetSearchForm () {
  297. this.queryParam = {
  298. }
  299. this.$refs.table.refresh(true)
  300. },
  301. doExport () {
  302. const parameter = {
  303. ...this.queryParam
  304. }
  305. exportSbInfo(parameter).then(file => {
  306. this.BaseTool.UPLOAD.downLoadExportExcel(file)
  307. })
  308. },
  309. onSelect: function (selectedKeys, info) {
  310. this.selectedKeys = selectedKeys
  311. this.queryParam.typeId = selectedKeys.length > 0 ? selectedKeys[0] : ''
  312. this.$refs.table.refresh(true)
  313. },
  314. onExpand (expandedKeys) {
  315. this.expandedKeys = expandedKeys
  316. this.autoExpandParent = false
  317. }
  318. }
  319. }
  320. </script>