<template>
  <div id="makeUpExam">
    <el-form-item label="关联商品" prop="makeGoodsId">
      <div>
        <el-button @click="goToActiveGoods">选择商品</el-button>
        <span v-if="listData.makeGoodsId" style="margin-left: 12px"
          >{{ listData.makeGoodsCode }} - {{ listData.makeGoodsName }}</span
        >
        <el-button
          style="margin-left: 12px"
          v-if="listData.makeGoodsId"
          type="text"
          @click="clearGoods"
          >删除</el-button
        >
      </div>
    </el-form-item>
    <make-check ref="makeCheck" @backData="backMakeData" />
  </div>
</template>

<script>
import makeCheck from "./makeCheck.vue";
export default {
  components: { makeCheck },
  props: ["listData"],
  data() {
    return {};
  },
  methods: {
    goToActiveGoods() {
      //搜索条件
      var data = {
        businessId: this.listData.businessId,
        status: 1,
        pageSize: 10,
        pageNum: 1,
        filtration:
          this.listData.goodsType === 3
            ? 2
            : this.listData.goodsType === 4
            ? 1
            : "",
      };
      //打开选择补考/前培组件
      this.$refs.makeCheck.openBox(data, {
        makeGoodsId: this.listData.makeGoodsId,
        makeGoodsName: this.listData.makeGoodsName,
        makeGoodsCode: this.listData.makeGoodsCode,
      });
    },
    backMakeData(activeObj) {
      this.$set(this.listData, "makeGoodsId", activeObj.makeGoodsId);
      this.$set(this.listData, "makeGoodsName", activeObj.makeGoodsName);
      this.$set(this.listData, "makeGoodsCode", activeObj.makeGoodsCode);
      this.$bus.$emit("validateMakeId");
    },
    clearGoods() {
      this.$set(this.listData, "makeGoodsId", "");
      this.$set(this.listData, "makeGoodsName", "");
      this.$set(this.listData, "makeGoodsCode", "");
      this.$bus.$emit("validateMakeId");
    },
  },
};
</script>

<style lang="less" scoped>
</style>
