<template>
  <view class="container">
    <view class="content">
      <view class="floot" v-if="showCont" v-for="(item, index) in details" :key="index">
        <view class="floot_title colorCustom">{{item.PrescribeTypeName}}</view>
        <view class="floot_box">
          <view class="flootBox_item border_top" v-for="(detailsItem, subIndex) in item.Data_1" :key="subIndex">
            <view class="name">{{detailsItem.Project}}</view>
            <view>
              <text class="text">用药计量:{{detailsItem.OneDose}}{{detailsItem.OneDoseUnit}}</text>
              <text class="text">用药天数:{{detailsItem.DosageDays}}天</text>
              <text class="text">用药频次:{{detailsItem.UsageName}}</text>
            </view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>

<script setup lang="ts">
import { ref, getCurrentInstance } from 'vue';
import { useOnLoad } from '@dcloudio/uni-app';
import { common } from '@/utils';
import { queryInpatientDocAdviceList } from '@/pagesPatient/service/record';

const { proxy } = getCurrentInstance() as any;
const app = getApp();

const showCont = ref(false);
const details = ref<any[]>([]);

useOnLoad((options: any) => {
  let currentUser = app.globalData.currentUser;
  let queryBean: any = {};
  
  if (options.queryBean) {
    try {
      queryBean = JSON.parse(options.queryBean);
    } catch (e) {
      console.error('JSON parse error:', e);
    }
  }
  
  main(currentUser, queryBean);
});

const main = async (currentUser: any, queryBean: any) => {
  let reqData = {
    hosId: app.globalData.districtId || app.globalData.hosId,
    CardNo: queryBean.CardNo,
    CardType: currentUser.cardType,
    MemberId: currentUser.memberId,
    Store: {
      cardEncryptionStore: currentUser.encryptionStore || '',
      baseMemberEncryptionStore: currentUser.baseMemberEncryptionStore
    }
  };
  
  let { resp } = await queryInpatientDocAdviceList(reqData);
  if (common.isNotEmpty(resp)) {
    details.value = resp;
    showCont.value = true;
  }
};
</script>

<style lang="scss">
.floot {
  border-radius: 24upx;
  background: #fff;
  padding: 0 30upx;
  margin: 30upx;
}
.floot_title {
  font-size: 36upx;
  padding: 32upx 0;
}
.flootBox_item {
  padding: 35upx 0;
}
.name {
  font-size: 32upx;
  color: #333;
  margin-bottom: 18upx;
}
.text {
  font-size: 24upx;
  color: #999;
  margin-right: 15upx;
}
</style>
