123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314 |
- <template>
- <a-modal
- centered
- class="chooseProducts-modal"
- :footer="null"
- :maskClosable="false"
- title="选择产品"
- v-model="isShow"
- @cancel="isShow=false"
- :width="900">
- <a-spin :spinning="spinning" tip="Loading...">
- <div class="products-con">
- <div>
- <!-- 搜索条件 -->
- <div class="table-page-search-wrapper">
- <a-form-model
- ref="ruleForm"
- class="form-model-con"
- layout="inline"
- :model="queryParam"
- :rules="rules"
- @keyup.enter.native="handleSearch"
- :label-col="formItemLayout.labelCol"
- :wrapper-col="formItemLayout.wrapperCol">
- <a-row :gutter="15">
- <a-col :md="6" :sm="24">
- <a-form-model-item label="产品编码">
- <a-input id="chooseProducts-code" v-model.trim="queryParam.code" allowClear placeholder="请输入产品编码"/>
- </a-form-model-item>
- </a-col>
- <a-col :md="6" :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="6" :sm="24">
- <a-form-model-item label="产品分类">
- <productTypeAll :isAll="type!='default'" placeholder="请选择产品分类" @change="changeProductType" v-model="queryParam.productType" id="chooseProducts-productType"></productTypeAll>
- </a-form-model-item>
- </a-col>
- <a-col :md="6" :sm="24" style="margin-bottom: 10px;">
- <a-button type="primary" @click="handleSearch" :disabled="disabled" id="chooseProducts-refresh">查询</a-button>
- <a-button style="margin-left: 5px" @click="resetSearchForm" :disabled="disabled" id="chooseProducts-reset">重置</a-button>
- </a-col>
- </a-row>
- </a-form-model>
- </div>
- <p style="font-weight: bold;">当前已选:{{ rowSelectionInfo&&rowSelectionInfo.selectedRowKeys.length }}个</p>
- <!-- 列表 -->
- <s-table
- class="sTable"
- ref="table"
- size="small"
- :rowKey="(record) => record.productSn"
- rowKeyName="productSn"
- :row-selection="{ columnWidth: 40, getCheckboxProps:record =>({props: { disabled: (this.type == 'supplier') && (this.chooseData && this.chooseData.indexOf(record.productSn) > -1) }}) }"
- @rowSelection="rowSelectionFun"
- :columns="columns"
- :data="loadData"
- :defaultLoadData="false"
- bordered>
- </s-table>
- </div>
- <!-- 按钮 -->
- <div class="btn-con">
- <a-button
- id="chooseProducts-cancel"
- class="button-cancel"
- @click="isShow=false"
- style="padding: 0 30px;">取消</a-button>
- <a-button
- type="primary"
- id="chooseProducts-save"
- @click="handleSave"
- style="padding: 0 30px;margin-left: 15px;">保存</a-button>
- </div>
- </div>
- </a-spin>
- </a-modal>
- </template>
- <script>
- import { STable } from '@/components'
- import tablePagination from '@/views/common/tablePagination.vue'
- import ProductBrand from '@/views/common/productBrand.js'
- import productTypeAll from '@/views/common/productTypeAll.js'
- import { dealerScopeValidProduct } from '@/api/dealerScope'
- import { productPricedList, productPricingList } from '@/api/product'
- export default {
- name: 'ChooseProductsModal',
- components: { STable, tablePagination, ProductBrand, productTypeAll },
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- chooseData: {
- type: Array,
- default: () => {
- return []
- }
- },
- type: { // 类型,经销权设置dealership, 供应商添加产品supplier
- type: String,
- default: 'default'
- },
- dealerSn: {
- type: String || Number,
- default: ''
- }
- },
- data () {
- return {
- spinning: false,
- isShow: this.openModal, // 是否打开弹框
- formItemLayout: {
- labelCol: { span: 4 },
- wrapperCol: { span: 20 }
- },
- queryParam: { // 查询条件
- code: '', // 产品编码
- productBrandSn: undefined, // 产品品牌
- productType: [],
- productTypeSn1: '', // 产品一级分类
- productTypeSn2: '', // 产品二级分类
- productTypeSn3: '' // 产品三级分类
- },
- rules: {
- productBrandSn: [ { required: true, message: '请选择产品品牌', trigger: 'change' } ],
- productType: [ { required: true, message: '请选择产品分类', trigger: 'change' } ]
- },
- disabled: false, // 查询、重置按钮是否可操作
- loading: false, // 表格加载中
- columns: [
- { title: '序号', dataIndex: 'no', width: 80, align: 'center' },
- { title: '产品编码', dataIndex: 'code', align: 'left',width: 200 },
- { title: '产品名称', dataIndex: 'name', align: 'left', ellipsis: true, customRender: function (text) { return text || '--' } }
- ],
- // 加载数据方法 必须为 Promise 对象
- loadData: parameter => {
- this.disabled = true
- this.spinning = true
- let url = productPricedList // 获取定过价的产品
- if (this.type == 'supplier') { // 供应商增加产品
- url = productPricingList // 获取定价产品
- }
- const params = Object.assign(parameter, this.queryParam)
- if (this.type != 'supplier' && this.type != 'dealership') { // 促销
- params.onlineFalg = 1
- }
- return url(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
- }
- this.spinning = false
- return data
- })
- },
- rowSelectionInfo: null
- }
- },
- methods: {
- // 表格选中项
- rowSelectionFun (obj) {
- this.rowSelectionInfo = obj || null
- },
- // 查询
- handleSearch () {
- const _this = this
- _this.$refs.ruleForm.validate(valid => {
- if (valid) {
- if (_this.type == 'dealership') { // 设置经销权时选择产品
- if (!_this.queryParam.productBrandSn && !_this.queryParam.productTypeSn1) {
- _this.$message.info('请选择产品品牌或产品分类')
- return
- }
- // 校验产品是否被包含在品牌分类中
- const params = []
- if (_this.queryParam.productBrandSn) {
- params.push({
- dealerSn: _this.dealerSn,
- goodsType: 'BRAND',
- goodsSn: _this.queryParam.productBrandSn
- })
- }
- if (_this.queryParam.productTypeSn1) {
- params.push({
- dealerSn: _this.dealerSn,
- goodsType: 'CATEGORY',
- goodsSn: _this.queryParam.productTypeSn1
- })
- }
- if (_this.queryParam.productTypeSn2) {
- params.push({
- dealerSn: _this.dealerSn,
- goodsType: 'CATEGORY',
- goodsSn: _this.queryParam.productTypeSn2
- })
- }
- if (_this.queryParam.productTypeSn3) {
- params.push({
- dealerSn: _this.dealerSn,
- goodsType: 'CATEGORY',
- goodsSn: _this.queryParam.productTypeSn3
- })
- }
- dealerScopeValidProduct(params).then(res => {
- if (res.status == 200) {
- _this.$refs.table.refresh(true)
- }
- })
- } else {
- _this.$refs.table.refresh(true)
- }
- } else {
- return false
- }
- })
- },
- // 重置数据
- resetData () {
- this.queryParam.code = ''
- this.queryParam.productBrandSn = undefined
- this.queryParam.productTypeSn1 = ''
- this.queryParam.productTypeSn2 = ''
- this.queryParam.productTypeSn3 = ''
- this.queryParam.productType = []
- },
- // 重置
- resetSearchForm () {
- this.resetData()
- this.$refs.table.clearTable()
- },
- // 保存
- handleSave () {
- const _this = this
- if (!this.rowSelectionInfo || (this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.length < 1)) {
- this.$message.warning('请在列表勾选后再进行操作!')
- return
- }
- if (this.type == 'supplier') { // 供应商增加产品
- const arr = []
- this.rowSelectionInfo && this.rowSelectionInfo.selectedRowKeys.map(item => {
- if (_this.chooseData.indexOf(item) == -1) {
- arr.push(item)
- }
- })
- this.$emit('ok', arr)
- } else {
- this.$emit('ok', this.rowSelectionInfo && this.rowSelectionInfo.selectedRows)
- }
- this.isShow = false
- },
- // 产品分类 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.$emit('close')
- this.$refs.table.clearTable()
- this.resetData()
- } else {
- const _this = this
- let selectedRows = []
- let selectedRowKeys = []
- if (this.type == 'supplier') { // 供应商增加产品
- selectedRows = []
- selectedRowKeys = this.chooseData
- } else {
- selectedRows = this.chooseData
- selectedRowKeys = []
- this.chooseData.map(item => {
- selectedRowKeys.push(item.goodsSn)
- })
- }
- this.$nextTick(() => { // 页面渲染完成后的回调
- _this.$refs.table.setTableSelected(selectedRowKeys, selectedRows) // 设置表格选中项
- })
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .chooseProducts-modal{
- .products-con{
- .btn-con{
- text-align: center;
- margin: 30px 0 20px;
- .button-cancel{
- font-size: 12px;
- }
- }
- }
- }
- </style>
|