JSelectMaterialModal2.vue 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <template>
  2. <a-modal
  3. width="100%"
  4. :visible="visible"
  5. :title="title"
  6. :wrapClassName="wrapClassNameInfo()"
  7. @ok="handleSubmit"
  8. @cancel="close"
  9. cancelText="关闭(ESC)"
  10. style="top: 0; height: 100%"
  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 label="颜色" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
  31. <a-input placeholder="请输入颜色" v-model="queryParam.color"></a-input>
  32. </a-form-item>
  33. </a-col>
  34. <!-- <a-col :md="6" :sm="8">
  35. <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="仓库">
  36. <a-select
  37. placeholder="选择仓库"
  38. v-model="queryParam.depotId"
  39. @change="onDepotChange"
  40. :dropdownMatchSelectWidth="false"
  41. showSearch
  42. optionFilterProp="children"
  43. allow-clear
  44. >
  45. <a-select-option v-for="(item, index) in depotList" :key="index" :value="item.id">
  46. {{ item.depotName }}
  47. </a-select-option>
  48. </a-select>
  49. </a-form-item>
  50. </a-col> -->
  51. <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
  52. <a-col :md="6" :sm="8">
  53. <a-button type="primary" @click="loadMaterialData(1)">查询</a-button>
  54. <a-button style="margin-left: 8px" @click="searchReset(1)">重置</a-button>
  55. <a-tooltip title="没查询到,决定新增商品!">
  56. <a-button style="margin-left: 8px" @click="addMaterial">新增</a-button>
  57. </a-tooltip>
  58. <a @click="handleToggleSearch" style="margin-left: 8px">
  59. {{ toggleSearchStatus ? '收起' : '展开' }}
  60. <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
  61. </a>
  62. </a-col>
  63. </span>
  64. <template v-if="toggleSearchStatus">
  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. color: '',
  178. brand: '',
  179. categoryId: undefined,
  180. mfrs: '',
  181. enableSerialNumber: undefined,
  182. enableBatchNumber: undefined,
  183. position: '',
  184. },
  185. labelCol: {
  186. xs: { span: 24 },
  187. sm: { span: 5 },
  188. },
  189. wrapperCol: {
  190. xs: { span: 24 },
  191. sm: { span: 16 },
  192. },
  193. categoryTree: [],
  194. columns: [
  195. {
  196. title: '操作',
  197. dataIndex: 'action',
  198. align: 'center',
  199. width: 60,
  200. scopedSlots: { customRender: 'action' },
  201. },
  202. // { dataIndex: 'mBarCode', title: '条码', scopedSlots: { customRender: 'customBarCode' } },
  203. // { dataIndex: 'batchNumber', title: '批次号' },
  204. { dataIndex: 'barCode', 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].barCode ||
  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 ? '100%' : '1550px'
  326. let screenWidth = document.body.clientWidth
  327. if (screenWidth < 500) {
  328. this.scrollTrigger = { x: 800 }
  329. } else {
  330. this.scrollTrigger = {
  331. x: 'max-content',
  332. }
  333. }
  334. },
  335. showModal(barCode) {
  336. this.visible = true
  337. this.title = '选择商品'
  338. this.queryParam.q = barCode
  339. this.$nextTick(() => this.$refs.material.focus())
  340. this.loadTreeData()
  341. // this.getDepotList()
  342. // this.initDepotSelect()
  343. this.loadMaterialData()
  344. this.form.resetFields()
  345. },
  346. getQueryParams() {
  347. let param = Object.assign({}, this.queryParam, this.isorter)
  348. param.mpList = getMpListShort(Vue.ls.get('materialPropertyList')) //扩展属性
  349. param.page = this.ipagination.current
  350. param.rows = this.ipagination.pageSize
  351. return filterObj(param)
  352. },
  353. getQueryField() {
  354. let str = 'id,'
  355. for (let a = 0; a < this.columns.length; a++) {
  356. str += ',' + this.columns[a].dataIndex
  357. }
  358. return str
  359. },
  360. searchReset(num) {
  361. let that = this
  362. if (num !== 0) {
  363. that.queryParam = {}
  364. that.loadMaterialData(1)
  365. }
  366. that.selectedRowKeys = []
  367. that.selectMaterialIds = []
  368. },
  369. addMaterial() {
  370. this.$refs.modalForm.add()
  371. this.$refs.modalForm.title = '新增商品'
  372. },
  373. handleEdit(record) {
  374. getMaterialById({ mid: record.mid }).then((res) => {
  375. this.$refs.modalForm.edit(res.data)
  376. this.$refs.modalForm.title = '编辑'
  377. this.$refs.modalForm.disableSubmit = false
  378. this.$refs.modalForm.showOkFlag = true
  379. })
  380. },
  381. getImgUrl(imgName, type) {
  382. if (imgName && imgName.split(',')) {
  383. type = type ? type + '/' : ''
  384. return getFileAccessHttpUrl('systemConfig/static/' + type + imgName.split(',')[0])
  385. } else {
  386. return ''
  387. }
  388. },
  389. close() {
  390. this.searchReset(0)
  391. this.visible = false
  392. },
  393. handleTableChange(pagination, filters, sorter) {
  394. if (Object.keys(sorter).length > 0) {
  395. this.isorter.column = sorter.field
  396. this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
  397. }
  398. this.ipagination = pagination
  399. this.loadMaterialData()
  400. },
  401. handleSubmit() {
  402. let that = this
  403. this.getSelectMaterialRows()
  404. that.$emit('ok', that.selectMaterialRows, that.selectMaterialIds)
  405. that.searchReset(0)
  406. that.close()
  407. },
  408. //获取选择信息
  409. getSelectMaterialRows(rowId) {
  410. let dataSource = this.dataSource
  411. let materialIds = ''
  412. this.selectMaterialRows = []
  413. console.log('getSelectMaterialRows', this.selectedRowKeys)
  414. for (let i = 0, len = dataSource.length; i < len; i++) {
  415. if (this.selectedRowKeys.includes(dataSource[i].id)) {
  416. this.selectMaterialRows.push(dataSource[i])
  417. materialIds = materialIds + ',' + dataSource[i].barCode
  418. }
  419. }
  420. console.log('materialIds=====',materialIds)
  421. this.selectMaterialIds = materialIds.substring(1)
  422. },
  423. getDepotList() {
  424. let that = this
  425. getAction('/depot/findDepotByCurrentUser').then((res) => {
  426. if (res.code === 200) {
  427. that.depotList = res.data
  428. }
  429. })
  430. },
  431. // initDepotSelect() {
  432. // if (this.rows) {
  433. // if (JSON.parse(this.rows).depotId) {
  434. // const id = JSON.parse(this.rows).depotId - 0
  435. // this.queryParam.depotId = id + ''
  436. // }
  437. // }
  438. // },
  439. // onDepotChange(value) {
  440. // this.queryParam.depotId = value
  441. // },
  442. onSelectChange(selectedRowKeys, selectionRows) {
  443. this.selectedRowKeys = selectedRowKeys
  444. this.selectionRows = selectionRows
  445. console.log('onSelectChange', selectedRowKeys, selectionRows)
  446. },
  447. onSearch() {
  448. if (this.dataSource && this.dataSource.length === 1) {
  449. if (
  450. this.queryParam.q === this.dataSource[0].mBarCode ||
  451. this.queryParam.q === this.dataSource[0].name ||
  452. this.queryParam.q === this.dataSource[0].mnemonic
  453. ) {
  454. let arr = []
  455. arr.push(this.dataSource[0].id)
  456. this.selectedRowKeys = arr
  457. this.handleSubmit()
  458. } else {
  459. this.loadMaterialData(1)
  460. }
  461. } else {
  462. this.loadMaterialData(1)
  463. }
  464. },
  465. modalFormOk() {
  466. this.loadMaterialData()
  467. },
  468. rowAction(record, index) {
  469. return {
  470. on: {
  471. click: () => {
  472. let arr = []
  473. arr.push(record.id)
  474. this.selectedRowKeys = arr
  475. },
  476. dblclick: () => {
  477. let arr = []
  478. arr.push(record.id)
  479. this.selectedRowKeys = arr
  480. this.handleSubmit()
  481. },
  482. },
  483. }
  484. },
  485. findAllSelect() {
  486. this.$emit('all', this.queryParam)
  487. },
  488. },
  489. }
  490. </script>
  491. <style scoped>
  492. .ant-table-tbody .ant-table-row td {
  493. padding-top: 10px;
  494. padding-bottom: 10px;
  495. }
  496. #components-layout-demo-custom-trigger .trigger {
  497. font-size: 18px;
  498. line-height: 64px;
  499. padding: 0 24px;
  500. cursor: pointer;
  501. transition: color 0.3s;
  502. }
  503. .item-info {
  504. float: left;
  505. width: 30px;
  506. height: 30px;
  507. margin-left: 8px;
  508. }
  509. .item-img {
  510. cursor: pointer;
  511. position: static;
  512. display: block;
  513. width: 100%;
  514. height: 100%;
  515. object-fit: cover;
  516. }
  517. </style>