<template>
  <div>
    <div v-for="(music, index) in item.chioseMusic" :key="index">
      <div class="chioseMusic">
        <div class="flexRow">
          <p class="title">可选乐器{{ index + 1 }}:</p>
          <el-select
            style="width: 180px"
            :disabled="basdisabled"
            v-model="music.musical"
            @change="
              (val) => {
                chioseMusic(val, music);
              }
            "
          >
            <el-option
              v-for="(item, index) in item.goodsList"
              :key="index"
              :label="item.name"
              :value="item.id"
              :disabled="checkDisabled(item)"
            >
            </el-option>
          </el-select>
        </div>
        <div class="flexRow">
          <p class="title">乐器选择方式:</p>
          <el-checkbox-group v-model="music.type" class="marginLeft10">
            <el-checkbox :disabled="basdisabled" label="GROUP"
              >团购</el-checkbox
            >
            <el-checkbox :disabled="basdisabled" label="LEASE"
              >租赁</el-checkbox
            >
            <el-checkbox :disabled="basdisabled" label="FREE">免费</el-checkbox>
          </el-checkbox-group>
        </div>
        <div class="flexRow">
          <p
            class="title"
            v-show="
              music.type && music.type.length > 0
                ? music.type.includes('GROUP')
                : false
            "
          >
            团购价:
          </p>

          <div
            v-show="
              music.type && music.type.length > 0
                ? music.type.includes('GROUP')
                : false
            "
            style="width: 180px"
          >
            <el-input type="number" v-model="music.groupPrice" disabled>
              <template slot="append">元</template></el-input
            >
          </div>
          <p
            class="title"
            v-show="
              music.type && music.type.length > 0
                ? music.type.includes('LEASE')
                : false
            "
          >
            租赁押金:
          </p>
          <div
            v-show="
              music.type && music.type.length > 0
                ? music.type.includes('LEASE')
                : false
            "
            style="width: 180px"
          >
            <el-input
              type="number"
              v-model="music.borrowPrice"
              :disabled="basdisabled"
            >
              <template slot="append">元</template></el-input
            >
          </div>
          <!-- <div v-else
               style="width:180px">
            <el-input value="--"
                      disabled> <template slot="append">元</template></el-input>
          </div> -->
          <i
            class="el-icon-close marginLeft10"
            v-if="
              item.chioseMusic.length > 1 &&
              !basdisabled &&
              (music.type.includes('LEASE') || music.type.includes('GROUP'))
            "
            @click="deleteMusic(music)"
            style="font-size: 20px; cursor: pointer"
          ></i>
        </div>
        <div
          style="margin-top: 5px"
          v-show="
            music.type && music.type.length > 0
              ? music.type.includes('GROUP')
              : false
          "
        >
          <div class="flexRow">
            <p class="title">团购乐器减免课程费用:</p>
            <el-radio-group
              v-model="music.groupRemissionCourseFee"
              v-show="
                music.type && music.type.length > 0
                  ? music.type.includes('GROUP')
                  : false
              "
            >
              <el-radio :disabled="basdisabled" :label="true">是</el-radio>
              <el-radio :disabled="basdisabled" :label="false">否</el-radio>
            </el-radio-group>
          </div>
        </div>
      </div>
      <el-divider></el-divider>
    </div>
    <div class="coreItemRow" v-if="!basdisabled">
      <p class="title"></p>
      <el-button
        type="info"
        plain
        style="width: 558px"
        size="mini"
        icon="el-icon-plus"
        @click="addMusic"
        >新增可选乐器</el-button
      >
    </div>
  </div>
</template>
<script>
export default {
  props: ["item", "basdisabled", "activeSoundList"],
  data() {
    return {
      radio: "",
      goods: "",
    };
  },
  created() {},
  mounted() {},
  methods: {
    chioseMusic(val, music) {
      this.item.goodsList.map((some, index) => {
        if (some.id == val) {
          music.groupPrice = some.groupPurchasePrice;
        }
      });
    },
    addMusic() {
      this.item.chioseMusic.push({
        musical: "",
        type: ["GROUP"],
        groupPrice: null,
        borrowPrice: 1500,
        groupRemissionCourseFee: 0,
      });
      this.$emit("lookMusic");
    },
    deleteMusic(music) {
      this.item.chioseMusic.forEach((element, index) => {
        if (element.musical == music.musical) {
          this.item.chioseMusic.splice(index, 1);
        }
      });
    },
    checkDisabled(item) {
      let flag = false;
      this.activeSoundList.forEach((musics) => {
        musics.chioseMusic.forEach((music) => {
          if (item.id == music.musical) {
            flag = true;
          }
        });
      });
      return flag;
    },
    changeFee(val, music) {
      this.$set(music, "groupRemissionCourseFee", val);
    },
  },
};
</script>
<style lang="scss" scoped>
.chioseMusic {
  width: 100%;
  margin: 30px 0 0;
}
.coreItemRow {
  padding-left: 20px;
  height: 50px;
  line-height: 50px;
  display: flex;
  flex-direction: row;
  align-items: center;
  width: 100%;
}
p {
  margin-right: 10px;
}
.title {
  width: 140px !important;
  text-align: right;
  margin-right: 10px;
}
.marginLeft10 {
  margin-left: 10px;
}
.flexRow {
  display: flex;
  flex-direction: row;
  align-items: center;
  padding-left: 20px;
  margin-top: 10px;
  width: 100%;
}
</style>
