Newer
Older
smartKitchenFront / src / components / mycomponent / dialog / brandAddDialog.vue
<!--品牌新增弹窗-->
<template>
  <div v-if="isShowInfo" class="brandDialog dialog">
    <dialog-header :title="title" @close="close" />
    <div class="inputContent">
      <div class="inputBox">
        <red-star />
        <input-vue v-model="addInfo.brandCode" title="编号" placeholder="请输入唯一编号" />
      </div>
      <div class="inputBox">
        <red-star />
        <input-vue v-model="addInfo.brandName" title="名称" placeholder="请输入品牌名称" />
      </div>
      <div class="inputBox">
        <red-star />
        <input-vue v-model="addInfo.brandProperty" title="性质" placeholder="请输入品牌性质" />
      </div>
      <div class="inputBox">
        <red-star />
        <input-vue title="供应商">
          <el-select
            v-model="addInfo.supplierIds"
            style="width:100%"
            filterable
            multiple
            allow-create
            default-first-option
            placeholder="请输入或选则 可多选"
          >
            <el-option
              v-for="item in supplierList"
              :key="item.supplierCode"
              :label="item.supplierName"
              :value="item.supplierCode"
            />
          </el-select>
        </input-vue>
      </div>
      <div class="inputBox">
        <red-star />
        <input-vue title="品类">
          <el-select
            v-model="addInfo.categoryIds"
            style="width:100%"
            multiple
            filterable
            allow-create
            default-first-option
            placeholder="请输入或选则 可多选"
          >
            <el-option v-for="item in categoryList" :key="item.id" :label="item.categoryName" :value="item.id" />
          </el-select>
        </input-vue>
      </div>
      <div class="inputBox">
        &nbsp;
        <input-vue title="备注">
          <el-input v-model="addInfo.remark" type="textarea" :rows="2" placeholder="请输入内容" />
        </input-vue>
      </div>
    </div>
    <div class="btnBox">
      <el-button type="primary" class="save" @click="save">
        保存
      </el-button>
      <el-button type="info" class="close" @click="close">
        取消
      </el-button>
    </div>
  </div>
</template>

<script>
import InputVue from '../input/inputVue.vue'
import RedStar from '../redStar.vue'
import DialogHeader from './dialogHeader.vue'
import { Message } from 'element-ui'
// 逻辑
import { add, update } from '../../../api/product/brand'
import { C_list } from '../../../api/product/category'
import { S_list } from '../../../api/supplier/supplier'

export default {
  components: {
    DialogHeader,
    RedStar,
    InputVue
  },
  props: {
    isShowInfo: {
      type: Boolean,
      default: true
    },
    title: '',
    dataInfo: {
      type: Object
    }
  },
  data() {
    return {
      categoryList: [],
      supplierList: [],
      addInfo: {
        brandCode: '', // 编号
        brandName: '',
        brandProperty: '',
        supplierIds: '',
        categoryIds: '',
        remark: ''
      }
    }
  },
  watch: {
    dataInfo: {
      handler(vla) {
        if (vla != '') {
          this.addInfo = {
            brandCode: vla.brandCode, // 编号
            brandName: vla.brandName,
            brandProperty: vla.brandProperty,
            supplierIds: this.supplierName(vla.suppliers),
            categoryIds: this.categoryName(vla.categorys),
            remark: vla.remark
          }
        } else {
          this.addInfo = {
            brandCode: '', // 编号
            brandName: '',
            brandProperty: '',
            supplierIds: [],
            categoryIds: [],
            remark: ''
          }
        }
      },
      deep: true
    }
  },
  mounted() {
    //   获取品类列表
    C_list().then(res => {
      console.log(res, '品类列表')
      this.categoryList = res
    })
    //  获取供应商列表
    S_list().then(res => {
      console.log(res, '供应商列表')
      this.supplierList = res
    })
  },
  methods: {
    close() {
      this.$emit('close')
    },
    save() {
      if (this.title == '新增品牌') {
        add(this.addInfo).then(res => {
          if (!res.code) {
            this.close()
            this.$emit('refresh')
            Message.success('保存成功')
          }
        })
      } else {
        update(this.addInfo).then(res => {
          if (!res.code) {
            this.close()
            this.$emit('refresh')
            Message.success('更新成功')
          }
        })
      }
    },
    //  数据处理
    categoryName(category) {
      const ary = []
      if (category.length == 0) return ''
      category.forEach(ele => {
        ary.push(ele.categoryId)
      })
      return ary
    },
    supplierName(supplier) {
      const ary = []
      if (supplier.length == 0) return ''
      supplier.forEach(ele => {
        ary.push(ele.supplierName)
      })
      return ary
    }

  }
}
</script>

<style lang="scss" scoped>
.brandDialog {
  width: 500px;

  .inputContent {
    padding: 20px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;

    .inputBox {
      width: 100%;
      display: flex;
      align-items: center;
    }
  }

  .btnBox {
    padding: 30px;
    box-sizing: border-box;
    display: flex;
    align-items: center;
    justify-content: space-evenly;

    .save,
    .close {
      width: 100px;
    }
  }
}
</style>