123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203 |
- <template>
- <a-modal
- centered
- class="chooseType-modal"
- :footer="null"
- :maskClosable="false"
- title="选择产品分类"
- v-model="isShow"
- @cancel="isShow=false"
- width="50%">
- <div class="chooseType-con">
- <div>
- <a-checkbox :checked="checkAll" :disabled="!linkageStatus&&chooseList.length>0 " @change="onCheckAllChange">全选</a-checkbox>
- </div>
- <a-divider style="margin:10px 0;" />
- <a-tree
- style="height: 400px;overflow-y: scroll;"
- checkable
- @check="onCheck"
- :checkStrictly="linkageStatus"
- v-model="checkedKeys"
- :treeData="productTypeList"
- :replaceFields="replaceFields"
- />
- <!-- 按钮 -->
- <div class="btn-con">
- <a-button
- id="chooseType-cancel"
- class="button-cancel"
- @click="isShow=false"
- style="padding: 0 30px;">取消</a-button>
- <a-button
- type="primary"
- id="chooseType-submit"
- @click="handleSave"
- style="padding: 0 30px;margin-left: 15px;">保存</a-button>
- </div>
- </div>
- </a-modal>
- </template>
- <script>
- import { productTypeQuery, productTypeQueryAll } from '@/api/productType'
- export default {
- name: 'ChooseTypeModal',
- props: {
- openModal: { // 弹框显示状态
- type: Boolean,
- default: false
- },
- chooseData: {
- type: Array,
- default: () => {
- return []
- }
- },
- type: { // 类型,促销规则promo
- type: String,
- default: ''
- },
- linkageStatus: { // 父子是否联动
- type: Boolean,
- default: true
- }
- },
- data () {
- return {
- isShow: this.openModal, // 是否打开弹框
- checkedKeys: [], // 选中项
- checkedRows: [], // 选中项 整条数据
- checkAll: false, // 全选
- indeterminate: true,
- replaceFields: {
- children: 'children',
- title: 'productTypeName',
- key: 'productTypeSn'
- },
- productTypeList: [],
- chooseList: []
- }
- },
- methods: {
- // 产品分类 列表
- getProductType () {
- if (this.type == 'promo') {
- productTypeQueryAll({}).then(res => {
- if (res.status == 200) {
- this.productTypeList = res.data
- } else {
- this.productTypeList = []
- }
- })
- } else {
- productTypeQuery({}).then(res => {
- if (res.status == 200) {
- if (!this.linkageStatus && this.chooseData.length > 0) {
- this.handleDisabled(res.data, this.chooseData)
- }
- if (!this.linkageStatus && this.chooseList.length > 0) {
- this.handleDisabled(res.data, this.chooseList)
- }
- this.productTypeList = res.data
- } else {
- this.productTypeList = []
- }
- })
- }
- },
- // 保存
- handleSave () {
- if (this.checkedKeys.checked && this.checkedKeys.checked.length < 1) {
- this.$message.warning('请在列表勾选后再进行操作!')
- return
- }
- this.$emit('ok', this.checkedRows)
- this.isShow = false
- },
- // 全选
- onCheckAllChange (e) {
- this.checkAll = e.target.checked
- if (e.target.checked) {
- this.checkedKeys = []
- this.checkedRows = []
- this.recursionFun(this.productTypeList)
- } else {
- this.checkedKeys = []
- this.checkedRows = []
- }
- },
- // 递归函数
- recursionFun (data) {
- if (data) {
- data.map((item, index) => {
- this.checkedKeys.push(item.productTypeSn)
- this.checkedRows.push(item)
- if (item.children && item.children.length > 0) {
- this.recursionFun(item.children)
- }
- })
- }
- },
- handleAllDisabled (list) {
- this.chooseList = list
- },
- // 禁用递归
- handleDisabled (data, selectData) {
- if (data) {
- data.map(item => {
- const posNum = selectData.findIndex(con => con.goodsSn == item.productTypeSn)
- if (posNum != -1) {
- item = Object.assign(item, selectData[posNum])
- }
- if (item.children && item.children.length > 0) {
- this.handleDisabled(item.children, selectData)
- }
- })
- }
- },
- onCheck (checkedKeys, info) {
- this.checkedRows = []
- info.checkedNodes.map((item, index) => {
- this.checkedRows.push(item.data.props)
- })
- }
- },
- watch: {
- // 父页面传过来的弹框状态
- openModal (newValue, oldValue) {
- this.isShow = newValue
- },
- // 重定义的弹框状态
- isShow (newValue, oldValue) {
- if (!newValue) {
- this.$emit('close')
- this.checkAll = false
- } else {
- this.getProductType()
- const _this = this
- this.checkedRows = this.chooseData
- this.checkedKeys = []
- this.chooseData.forEach(item => {
- _this.checkedKeys.push(item.goodsSn)
- })
- }
- }
- }
- }
- </script>
- <style lang="less" scoped>
- .chooseType-modal{
- .chooseType-con{
- .btn-con{
- text-align: center;
- margin: 30px 0 20px;
- .button-cancel{
- font-size: 12px;
- }
- }
- }
- }
- </style>
|