JSelectMaterialModal.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. <template>
  2. <a-modal
  3. :width="modalWidth"
  4. :visible="visible"
  5. :title="title"
  6. :wrapClassName="wrapClassNameInfo()"
  7. @ok="handleSubmit"
  8. @cancel="close"
  9. cancelText="关闭(ESC)"
  10. style="top: 20px; height: 95%"
  11. >
  12. <a-row :gutter="10" style="padding: 10px; margin: -10px">
  13. <a-col :md="24" :sm="24">
  14. <!-- 查询区域 -->
  15. <div class="table-page-search-wrapper">
  16. <!-- 搜索区域 -->
  17. <a-form layout="inline" @keyup.enter.native="onSearch">
  18. <a-row :gutter="24">
  19. <a-col :md="6" :sm="8">
  20. <a-form-item label="关键词" :labelCol="labelCol" :wrapperCol="wrapperCol">
  21. <a-input ref="material" placeholder="请输入条码、名称、助记码等查询" v-model="queryParam.q"></a-input>
  22. </a-form-item>
  23. </a-col>
  24. <a-col :md="6" :sm="8">
  25. <a-form-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
  26. <a-input placeholder="请输入规格、型号" v-model="queryParam.standardOrModel"></a-input>
  27. </a-form-item>
  28. </a-col>
  29. <a-col :md="6" :sm="8">
  30. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="仓库">
  31. <a-select
  32. placeholder="选择仓库"
  33. v-model="queryParam.depotId"
  34. @change="onDepotChange"
  35. :dropdownMatchSelectWidth="false"
  36. showSearch
  37. optionFilterProp="children"
  38. allow-clear
  39. >
  40. <a-select-option v-for="(item, index) in depotList" :key="index" :value="item.id">
  41. {{ item.depotName }}
  42. </a-select-option>
  43. </a-select>
  44. </a-form-item>
  45. </a-col>
  46. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  47. <a-col :md="6" :sm="8">
  48. <a-button type="primary" @click="loadMaterialData(1)">查询</a-button>
  49. <a-button style="margin-left: 8px" @click="searchReset(1)">重置</a-button>
  50. <a-tooltip title="没查询到,决定新增商品!">
  51. <a-button style="margin-left: 8px" @click="addMaterial">新增</a-button>
  52. </a-tooltip>
  53. <a @click="handleToggleSearch" style="margin-left: 8px">
  54. {{ toggleSearchStatus ? '收起' : '展开' }}
  55. <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
  56. </a>
  57. </a-col>
  58. </span>
  59. <template v-if="toggleSearchStatus">
  60. <a-col :md="6" :sm="8">
  61. <a-form-item label="颜色" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
  62. <a-input placeholder="请输入颜色" v-model="queryParam.color"></a-input>
  63. </a-form-item>
  64. </a-col>
  65. <a-col :md="6" :sm="8">
  66. <a-form-item label="品牌" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
  67. <a-input placeholder="请输入品牌" v-model="queryParam.brand"></a-input>
  68. </a-form-item>
  69. </a-col>
  70. <a-col :md="6" :sm="8">
  71. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="类别">
  72. <a-tree-select
  73. style="width: 100%"
  74. :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
  75. allow-clear
  76. :treeData="categoryTree"
  77. v-model="queryParam.categoryId"
  78. placeholder="请选择类别"
  79. >
  80. </a-tree-select>
  81. </a-form-item>
  82. </a-col>
  83. <a-col :md="6" :sm="8">
  84. <a-form-item label="制造商" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
  85. <a-input placeholder="请输入制造商" v-model="queryParam.mfrs"></a-input>
  86. </a-form-item>
  87. </a-col>
  88. <a-col :md="6" :sm="24">
  89. <a-form-item label="序列号" :labelCol="labelCol" :wrapperCol="wrapperCol">
  90. <a-select placeholder="有无序列号" v-model="queryParam.enableSerialNumber">
  91. <a-select-option value="1">有</a-select-option>
  92. <a-select-option value="0">无</a-select-option>
  93. </a-select>
  94. </a-form-item>
  95. </a-col>
  96. <a-col :md="6" :sm="24">
  97. <a-form-item label="仓库货架" :labelCol="labelCol" :wrapperCol="wrapperCol">
  98. <a-input placeholder="请输入仓库货架" v-model="queryParam.position"></a-input>
  99. </a-form-item>
  100. </a-col>
  101. <!-- <a-col :md="6" :sm="24">
  102. <a-form-item label="批号" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
  103. <a-select placeholder="有无批号" v-model="queryParam.enableBatchNumber">
  104. <a-select-option value="1">有</a-select-option>
  105. <a-select-option value="0">无</a-select-option>
  106. </a-select>
  107. </a-form-item>
  108. </a-col> -->
  109. </template>
  110. </a-row>
  111. </a-form>
  112. <a-button v-if="isStock" type="primary" @click="findAllSelect">一键全选</a-button>
  113. <a-table
  114. ref="table"
  115. :scroll="scrollTrigger"
  116. size="middle"
  117. rowKey="id"
  118. :columns="columns"
  119. :dataSource="dataSource"
  120. :pagination="ipagination"
  121. :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: getType }"
  122. :loading="loading"
  123. :customRow="rowAction"
  124. @change="handleTableChange"
  125. >
  126. <template slot="customBarCode" slot-scope="text, record">
  127. <div :style="record.imgName ? 'float:left;line-height:30px' : 'float:left;'">{{ record.mBarCode }}</div>
  128. <a-popover placement="right" trigger="click">
  129. <template slot="content">
  130. <img :src="getImgUrl(record.imgName, record.imgLarge)" width="500px" />
  131. </template>
  132. <div class="item-info" v-if="record.imgName">
  133. <img
  134. v-if="record.imgName"
  135. :src="getImgUrl(record.imgName, record.imgSmall)"
  136. class="item-img"
  137. title="查看大图"
  138. />
  139. </div>
  140. </a-popover>
  141. </template>
  142. <template slot="customName" slot-scope="text, record">
  143. {{ record.name }}
  144. <a-tag v-if="record.enableSerialNumber == 1" color="orange">序</a-tag>
  145. <a-tag v-if="record.enableBatchNumber == 1" color="orange">批</a-tag>
  146. </template>
  147. <span slot="action" slot-scope="text, record">
  148. <a @click.stop="handleEdit(record)">编辑</a>
  149. </span>
  150. </a-table>
  151. </div>
  152. </a-col>
  153. </a-row>
  154. <material-modal ref="modalForm" @ok="modalFormOk"></material-modal>
  155. </a-modal>
  156. </template>
  157. <script>
  158. import { getAction, getFileAccessHttpUrl } from '@/api/manage'
  159. import { filterObj, getMpListShort } from '@/utils/util'
  160. import { getMaterialBySelect, queryMaterialCategoryTreeList, getMaterialById } from '@/api/api'
  161. import { JeecgListMixin } from '@/mixins/JeecgListMixin'
  162. import { mixinDevice } from '@/utils/mixin'
  163. import Vue from 'vue'
  164. export default {
  165. name: 'JSelectMaterialModal',
  166. mixins: [JeecgListMixin, mixinDevice],
  167. components: {
  168. MaterialModal: () => import('@/views/material/modules/MaterialModal'),
  169. },
  170. props: ['rows', 'multi', 'barCode', 'isStock'],
  171. data() {
  172. return {
  173. modalWidth: 1450,
  174. queryParam: {
  175. q: '',
  176. standardOrModel: '',
  177. depotId: undefined,
  178. color: '',
  179. brand: '',
  180. categoryId: undefined,
  181. mfrs: '',
  182. enableSerialNumber: undefined,
  183. enableBatchNumber: undefined,
  184. position: '',
  185. },
  186. labelCol: {
  187. xs: { span: 24 },
  188. sm: { span: 5 },
  189. },
  190. wrapperCol: {
  191. xs: { span: 24 },
  192. sm: { span: 16 },
  193. },
  194. categoryTree: [],
  195. columns: [
  196. {
  197. title: '操作',
  198. dataIndex: 'action',
  199. align: 'center',
  200. width: 60,
  201. scopedSlots: { customRender: 'action' },
  202. },
  203. // { dataIndex: 'mBarCode', title: '条码', scopedSlots: { customRender: 'customBarCode' } },
  204. { dataIndex: 'batchNumber', title: '批次号' },
  205. { dataIndex: 'name', title: '名称', scopedSlots: { customRender: 'customName' } },
  206. { dataIndex: 'categoryName', title: '类别' },
  207. // { dataIndex: 'standard', title: '规格' },
  208. { dataIndex: 'model', title: '型号' },
  209. { dataIndex: 'color', title: '颜色' },
  210. { dataIndex: 'brand', title: '品牌' },
  211. { dataIndex: 'supplierName', title: '供应商' },
  212. { dataIndex: 'unit', title: '单位' },
  213. { dataIndex: 'sku', title: '多属性' },
  214. { dataIndex: 'inventory', title: '库存' },
  215. { dataIndex: 'productionDate', title: '生产日期' },
  216. { dataIndex: 'expiryNum', title: '保质期' },
  217. { dataIndex: 'barCode', title: '商品条码' },
  218. { dataIndex: 'depotName', title: '仓库名称' },
  219. { dataIndex: 'position', title: '仓库货架' },
  220. // { dataIndex: 'expand', title: '扩展信息' },
  221. ],
  222. scrollTrigger: {},
  223. dataSource: [],
  224. selectedRowKeys: [],
  225. selectMaterialRows: [],
  226. selectMaterialIds: [],
  227. title: '选择商品',
  228. ipagination: {
  229. current: 1,
  230. pageSize: 10,
  231. pageSizeOptions: ['10', '20', '30'],
  232. showTotal: (total, range) => {
  233. return range[0] + '-' + range[1] + ' 共' + total + '条'
  234. },
  235. showQuickJumper: true,
  236. showSizeChanger: true,
  237. total: 0,
  238. },
  239. isorter: {
  240. column: 'createTime',
  241. order: 'desc',
  242. },
  243. departTree: [],
  244. depotList: [],
  245. visible: false,
  246. form: this.$form.createForm(this),
  247. loading: false,
  248. expandedKeys: [],
  249. disableMixinCreated: true,
  250. }
  251. },
  252. computed: {
  253. // 计算属性的 getter
  254. getType: function () {
  255. return this.multi == true ? 'checkbox' : 'radio'
  256. },
  257. },
  258. watch: {
  259. barCode: {
  260. immediate: true,
  261. handler() {
  262. this.initBarCode()
  263. },
  264. },
  265. },
  266. created() {
  267. // 该方法触发屏幕自适应
  268. this.resetScreenSize()
  269. },
  270. methods: {
  271. initBarCode() {
  272. if (this.barCode) {
  273. this.$emit('initComp', this.barCode)
  274. } else {
  275. // JSelectUserByDep组件bug issues/I16634
  276. this.$emit('initComp', '')
  277. }
  278. },
  279. loadMaterialData(arg) {
  280. if (arg === 1) {
  281. this.ipagination.current = 1
  282. }
  283. this.loading = true
  284. let params = this.getQueryParams() //查询条件
  285. getMaterialBySelect(params).then((res) => {
  286. if (res) {
  287. this.dataSource = res.rows
  288. this.ipagination.total = res.total
  289. if (res.total === 1) {
  290. if (
  291. this.queryParam.q === this.dataSource[0].batchNumber ||
  292. this.queryParam.q === this.dataSource[0].name ||
  293. this.queryParam.q === this.dataSource[0].mnemonic
  294. ) {
  295. this.title = '选择商品【再次回车可以直接选中】'
  296. this.$nextTick(() => this.$refs.material.focus())
  297. } else {
  298. this.title = '选择商品'
  299. }
  300. } else {
  301. this.title = '选择商品'
  302. }
  303. }
  304. this.loading = false
  305. this.onClearSelected()
  306. })
  307. },
  308. loadTreeData() {
  309. let that = this
  310. let params = {}
  311. params.id = ''
  312. queryMaterialCategoryTreeList(params).then((res) => {
  313. if (res) {
  314. that.categoryTree = []
  315. for (let i = 0; i < res.length; i++) {
  316. let temp = res[i]
  317. that.categoryTree.push(temp)
  318. }
  319. }
  320. })
  321. },
  322. // 触发屏幕自适应
  323. resetScreenSize() {
  324. let realScreenWidth = window.screen.width
  325. this.modalWidth = realScreenWidth < 1600 ? '1300px' : '1550px'
  326. let screenWidth = document.body.clientWidth
  327. if (screenWidth < 500) {
  328. this.scrollTrigger = { x: 800 }
  329. } else {
  330. this.scrollTrigger = {}
  331. }
  332. },
  333. showModal(barCode) {
  334. this.visible = true
  335. this.title = '选择商品'
  336. this.queryParam.q = barCode
  337. this.$nextTick(() => this.$refs.material.focus())
  338. this.loadTreeData()
  339. this.getDepotList()
  340. this.initDepotSelect()
  341. this.loadMaterialData()
  342. this.form.resetFields()
  343. },
  344. getQueryParams() {
  345. let param = Object.assign({}, this.queryParam, this.isorter)
  346. param.mpList = getMpListShort(Vue.ls.get('materialPropertyList')) //扩展属性
  347. param.page = this.ipagination.current
  348. param.rows = this.ipagination.pageSize
  349. return filterObj(param)
  350. },
  351. getQueryField() {
  352. let str = 'id,'
  353. for (let a = 0; a < this.columns.length; a++) {
  354. str += ',' + this.columns[a].dataIndex
  355. }
  356. return str
  357. },
  358. searchReset(num) {
  359. let that = this
  360. if (num !== 0) {
  361. that.queryParam = {}
  362. that.loadMaterialData(1)
  363. }
  364. that.selectedRowKeys = []
  365. that.selectMaterialIds = []
  366. },
  367. addMaterial() {
  368. this.$refs.modalForm.add()
  369. this.$refs.modalForm.title = '新增商品'
  370. },
  371. handleEdit(record) {
  372. getMaterialById({ mid: record.mid }).then((res) => {
  373. this.$refs.modalForm.edit(res.data)
  374. this.$refs.modalForm.title = '编辑'
  375. this.$refs.modalForm.disableSubmit = false
  376. this.$refs.modalForm.showOkFlag = true
  377. })
  378. },
  379. getImgUrl(imgName, type) {
  380. if (imgName && imgName.split(',')) {
  381. type = type ? type + '/' : ''
  382. return getFileAccessHttpUrl('systemConfig/static/' + type + imgName.split(',')[0])
  383. } else {
  384. return ''
  385. }
  386. },
  387. close() {
  388. this.searchReset(0)
  389. this.visible = false
  390. },
  391. handleTableChange(pagination, filters, sorter) {
  392. if (Object.keys(sorter).length > 0) {
  393. this.isorter.column = sorter.field
  394. this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
  395. }
  396. this.ipagination = pagination
  397. this.loadMaterialData()
  398. },
  399. handleSubmit() {
  400. let that = this
  401. this.getSelectMaterialRows()
  402. that.$emit('ok', that.selectMaterialRows, that.selectMaterialIds)
  403. that.searchReset(0)
  404. that.close()
  405. },
  406. //获取选择信息
  407. getSelectMaterialRows(rowId) {
  408. let dataSource = this.dataSource
  409. let materialIds = ''
  410. this.selectMaterialRows = []
  411. for (let i = 0, len = dataSource.length; i < len; i++) {
  412. if (this.selectedRowKeys.includes(dataSource[i].id)) {
  413. this.selectMaterialRows.push(dataSource[i])
  414. materialIds = materialIds + ',' + dataSource[i].batchNumber
  415. }
  416. }
  417. this.selectMaterialIds = materialIds.substring(1)
  418. },
  419. getDepotList() {
  420. let that = this
  421. getAction('/depot/findDepotByCurrentUser').then((res) => {
  422. if (res.code === 200) {
  423. that.depotList = res.data
  424. }
  425. })
  426. },
  427. initDepotSelect() {
  428. if (this.rows) {
  429. if (JSON.parse(this.rows).depotId) {
  430. const id = JSON.parse(this.rows).depotId - 0
  431. this.queryParam.depotId = id + ''
  432. }
  433. }
  434. },
  435. onDepotChange(value) {
  436. this.queryParam.depotId = value
  437. },
  438. onSelectChange(selectedRowKeys, selectionRows) {
  439. this.selectedRowKeys = selectedRowKeys
  440. this.selectionRows = selectionRows
  441. },
  442. onSearch() {
  443. if (this.dataSource && this.dataSource.length === 1) {
  444. if (
  445. this.queryParam.q === this.dataSource[0].mBarCode ||
  446. this.queryParam.q === this.dataSource[0].name ||
  447. this.queryParam.q === this.dataSource[0].mnemonic
  448. ) {
  449. let arr = []
  450. arr.push(this.dataSource[0].id)
  451. this.selectedRowKeys = arr
  452. this.handleSubmit()
  453. } else {
  454. this.loadMaterialData(1)
  455. }
  456. } else {
  457. this.loadMaterialData(1)
  458. }
  459. },
  460. modalFormOk() {
  461. this.loadMaterialData()
  462. },
  463. rowAction(record, index) {
  464. return {
  465. on: {
  466. click: () => {
  467. let arr = []
  468. arr.push(record.id)
  469. this.selectedRowKeys = arr
  470. },
  471. dblclick: () => {
  472. let arr = []
  473. arr.push(record.id)
  474. this.selectedRowKeys = arr
  475. this.handleSubmit()
  476. },
  477. },
  478. }
  479. },
  480. findAllSelect() {
  481. this.$emit('all', this.queryParam)
  482. },
  483. },
  484. }
  485. </script>
  486. <style scoped>
  487. .ant-table-tbody .ant-table-row td {
  488. padding-top: 10px;
  489. padding-bottom: 10px;
  490. }
  491. #components-layout-demo-custom-trigger .trigger {
  492. font-size: 18px;
  493. line-height: 64px;
  494. padding: 0 24px;
  495. cursor: pointer;
  496. transition: color 0.3s;
  497. }
  498. .item-info {
  499. float: left;
  500. width: 30px;
  501. height: 30px;
  502. margin-left: 8px;
  503. }
  504. .item-img {
  505. cursor: pointer;
  506. position: static;
  507. display: block;
  508. width: 100%;
  509. height: 100%;
  510. object-fit: cover;
  511. }
  512. </style>