<template>
  <el-dialog title="退菜" width="410px" v-model="show" @close="reset" :modal="modal">
    <div
      class="u-p-b-16 u-m-t-10 flex u-row-between border-bottom"
      v-for="(goods, index) in goodsList"
      :key="index"
    >
      <div class="">
        <div>菜品名称</div>
        <div class="u-m-t-10">
          {{ goods.productName || "" }}
        </div>
      </div>
      <div class="">
        <div>退菜数量</div>
        <div class="u-flex u-m-t-10">
          <el-input-number
            :min="1"
            v-model="goods.selNumber"
            :max="goods.num - goods.refundNum"
          ></el-input-number>
        </div>
      </div>
    </div>

    <div class="u-m-t-20">
      <div>
        <span>退菜原因</span>
        <span class="color-red">*</span>
      </div>
    </div>

    <div class="u-flex u-flex-wrap tags">
      <div
        class="tag"
        v-for="(tag, index) in tags"
        @click="changeSel(tag)"
        :key="index"
        :class="{ active: tag.checked }"
      >
        {{ tag.label }}
      </div>
    </div>
    <div class="u-m-t-20">
      <el-input v-model="note" placeholder="请输入自定义备注"></el-input>
    </div>
    <div class="u-m-t-20">
      <el-checkbox v-model="isPrint">打印退菜单</el-checkbox>
    </div>
    <template #footer>
      <div>
        <el-button @click="close">取消</el-button>
        <el-button type="primary" @click="confirm">确定</el-button>
      </div>
    </template>
  </el-dialog>
</template>
  <script>
import { ElMessage } from "element-plus";
export default {
  props: {
    modal: {
      type: Boolean,
      default: true,
    },
  },
  data() {
    return {
      max: 1,
      number: 1,
      isPrint: false,
      tagSel: -1,
      show: false,
      tags: [
        { label: "不想要了", checked: false },
        { label: "食材不足", checked: false },
        { label: "等待时间过长", checked: false },
      ],
      note: "",
      goodsList: [],
      orderDetail: {},
    };
  },
  computed: {
    isSeatFee() {
      return false;
    },
  },
  methods: {
    changeSel(item) {
      item.checked = !item.checked;
    },
    reset() {
      this.note = "";
      this.number = 1;
      this.tags.map((v) => {
        v.checked = false;
      });
      console.log(this.number);
    },
    delTag(index) {
      this.tags.splice(index, 1);
    },
    addNote(tag) {
      if (this.note.length <= 0) {
        return (this.note = tag);
      }
      this.note = tag + "," + this.note;
    },
    open(arr, detail) {
      console.log(arr);
      console.log(detail);
      this.goodsList = arr;
      this.orderDetail = detail;
      this.show = true;
      if (item.productId != "-999") {
        this.number = 1;
      } else {
        this.number = this.max;
      }
    },
    close() {
      this.show = false;
      this.number = 1;
    },
    confirm() {
      const selTag = this.tags
        .filter((item) => item.checked)
        .map((item) => item.label)
        .join(",");
      const note = selTag + (this.note.length > 0 ? "," + this.note : "");
      console.log(note);
      if (!note) {
        return ElMessage.error("请输入退菜原因");
      }
      this.$emit("confirm", {
        refundReason: note,
        refundAmount: 0,
        refundDetails: this.goodsList
          .filter((v) => v.selNumber)
          .map((v) => {
            return {
              id: v.id,
              num: v.selNumber,
              returnAmount: 0,
            };
          }),
      });
      this.close();
    },
  },
  mounted() {},
};
</script>
  
  <style lang="scss" scoped>
:deep(.el-dialog__body) {
  margin-bottom: 14px;
  margin-top: 14px;
  padding: 0 20px;
}
:deep(.el-tag) {
  margin-top: 10px;
  margin-right: 10px;
  margin-bottom: 5px;
  cursor: pointer;
  font-size: 15px;
  line-height: 35px;
  height: 35px;
}
.tags {
  .tag {
    margin: 10px 10px 0 0;
    border: 1px solid #dcdfe6;
    border-radius: 4px;
    padding: 10px 13px;
    font-size: 14px;
    color: #000;
    cursor: pointer;
    &.active {
      color: #1890ff;
      background: #e8f4ff;
      border-color: #a3d3ff;
    }
  }
}
:deep(.number-box .el-input__inner::-webkit-inner-spin-button) {
  -webkit-appearance: none;
  margin: 0;
}
:deep(.number-box .el-input__inner::-webkit-outer-spin-button) {
  -webkit-appearance: none;
  margin: 0;
}
</style>