123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- <template>
- <a-modal
- centered
- class="chooseBrand-modal"
- :footer="null"
- :maskClosable="false"
- title="选择产品品牌"
- v-model="isShow"
- @cancel="isShow=false"
- :width="800">
- <div class="chooseBrand-con">
- <div>
- <a-checkbox :checked="checkAll" :disabled="disabledList.length>0" @change="onCheckAllChange">全选</a-checkbox>
- <span v-if="pageType==='1'">
- <a-checkbox :checked="checkOwn" :disabled="disabledList.length>0" @change="onCheckOwnChange">自主品牌</a-checkbox>
- <a-checkbox :checked="checkAgent" :disabled="disabledList.length>0" @change="onCheckAgentChange">代理品牌</a-checkbox>
- </span>
- </div>
- <a-divider />
- <a-checkbox-group v-model="checkedList" @change="onChange" style="width: 100%;">
- <a-row style="height: 400px;overflow-y: scroll;">
- <a-col :span="6" v-for="item in brandList" :key="item.brandSn">
- <a-checkbox :value="item.brandSn" :disabled="item.isDisabled">
- {{ item.brandName }}
- </a-checkbox>
- </a-col>
- </a-row>
- </a-checkbox-group>
- <!-- 按钮 -->
- <div class="btn-con">
- <a-button
- type="primary"
- id="chooseBrand-submit"
- size="large"
- class="button-primary"
- @click="handleSave"
- style="padding: 0 60px;">保存</a-button>
- <a-button
- id="chooseBrand-cancel"
- size="large"
- class="button-cancel"
- @click="isShow=false"
- style="padding: 0 60px;margin-left: 15px;">取消</a-button>
- </div>
- </div>
- </a-modal>
- </template>
- <script>
- import { productBrandQuery } from '@/api/productBrand'
- export default {
- name: 'ChooseBrandModal',
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- chooseData: {
- type: Array,
- default: () => {
- return []
- }
- },
- pageType: { // 弹框显示状态
- type: [String, Number],
- default: ''
- }
- },
- data () {
- return {
- isShow: this.openModal, // 是否打开弹框
- checkAll: false, // 全选
- checkOwn: false, // 自主品牌
- checkAgent: false, // 代理品牌
- checkedList: [], // 选中项
- checkedRowList: [], // 选中项
- brandList: [], // 品牌数据
- brandOwnList: [],
- brandAgentList: [],
- disabledList: []
- }
- },
- methods: {
- // 保存
- handleSave () {
- const _this = this
- if (this.checkedList.length < 1) {
- this.$message.warning('请在列表勾选后再进行操作!')
- return
- }
- this.checkedRowList = []
- _this.brandList.map(item => {
- if (_this.checkedList.indexOf(item.brandSn) != -1) {
- _this.checkedRowList.push(item)
- }
- })
- this.$emit('ok', this.checkedRowList)
- this.isShow = false
- },
- // change
- onChange (checkedList) {
- const _this = this
- this.checkAll = checkedList.length === this.brandList.length
- this.brandList.map(item => {
- if (_this.checkedList.indexOf(item.brandSn) != -1) {
- _this.checkedRowList.push(item)
- }
- })
- if (this.pageType == '1') {
- const newCheckList = []
- this.brandList.forEach(con => {
- if (checkedList.includes(con.brandSn)) {
- newCheckList.push(con)
- }
- })
- const obj = _this.handleArr(newCheckList)
- this.checkOwn = obj.ownList.length === this.brandOwnList.length
- this.checkAgent = obj.agentList.length === this.brandAgentList.length
- }
- },
- // 全选
- onCheckAllChange (e) {
- const _this = this
- this.checkAll = e.target.checked
- this.checkOwn = e.target.checked
- this.checkAgent = e.target.checked
- if (e.target.checked) {
- this.checkedList = []
- this.checkedRowList = []
- this.brandList.map(item => {
- _this.checkedList.push(item.brandSn)
- _this.checkedRowList.push(item)
- })
- } else {
- this.checkedList = []
- this.checkedRowList = []
- }
- },
- onCheckOwnChange (e) {
- const _this = this
- this.checkOwn = e.target.checked
- if (e.target.checked) {
- this.checkedList = []
- this.checkedRowList = []
- this.brandList.map(item => {
- if (item.brandType == 1) {
- _this.checkedList.push(item.brandSn)
- _this.checkedRowList.push(item)
- }
- })
- } else {
- const noArr = this.getDifferData(this.checkedList, this.brandOwnList)
- _this.checkedList = noArr
- }
- _this.onChange(_this.checkedList)
- },
- getDifferData (list1, list2) {
- list2.forEach(item => {
- const pos = list1.indexOf(item.brandSn)
- if (pos != -1) {
- list1.splice(pos, 1)
- }
- })
- return list1
- },
- onCheckAgentChange (e) {
- const _this = this
- this.checkAgent = e.target.checked
- if (e.target.checked) {
- this.checkedList = []
- this.checkedRowList = []
- this.brandList.map(item => {
- if (item.brandType == 2) {
- _this.checkedList.push(item.brandSn)
- _this.checkedRowList.push(item)
- }
- })
- } else {
- const noArr = this.getDifferData(this.checkedList, this.brandAgentList)
- _this.checkedList = noArr
- }
- _this.onChange(_this.checkedList)
- },
- // 获取品牌数据
- getBrandList () {
- productBrandQuery({}).then(res => {
- if (res.status == 200) {
- const obj = this.handleArr(res.data)
- this.brandList = res.data
- this.brandOwnList = obj.ownList
- this.brandAgentList = obj.agentList
- } else {
- this.brandList = []
- }
- })
- },
- handleArr (list) {
- const ownList = []
- const agentList = []
- list.forEach(item => {
- if (item.brandType == 1) {
- ownList.push(item)
- } else {
- agentList.push(item)
- }
- })
- return { ownList, agentList }
- },
- // 禁用
- handleDisabled (list) {
- this.disabledList = list
- this.brandList.map(item => {
- if (list.includes(item.brandSn)) {
- item.isDisabled = true
- } else {
- item.isDisabled = false
- }
- })
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.checkAll = false
- this.checkOwn = false
- this.checkAgent = false
- } else {
- const _this = this
- this.checkedRowList = this.chooseData
- this.checkedList = []
- this.chooseData.map(item => {
- _this.checkedList.push(item.goodsSn)
- })
- if (this.brandList.length == 0) {
- this.getBrandList()
- }
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .chooseBrand-modal{
- .chooseBrand-con{
- .btn-con{
- text-align: center;
- margin: 30px 0 20px;
- .button-cancel{
- font-size: 12px;
- }
- }
- }
- }
- </style>
|