123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <template>
- <a-modal
- centered
- class="chooseBrand-modal"
- :footer="null"
- :maskClosable="false"
- title="选择产品品牌"
- v-model="isShow"
- @cancle="isShow=false"
- :width="800">
- <div class="chooseBrand-con">
- <div>
- <a-checkbox :checked="checkAll" @change="onCheckAllChange">全选</a-checkbox>
- </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">
- {{ 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 []
- }
- }
- },
- data () {
- return {
- isShow: this.openModal, // 是否打开弹框
- checkAll: false, // 全选
- checkedList: [], // 选中项
- checkedRowList: [], // 选中项
- brandList: [] // 品牌数据
- }
- },
- 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)
- }
- })
- },
- // 全选
- onCheckAllChange (e) {
- const _this = this
- this.checkAll = 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 = []
- }
- },
- // 获取品牌数据
- getBrandList () {
- productBrandQuery({}).then(res => {
- if (res.status == 200) {
- this.brandList = res.data
- } else {
- this.brandList = []
- }
- })
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.checkAll = 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>
|