<template>
  <div class="ui-appUserMenu">
    <div class="ui-menu-date-box">
      <div v-if="nutrient && nutrient.length > 0">
        <div class="font_30 color333 bold">营养素</div>
        <div class="ui-not-start">
          <div v-for="(item, index) in nutrient" :key="index" :class="index + 1 != nutrient.length ? 'ui-nutrient-item' : ''" class="f-fbc">
            <div class="f-fcl">
              <img class="ui-nutrient_icon" :src="item.icon" alt="" />
              <div class="font_30 color333 bold">{{ item.name }}</div>
            </div>
          </div>
        </div>
      </div>
      <div>
        <div class="ui-calendar-box">
          <div class="ui-calendar-date">
            <div class="calendar_title f-fbc">
              <img class="triangle_icon" src="https://image.fulllinkai.com/202411/05/fd04e833fb45ca7c14d25a877d4c9581.png" alt="" @click="upMonth" />
              <div class="font_28 color0E">{{ year }}年{{ month }}月</div>
              <img class="triangle_icon_v2" src="https://image.fulllinkai.com/202411/05/358000854fe0ad24249b85f64640f9a4.png" alt="" @click="nextMonth" />
            </div>
            <div class="week_box">
              <div v-for="(item, index) in weekList" :key="index" class="font_28 text-center week_num">{{ item }} </div>
            </div>
          </div>
          <div class="calendar_day">
            <div v-for="index in nbsp" :key="index + '-only'" class="day_number font_28 colorF">空</div>
            <div v-for="(item, index) in signInList" :key="index" class="day_number ui-relative">
              <img v-if="copyYear == year && month == copyMonth && date == index + 1" class="ui-toDay-icon" src="https://image.fulllinkai.com/202411/05/6c704d26056175e681093ecb90f50ecd.png" alt="" />
              <!--              <img v-else-if="item == 5" class="ui-right-icon" src="https://image.fulllinkai.com/202411/07/12c66a726bd8458331250d059ae8ca8f.png" alt="" />-->
              <!--              <img v-else-if="item == 6" class="ui-right-icon" src="https://image.fulllinkai.com/202411/07/86ba822a51499157b1ecfd1e5d0d7584.png" alt="" />-->
              <!--              <img v-else-if="item == 7" class="ui-right-icon" src="https://image.fulllinkai.com/202411/07/017af8f5179d7c1843c9d80dae0060b8.png" alt="" />-->
              <div v-if="item == 1 || item == 2 || item == 5" class="number_box menuV3 text-center" :class="index == signIndex ? 'ui-select-menu-three' : ''" @click.stop="getMenu(item, index + 1)">
                <div class="bold font_32 ui-pt-10">{{ index + 1 }}</div>
                <!--                <div v-if="role != 0" class="font_20 ui-text-pt">准备</div>-->
              </div>
              <div v-else-if="item == 3 || item == 6" class="number_box menuV3 text-center" :class="index == signIndex ? 'ui-select-menu-three' : ''" @click.stop="getMenu(item, index + 1)">
                <div class="bold font_32 ui-pt-10">{{ index + 1 }}</div>
                <!--                <div v-if="role != 0" class="font_20 ui-text-pt">装修</div>-->
              </div>
              <div v-else-if="item == 4 || item == 7" class="number_box menuV3 text-center" :class="index == signIndex ? 'ui-select-menu-three' : ''" @click.stop="getMenu(item, index + 1)">
                <div class="bold font_32 ui-pt-10">{{ index + 1 }}</div>
                <!--                <div v-if="role != 0" class="font_20 ui-text-pt">清洁</div>-->
              </div>
              <div v-else class="number_box text-center" @click.stop="getMenu(item, index + 1, 'empty')">
                <div class="bold font_32 ui-pt-10">{{ index + 1 }}</div>
                <div class="font_20 colorF ui-text-pt">--</div>
              </div>
            </div>
          </div>
        </div>
        <div v-if="role != 0" class="f-fcl ui-pl-20 ui-pb-16">
          <div v-for="(item, index) in controlsTab" :key="index" class="ui-controls-item f-fcc ui-relative" :class="index == controlsTabIndex ? 'color0E bold font_36' : 'colorB2 font_28 ui-controls-item-mb'" @click="controlsTabIndex = index">
            {{ item }}
            <!--            <div v-if="index == controlsTabIndex" class="ui-controls-bottom-line" :style="{ background: currentMenu.phase_title == '准备日' ? '#ffa949 ' : currentMenu.phase_title == '清洁日' ? '#18ca6e' : '#9679ff' }"></div>-->
            <div v-if="index == controlsTabIndex" class="ui-controls-bottom-line" :style="{ background: '#18ca6e' }"></div>
          </div>
        </div>
        <div v-if="controlsTabIndex == 0">
          <div class="ui-log-type-box">
            <div v-for="(item, index) in logTypes" :key="index" class="font_28 ui-log-type-item f-fcc ui-mr-20" :class="logTypeIndex == index ? 'colorF ui-act-log' : 'colorB2'" @click="changeLogType(item, index)">{{ item.name }}</div>
          </div>
          <div class="ui-condition-box">
            <div v-if="logList && logList.length != 0">
              <div v-for="(item, index) in logList" :key="index" class="font_28 color76c ui-pb-20" :class="index + 1 != logList.length ? 'ui-condition-line' : ''">{{ item.create_time }}&nbsp;&nbsp;{{ item.remark }}</div>
            </div>
            <div v-else>
              <img class="ui-no-controls-icon" src="https://image.fulllinkai.com/202411/07/f4684549d0bb1f77304162632262005c.png" alt="" />
            </div>
          </div>
        </div>
        <div v-else class="ui-pl-20 ui-pr-20">
          <div v-if="currentMenu.phase_title" class="ui-menu-hint colorF ui-relative" :style="{ background: '#18ca6e' }">
            <div class="font_36 bold">{{ currentMenu.phase_date.split('-')[1] }}月{{ currentMenu.phase_date.split('-')[2] }}日</div>
            <!--            <div v-if="role != 0" class="font_24 ui-pt-14">{{ currentMenu.phase_date.split('-')[1] }}月{{ currentMenu.phase_date.split('-')[2] }}日</div>-->
            <!--            <div v-else class="font_24 ui-pt-14">😊{{ currentMenu.phase_date.split('-')[1] }}月{{ currentMenu.phase_date.split('-')[2] }}日，是{{ currentMenu.phase_title == '准备日' ? '您的自由准备日' : currentMenu.phase_title == '清洁日' ? '您的幸福清洁日' : '您的快乐装修日' }}哟!</div>-->
            <!--            <img v-if="currentMenu.phase_title == '准备日'" class="ui-menu-hint-icon" src="https://image.fulllinkai.com/202411/06/37f5f549f99e5817fbfc9d9a62498abf.png" alt="" />-->
            <img class="ui-menu-hint-icon" src="https://image.fulllinkai.com/202411/06/48972ed0d4c3df70315fe4312fe051fb.png" alt="" />
            <!--            <img v-if="currentMenu.phase_title == '装修日'" class="ui-menu-hint-icon" src="https://image.fulllinkai.com/202411/06/101ef68e1b3900b17eed8771d2aab191.png" alt="" />-->
          </div>
          <div v-if="role != 0 && !currentMenu.state" class="ui-menu-edit-btn colorF f-fcc font_32" @click="addCondition(1)">编辑餐单</div>
          <div v-if="currentMenu.state" class="ui-menu-no-data-box">
            <span v-if="role != 0">
              <img class="ui-not-start_icon" src="https://image.fulllinkai.com/202411/06/523974f4a689b1fbf5c5278691b313cf.png" alt="" />
              <div v-if="schemeStatus == 1">
                <div v-if="isAudit == 0" class="font_28 color76c text-center">餐单还未设置，请先设置餐单</div>
                <div v-else-if="isAudit == 1" class="font_28 color76c text-center">餐单正在审核中，请联系主教练审核</div>
                <div v-else>
                  <div class="font_28 color76c text-center" @click="addCondition(0)">
                    暂未设置餐单，请先
                    <span class="theme">创建</span>
                  </div>
                  <div class="ui-menu-edit-btn colorF f-fcc font_32" @click="copyTips">复制前一天餐单</div>
                </div>
              </div>
              <div v-else>
                <div v-if="isAudit == 0" class="font_28 color76c text-center">方案还未设置，请先设置方案</div>
              </div>
            </span>
            <span v-else>
              <img class="ui-not-start_icon" src="https://image.fulllinkai.com/202301/09/9b76880683c76aea6d926ad19625a70e.png" alt="" />
              <div class="font_28 color76c text-center">当天没有餐单，请联系主教练添加</div>
            </span>
          </div>
          <div v-else class="ui-menu-box">
            <!--            <div class="ui-switch-box f-fcr">-->
            <!--              <div class="font_24 color76c ui-pr-8">大图</div>-->
            <!--              <van-switch v-model="checked" active-color="#18ca6e" inactive-color="#dbdbdb" size="12px" />-->
            <!--            </div>-->
            <div v-if="!checked">
              <div v-if="showDeleteClick" class="font_32 ui-pt-14 color6">营养品左滑可进行删除操作</div>
              <div v-if="currentMenu.menu.beforeMorning.food.length > 0 || currentMenu.menu.beforeMorning.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>早餐前</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('beforeMorning')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.beforeMorning.food" :key="index" @click="viewImage(item, '早餐前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('早餐前', item, 'beforeMorning', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.beforeMorning.nutrient" :key="index" @click="viewImage(item, '早餐前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('早餐前', item, 'beforeMorning', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.morning.food.length > 0 || currentMenu.menu.morning.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>早餐</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('morning')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.morning.food" :key="index" @click="viewImage(item, '早餐')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('早餐', item, 'morning', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.morning.nutrient" :key="index" @click="viewImage(item, '早餐')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('早餐', item, 'morning', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.forenoon.food.length > 0 || currentMenu.menu.forenoon.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>上午</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('forenoon')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.forenoon.food" :key="index" @click="viewImage(item, '上午')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('上午', item, 'forenoon', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.forenoon.nutrient" :key="index" @click="viewImage(item, '上午')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('上午', item, 'forenoon', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.beforeNoon.food.length > 0 || currentMenu.menu.beforeNoon.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>午餐前</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('beforeNoon')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.beforeNoon.food" :key="index" @click="viewImage(item, '午餐前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('午餐前', item, 'beforeNoon', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.beforeNoon.nutrient" :key="index" @click="viewImage(item, '午餐前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('午餐前', item, 'beforeNoon', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.noon.food.length > 0 || currentMenu.menu.noon.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>午餐</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('noon')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.noon.food" :key="index" @click="viewImage(item, '午餐')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('午餐', item, 'noon', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.noon.nutrient" :key="index" @click="viewImage(item, '午餐')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('午餐', item, 'noon', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.afternoon.food.length > 0 || currentMenu.menu.afternoon.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>下午</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('afternoon')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.afternoon.food" :key="index" @click="viewImage(item, '下午')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('下午', item, 'afternoon', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.afternoon.nutrient" :key="index" @click="viewImage(item, '下午')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('下午', item, 'afternoon', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.midnight.food.length > 0 || currentMenu.menu.midnight.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>晚餐前</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('midnight')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.midnight.food" :key="index" @click="viewImage(item, '晚餐前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('晚餐前', item, 'midnight', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.midnight.nutrient" :key="index" @click="viewImage(item, '晚餐前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('晚餐', item, 'midnight', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.evening.food.length > 0 || currentMenu.menu.evening.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>晚餐</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('evening')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.evening.food" :key="index" @click="viewImage(item, '晚餐')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('晚餐', item, 'evening', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.evening.nutrient" :key="index" @click="viewImage(item, '晚餐')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('晚餐', item, 'evening', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
              <div v-if="currentMenu.menu.sleep.food.length > 0 || currentMenu.menu.sleep.nutrient.length > 0" class="ui-menu-pb">
                <div class="ui-menu-item f-fbc font_32 color0E bold">
                  <div>睡前</div>
                  <div v-if="showDeleteClick" class="ui-menu-item-add" @click="toShowTip('sleep')">添加</div>
                </div>
                <div v-for="(item, index) in currentMenu.menu.sleep.food" :key="index" @click="viewImage(item, '睡前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('睡前', item, 'sleep', 'food')" />
                    </template>
                  </van-swipe-cell>
                </div>
                <div v-for="(item, index) in currentMenu.menu.sleep.nutrient" :key="index" @click="viewImage(item, '睡前')">
                  <van-swipe-cell>
                    <div class="ui-menu-data f-fbc">
                      <div class="f-fcl">
                        <img class="ui-menu-pic" :src="item.pic" alt="" />
                        <div class="font_28 color76c">{{ item.title }}</div>
                      </div>
                      <div class="font_28 theme">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                    <template v-if="showDeleteClick" #right>
                      <van-button class="ui-right-btn" square type="danger" text="删除" @click="deleteMenuOne('睡前', item, 'sleep', 'nutrient')" />
                    </template>
                  </van-swipe-cell>
                </div>
              </div>
            </div>
            <div v-else class="ui-pt-16">
              <div v-if="currentMenu.menu.beforeMorning.food.length > 0 || currentMenu.menu.beforeMorning.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">早餐前</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.beforeMorning.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}{{ index == 1 ? '多种植物蛋白粉一共植物蛋白400g/罐' : '' }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.beforeMorning.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-if="currentMenu.menu.morning.food.length > 0 || currentMenu.menu.morning.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">早餐</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.morning.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.morning.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-if="currentMenu.menu.forenoon.food.length > 0 || currentMenu.menu.forenoon.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">上午</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.forenoon.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.forenoon.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-if="currentMenu.menu.noon.food.length > 0 || currentMenu.menu.noon.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">午餐</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.noon.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.noon.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-if="currentMenu.menu.afternoon.food.length > 0 || currentMenu.menu.afternoon.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">下午</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.afternoon.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.afternoon.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-if="currentMenu.menu.evening.food.length > 0 || currentMenu.menu.evening.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">晚餐</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.evening.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.evening.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
              <div v-if="currentMenu.menu.sleep.food.length > 0 || currentMenu.menu.sleep.nutrient.length > 0" class="ui-menu-pb-v2">
                <div class="ui-menu-item-v2 font_32 color0E bold">睡前</div>
                <div class="f-fbc f-wrap">
                  <div v-for="(item, index) in currentMenu.menu.sleep.food" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                  <div v-for="(item, index) in currentMenu.menu.sleep.nutrient" :key="index" class="ui-menu-data-v2">
                    <img class="ui-menu-pic-v2" :src="item.pic" alt="" />
                    <div class="ui-menu-mask">
                      <div class="font_28 color76c">{{ item.title }}</div>
                      <div class="font_28 theme ui-pt-12">{{ item.oneNum || '1' }} {{ item.unit }}</div>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
          <div v-if="!currentMenu.state && currentMenu.hint && currentMenu.hint.length > 0">
            <div class="ui-hint-box">
              <div class="f-fbc ui-pb-36">
                <div class="font_30 bold color3">温馨提示</div>
                <div v-if="role != 0" class="font_26 theme" @click="addCondition(2)">编辑</div>
              </div>
              <div v-for="(item, index) in currentMenu.hint" :key="index" class="ui-hint-item">
                <!--                <img v-if="item.type == 1" class="ui-hint-iconV2 flo_l" src="https://image.fulllinkai.com/202411/06/32428cc891cb7d4084c54b1f31b9aed8.png" alt="" />-->
                <!--                <img v-else-if="item.type == 2" class="ui-hint-iconV2 flo_l" src="https://image.fulllinkai.com/202411/06/54dca9705fcfb5e046973cd44b7fbfd5.png" alt="" />-->
                <!--                <img v-else class="ui-hint-iconV2 flo_l" src="https://image.fulllinkai.com/202301/08/d6627a4cd24253a274fd379f67b070cb.png" alt="" />-->
                <div class="font_28 color76c ui-hint-text">{{ item.content }}</div>
                <div v-if="index + 1 != currentMenu.hint.length" class="ui-line"></div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
    <van-popup v-model:show="showAddHint" round position="bottom" :close-on-click-overlay="false" :lock-scroll="true" :duration="0.5">
      <div class="ui-add-box ui-relative">
        <img class="ui-add-close-icon" src="https://image.fulllinkai.com/202411/05/3a14b8cc539285e3ba96b0977749bfc5.png" alt="" @click="showAddHint = false" />
        <div class="color0E font_34 text-center bold ui-add-title">编辑提示</div>
        <div class="ui-pl-40 ui-pr-40 ui-mb-40 ui-hint-edit-box">
          <div v-for="(item, index) in hintList" :key="index" class="f-fcl ui-mb-26">
            <van-field v-model="item.content" class="ui-add-hint-input font_30 color3 f-fcc" rows="1" type="textarea" placeholder="请输入提示内容" autosize />
            <div class="font_26 f-fcc ui-add-controls-btn" @click="deleteHint(index)">删除</div>
            <div v-if="index + 1 == hintList.length" class="font_26 f-fcc ui-add-controls-btn-v2" @click="addHint">添加</div>
          </div>
        </div>
        <div class="ui-btn-box f-fcc font_36 color0E" @click="verifyHint">确定</div>
      </div>
    </van-popup>
    <van-popup v-model:show="showAddMenu" round position="bottom" :close-on-click-overlay="false" :lock-scroll="true" :duration="0.5">
      <div class="ui-add-box ui-relative">
        <img class="ui-add-close-icon" src="https://image.fulllinkai.com/202411/05/3a14b8cc539285e3ba96b0977749bfc5.png" alt="" @click="(showAddMenu = false), (menuTypeValue = '准备日')" />
        <div class="ui-pl-40">
          <div class="color0E font_36 text-center bold ui-add-title">编辑当天餐单</div>
          <div class="font_30 color76c ui-pb-20">类型</div>
          <div class="f-fcl ui-pb-20 f-wrap">
            <div v-for="(item, index) in menuTypeList" :key="index" class="ui-item-select font_30 f-fcc ui-relative ui-mb-20" :class="menuTypeValue == item.value ? 'ui-item-select-act' : 'colorB2'" :style="{ display: item.show ? 'flex' : 'none' }" @click="selectMenuTypeChange(item)">
              <img v-if="menuTypeValue == item.value" class="ui-select-icon" src="https://image.fulllinkai.com/202411/05/0cd995a8298d57b6e3ae7c0f6d61ceac.png" alt="" />
              {{ item.name }}
            </div>
          </div>
          <div class="ui-select-input-box f-fcl font_30 color0E">
            <div>时间：</div>
            <van-field v-model="time" class="ui-select-input" readonly />
          </div>
        </div>
        <div class="ui-btn-box f-fcc font_36 color0E" @click="addMenuAffirm">确定</div>
      </div>
    </van-popup>
    <van-popup v-model:show="showTips" round :close-on-click-overlay="false" :lock-scroll="true" :duration="0.5">
      <div class="ui-tips-box">
        <div class="ui-tips-list">
          <div class="ui-nutrient-box f-fcl f-wrap">
            <div v-for="(item, index) in selectNutrientList" :key="index" class="ui-symptom-item f-fcl" @click="selectNutrientV(item, index)">
              <img v-if="item.state == 0" class="ui-nutrient-icon" src="https://image.fulllinkai.com/202311/06/26bb5f6433fda7c8ed7a84c69541510e.png" alt="" />
              <img v-else class="ui-nutrient-icon" src="https://image.fulllinkai.com/202311/06/01ebb8b61dabff973425719fca318dda.png" alt="" />
              <div class="font_28 color3">{{ index + 1 }}. {{ item.name }}</div>
            </div>
          </div>
          <div class="ui-menu-num-box ui-mt-20">
            <div v-for="(item, index) in showMenuList(selectNutrientList)" :key="index">
              <div v-if="item.config && item.config.length && item.config.some((val) => val.state == 1)" class="ui-menu-num-line ui-pt-16 ui-pb-6">
                <div class="font_30 color3 bold">{{ item.title }}</div>
                <div v-for="(itemV2, indexV2) in item.config" :key="indexV2">
                  <div v-if="itemV2.state" class="f-fbc ui-pb-20 ui-pt-20">
                    <div class="f-fcl">
                      <img class="ui-select-nutrient-icon" :src="itemV2.icon" alt="" />
                      <div>
                        <div class="ui-select-nutrient-name ellipsis_1 font_28 color3 bold">{{ itemV2.name }}</div>
                        <div class="font_26 color6 ui-pt-6">{{ itemV2.unit }}</div>
                      </div>
                    </div>
                    <div class="ui-stepper-box f-fbc">
                      <img class="ui-stepper-icon" src="https://image.fulllinkai.com/202307/13/cbff16e20c89514f8766b1bfa708c3e9.png" alt="" @click="minusNutrientChange(itemV2)" />
                      <van-field v-model="itemV2.oneNum" type="number" maxlength="4" :min="0" class="ui-stepper-input-box f-fcc font_28 color3" @update:model-value="changeMenuNum($event, itemV2)" />
                      <img class="ui-stepper-icon" src="https://image.fulllinkai.com/202307/13/4147b66b88a1932a3a2a40bcedddec99.png" alt="" @click="addNutrientChange(itemV2)" />
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>

        <div class="ui-btn-box f-fbc">
          <div class="ui-btn font_32 f-fcc color6" @click="showTips = false">取消</div>
          <div class="ui-btn-v2 font_32 f-fcc colorTheme" @click="comfirnDeleteOneMenu">确定</div>
        </div>
      </div>
      <!--      <div class="ui-tips-box">-->
      <!--        <div class="color3 font_32 text-center">{{ '是否删除' + time + ' ' + showDeleteDetail.title + '的' + showDeleteDetail.item.title }}</div>-->
      <!--        <div class="ui-btn-box f-fbc">-->
      <!--          <div class="ui-btn font_32 f-fcc color6" @click="showTips = false">取消</div>-->
      <!--          <div class="ui-btn-v2 font_32 f-fcc colorTheme" @click="comfirnDeleteOneMenu">确定</div>-->
      <!--        </div>-->
      <!--      </div>-->
    </van-popup>
  </div>
  <van-image-preview v-model:show="showImages" :images="viewImages" :show-index="false">
    <template #image="{ src, style }">
      <img :src="src" :style="[{ width: '100%' }, style]" />
      <div class="font_32 colorF ui-view-image-title">{{ viewImageType }}</div>
      <div class="font_40 colorF ui-view-image-name">
        <span>{{ viewImageData.title }}&nbsp;</span>
        <span class="theme">{{ viewImageData.oneNum || 1 }}&nbsp;</span>
        <span class="theme">{{ viewImageData.unit }}</span>
      </div>
    </template>
  </van-image-preview>
</template>
<script setup lang="ts">
  import { ref, onMounted } from 'vue';
  import { showToast, showConfirmDialog } from 'vant';
  import _ from 'lodash';
  import weChat from '@/utils/weChat';
  import requestGo from '@/utils/requestGo';
  import { useUserStore } from '@/store/modules/user';
  import router from '@/router';

  defineOptions({ name: 'AppUserMenu' });

  const userStore = useUserStore() as any;
  const showImages = ref(false);
  const viewImages = ref<any[]>([]);
  const viewImageData = ref<any>({});
  const viewImageType = ref('');
  const viewImage = (e, type) => {
    viewImages.value = [e.pic];
    viewImageData.value = e;
    viewImageType.value = type;
    showImages.value = true;
  };
  const role = ref<any>(0);
  const orderId = ref<any>(0);
  const schemeStatus = ref<any>(''); // 方案是否已设置
  const cacheEditContentList = ref<any[]>([]);
  const editContentList = ref<any[]>([]);
  const controlsTab = ref<any[]>(['操作记录', '餐单']);
  const controlsTabIndex = ref<any>(1);
  const checked = ref(false);
  const throttle = ref(true);
  const showAddMenu = ref(false);
  const menuEditText = ref<any>('创建');
  const menuTypeValue = ref('准备日');
  const time = ref<any>('');
  const isAudit = ref<any>(false); // 用户的餐单模板是否审核
  const intraday = ref('');
  const menuTypeList = ref<any>([
    { name: '方案日', value: '准备日', show: true },
    { name: '方案日', value: '清洁日', show: true },
    { name: '方案日', value: '装修日', show: true },
    { name: '取消餐单', value: '取消餐单', show: true },
  ]); // 类型数据
  const flag = ref(false); // 提示有营养元素余量低于20%
  const showAddHint = ref(false); // 温馨提示弹框Kye
  const hintList = ref<any[]>([]);
  const loading = ref(false);

  const initMenuState = ref(false); // 第一次请求餐单状态，第二次不再请求
  const nutrient = ref<any[]>([]); // 营养素数据
  const menuList = ref<any[]>([]); // 餐单数据
  const logList = ref<any[]>([]); // 餐单操作记录
  const logKey = ref<any>('set_guide_template'); // 记录类型
  const logTypes = ref<any[]>([
    { name: '设置餐单', type: 'set_guide_template' },
    { name: '审核餐单', type: 'check_guide' },
    { name: '设置餐单日历', type: 'set_date_guide' },
    { name: '餐单待发送', type: 'system_send_date_guide' },
    { name: '转发每日餐单', type: 'send_date_guide' },
  ]);
  const logTypeIndex = ref(0);
  const currentMenu = ref<any>({ state: 1 });
  const menuIndex = ref(null); // 当前选中的餐单下标
  const menuMonth = ref<any>(''); // 储存当前选中的餐单月份
  const signInList = ref<any[]>([]); // 日历日期
  const signIndex = ref<any>(0); // 所选日历日期下标
  const weekList = ref<any[]>(['日', '一', '二', '三', '四', '五', '六']);
  const currentDate = ref<any>(''); // 当前时间
  const year = ref<any>(''); // 年
  const day = ref<any>(''); // 天
  const month = ref<any>(''); // 月份
  const copyMonth = ref<any>(''); // 存储月份
  const copyYear = ref<any>(''); // 存储年
  const date = ref<any>(''); // 日期
  const nbsp = ref<any>([]); // 空格
  const showDeleteClick = ref(false); // 是否展示删除按钮
  const showTips = ref(false); // 删除弹窗
  const showDeleteDetail = ref({
    title: '',
    item: {},
  });

  // 获取每日食谱所需数据
  const getRecipe = () => {
    signInList.value = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
    if (!loading.value) {
      loading.value = true;
      weChat({ url: `/h5/user/guides?date=${year.value}-${month.value}&chat_id=${userStore.chatId}&is_im=1&role=${role.value}`, method: 'get' })
        .then((res) => {
          const result = res.data;
          signInList.value = result.date_arr;
          menuList.value = result.guides;
          flag.value = result.flag;
          schemeStatus.value = result.scheme_status;
          isAudit.value = result.template_is_check;
          if (!initMenuState.value) {
            signIndex.value = date.value - 1;
          }
          if (menuList.value && menuList.value.length > 0 && !initMenuState.value) {
            initMenuState.value = true;
            let m = month.value > 9 ? month.value : `0${month.value}`;
            let d = date.value > 9 ? date.value : `0${date.value}`;
            let t = `${year.value}-${m}-${d}`;
            menuList.value.forEach((item) => {
              if (item.phase_date === t) {
                currentMenu.value = item;
                if (item.phase_title == '准备日') {
                  selectNutrientList.value = _.cloneDeep(readyNutrientList.value);
                } else if (item.phase_title == '清洁日') {
                  selectNutrientList.value = _.cloneDeep(cleanNutrientList.value);
                } else if (item.phase_title == '装修日') {
                  selectNutrientList.value = _.cloneDeep(fitmentNutrientList.value);
                }
              }
              // 区分颜色
              signInList.value.forEach((j, index) => {
                if (j) {
                  // 判断是否能查看
                  if (item.phase_date) {
                    if (index == item.phase_date.split('-')[2] * 1 - 1) {
                      if (item.phase_title == '准备日' && item.send_status) {
                        signInList.value[index] = 5;
                      } else if (item.phase_title == '装修日' && item.send_status) {
                        signInList.value[index] = 6;
                      } else if (item.phase_title == '清洁日' && item.send_status) {
                        signInList.value[index] = 7;
                      } else if (item.phase_title == '装修日') {
                        signInList.value[index] = 3;
                      } else if (item.phase_title == '清洁日') {
                        signInList.value[index] = 4;
                      }
                    }
                  }
                }
              });
            });
            if (currentMenu.value.hint && currentMenu.value.hint.length > 0) {
              let hint = [] as any;
              currentMenu.value.hint.forEach((item) => {
                hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
              });
              currentMenu.value.hint = hint;
            }
            setTimeout(() => {
              if (currentMenu.value.state === 1) {
                d = date.value > 9 ? date.value + 1 : `0${date.value}${1}`;
                t = `${year.value}-${m}-${d}`;
                menuList.value.forEach((item) => {
                  if (item.phase_date === t) {
                    currentMenu.value = item;
                    menuIndex.value = date.value + 1;
                    menuMonth.value = month.value;
                  }
                });
              }
              if (currentMenu.value.hint && currentMenu.value.hint.length > 0) {
                let hint = [] as any;
                currentMenu.value.hint.forEach((item) => {
                  hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
                });
                currentMenu.value.hint = hint;
              }
              searchingAlreadyHave();
            }, 50);
          } else {
            updateData();
          }
          loading.value = false;
          nutrient.value = result.nutrient;
        })
        .catch((err) => {
          loading.value = false;
          console.log(err);
        });
    }
  };

  const getLog = () => {
    requestGo({ url: `app/server/get/dma/process/log/list?order_id=${orderId.value}&key=${logKey.value}`, hideLoading: true, method: 'get' })
      .then((res) => {
        logList.value = res.data;
      })
      .catch((err) => {
        console.log(err);
      });
  };

  const changeLogType = (e, index) => {
    logKey.value = e.type;
    logTypeIndex.value = index;
    getLog();
  };

  // 编辑餐单时列表显示转换结构
  const searchingAlreadyHave = () => {
    editContentList.value = JSON.parse(JSON.stringify(cacheEditContentList.value));
    if (currentMenu.value.state == 1) {
      return;
    }

    let beforeMorningFood = currentMenu.value.menu.beforeMorning.food;
    let beforeMorningNutrient = currentMenu.value.menu.beforeMorning.nutrient;
    let morningFood = currentMenu.value.menu.morning.food;
    let morningNutrient = currentMenu.value.menu.morning.nutrient;
    let forenoonFood = currentMenu.value.menu.forenoon.food;
    let forenoonNutrient = currentMenu.value.menu.forenoon.nutrient;
    let beforeNoonFood = currentMenu.value.menu.beforeNoon.food;
    let beforeNoonNutrient = currentMenu.value.menu.beforeNoon.nutrient;
    let noonFood = currentMenu.value.menu.noon.food;
    let noonNutrient = currentMenu.value.menu.noon.nutrient;
    let afternoonFood = currentMenu.value.menu.afternoon.food;
    let afternoonNutrient = currentMenu.value.menu.afternoon.nutrient;
    let midnightFood = currentMenu.value.menu.midnight.food;
    let midnightNutrient = currentMenu.value.menu.midnight.nutrient;
    let eveningFood = currentMenu.value.menu.evening.food;
    let eveningNutrient = currentMenu.value.menu.evening.nutrient;
    let sleepFood = currentMenu.value.menu.sleep.food;
    let sleepNutrient = currentMenu.value.menu.sleep.nutrient;

    editContentList.value.forEach((j) => {
      // 早餐前食物
      beforeMorningFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[0] = 1;
        }
      });
      // 早餐前营养元素
      beforeMorningNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[0] = 1;
        }
      });
      // 早餐食物
      morningFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[0] = 1;
        }
      });
      // 早餐营养元素
      morningNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[0] = 1;
        }
      });
      // 上午食物
      forenoonFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[1] = 1;
        }
      });
      // 上午营养元素
      forenoonNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[1] = 1;
        }
      });
      // 午餐前食物
      beforeNoonFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[2] = 1;
        }
      });
      // 午餐前营养元素
      beforeNoonNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[2] = 1;
        }
      });
      // 午餐食物
      noonFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[2] = 1;
        }
      });
      // 午餐营养元素
      noonNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[2] = 1;
        }
      });
      // 下午食物
      afternoonFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[3] = 1;
        }
      });
      // 下午营养元素
      afternoonNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[3] = 1;
        }
      });
      // 晚餐前食物
      midnightFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[5] = 1;
        }
      });
      // 晚餐前营养元素
      midnightNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[5] = 1;
        }
      });
      // 晚餐食物
      eveningFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[4] = 1;
        }
      });
      // 晚餐营养元素
      eveningNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[4] = 1;
        }
      });
      // 睡前食物
      sleepFood.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[6] = 1;
        }
      });
      // 睡前营养元素
      sleepNutrient.forEach((item) => {
        if (j.title == item.title && j.id == item.id) {
          j.list[6] = 1;
        }
      });
    });
  };

  const updateData = () => {
    let m = month.value > 9 ? month.value : `0${month.value}`;
    let d = signIndex.value + 1 > 9 ? signIndex.value + 1 : `0${signIndex.value + 1}`;
    let t = `${year.value}-${m}-${d}`;
    menuList.value.forEach((item) => {
      if (item.phase_date === t) {
        currentMenu.value = item;
      }
      // 区分颜色
      signInList.value.forEach((j, index) => {
        if (j) {
          // 判断是否能查看
          if (item.phase_date) {
            if (index == item.phase_date.split('-')[2] * 1 - 1) {
              if (item.phase_title == '准备日' && item.send_status) {
                signInList.value[index] = 5;
              } else if (item.phase_title == '装修日' && item.send_status) {
                signInList.value[index] = 6;
              } else if (item.phase_title == '清洁日' && item.send_status) {
                signInList.value[index] = 7;
              } else if (item.phase_title == '装修日') {
                signInList.value[index] = 3;
              } else if (item.phase_title == '清洁日') {
                signInList.value[index] = 4;
              }
            }
          }
        }
      });
    });
    if (currentMenu.value.hint && currentMenu.value.hint.length > 0) {
      let hint = [] as any;
      currentMenu.value.hint.forEach((item) => {
        hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
      });
      currentMenu.value.hint = hint;
    }
    setTimeout(() => {
      if (currentMenu.value.state === 1) {
        d = signIndex.value + 1 > 9 ? signIndex.value + 1 : `0${signIndex.value + 1}`;
        t = `${year.value}-${m}-${d}`;
        menuList.value.forEach((item) => {
          if (item.phase_date === t) {
            currentMenu.value = item;
            menuIndex.value = date.value;
            menuMonth.value = month.value;
          }
        });
      }
      if (currentMenu.value.hint && currentMenu.value.hint.length > 0) {
        let hint = [] as any;
        currentMenu.value.hint.forEach((item) => {
          hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
        });
        currentMenu.value.hint = hint;
      }
      searchingAlreadyHave();
    }, 50);
  };

  // 获取可添加营养素数据
  const getNutrientList = () => {
    weChat({ url: `/h5/get/order/food?chat_id=${userStore.chatId}&is_im=1`, hideLoading: true, method: 'get' })
      .then((res) => {
        const result = res.data;
        initCalendar();
        if (result && result.length > 0) {
          result.forEach((item) => {
            editContentList.value.push({
              title: item.name,
              pic: item.icon,
              id: item.id,
              num: item.num,
              price: item.price,
              unit: item.unit,
              type: item.type,
              list: [0, 0, 0, 0, 0, 0, 0, 0, 0],
            });
            cacheEditContentList.value = JSON.parse(JSON.stringify(editContentList.value));
          });
        }
      })
      .catch((err) => {
        console.log(err);
      });
  };

  // 添加餐单温馨提示
  const addHintAffirm = () => {
    if (!userStore.serviceUserId) {
      showToast('群id对应群或群订单不存在');
      return;
    }
    let cacheCurrentMenu = JSON.parse(JSON.stringify(currentMenu.value));
    let data = {
      chat_id: userStore.chatId,
      phase_date: cacheCurrentMenu.phase_date,
      phase_title: cacheCurrentMenu.phase_title,
      menu: cacheCurrentMenu.menu,
      hint: cacheCurrentMenu.hint,
      is_im: 1,
    };
    if (throttle.value) {
      throttle.value = false;
      weChat({ url: `/h5/guides/${currentMenu.value.id}`, data, method: 'put' })
        .then(() => {
          showAddHint.value = false;
          throttle.value = true;
          showToast('编辑成功');
        })
        .catch((err) => {
          throttle.value = true;
          console.log(err);
        });
    }
  };

  const addMenuAffirm = () => {
    let data = {
      chat_id: userStore.chatId,
      phase_date: time.value,
      type: menuTypeValue.value == '准备日' ? 0 : menuTypeValue.value == '装修日' ? 1 : 2,
      is_im: 1,
    };
    if (!userStore.serviceUserId) {
      showToast('群id对应群或群订单不存在');
      return;
    }
    if (throttle.value) {
      throttle.value = false;
      weChat({ url: `h5/set/user/guide`, data, method: 'post' })
        .then((res) => {
          let result = res.data;
          showAddMenu.value = false;
          throttle.value = true;
          showToast('设置成功');
          currentMenu.value = {
            phase_date: result.phase_date,
            phase_title: result.phase_title,
            id: result.id,
            user_id: result.user_id,
            order_id: result.order_id,
            menu: result.menu,
            hint: [],
          };
          if (result.hint) {
            let hint = [] as any;
            JSON.parse(result.hint).forEach((item) => {
              hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
            });
            currentMenu.value.hint = hint;
          }
          menuList.value.push(currentMenu.value);
          if (result.phase_title == '准备日' && result.send_status) {
            signInList.value[signIndex.value] = 5;
          } else if (result.phase_title == '装修日' && result.send_status) {
            signInList.value[signIndex.value] = 6;
          } else if (result.phase_title == '清洁日' && result.send_status) {
            signInList.value[signIndex.value] = 7;
          } else if (result.phase_title == '装修日') {
            signInList.value[signIndex.value] = 3;
          } else if (result.phase_title == '清洁日') {
            signInList.value[signIndex.value] = 4;
          } else {
            signInList.value[signIndex.value] = 1;
          }
        })
        .catch((err) => {
          throttle.value = true;
          console.log(err);
        });
    }
  };

  // 复制所选日期前一天餐单
  const copyTips = () => {
    let data = {
      chat_id: userStore.chatId,
      phase_date: time.value,
    };
    if (!userStore.serviceUserId) {
      showToast('群id对应群或群订单不存在');
      return;
    }
    showConfirmDialog({
      title: '温馨提示',
      message: `是否为 ${time.value} 复制最近一次餐单？`,
    })
      .then(() => {
        // on confirm
        if (throttle.value) {
          throttle.value = false;
          weChat({ url: `/h5/orders/copy/guide`, data, method: 'post' })
            .then((res) => {
              let result = res.data;
              showToast('餐单已复制');
              throttle.value = true;
              currentMenu.value = {
                phase_date: result.phase_date,
                phase_title: result.phase_title,
                id: result.id,
                user_id: result.user_id,
                order_id: result.order_id,
                menu: result.menu,
                hint: [],
              };
              if (result.hint && result.hint.length > 0) {
                let hint = [] as any;
                result.hint.forEach((item) => {
                  hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
                });
                currentMenu.value.hint = hint;
              }
              menuList.value.push(currentMenu.value);
              if (result.phase_title == '准备日' && result.send_status) {
                signInList.value[signIndex.value] = 5;
              } else if (result.phase_title == '装修日' && result.send_status) {
                signInList.value[signIndex.value] = 6;
              } else if (result.phase_title == '清洁日' && result.send_status) {
                signInList.value[signIndex.value] = 7;
              } else if (result.phase_title == '装修日') {
                signInList.value[signIndex.value] = 3;
              } else if (result.phase_title == '清洁日') {
                signInList.value[signIndex.value] = 4;
              } else {
                signInList.value[signIndex.value] = 1;
              }
            })
            .catch((err) => {
              throttle.value = true;
              console.log(err);
            });
        }
      })
      .catch(() => {});
  };
  // 取消某天的餐单某个元素
  const deleteMenuOne = (dayName, data, dayTime, type) => {
    console.log(data, dayTime, type, '11');
    console.log(currentMenu.value, '22');
    console.log(currentMenu.value.menu[dayTime], '33');
    console.log(currentMenu.value.menu[dayTime][type], '444');
    console.log(currentMenu.value.menu[dayTime][type], '444');

    console.log(currentMenu.value.menu[dayTime][type], '444');
    // showTips.value = true;
    // showDeleteDetail.value = {
    //   title: dayTime,
    //   item,
    // };
    showConfirmDialog({
      title: '温馨提示',
      message: `是否删除${time.value} ${dayName}的${data.title}？`,
    })
      .then((res) => {
        currentMenu.value.menu[dayTime][type] = currentMenu.value.menu[dayTime][type].filter((item) => {
          console.log(item.id, data.id, 'ggg');
          return item.id != data.id;
        });
        submitConfirm();
        // showConfirmDialog({
        //   title: '温馨提示',
        //   message: `是否需要删除已经生成的日餐单中的该食品/营养品？`,
        // }).then((res) => {
        //   console.log('111');
        // });
      })
      .catch(() => {
        console.log('333');
      });
  };

  // 取消某天的餐单
  const deleteMenu = () => {
    let data = {
      chat_id: userStore.chatId,
    };
    showConfirmDialog({
      title: '温馨提示',
      message: `是否取消 ${currentMenu.value.phase_date} 的餐单？`,
    })
      .then(() => {
        // on confirm
        weChat({ url: `/h5/orders/guides/${currentMenu.value.id}`, data, method: 'delete' })
          .then(() => {
            menuList.value.forEach((item, index) => {
              if (item.phase_date == currentMenu.value.phase_date) {
                menuList.value.splice(index, 1);
              }
            });
            currentMenu.value = { state: 1 };
            signInList.value[signIndex.value] = 0;
            showAddMenu.value = false;
            showToast('餐单已取消');
          })
          .catch((err) => {
            console.log(err);
          });
      })
      .catch(() => {});
  };

  // 创建餐单
  const addCondition = (type) => {
    if (isAudit.value == 0) {
      showToast('该用户的餐单模板暂设置');
      return;
    } else if (isAudit.value == 1) {
      showToast('该用户的餐单模板暂未审核');
      return;
    }
    if (type == 0 || type == 1) {
      menuTypeValue.value = currentMenu.value.phase_title ? currentMenu.value.phase_title : '准备日';
      menuTypeList.value[3].show = !currentMenu.value.state;
      if (type == 0) {
        menuEditText.value = '创建';
      } else {
        menuEditText.value = '编辑';
      }
      showAddMenu.value = true;
    } else {
      hintList.value = currentMenu.value.hint;
      showAddHint.value = true;
    }
  };

  // 初始化日期
  const initCalendar = () => {
    currentDate.value = new Date(); // 本地时间
    year.value = currentDate.value.getFullYear(); // 年
    month.value = currentDate.value.getMonth() + 1; // 月
    copyYear.value = currentDate.value.getFullYear(); // 年
    copyMonth.value = currentDate.value.getMonth() + 1; // 月
    date.value = currentDate.value.getDate(); // 今日
    day.value = currentDate.value.getDay() + 1; // 天
    let store = `${year.value}-${month.value}-01`;
    day.value = new Date(store.replace(/-/g, '/')).getDay(); // 当前月份1号在星期几
    if (day.value == 0) {
      nbsp.value = 0;
    } else {
      nbsp.value = day.value;
    }
    getRecipe();
  };

  // 上一月
  const upMonth = () => {
    if (loading.value) {
      showToast('操作频率过快');
      return;
    }
    year.value = month.value < 2 ? year.value - 1 : year.value;
    month.value = month.value < 2 ? 12 : month.value - 1;
    currentDate.value = new Date(year.value, month.value - 1, date.value);
    let store = `${year.value}-${month.value}-01`;
    day.value = new Date(store.replace(/-/g, '/')).getDay(); // 当前月份1号在星期几
    if (day.value == 0) {
      nbsp.value = 0;
    } else {
      nbsp.value = day.value;
    }
    getRecipe();
  };

  // 下一月
  const nextMonth = () => {
    if (loading.value) {
      showToast('操作频率过快');
      return;
    }
    year.value = month.value > 11 ? year.value + 1 : year.value;
    month.value = month.value > 11 ? 1 : month.value + 1;
    currentDate.value = new Date(year.value, month.value - 1, date.value);
    day.value = currentDate.value.getDay() + 1;
    let store = `${year.value}-${month.value}-01`;
    day.value = new Date(store.replace(/-/g, '/')).getDay(); // 当前月份1号在星期几
    if (day.value == 0) {
      nbsp.value = 0;
    } else {
      nbsp.value = day.value;
    }
    getRecipe();
  };

  // 选择日期获取对应餐单
  const getMenu = (item, index, typeDay) => {
    let m = month.value > 9 ? month.value : `0${month.value}`;
    let d = index > 9 ? index : `0${index}`;
    let t = `${year.value}-${m}-${d}`;
    // 所选时间小于当天不能创建餐单
    if (item == 0 && t < intraday.value) {
      showToast('当前日期没有餐单');
      return;
    } else if (t >= intraday.value) {
      time.value = t;
    }
    signIndex.value = index - 1;
    let state = false;
    menuMonth.value = month.value;
    menuIndex.value = index;
    menuList.value.forEach((item) => {
      if (item.phase_date === t) {
        if (typeDay != 'empty') {
          state = true;
          currentMenu.value = item;
          if (item.phase_title == '准备日') {
            selectNutrientList.value = _.cloneDeep(readyNutrientList.value);
          } else if (item.phase_title == '清洁日') {
            selectNutrientList.value = _.cloneDeep(cleanNutrientList.value);
          } else if (item.phase_title == '装修日') {
            selectNutrientList.value = _.cloneDeep(fitmentNutrientList.value);
          }
        }
      }
    });
    if (currentMenu.value.hint && currentMenu.value.hint.length > 0) {
      let hint = [] as any;
      currentMenu.value.hint.forEach((item) => {
        hint.push({ content: item.content ? item.content : item, type: item.type ? item.type : 0 });
      });
      currentMenu.value.hint = hint;
    }
    // 未检测到餐单就展示创建样式
    setTimeout(() => {
      if (!state) {
        currentMenu.value = { state: 1 };
      }
      searchingAlreadyHave();
    }, 100);
  };

  // 设置当天餐单时类型选择
  const selectMenuTypeChange = (e) => {
    if (e.value == '取消餐单') {
      showAddMenu.value = false;
      // 删除当天的餐单
      deleteMenu();
    }
    menuTypeValue.value = e.value;
  };

  const addHint = () => {
    hintList.value.push({ content: '', type: '' });
  };

  const deleteHint = (index) => {
    if (hintList.value.length == 1) {
      showToast('至少保留一条提示');
      return;
    }
    hintList.value.splice(index, 1);
  };

  // 保存编辑的温馨提示
  const verifyHint = () => {
    let state = false;
    hintList.value.forEach((item) => {
      if (!item.content) {
        state = true;
      }
    });
    if (state) {
      showToast('请完善提示内容');
      return;
    }
    currentMenu.value.hint = hintList.value;
    addHintAffirm();
  };
  const selectNutrientList = ref<any[]>([]);
  const readyNutrientList = ref<any>([]);
  const fitmentNutrientList = ref<any>([]);
  const cleanNutrientList = ref<any>([]);
  // 获取餐单模版
  const getGuide = () => {
    requestGo({ url: `/app/server/get/guide/template?chat_id=${userStore.chatId}`, method: 'get' })
      // weChat({ url: `h5/get/guide/template?chat_id=${userStore.chatId}`, method: 'get' })
      .then((res) => {
        let result = res.data.templates;
        console.log(result);
        if (result && result.length > 0) {
          result.forEach((item) => {
            if (item.type == 0) {
              readyNutrientList.value = deleteDuplicate(item.init_guide.list);
              console.log(item.init_guide.hint, '7777');
            } else if (item.type == 1) {
              fitmentNutrientList.value = deleteDuplicate(item.init_guide.list);
            } else {
              cleanNutrientList.value = deleteDuplicate(item.init_guide.list);
            }
          });
          let arr = [] as any;
          setTimeout(() => {
            readyNutrientList.value.forEach((item) => {
              item.oneNum = item.oneNum || 1;
              item.state = 0;
              item.acquiesce = 0;
            });
            fitmentNutrientList.value.forEach((item) => {
              item.oneNum = item.oneNum || 1;
              item.state = 0;
              item.acquiesce = 0;
            });
            cleanNutrientList.value.forEach((item) => {
              item.oneNum = item.oneNum || 1;
              item.state = 0;
              item.acquiesce = 0;
            });
          });
          // selectNutrientList.value = readyNutrientList.value;
        } else {
          schemeStatus.value = '0';
        }
        getNutrientList();
      })
      .catch((err) => {
        console.log(err);
      });
  };

  // 去除重复数据
  const deleteDuplicate = (e) => {
    if (e && e.length > 0) {
      e.forEach((i) => {
        if (i.config && i.config.length > 0) {
          let arr = i.config.map((item) => {
            return item.time;
          });
          i.config = i.config.filter((item, index) => {
            return arr.indexOf(item.time) == index;
          });
        }
      });
    }
    return e;
  };
  // 展示
  const dateName = ref('');
  const toShowTip = (name) => {
    dateName.value = name;
    currentMenu.value.menu[name].food;
    currentMenu.value.menu[name].nutrient;
    selectNutrientList.value = selectNutrientList.value.map((item) => {
      currentMenu.value.menu[name].food.map((itemV2) => {
        console.log(itemV2);
        if (itemV2.title == item.name) {
          item.state = 1;
          item.config = [
            {
              acquiesce: 1,
              oneNum: itemV2.oneNum,
              sku_id: 1,
              state: 1,
              time: dateName.value,
            },
          ];
        }
      });
      currentMenu.value.menu[name].nutrient.map((itemV2) => {
        console.log(itemV2);
        if (itemV2.title == item.name) {
          item.state = 1;
          item.config = [
            {
              acquiesce: 1,
              oneNum: itemV2.oneNum,
              sku_id: 1,
              state: 1,
              time: dateName.value,
            },
          ];
        }
      });
      if (!item.state) {
        item.config = [
          {
            acquiesce: 1,
            oneNum: item.oneNum,
            sku_id: 1,
            state: 1,
            time: dateName.value,
          },
        ];
      }
      return item;
    });
    console.log(selectNutrientList.value, 'vvv');
    showTips.value = true;
  };
  // 选择营养元素或食物
  const selectNutrientV = (e, index) => {
    console.log('222');
    if (e.state == 0) {
      console.log('3333');
      e.state = 1;
      // if (selectNutrientList.value[index].config && selectNutrientList.value[index].config.length) {
      //   let setatus = false;
      //   let setatusIdx = 0;
      //   selectNutrientList.value[index].config.forEach((item, idx) => {
      //     if (item.time == dateName.value) {
      //       setatus = true;
      //       setatusIdx = idx;
      //     }
      //     // if (item.acquiesce) {
      //     //   item.state = 1;
      //     // } else {
      //     //   selectNutrientList.value[index].config.splice(idx, 1);
      //     // }
      //   });
      //   if (setatus) {
      //     selectNutrientList.value[index].config.push({});
      //   } else {
      //     selectNutrientList.value[index].config.splice(setatusIdx, 1);
      //   }
      // }
    } else {
      e.state = 0;
      //   if (selectNutrientList.value[index].config && selectNutrientList.value[index].config.length) {
      //     selectNutrientList.value[index].config.forEach((item) => {
      //       item.state = 0;
      //     });
      //   }
    }
    // assignment();
  };
  // 增加营养元素或食物数量
  const addNutrientChange = (e) => {
    selectNutrientList.value.forEach((item) => {
      if (item.id == e.id && item.config && item.config.length > 0) {
        item.config.forEach((j) => {
          if (e.time == j.time) {
            j.oneNum++;
          }
        });
      }
    });
  };

  // 减少营养元素或食物数量
  const minusNutrientChange = (e) => {
    if (e.oneNum - 1 <= 0) {
      return;
    }
    selectNutrientList.value.forEach((item) => {
      if (item.id == e.id && item.config && item.config.length > 0) {
        item.config.forEach((j) => {
          if (e.time == j.time) {
            j.oneNum--;
          }
        });
      }
    });
  };

  // 监听输入的数量改变对应的数据
  // 辅助函数：确保值是 0.5 的倍数
  const toHalfMultiple = (value) => {
    const num = parseFloat(value);
    if (isNaN(num)) return 0;
    // 四舍五入到最近的 0.5 倍数
    return Math.round(num * 2) / 2;
  };

  // 修改后的方法
  const changeMenuNum = (e, row) => {
    // 将输入值转换为数字并限制为 0.5 的倍数
    let newValue = toHalfMultiple(e);

    // 可选：添加边界限制（不能小于0）
    if (newValue < 0) {
      newValue = 0;
    }

    selectNutrientList.value.forEach((item) => {
      if (item.id == row.id && item.config && item.config.length > 0) {
        item.config.forEach((j) => {
          if (row.time == j.time) {
            j.oneNum = newValue;
          }
        });
      }
    });
    // assignment();
  };

  const showMenuList = (e) => {
    let menuList = [
      { title: '早餐前', time: 'beforeMorning', config: [] },
      { title: '早餐', time: 'morning', config: [] },
      { title: '上午', time: 'forenoon', config: [] },
      { title: '午餐前', time: 'beforeNoon', config: [] },
      { title: '午餐', time: 'noon', config: [] },
      { title: '下午', time: 'afternoon', config: [] },
      { title: '晚餐前', time: 'midnight', config: [] },
      { title: '晚餐', time: 'evening', config: [] },
      { title: '睡前', time: 'sleep', config: [] },
    ] as any;
    menuList.filter((item) => {
      return item.time == dateName.value;
    });

    if (e && e.length > 0) {
      e.forEach((item) => {
        if (item.state) {
          item.config.forEach((j) => {
            menuList.forEach((i) => {
              if (j.time == i.time) {
                i.config.push({
                  time: j.time,
                  oneNum: j.oneNum,
                  state: j.state,
                  unit: item.unit,
                  name: item.name,
                  icon: item.icon,
                  id: item.id,
                  type: item.type,
                  number: item.num || 0,
                  title: item.title,
                  price: item.price,
                });
              }
            });
          });
        }
      });
    }
    return menuList;
  };
  const comfirnDeleteOneMenu = () => {
    console.log(selectNutrientList.value, '333');
    console.log(showMenuList(selectNutrientList.value), '333');
    showMenuList(selectNutrientList.value).map((item) => {
      if (item.time == dateName.value) {
        item.food = item.config.filter((itemV2) => {
          console.log(itemV2.type, 'type');
          return itemV2.type == 'FOOD';
        });

        item.nutrient = item.config.filter((itemV2) => {
          console.log(itemV2.type, 'type');
          return itemV2.type == 'NUTRIENT';
        });
        console.log(item.food, item.nutrient);
        item.food = item.food.map((itemV2) => {
          console.log(itemV2, 'vvv');
          return {
            id: itemV2.id,
            number: itemV2.number,
            oneNum: itemV2.oneNum,
            pic: itemV2.icon,
            price: itemV2.price,
            title: itemV2.name,
            unit: itemV2.unit,
          };
        });
        item.nutrient = item.nutrient.map((itemV2) => {
          console.log(itemV2, 'vvv');
          return {
            id: itemV2.id,
            number: itemV2.number,
            oneNum: itemV2.oneNum,
            pic: itemV2.icon,
            price: itemV2.price,
            title: itemV2.name,
            unit: itemV2.unit,
          };
        });
        currentMenu.value.menu[dateName.value].food = item.food;
        currentMenu.value.menu[dateName.value].nutrient = item.nutrient;
      }
    });
    console.log(dateName.value, '333ff');
    console.log(currentMenu.value.menu, '333ff');
    console.log(currentMenu.value.menu[dateName.value], '333ff');

    submitConfirm();
  };
  // 修改餐单
  const submitConfirm = () => {
    let data = {
      hint: JSON.stringify(currentMenu.value.hint),
      menu: JSON.stringify(currentMenu.value.menu),
    };
    requestGo({ url: `app/user/update/date/guide/${currentMenu.value.id}`, method: 'put', data }).then((res) => {
      console.log('123');
      showTips.value = false;
    });
  };
  onMounted(() => {
    let route = router.currentRoute.value.query;
    let standing = route.role as any;
    let chiefCoach = false; // 是否主教练身份
    let viceCoach = false; // 是否副教练身份
    let service = false; // 是否客服身份
    if (standing) {
      standing.split(',').forEach((item) => {
        if (item == '1') {
          chiefCoach = true;
          showDeleteClick.value = true;
        }
        if (item == '2') {
          viceCoach = true;
          showDeleteClick.value = true;
        }
        if (item == '3') {
          service = true;
          showDeleteClick.value = true;
        }
      });
      if (chiefCoach) {
        role.value = 1;
      } else if (service) {
        role.value = 3;
      } else if (viceCoach) {
        role.value = 2;
      }
    }
    if (route.order_id) {
      orderId.value = route.order_id;
    }
    // 日志类型
    if (route.key) {
      logKey.value = route.key;
      controlsTabIndex.value = 0;
      logTypes.value.forEach((item, index) => {
        if (item.type == route.key) {
          logTypeIndex.value = index;
        }
      });
    }
    if (route.chat_id) {
      userStore.chatId = route.chat_id;
    }
    let date = new Date();
    let m = date.getMonth() + 1 > 9 ? `${date.getMonth() + 1}` : `0${date.getMonth() + 1}`;
    let d = date.getDate() > 9 ? `${date.getDate()}` : `0${date.getDate()}`;
    intraday.value = `${date.getFullYear()}-${m}-${d}`;
    time.value = `${date.getFullYear()}-${m}-${d}`;
    // 获取日志
    getLog();
    if (showDeleteClick.value) {
      getGuide();
    } else {
      getNutrientList();
    }
  });
