123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299 |
- <template>
- <a-drawer
- :zIndex="zIndex"
- title="选择产品"
- placement="right"
- :visible="isShow"
- width="80%"
- :get-container="false"
- :wrap-style="{ position: 'absolute' }"
- :headerStyle="{ padding: '10px' }"
- @close="onClose"
- wrapClassName="chooseProducts-modal">
- <a-spin :spinning="spinning" tip="Loading...">
- <div class="products-con">
- <!-- 搜索条件 -->
- <div class="table-page-search-wrapper">
- <a-form-model
- ref="ruleForm"
- class="form-model-con"
- layout="inline"
- :model="queryParam"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol">
- <a-row :gutter="15">
- <a-col :md="8" :sm="24">
- <a-form-model-item label="产品编码">
- <a-input id="chooseProducts-code" v-model.trim="queryParam.productCode" allowClear placeholder="请输入产品编码"/>
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24">
- <a-form-model-item label="原厂编码">
- <a-input id="chooseProducts-code" v-model.trim="queryParam.origCode" allowClear placeholder="请输入原厂编码"/>
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24">
- <a-form-model-item label="产品名称">
- <a-input id="chooseProducts-name" v-model.trim="queryParam.productName" allowClear placeholder="请输入产品名称"/>
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24">
- <a-form-model-item label="产品分类">
- <productTypeAll placeholder="请选择产品分类" @change="changeProductType" v-model="queryParam.productType" id="chooseProducts-productType"></productTypeAll>
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24">
- <a-form-model-item label="产品品牌">
- <ProductBrand id="chooseProducts-productBrandSn" v-model="queryParam.productBrandSn"></ProductBrand>
- </a-form-model-item>
- </a-col>
- <a-col :md="8" :sm="24" style="margin-bottom: 10px;">
- <a-button type="primary" @click="$refs.table.refresh()" :disabled="disabled" id="chooseProducts-refresh">查询</a-button>
- <a-button style="margin-left: 5px" @click="resetData" :disabled="disabled" id="chooseProducts-reset">重置</a-button>
- </a-col>
- </a-row>
- </a-form-model>
- </div>
- <div style="margin-bottom: 10px">
- <a-button type="primary" ghost :loading="loading" @click="handleSave">批量添加</a-button>
- <span style="margin-left: 5px">
- <template v-if="selectCount"> {{ `已选 ${selectCount} 项` }} </template>
- </span>
- </div>
- <!-- 列表 -->
- <s-table
- class="sTable"
- ref="table"
- size="small"
- :rowKey="(record) => record.productSn"
- rowKeyName="productSn"
- :row-selection="{ columnWidth: 40, getCheckboxProps: record => ({ props: { disabled: !record.terminalPrice } })}"
- @rowSelection="rowSelectionFun"
- :columns="columns"
- :pagination="{pageSizeOptions: ['20','50','100','200','500']}"
- :data="loadData"
- :defaultLoadData="false"
- style="max-height:700px;"
- :scroll="{ y: 550 }"
- bordered>
- <!-- 产品分类 -->
- <template slot="productType" slot-scope="text, record">
- <span v-if="record.productTypeName2 || record.productTypeName3">{{ record.productTypeName2 }} {{ record.productTypeName3 ? '>' : '' }} {{ record.productTypeName3 }}</span>
- <span v-else>--</span>
- </template>
- <!-- 包装数 -->
- <template slot="productQty" slot-scope="text, record">
- <span v-if="record.packQty">
- {{ record.packQty }}{{ record.unit }}/{{ record.packQtyUnit?record.packQtyUnit:'--' }}
- </span>
- <span v-else>--</span>
- </template>
- </s-table>
- </div>
- </a-spin>
- </a-drawer>
- </template>
- <script>
- import { commonMixin } from '@/utils/mixin'
- import { STable } from '@/components'
- import { queryWaitingProductPage } from '@/api/promoActive'
- import ProductBrand from '@/views/common/productBrand.js'
- import productTypeAll from '@/views/common/productTypeAll.js'
- export default {
- name: 'ChooseProductsModal',
- components: { STable, ProductBrand, productTypeAll },
- mixins: [commonMixin],
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- chooseData: {// 隐藏选择的产品
- type: Array,
- default: () => {
- return []
- }
- },
- chooseType: {// 选中的分类
- type: Array,
- default: () => {
- return []
- }
- },
- chooseProduct: {// 当前行选中的数据
- type: Array,
- default: () => {
- return []
- }
- },
- itemSn: {
- type: String,
- default: ''
- },
- zIndex: { // 层级
- type: [String, Number],
- default: 1000
- }
- },
- data () {
- const _this = this
- return {
- spinning: false,
- isShow: this.openModal, // 是否打开弹框
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 20 }
- },
- queryParam: { // 查询条件
- productName: '', // 产品名称
- productCode: '', // 产品编码
- origCode: '', // 原厂编码
- productBrandSn: undefined, // 产品品牌
- productType: [],
- productTypeSn1: '', // 产品一级分类
- productTypeSn2: '', // 产品二级分类
- productTypeSn3: '', // 产品三级分类
- hideProductSnList: [],
- productTypeSnList: []
- },
- chooseDataList: [],
- disabled: false, // 查询、重置按钮是否可操作
- loading: false, // 表格加载中
- columns: [
- { title: '序号', dataIndex: 'no', width: 60, align: 'center' },
- { title: '产品编码', dataIndex: 'code', align: 'center', width: '12%' },
- { title: '产品名称', dataIndex: 'name', align: 'left', width: '18%', ellipsis: true, customRender: function (text) { return text || '--' } },
- { title: '原厂编码', dataIndex: 'origCode', align: 'center', ellipsis: true, customRender: function (text) { return text || '--' } },
- { title: '终端价', dataIndex: 'terminalPrice', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
- // { title: '市级价', dataIndex: 'cityPrice', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
- // { title: '特约价', dataIndex: 'specialPrice', width: '6%', align: 'right', customRender: function (text) { return ((text || text == 0) ? _this.toThousands(text) : '--') } },
- { title: '品牌', dataIndex: 'productBrandName', align: 'center', width: '8%', ellipsis: true, customRender: function (text) { return text || '--' } },
- { title: '产品分类', scopedSlots: { customRender: 'productType' }, align: 'center' },
- { title: '包装数', scopedSlots: { customRender: 'productQty' }, width: '6%', align: 'center' },
- { title: '单位', dataIndex: 'unit', align: 'center', width: '6%', ellipsis: true, customRender: function (text) { return text || '--' } }
- ],
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- this.disabled = true
- this.spinning = true
- const params = Object.assign(parameter, this.queryParam)
- params.hideProductSnList = this.chooseData
- params.productTypeSnList = this.chooseType
- params.promoActiveSn = this.itemSn
- return queryWaitingProductPage(params).then(res => {
- let data
- if (res.status == 200) {
- data = res.data
- const no = (data.pageNo - 1) * data.pageSize
- for (var i = 0; i < data.list.length; i++) {
- data.list[i].no = no + i + 1
- }
- this.disabled = false
- const _this = this
- // 选中回显
- if (_this.chooseProduct && _this.chooseProduct.length > 0) {
- const selectedRows = []
- let selectedRowKeys = []
- data.list.forEach(item => {
- const flag = _this.chooseProduct.includes(item.productSn)
- if (flag) {
- selectedRows.push(item)
- }
- })
- selectedRowKeys = _this.chooseProduct
- _this.$nextTick(() => { // 页面渲染完成后的回调
- _this.$refs.table.setTableSelected(selectedRowKeys, selectedRows) // 设置表格选中项
- })
- }
- }
- _this.spinning = false
- return data
- })
- },
- rowSelectionInfo: null
- }
- },
- computed: {
- selectCount () {
- return this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length
- }
- },
- methods: {
- // 表格选中项
- rowSelectionFun (obj) {
- this.rowSelectionInfo = obj || null
- },
- // 重置数据
- resetData () {
- this.queryParam.productName = ''
- this.queryParam.productCode = ''
- this.queryParam.origCode = ''
- this.queryParam.productBrandSn = undefined
- this.queryParam.productTypeSn1 = ''
- this.queryParam.productTypeSn2 = ''
- this.queryParam.productTypeSn3 = ''
- this.queryParam.productType = []
- this.$nextTick(() => {
- this.$refs.table.refresh(true)
- })
- },
- // 清空选项
- resetSearchForm () {
- this.$refs.table.clearSelected()
- },
- // 批量添加
- handleSave () {
- if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
- this.$message.warning('请在列表勾选后再进行操作!')
- return
- }
- const resultList = JSON.parse(JSON.stringify(this.rowSelectionInfo && this.rowSelectionInfo.selectedRows))
- this.$emit('ok', resultList)
- this.isShow = false
- },
- // 关闭弹框
- onClose () {
- this.isShow = false
- this.$emit('close')
- },
- // 产品分类 change
- changeProductType (val, opt) {
- this.queryParam.productTypeSn1 = val[0] ? val[0] : ''
- this.queryParam.productTypeSn2 = val[1] ? val[1] : ''
- this.queryParam.productTypeSn3 = val[2] ? val[2] : ''
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.resetSearchForm()
- this.rowSelectionInfo = null
- this.$emit('close')
- } else {
- const _this = this
- _this.resetData()
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .chooseProducts-modal{
- .products-con{
- .btn-con{
- text-align: center;
- margin: 30px 0 20px;
- .button-cancel{
- font-size: 12px;
- }
- }
- }
- }
- </style>
|