Newer
Older
smartKitchenFront / src / components / mycomponent / dialog / ElbrandDialog.vue
liuyangyingjie on 26 Oct 2022 5 KB first commit
<template>
  <el-dialog :title="title" width='520px' :visible.sync="isShowInfo" append-to-body @close='close'>
    <div class="brandDialog ">
      <div class="inputContent">
        <div class="inputBox">
          <red-star />
          <input-vue title="编号" placeholder="请输入唯一编号" v-model="addInfo.brandCode"></input-vue>
        </div>
        <div class="inputBox">
          <red-star />
          <input-vue title="名称" placeholder="请输入品牌名称" v-model="addInfo.brandName"></input-vue>
        </div>
        <div class="inputBox">
          <red-star />
          <input-vue title="性质" placeholder="请输入品牌性质" v-model="addInfo.brandProperty"></input-vue>
        </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.id">
              </el-option>
            </el-select>
          </input-vue>
        </div>
        <div class="inputBox">

          <red-star />
          <input-vue title="品类">
            <el-select style="width:100%" v-model="addInfo.categoryIds" 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-option>
            </el-select>
          </input-vue>
        </div>
        <div class="inputBox">
          &nbsp;
          <input-vue title="备注">
            <el-input type="textarea" :rows="2" placeholder="请输入内容" v-model="addInfo.remark">
            </el-input>
          </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>
  </el-dialog>
</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: ''
      }
    }
  },
  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");
      // 重置输入框
      this.resetData()
    },
    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("更新成功")
          }

        })
      }

    },
    resetData () {
      this.addInfo = {
        brandCode: '',//编号
        brandName: '',
        brandProperty: '',
        supplierIds: [],
        categoryIds: [],
        remark: ''
      }
    },
    //  数据处理
    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.supplierId)
      });
      return ary
    }

  },
  watch: {
    dataInfo: {
      handler (vla) {
        console.log(vla);
        if (vla != '') {
          this.addInfo = {
            id: vla.id,
            brandCode: vla.brandCode,//编号
            brandName: vla.brandName,
            brandProperty: vla.brandProperty,
            supplierIds: this.supplierName(vla.suppliers),
            categoryIds: this.categoryName(vla.categorys),
            remark: vla.remark,
          }

        }
      },
      deep: true
    }
  },
};
</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>