</script>
<style lang="scss">
  .ui-appUserMenu {
    .van-popup {
      overflow-y: initial;
    }
  }
</style>
<style lang="scss" scoped>
  .ui-appUserMenu {
    background: #f8f8f8;
    overflow-y: auto;
    height: 100vh;
  }

  .theme {
    color: #18ca6e;
  }

  .ui-menu-date-box {
    padding: 0 0 px2rem(260) 0;

    .ui-not-start {
      padding: px2rem(30);
      background: #ffffff;
      border-radius: px2rem(24);
      margin-top: px2rem(20);
      margin-bottom: px2rem(50);

      .ui-nutrient-item {
        margin-bottom: px2rem(28);
      }

      .ui-nutrient_icon {
        width: px2rem(40);
        height: px2rem(40);
        display: block;
        margin-right: px2rem(16);
        border-radius: px2rem(8);
        object-fit: cover;
        object-position: center;
      }

      .ui-not-start_icon {
        width: px2rem(140);
        height: px2rem(132);
        display: block;
        margin: px2rem(10) auto px2rem(20) auto;
      }
    }

    .ui-calendar-box {
      height: 100%;
      padding: 0 px2rem(30);
      background: #ffffff;
      border-radius: 0 0 px2rem(32) px2rem(32);
      margin-bottom: px2rem(32);

      .ui-calendar-date {
        background: linear-gradient(to bottom, #f8f8f8 0%, #ffffff 100%);
        height: px2rem(154);
        border-radius: px2rem(32) px2rem(32) 0 0;
        margin-bottom: px2rem(40);

        .calendar_title {
          padding: 0 px2rem(20);
          height: px2rem(94);

          .triangle_icon,
          .triangle_icon_v2 {
            width: px2rem(54);
            height: px2rem(54);
            display: block;
          }
        }

        .week_box {
          display: flex;
          justify-content: space-between;
          flex-wrap: wrap;
          padding-top: px2rem(20);

          .week_num {
            width: 14.2%;
          }
        }
      }

      .calendar_day {
        display: flex;
        justify-content: space-between;
        flex-wrap: wrap;

        .day_number {
          width: 14.2%;
          padding-bottom: px2rem(26);

          .ui-toDay-icon {
            width: px2rem(32);
            height: px2rem(32);
            position: absolute;
            z-index: 2;
            top: px2rem(-2);
            right: px2rem(10);
            object-fit: cover;
            object-position: center;
          }

          .ui-right-icon {
            width: px2rem(24);
            height: px2rem(22);
            position: absolute;
            z-index: 2;
            top: px2rem(2);
            right: px2rem(16);
            object-fit: cover;
            object-position: center;
          }

          .number_box {
            width: px2rem(76);
            height: px2rem(88);
            border-radius: px2rem(12);
            background: #ffffff;
            margin: 0 auto;

            .ui-text-pt {
              padding-top: px2rem(2);
            }
          }

          .menu {
            color: #ffa949;
            background: #ffeedb;
          }

          .menuV2 {
            color: #8670ff;
            background: #f3f1ff;
          }

          .menuV3 {
            color: #18ca6e;
            background: #e2fcee;
          }

          .ui-select-menu-one {
            color: #ffffff;
            background: #ffa949;
          }

          .ui-select-menu-two {
            color: #ffffff;
            background: #9679ff;
          }

          .ui-select-menu-three {
            color: #ffffff;
            background: #18ca6e;
          }
        }
      }

      .calendar_day:after {
        content: '';
        flex: auto;
      }
    }

    .ui-controls-item {
      width: px2rem(172);
      height: px2rem(76);

      .ui-controls-bottom-line {
        width: px2rem(36);
        height: px2rem(8);
        border-radius: px2rem(36);
        position: absolute;
        bottom: 0;
        left: 50%;
        transform: translateX(-50%);
      }
    }

    .ui-controls-item-mb {
      margin-bottom: px2rem(-4);
    }

    .ui-log-type-box {
      padding: px2rem(32) 0 0 px2rem(32);
      border-radius: px2rem(32) px2rem(32) 0 0;
      background: #ffffff;
      display: flex;
      justify-content: left;
      overflow-x: scroll;
      white-space: nowrap;

      .ui-log-type-item {
        width: fit-content;
        background: #f8f8f8;
        padding: px2rem(12) px2rem(28);
        border-radius: px2rem(50);
      }

      .ui-act-log {
        background: #18ca6e;
      }
    }

    .ui-log-type-box::-webkit-scrollbar {
      display: none;
    }

    .ui-condition-box {
      padding: px2rem(32);
      background: #ffffff;
      border-radius: 0 0 px2rem(32) px2rem(32);

      .ui-condition-line {
        border-bottom: px2rem(2) solid #f8f8f8;
        margin-bottom: px2rem(40);
      }
    }

    .ui-no-controls-icon {
      width: px2rem(240);
      height: px2rem(232);
      display: block;
      margin: px2rem(40) auto px2rem(80) auto;
    }

    .ui-triangle-box {
      padding: 0 px2rem(30) px2rem(20) px2rem(30);
      background: #ffffff;
      border-radius: 0 0 px2rem(24) px2rem(24);
      margin-bottom: px2rem(20);
      margin-top: px2rem(-10);

      .ui-triangle-icon {
        width: px2rem(20);
        height: px2rem(12);
        display: block;
        margin-left: px2rem(12);
      }
    }

    .ui-menu-edit-btn {
      position: fixed;
      bottom: px2rem(60);
      left: 50%;
      transform: translateX(-50%);
      width: px2rem(686);
      height: px2rem(100);
      background: #18ca6e;
      border-radius: px2rem(50);
      z-index: 5;
    }

    .ui-menu-no-data-box {
      padding: px2rem(120) px2rem(20);
      background: #ffffff;
      border-radius: px2rem(32);

      .ui-not-start_icon {
        width: px2rem(140);
        height: px2rem(132);
        display: block;
        margin: 0 auto px2rem(30) auto;
      }
    }

    .ui-menu-hint {
      padding: px2rem(32) px2rem(32) px2rem(60) px2rem(32);
      border-radius: px2rem(32) px2rem(32) 0 0;
      margin-bottom: px2rem(-28);

      .ui-menu-hint-icon {
        width: px2rem(262);
        height: px2rem(188);
        position: absolute;
        right: 0;
        top: 0;
      }
    }

    .ui-menu-box {
      padding: 0 px2rem(20);
      background: #ffffff;
      border-radius: px2rem(32);
      position: relative;
      z-index: 2;
      margin-bottom: px2rem(32);

      .ui-switch-box {
        position: absolute;
        right: px2rem(20);
        top: px2rem(36);
      }

      .ui-menu-pb {
        padding: px2rem(32) 0;
      }

      .ui-menu-pb-v2 {
        padding: px2rem(16) 0;
      }

      .ui-menu-item {
        border-bottom: px2rem(2) solid #f8f8f8;
        padding-bottom: px2rem(12);
        margin-bottom: px2rem(-8);

        .ui-menu-item-add {
          font-size: 14px;
        }

        .ui-menu-add-box {
          width: px2rem(112);
          height: px2rem(40);
          border-radius: px2rem(22);
          border: px2rem(2) solid #b2e3d2;

          .ui-add-icon {
            width: px2rem(20);
            height: px2rem(20);
            display: block;
            margin-right: px2rem(4);
          }
        }
      }

      .ui-menu-data {
        padding-top: px2rem(20);

        .ui-menu-pic {
          width: px2rem(48);
          height: px2rem(48);
          display: block;
          border-radius: px2rem(8);
          margin-right: px2rem(16);
          object-position: center;
          object-fit: cover;
        }
      }

      .ui-menu-item-v2 {
        padding-bottom: px2rem(12);
      }

      .ui-menu-data-v2 {
        padding-top: px2rem(12);

        .ui-menu-pic-v2 {
          width: px2rem(326);
          height: px2rem(326);
          display: block;
          border-radius: px2rem(20);
          object-position: center;
          object-fit: cover;
        }

        .ui-menu-mask {
          width: px2rem(326);
          min-height: px2rem(134);
          max-height: px2rem(176);
          margin-top: px2rem(-60);
          box-sizing: border-box;
          padding: px2rem(20);
          border-radius: px2rem(20) px2rem(20) 0 0;
          background: rgba(255, 255, 255, 0.8);
          position: relative;
          z-index: 2;
        }
      }
    }
  }

  .ui-hint-box {
    padding: px2rem(30);
    background: #ffffff;
    border-radius: px2rem(24);

    .ui-hint-item {
      overflow: hidden;
    }

    .ui-hint-iconV2 {
      min-width: px2rem(32);
      max-width: px2rem(32);
      height: px2rem(32);
      display: block;
      margin-right: px2rem(8);
      margin-top: px2rem(2);
    }

    .ui-hint-text {
      white-space: pre-wrap;
      word-wrap: break-word;
      word-break: normal;
    }

    .ui-line {
      width: 100%;
      height: px2rem(2);
      margin: px2rem(24) 0;
      background: #f8f8f8;
    }
  }

  .ui-add-box {
    padding-top: px2rem(32);
    background: #ffffff;
    border-radius: px2rem(24);

    .ui-hint-edit-box {
      max-height: px2rem(600);
      overflow-y: scroll;
    }

    .ui-add-close-icon {
      width: px2rem(52);
      height: px2rem(52);
      position: absolute;
      right: px2rem(20);
      top: px2rem(20);
    }

    .ui-add-title {
      padding-bottom: px2rem(40);
    }

    .ui-add-hint-input {
      padding: px2rem(8) px2rem(20);
      min-height: px2rem(72);
      border-radius: px2rem(16);
      line-height: px2rem(40);
      border: px2rem(2) solid #f8f8f8;
    }

    .ui-add-controls-btn,
    .ui-add-controls-btn-v2 {
      min-width: px2rem(88);
      height: px2rem(54);
      border: px2rem(2) solid #ff5959;
      border-radius: px2rem(12);
      color: #ff5959;
      margin-left: px2rem(12);
    }

    .ui-add-controls-btn-v2 {
      color: #5ac7a0;
      border: px2rem(2) solid #5ac7a0;
    }

    textarea::-webkit-input-placeholder {
      color: #999999;
    }

    // 去除默认下划线
    ::v-deep(.van-cell:after) {
      position: relative;
    }

    .ui-item-select {
      width: px2rem(210);
      height: px2rem(86);
      border-radius: px2rem(20);
      border: px2rem(2) solid #f8f8f8;
      margin-right: px2rem(14);

      .ui-select-icon {
        width: px2rem(32);
        height: px2rem(32);
        position: absolute;
        top: px2rem(6);
        right: px2rem(18);
      }
    }

    .ui-item-select-act {
      background: #f0fff7;
      border: px2rem(2) solid #f0fff7;
      color: #18ca6e;
    }

    .ui-select-input-box {
      width: px2rem(642);
      height: px2rem(110);
      background: #f8f8f8;
      border: px2rem(2) solid #f8f8f8;
      border-radius: px2rem(20);
      padding-left: px2rem(24);
      margin-bottom: px2rem(40);
    }

    .ui-select-input {
      width: px2rem(300);
      padding: 0;
      background: initial;
      border-radius: px2rem(20);
    }

    .ui-btn-box {
      width: 100vw;
      height: px2rem(114);
      border-top: px2rem(12) solid #f8f8f8;

      .ui-btn,
      .ui-btn-v2 {
        width: px2rem(192);
        height: px2rem(68);
        border-radius: px2rem(34);
        margin-top: px2rem(74);
      }

      .ui-btn {
        border: px2rem(2) solid #d8d8d8;
      }

      .ui-btn-v2 {
        background: #5ac7a0;
        border-radius: px2rem(34);
        border: px2rem(2) solid #5ac7a0;
      }
    }
  }

  .ui-edit-box {
    position: relative;
    padding: px2rem(30) px2rem(24) px2rem(160) px2rem(24);
    background: #ffffff;
    border-radius: px2rem(24);

    .ui-close-icon {
      position: absolute;
      right: px2rem(30);
      top: px2rem(30);
      z-index: 22;
      width: px2rem(28);
      height: px2rem(28);
    }

    .ui-select-head {
      height: px2rem(84);
      background: #e9f9f6;
      margin-top: px2rem(30);
      border-radius: px2rem(24) px2rem(24) 0 0;
      border-bottom: px2rem(2) solid #eeeeee;

      .ui-select-name {
        height: px2rem(84);
      }
    }

    .ui-select-right-border {
      border-right: px2rem(2) solid #eeeeee;
    }

    .ui-select-top-border {
      border-top: px2rem(2) solid #eeeeee;
    }

    .ui-select-box {
      width: 100%;
      background: linear-gradient(180deg, #edfff9 0%, #f9fffd 47%, #ffffff 100%);
      max-height: calc(80vh - 20vh);
      overflow-x: hidden;
      overflow-y: auto;

      .ui-select-placeholder {
        width: 100%;
        height: px2rem(84);
      }

      .ui-select-content {
        overflow: hidden;
        background: linear-gradient(180deg, #edfff9 0%, #ffffff 100%);
      }

      .ui-select-name-v2 {
        padding: px2rem(12) 0;
        width: 24.4%;
      }

      .ui-select-icon-box {
        width: 10.8%;

        .ui-select-icon {
          width: px2rem(36);
          height: px2rem(36);
          display: block;
          margin: auto;
          position: relative;
          z-index: 102;
        }
      }

      .ui-select-line {
        width: 100%;
        height: px2rem(200);
        border-right: px2rem(2) solid #eeeeee;
        position: absolute;
        right: px2rem(-2);
        top: px2rem(-20);
      }
    }

    .ui-edit-confirm-btn {
      position: absolute;
      bottom: px2rem(50);
      left: 50%;
      transform: translateX(-50%);
      width: px2rem(560);
      height: px2rem(80);
      background: #5ac7a0;
      border-radius: px2rem(40);
    }
  }

  .ui-view-image-title {
    position: fixed;
    top: px2rem(20);
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
  }

  .ui-view-image-name {
    width: fit-content;
    padding: 0 px2rem(30);
    position: fixed;
    bottom: px2rem(120);
    left: 50%;
    transform: translateX(-50%);
    z-index: 999;
  }
  .ui-right-btn {
    display: block;
    height: 25px;
    margin-top: 10px;
    margin-left: 15px;
  }
  .ui-tips-box {
    position: relative;
    width: px2rem(600);
    padding-top: px2rem(62);
    background: #ffffff;
    border-radius: px2rem(24);

    .ui-tips-list {
      overflow-y: scroll;
      max-height: 500px;
    }
    .ui-btn-box {
      .ui-btn,
      .ui-btn-v2 {
        border-top: px2rem(2) solid #f5f5f5;
        width: 49.9%;
        height: px2rem(90);
      }

      .ui-btn-v2 {
        border-left: px2rem(2) solid #f5f5f5;
      }
    }
  }

  .ui-nutrient-box {
    padding: 0 px2rem(30) px2rem(40) px2rem(30);
    border-bottom: px2rem(10) solid #f8f8f8;

    .ui-symptom-item {
      margin: px2rem(40) px2rem(30) 0 0;

      .ui-nutrient-icon {
        width: px2rem(36);
        height: px2rem(36);
        display: block;
        margin-right: px2rem(10);
      }
    }
  }

  .ui-menu-num-box {
    padding: 0 px2rem(30);

    .ui-menu-num-line {
      border-bottom: px2rem(2) solid #f5f5f5;
    }

    .ui-select-nutrient-icon {
      width: px2rem(80);
      height: px2rem(80);
      border-radius: px2rem(8);
      display: block;
      object-fit: cover;
      object-position: center;
      margin-right: px2rem(16);
    }

    .ui-select-nutrient-name {
      max-width: px2rem(260);
      padding-bottom: px2rem(2);
    }

    .ui-stepper-box {
      width: px2rem(162);
      height: px2rem(52);
      padding: 0 px2rem(20);
      border-radius: px2rem(30);
      border: px2rem(2) solid #ececec;
      position: relative;

      .ui-stepper-icon {
        width: px2rem(24);
        height: px2rem(24);
        display: block;
      }

      .ui-stepper-input-box {
        width: px2rem(80);
        height: px2rem(52);
        border-left: px2rem(2) solid #ececec;
        border-right: px2rem(2) solid #ececec;

        .ui-stepper-input {
          border: initial;
          padding: initial;
          background: none;
        }

        ::v-deep(.van-field__control) {
          text-align: center;
        }
      }
    }

    ::v-deep(.van-cell) {
      padding: initial !important;
    }
  }
</style>
