relationCategoryDialog.vue 4.13 KB
<!-- 关联类目 -->
<template>
  <d2-dialog title="关联类目"
             :is-visible="categoryVisible"
             class="categoryDailog"
             width="40%"
             btn-ok-label="提交"
             @closeDialog="handleClose"
             @confirmDialog="handleAddConfirm">
    <el-form ref="categoryForm"
             :model="infoForm"
             :rules="formRules"
             label-width="120px">
      <el-form-item label="特色产品:">
        {{ info.featuredGoodsName }}
      </el-form-item>
      <el-form-item label="关联类目:"
                    prop="category">
        <el-select v-model="infoForm.category"
                   multiple
                   filterable
                   style="width:400px">
          <el-option v-for="item in baseData.noRelatcategoryList"
                     :key="item.id"
                     :label="item.categoryName"
                     :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item label="已关联类目:">
        {{ info.categoryName }}
      </el-form-item>
    </el-form>
  </d2-dialog>
</template>

<script>
import { queryGoodsCategoryBySceneId, editFeaturedGoods } from '@api/sceneCategory'
import { deepClone } from '@/common/util'
export default {
  name: 'RelationCategoryDialog',
  data() {
    return {
      userInfo: this.$store.state.d2admin.user.info,
      infoForm: {
        category: ''
      },

      formRules: {
        category: [
          { required: true, message: '请选择关联类目', trigger: 'change' }
        ]
      },
      selectLoading: false,
      // 基本数据
      baseData: {
        noRelatcategoryList: []
      }
    }
  },

  props: {
    categoryVisible: {
      type: Boolean,
      default: false
    },
    info: {
      type: Object,
      default: () => { }
    }
  },

  watch: {
  },

  created() {
  },
  components: {},

  computed: {

  },

  mounted() {
    this.queryCategory()
  },

  methods: {

    queryCategory() {
      var params = {}
      params.sceneType = this.info.sceneType
      params.categoryTypeList = this.info.categoryType
      queryGoodsCategoryBySceneId(params).then(res => {
        this.baseData.noRelatcategoryList = res
        console.log(this.baseData.noRelatcategoryList)
      })
    },

    handleAddConfirm() {
      this.$refs.categoryForm.validate(valid => {
        if (valid) {
          var infoForm = deepClone(this.infoForm)
          console.log(infoForm)
          var params = {}
          var obj
          var categoryNameList = []
          var categoryTypeList = []
          infoForm.category.forEach(item => {
            obj = {}
            obj = this.baseData.noRelatcategoryList.find(
              cat => cat.id === item
            )
            categoryNameList.push(obj.categoryName)
            categoryTypeList.push(obj.categoryType)
          })
          params.id = this.info.id
          params.categoryName = categoryNameList.join(",") + (this.info.categoryName ? (',' + this.info.categoryName) : '')
          params.categoryType = categoryTypeList.join(",") + (this.info.categoryType ? (',' + this.info.categoryType) : '')
          console.log(params)
          editFeaturedGoods(params).then(res => {
            this.notice.okTips()
            this.handleClose(true)
          })
        }
      })
    },

    handleClose(flag) {
      this.$emit('dialogClose', flag)
    }
  }
}
</script>
<style >
::v-deep .categoryVisible {
  /*下拉选择框-多选-内容过长-用...代替    begin    */
  .el-tag.el-tag--info {
    background-color: #f4f4f5;
    border-color: #e9e9eb;
    color: #909399;
    max-width: calc(100% - 50px);
    /* white-space: nowrap;
     text-overflow: ellipsis;
     overflow: hidden;*/
  }
  .el-tag.el-tag--info {
    width: calc(100% - 200px);
  }
  .el-tag.el-tag--info .el-select__tags-text {
    width: calc(100% - 20px);
    float: left;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
  }
}

/*下拉选择框-多选-内容过长-用...代替    end    */
::v-deep .categoryDailog .el-dialog {
  min-width: 700px;
}
::v-deep .categoryDailog .el-select-dropdown__item {
  width: 395px !important;
}
</style>