<template>
  <view v-if="isOpen" class="synchronous-dialog">
    <view class="synchronous-content">
      <!-- 巡检事项 -->
      <view class="form-item">
        <text class="form-label"
          ><text class="required">*</text>巡检事项：</text
        >
        <text>{{ inspectionItem }}</text>
      </view>

      <!-- 情况摘要（多选输入框） -->
      <view class="form-item">
        <text class="form-label"
          ><text class="required">*</text>情况摘要：</text
        >
        <textarea
          v-model="summary"
          placeholder="请输入情况摘要"
          auto-height
          class="input-box"
        ></textarea>
      </view>

      <!-- 固定词 -->
      <view class="form-item last">
        <text class="form-label"></text>
        <view class="fixed-words">
          <text
            v-for="(word, index) in fixedWords"
            :key="index"
            class="word"
            @click="selectWord(word)"
          >
            {{ word }}
          </text>
        </view>
      </view>
      <view class="row-item bottom-row">
        <view class="button btn" @click="handleClose">取消</view>
        <view class="button" @click="handleConfirm">确认</view>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  props: {
    // 父组件传递的巡检事项
    inspectionItem: {
      type: String,
      default: "",
    },
    // 父组件传递的固定词
    fixedWords: {
      type: Array,
      default: () => ["已检查", "正常", "异常", "需处理"],
    },
  },
  data() {
    return {
      summary: "", // 情况摘要
      isOpen: false,
    };
  },
  methods: {
    // 打开弹窗
    open(item) {
      this.summary = item.conclusion;
      this.isOpen = true;
    },
    // 关闭弹窗
    close() {
      this.isOpen = false;
    },
    // 选择固定词
    selectWord(word) {
      this.summary += word + " "; // 将选中的词添加到输入框
    },
    // 确认
    handleConfirm() {
			if(!this.summary || !this.summary.toString().trim()) {
				uni.showToast({
					title: "不能为空",
					icon: "none",
					duration: 2000,
				});
				return;
			}
      this.$emit("confirm", this.summary); // 将情况摘要回传给父组件
      this.handleClose();
    },
    // 关闭弹窗
    handleClose() {
      this.summary = ""; // 清空输入框
      this.close();
    },
  },
};
</script>

<style scoped lang="less">
.synchronous-dialog {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
  .synchronous-content {
    padding: 3% 20px 32px 24px;
    width: 400px;
    height: 300px;
    box-sizing: border-box;
    background-image: linear-gradient(
      -6deg,
      #f9ffe7 0%,
      #ffffff 12%,
      #fcfeff 73%,
      #ccf1ff 100%
    );
    border: 0.4px solid rgba(224, 224, 224, 1);
    border-radius: 12px;
    position: relative;

    .row-item {
      display: flex;
      align-items: center;
      justify-content: center;
    }

    .title {
      font-family: PingFangSC-Medium;
      font-size: 18px;
      color: #000000;
      text-align: center;
      line-height: 26px;
      font-weight: 500;
    }
    .count-num {
      margin: 5% 0 5% 0;
      align-items: flex-end;
      .num {
        display: inline-block;
        font-family: AlibabaPuHuiTi_2_65_Medium;
        font-size: 50px;
        color: #3774f6;
        line-height: 44px;
        font-weight: 500;
      }
    }

    .operating-instructions {
      margin-bottom: 8%;
      .title {
        font-size: 13px;
        color: #4a4a4a;
        line-height: 24px;
        font-weight: 600;
        text-align: left;
      }
      .instructions-item {
        font-size: 12px;
        color: #7c7c7c;
        line-height: 22px;
        font-weight: 400;
      }
    }

    // 打包按钮
    .bottom-row {
      position: absolute;
      bottom: 24px;
      left: 50%;
      transform: translateX(-50%);

      .button {
        display: flex;
        align-items: center;
        justify-content: center;
        background-image: linear-gradient(180deg, #3773f6 0%, #2c57f6 99%);
        box-shadow: 0px 10px 24px 0px rgba(51, 104, 246, 0.24);
        border-radius: 27px;
        width: 128px;
        height: 32px;
        margin: 10px;
        color: #fff;
        &.btn {
          background: #ffffff;
          color: #000000;
        }
      }
    }

    // 关闭按钮
    .close-button {
      position: absolute;
      bottom: -40px;
      left: 50%;
      transform: translateX(-50%);
      .iconfont {
        color: #fff;
        font-size: 24px;
      }
    }
  }
}
.form-item {
  width: 100%;
  display: flex;
  align-items: center;
  padding: 9.6px 0;
  line-height: 28.8px;
  border-bottom: 0.8px solid #f2f3f5;
  &.last {
    border: 0;
  }

  .fixed-words {
    .word {
      font-size: 11.2px;
      margin-right: 4px;
      padding: 4px 6px;
      border: 1px solid #c7c7c7;
      border-radius: 4px;
    }
  }
  .form-label {
    font-size: 11.2px;
    font-weight: bold;
    margin-right: 25.6px;
    width: 64px;
    text-align: right;

    .required {
      color: red;
      margin-right: 3.2px;
    }
  }

  .switch-container {
    display: flex;
    gap: 9.6px;

    .status-btn {
      flex: 1;
      padding: 5.6px 19.2px;
      font-size: 12.8px;
      color: #000000;
      background: #f2f2f2;
      text-align: center;
      font-weight: 400;
      line-height: 17.6px;
      border-radius: 14.4px;

      &.active {
        color: #ffffff;
        background: #3774f6;
        border: 0.32px solid rgba(224, 224, 224, 1);
      }
    }
  }

  .input-box {
    flex: 1;
    border-radius: 3.2px;
    font-size: 12.8px;
    line-height: 19.2px;
  }

  .photo-limit {
    font-size: 12.8px;
    color: #959595;
    line-height: 19.2px;
    font-weight: 400;
  }

  .photo-container {
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 6.4px;

    .photo-item {
      position: relative;
      margin-right: 6.4px;
      margin-bottom: 6.4px;

      .photo {
        width: 57.6px;
        height: 57.6px;
        border-radius: 3.2px;
        margin-left: 9.6px;
      }

      .delete-photo {
        position: absolute;
        top: -6.4px;
        right: -6.4px;
        background-color: #ff4d4f;
        color: #fff;
        width: 12.8px;
        height: 12.8px;
        border-radius: 50%;
        text-align: center;
        line-height: 12.8px;
        font-size: 9.6px;
      }
    }
  }

  .photo-btn {
    background: #ffffff;
    border: 0.272px solid rgba(221, 221, 221, 1);
    border-radius: 1.64px;
    width: 57.6px;
    height: 57.6px;
    font-size: 57.6px;
    color: #cccccc;
    text-align: center;
    line-height: 51.2px;
  }
}
</style>
