Newer
Older
smartKitchenFront / src / components / mycomponent / dialog / orderAddDialog.vue
<!--下订单添加采购需求弹窗-->
<template>
  <el-dialog 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="产品品牌" class="inputWidth">
            <el-select
              v-model="addInfo.brandId"
              multiple
              filterable
              allow-create
              default-first-option
              placeholder="请输入或选则 可多选"
              style="width:100%"
            >
              <el-option
                v-for="item in brandList"
                :key="item.brandCode"
                :label="item.brandName"
                :value="item.brandName"
              />
            </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.categoryName"
              />
            </el-select>
          </input-vue>
        </div>
        <div class="inputBox">
          <red-star />
          <input-vue v-model="addInfo.productCode" title="产品型号" placeholder="请输入产品型号" />
        </div>
        <div class="inputBox">
          <red-star />
          <input-vue v-model="addInfo.productQuantity" title="产品数量" placeholder="请输入产品数量" />
        </div>
        <div class="inputBox">
          <red-star />
          <input-vue v-model="addInfo.productPrice" title="产品单价" placeholder="请输入产品单价" />
        </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 { Message } from 'element-ui'
// 逻辑
import { C_list } from '../../../api/product/category'
import { SelectList } from '../../../api/product/brand'
import { list } from '../../../api/product/product'
export default {
  components: {
    RedStar,
    InputVue
  },
  props: {
    isShowInfo: {
      type: Boolean,
      default: true
    },
    title: '',
    dataInfo: {
      type: Object
    }
  },
  data() {
    return {
      brandList: [],
      categoryList: [],
      tableData: [],
      addInfo: {
        brandId: '',
        categoryIds: '',
        productCode: '',
        productQuantity: '',
        productPrice: ''
      }
    }
  },
  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
    }
  },
  mounted() {
    // 获取产品型号
    list().then(res => {
      console.log(res, '产品型号')
    })
    // 获取品牌列表
    SelectList().then(res => {
      console.log(res, '产品品牌')
      this.brandList = res
    }),
    //   获取品类列表
    C_list().then(res => {
      console.log(res, '品类列表')
      this.categoryList = res.data
    })
  },
  methods: {
    close() {
      this.$emit('close')
      // 重置输入框
      this.resetData()
    },
    save() {
      this.$emit('tabData', this.addInfo)
      this.$emit('close')
      // 重置输入框
      this.resetData()
    },
    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
    }

  }
}
</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>