123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518 |
- <template>
- <a-modal
- :width="modalWidth"
- :visible="visible"
- :title="title"
- :wrapClassName="wrapClassNameInfo()"
- @ok="handleSubmit"
- @cancel="close"
- cancelText="关闭(ESC)"
- style="top: 20px; height: 95%"
- >
- <a-row :gutter="10" style="padding: 10px; margin: -10px">
- <a-col :md="24" :sm="24">
- <!-- 查询区域 -->
- <div class="table-page-search-wrapper">
- <!-- 搜索区域 -->
- <a-form layout="inline" @keyup.enter.native="onSearch">
- <a-row :gutter="24">
- <a-col :md="6" :sm="8">
- <a-form-item label="关键词" :labelCol="labelCol" :wrapperCol="wrapperCol">
- <a-input ref="material" placeholder="请输入条码、名称、助记码等查询" v-model="queryParam.q"></a-input>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="8">
- <a-form-item label="规格型号" :labelCol="labelCol" :wrapperCol="wrapperCol">
- <a-input placeholder="请输入规格、型号" v-model="queryParam.standardOrModel"></a-input>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="8">
- <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="仓库">
- <a-select
- placeholder="选择仓库"
- v-model="queryParam.depotId"
- @change="onDepotChange"
- :dropdownMatchSelectWidth="false"
- showSearch
- optionFilterProp="children"
- allow-clear
- >
- <a-select-option v-for="(item, index) in depotList" :key="index" :value="item.id">
- {{ item.depotName }}
- </a-select-option>
- </a-select>
- </a-form-item>
- </a-col>
- <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
- <a-col :md="6" :sm="8">
- <a-button type="primary" @click="loadMaterialData(1)">查询</a-button>
- <a-button style="margin-left: 8px" @click="searchReset(1)">重置</a-button>
- <a-tooltip title="没查询到,决定新增商品!">
- <a-button style="margin-left: 8px" @click="addMaterial">新增</a-button>
- </a-tooltip>
- <a @click="handleToggleSearch" style="margin-left: 8px">
- {{ toggleSearchStatus ? '收起' : '展开' }}
- <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
- </a>
- </a-col>
- </span>
- <template v-if="toggleSearchStatus">
- <a-col :md="6" :sm="8">
- <a-form-item label="颜色" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
- <a-input placeholder="请输入颜色" v-model="queryParam.color"></a-input>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="8">
- <a-form-item label="品牌" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
- <a-input placeholder="请输入品牌" v-model="queryParam.brand"></a-input>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="8">
- <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="类别">
- <a-tree-select
- style="width: 100%"
- :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
- allow-clear
- :treeData="categoryTree"
- v-model="queryParam.categoryId"
- placeholder="请选择类别"
- >
- </a-tree-select>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="8">
- <a-form-item label="制造商" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
- <a-input placeholder="请输入制造商" v-model="queryParam.mfrs"></a-input>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="24">
- <a-form-item label="序列号" :labelCol="labelCol" :wrapperCol="wrapperCol">
- <a-select placeholder="有无序列号" v-model="queryParam.enableSerialNumber">
- <a-select-option value="1">有</a-select-option>
- <a-select-option value="0">无</a-select-option>
- </a-select>
- </a-form-item>
- </a-col>
- <a-col :md="6" :sm="24">
- <a-form-item label="仓库货架" :labelCol="labelCol" :wrapperCol="wrapperCol">
- <a-input placeholder="请输入仓库货架" v-model="queryParam.position"></a-input>
- </a-form-item>
- </a-col>
- <!-- <a-col :md="6" :sm="24">
- <a-form-item label="批号" :labelCol="{ span: 5 }" :wrapperCol="{ span: 18, offset: 1 }">
- <a-select placeholder="有无批号" v-model="queryParam.enableBatchNumber">
- <a-select-option value="1">有</a-select-option>
- <a-select-option value="0">无</a-select-option>
- </a-select>
- </a-form-item>
- </a-col> -->
- </template>
- </a-row>
- </a-form>
- <a-button v-if="isStock" type="primary" @click="findAllSelect">一键全选</a-button>
- <a-table
- ref="table"
- :scroll="scrollTrigger"
- size="middle"
- rowKey="id"
- :columns="columns"
- :dataSource="dataSource"
- :pagination="ipagination"
- :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange, type: getType }"
- :loading="loading"
- :customRow="rowAction"
- @change="handleTableChange"
- >
- <template slot="customBarCode" slot-scope="text, record">
- <div :style="record.imgName ? 'float:left;line-height:30px' : 'float:left;'">{{ record.mBarCode }}</div>
- <a-popover placement="right" trigger="click">
- <template slot="content">
- <img :src="getImgUrl(record.imgName, record.imgLarge)" width="500px" />
- </template>
- <div class="item-info" v-if="record.imgName">
- <img
- v-if="record.imgName"
- :src="getImgUrl(record.imgName, record.imgSmall)"
- class="item-img"
- title="查看大图"
- />
- </div>
- </a-popover>
- </template>
- <template slot="customName" slot-scope="text, record">
- {{ record.name }}
- <a-tag v-if="record.enableSerialNumber == 1" color="orange">序</a-tag>
- <a-tag v-if="record.enableBatchNumber == 1" color="orange">批</a-tag>
- </template>
- <span slot="action" slot-scope="text, record">
- <a @click.stop="handleEdit(record)">编辑</a>
- </span>
- </a-table>
- </div>
- </a-col>
- </a-row>
- <material-modal ref="modalForm" @ok="modalFormOk"></material-modal>
- </a-modal>
- </template>
- <script>
- import { getAction, getFileAccessHttpUrl } from '@/api/manage'
- import { filterObj, getMpListShort } from '@/utils/util'
- import { getMaterialBySelect, queryMaterialCategoryTreeList, getMaterialById } from '@/api/api'
- import { JeecgListMixin } from '@/mixins/JeecgListMixin'
- import { mixinDevice } from '@/utils/mixin'
- import Vue from 'vue'
- export default {
- name: 'JSelectMaterialModal',
- mixins: [JeecgListMixin, mixinDevice],
- components: {
- MaterialModal: () => import('@/views/material/modules/MaterialModal'),
- },
- props: ['rows', 'multi', 'barCode', 'isStock'],
- data() {
- return {
- modalWidth: 1450,
- queryParam: {
- q: '',
- standardOrModel: '',
- depotId: undefined,
- color: '',
- brand: '',
- categoryId: undefined,
- mfrs: '',
- enableSerialNumber: undefined,
- enableBatchNumber: undefined,
- position: '',
- },
- labelCol: {
- xs: { span: 24 },
- sm: { span: 5 },
- },
- wrapperCol: {
- xs: { span: 24 },
- sm: { span: 16 },
- },
- categoryTree: [],
- columns: [
- {
- title: '操作',
- dataIndex: 'action',
- align: 'center',
- width: 60,
- scopedSlots: { customRender: 'action' },
- },
- // { dataIndex: 'mBarCode', title: '条码', scopedSlots: { customRender: 'customBarCode' } },
- { dataIndex: 'batchNumber', title: '批次号' },
- { dataIndex: 'name', title: '名称', scopedSlots: { customRender: 'customName' } },
- { dataIndex: 'categoryName', title: '类别' },
- // { dataIndex: 'standard', title: '规格' },
- { dataIndex: 'model', title: '型号' },
- { dataIndex: 'color', title: '颜色' },
- { dataIndex: 'brand', title: '品牌' },
- { dataIndex: 'supplierName', title: '供应商' },
- { dataIndex: 'unit', title: '单位' },
- { dataIndex: 'sku', title: '多属性' },
- { dataIndex: 'inventory', title: '库存' },
- { dataIndex: 'productionDate', title: '生产日期' },
- { dataIndex: 'expiryNum', title: '保质期' },
- { dataIndex: 'barCode', title: '商品条码' },
- { dataIndex: 'depotName', title: '仓库名称' },
- { dataIndex: 'position', title: '仓库货架' },
- // { dataIndex: 'expand', title: '扩展信息' },
- ],
- scrollTrigger: {},
- dataSource: [],
- selectedRowKeys: [],
- selectMaterialRows: [],
- selectMaterialIds: [],
- title: '选择商品',
- ipagination: {
- current: 1,
- pageSize: 10,
- pageSizeOptions: ['10', '20', '30'],
- showTotal: (total, range) => {
- return range[0] + '-' + range[1] + ' 共' + total + '条'
- },
- showQuickJumper: true,
- showSizeChanger: true,
- total: 0,
- },
- isorter: {
- column: 'createTime',
- order: 'desc',
- },
- departTree: [],
- depotList: [],
- visible: false,
- form: this.$form.createForm(this),
- loading: false,
- expandedKeys: [],
- disableMixinCreated: true,
- }
- },
- computed: {
- // 计算属性的 getter
- getType: function () {
- return this.multi == true ? 'checkbox' : 'radio'
- },
- },
- watch: {
- barCode: {
- immediate: true,
- handler() {
- this.initBarCode()
- },
- },
- },
- created() {
- // 该方法触发屏幕自适应
- this.resetScreenSize()
- },
- methods: {
- initBarCode() {
- if (this.barCode) {
- this.$emit('initComp', this.barCode)
- } else {
- // JSelectUserByDep组件bug issues/I16634
- this.$emit('initComp', '')
- }
- },
- loadMaterialData(arg) {
- if (arg === 1) {
- this.ipagination.current = 1
- }
- this.loading = true
- let params = this.getQueryParams() //查询条件
- getMaterialBySelect(params).then((res) => {
- if (res) {
- this.dataSource = res.rows
- this.ipagination.total = res.total
- if (res.total === 1) {
- if (
- this.queryParam.q === this.dataSource[0].batchNumber ||
- this.queryParam.q === this.dataSource[0].name ||
- this.queryParam.q === this.dataSource[0].mnemonic
- ) {
- this.title = '选择商品【再次回车可以直接选中】'
- this.$nextTick(() => this.$refs.material.focus())
- } else {
- this.title = '选择商品'
- }
- } else {
- this.title = '选择商品'
- }
- }
- this.loading = false
- this.onClearSelected()
- })
- },
- loadTreeData() {
- let that = this
- let params = {}
- params.id = ''
- queryMaterialCategoryTreeList(params).then((res) => {
- if (res) {
- that.categoryTree = []
- for (let i = 0; i < res.length; i++) {
- let temp = res[i]
- that.categoryTree.push(temp)
- }
- }
- })
- },
- // 触发屏幕自适应
- resetScreenSize() {
- let realScreenWidth = window.screen.width
- this.modalWidth = realScreenWidth < 1600 ? '1300px' : '1550px'
- let screenWidth = document.body.clientWidth
- if (screenWidth < 500) {
- this.scrollTrigger = { x: 800 }
- } else {
- this.scrollTrigger = {}
- }
- },
- showModal(barCode) {
- this.visible = true
- this.title = '选择商品'
- this.queryParam.q = barCode
- this.$nextTick(() => this.$refs.material.focus())
- this.loadTreeData()
- this.getDepotList()
- this.initDepotSelect()
- this.loadMaterialData()
- this.form.resetFields()
- },
- getQueryParams() {
- let param = Object.assign({}, this.queryParam, this.isorter)
- param.mpList = getMpListShort(Vue.ls.get('materialPropertyList')) //扩展属性
- param.page = this.ipagination.current
- param.rows = this.ipagination.pageSize
- return filterObj(param)
- },
- getQueryField() {
- let str = 'id,'
- for (let a = 0; a < this.columns.length; a++) {
- str += ',' + this.columns[a].dataIndex
- }
- return str
- },
- searchReset(num) {
- let that = this
- if (num !== 0) {
- that.queryParam = {}
- that.loadMaterialData(1)
- }
- that.selectedRowKeys = []
- that.selectMaterialIds = []
- },
- addMaterial() {
- this.$refs.modalForm.add()
- this.$refs.modalForm.title = '新增商品'
- },
- handleEdit(record) {
- getMaterialById({ mid: record.mid }).then((res) => {
- this.$refs.modalForm.edit(res.data)
- this.$refs.modalForm.title = '编辑'
- this.$refs.modalForm.disableSubmit = false
- this.$refs.modalForm.showOkFlag = true
- })
- },
- getImgUrl(imgName, type) {
- if (imgName && imgName.split(',')) {
- type = type ? type + '/' : ''
- return getFileAccessHttpUrl('systemConfig/static/' + type + imgName.split(',')[0])
- } else {
- return ''
- }
- },
- close() {
- this.searchReset(0)
- this.visible = false
- },
- handleTableChange(pagination, filters, sorter) {
- if (Object.keys(sorter).length > 0) {
- this.isorter.column = sorter.field
- this.isorter.order = 'ascend' === sorter.order ? 'asc' : 'desc'
- }
- this.ipagination = pagination
- this.loadMaterialData()
- },
- handleSubmit() {
- let that = this
- this.getSelectMaterialRows()
- that.$emit('ok', that.selectMaterialRows, that.selectMaterialIds)
- that.searchReset(0)
- that.close()
- },
- //获取选择信息
- getSelectMaterialRows(rowId) {
- let dataSource = this.dataSource
- let materialIds = ''
- this.selectMaterialRows = []
- for (let i = 0, len = dataSource.length; i < len; i++) {
- if (this.selectedRowKeys.includes(dataSource[i].id)) {
- this.selectMaterialRows.push(dataSource[i])
- materialIds = materialIds + ',' + dataSource[i].batchNumber
- }
- }
- this.selectMaterialIds = materialIds.substring(1)
- },
- getDepotList() {
- let that = this
- getAction('/depot/findDepotByCurrentUser').then((res) => {
- if (res.code === 200) {
- that.depotList = res.data
- }
- })
- },
- initDepotSelect() {
- if (this.rows) {
- if (JSON.parse(this.rows).depotId) {
- const id = JSON.parse(this.rows).depotId - 0
- this.queryParam.depotId = id + ''
- }
- }
- },
- onDepotChange(value) {
- this.queryParam.depotId = value
- },
- onSelectChange(selectedRowKeys, selectionRows) {
- this.selectedRowKeys = selectedRowKeys
- this.selectionRows = selectionRows
- },
- onSearch() {
- if (this.dataSource && this.dataSource.length === 1) {
- if (
- this.queryParam.q === this.dataSource[0].mBarCode ||
- this.queryParam.q === this.dataSource[0].name ||
- this.queryParam.q === this.dataSource[0].mnemonic
- ) {
- let arr = []
- arr.push(this.dataSource[0].id)
- this.selectedRowKeys = arr
- this.handleSubmit()
- } else {
- this.loadMaterialData(1)
- }
- } else {
- this.loadMaterialData(1)
- }
- },
- modalFormOk() {
- this.loadMaterialData()
- },
- rowAction(record, index) {
- return {
- on: {
- click: () => {
- let arr = []
- arr.push(record.id)
- this.selectedRowKeys = arr
- },
- dblclick: () => {
- let arr = []
- arr.push(record.id)
- this.selectedRowKeys = arr
- this.handleSubmit()
- },
- },
- }
- },
- findAllSelect() {
- this.$emit('all', this.queryParam)
- },
- },
- }
- </script>
- <style scoped>
- .ant-table-tbody .ant-table-row td {
- padding-top: 10px;
- padding-bottom: 10px;
- }
- #components-layout-demo-custom-trigger .trigger {
- font-size: 18px;
- line-height: 64px;
- padding: 0 24px;
- cursor: pointer;
- transition: color 0.3s;
- }
- .item-info {
- float: left;
- width: 30px;
- height: 30px;
- margin-left: 8px;
- }
- .item-img {
- cursor: pointer;
- position: static;
- display: block;
- width: 100%;
- height: 100%;
- object-fit: cover;
- }
- </style>
|