<template>
  <view>
	  <nav-bar :navbarData="navbarData"></nav-bar>
    <view :style="'margin-top: ' + (height * 2 - 10) + 'rpx; height: calc(100vh - ' + (height * 2 - 2) + 'rpx)'">
      <view class="content" :style="editFlag !== 'E' ? 'height:95%' : ''">
        <view class="elementitem" v-for="(item, index) in elementData" :key="index">
          <van-row class="item">
            <van-col 
              v-if="item.hideTitle !== 'Y'" 
              :span="item.elementTypeCode === 'Label' ? '24' : '9'"
              :class="item.elementTypeCode === 'Label' ? 'title' : 'itemtitle'"
            >
              <view :class="item.elementTypeCode === 'Label' ? 'title' : ''">
                <view v-if="item.elementTypeCode === 'Label'" class="border"></view>
                <view>{{ item.IEMRTempElementDesc }}{{ item.elementTypeCode === 'Label' ? '' : '：' }}</view>
              </view>
            </van-col>
            <van-col :span="item.hideTitle !== 'Y' ? '15' : 24" class="itemdata">
              <view v-if="item.elementTypeCode === 'Input'" class="inputclass">
                <van-field 
                  :data-dataindex="index" 
                  v-model="item.IEMRTempElementData"
                  :disable-default-padding="false" 
                  title-width="0" 
                  type="text"
                  @change="(val) => inputOnChange(val, { dataindex: index })" 
                  autosize 
                  :border="false"
                  :placeholder="item.addItemFlag === 'Y' ? '总和' : '请输入'"
                  :disabled="item.disable === 'Y'" 
                  @blur="(val) => inputOnBlur(val, { dataindex: index })"
                  style="margin-top: 6px"
                ></van-field>
              </view>
              
              <view v-if="item.elementTypeCode === 'ScanCode'" class="scanCodeclass">
                <view 
                  :class="item.IEMRTempElementData === '腕带核对正确' ? 'scanViewColor_green' : 'scanViewColor_red'"
                >
                  {{ item.IEMRTempElementData }}
                </view>
                <image 
                  v-if="item.IEMRTempElementData !== '腕带核对正确'"
                  :src="imgDomain + '/images/icon/ydhl_scanBlue.png'" 
                  :data-dataindex="index"
                  class="custom-icon" 
				  @tap="(e) => inputScanOnChange(e, { dataindex: index })"
                />
              </view>
              
              <view v-if="item.elementTypeCode === 'Labelarea'" class="areaclass">
                <van-field 
                  :data-dataindex="index" 
                  v-model="item.IEMRTempElementData"
                  :disable-default-padding="false" 
                  title-width="0" 
                  type="textarea"
                  @change="(val) => inputOnChange(val, { dataindex: index })" 
                  autosize 
                  :border="false"
                  placeholder="请输入" 
                  :disabled="item.disable === 'Y'"
                ></van-field>
              </view>
              
              <view v-if="item.elementTypeCode === 'ComboBox'" class="comboboxclass">
                <van-row>
                  <checkbox-group @change="checkChange" :data-dataindex="index">
                    <view class="radio-container">
                      <view 
                        v-for="(checkitem, checkid) in item.elmentData"
                        :span="checkitem.descripts.length > 4 ? 24 : 12" 
                        :key="checkid"
                        style="border-bottom:1px solid #e4e5e4" 
                        :class="checkitem.descripts.length > 4 ? 'rowitem2' : 'rowitem'"
                      >
                        <checkbox 
                          :value="checkitem.descripts" 
                          shape="square"
                          :disabled="item.disable === 'Y'"
                          :checked="getCheckFlag(item.IEMRTempElementData, checkitem.descripts)"
                        >
                          {{checkitem.descripts}}
                        </checkbox>
                      </view>
                    </view>
                  </checkbox-group>
                </van-row>
              </view>
              
              <view v-if="item.elementTypeCode === 'RadioBox'" class="radioboxclass">
                <van-row>
                  <radio-group @change="checkChange" :data-dataindex="index">
                    <view class="radio-container">
                      <view 
                        v-for="(checkitem, checkid) in item.elmentData" 
                        :key="checkid"
                        :class="checkitem.descripts.length > 4 ? 'rowitem2' : 'rowitem'"
                      >
                        <radio 
                          :value="checkitem.descripts"
                          :checked="item.IEMRTempElementData.value === checkitem.descripts || item.IEMRTempElementData === checkitem.descripts"
                        >
                          {{checkitem.descripts}}
                        </radio>
                      </view>
                    </view>
                  </radio-group>
                </van-row>
              </view>
              
              <view v-if="item.elementTypeCode === 'Select'" class="selectclass">
                <van-cell 
                  :is-link="item.IEMRTempElementData === ''" 
                  arrow-direction="down"
                  :value="item.IEMRTempElementData" 
                  :border="false" 
                  :data-dataindex="index"
                  @tap="(e) => selectItem(e, { dataindex: index })"
                >
					<span>{{item.IEMRTempElementData}}</span>
                  <van-icon 
                    v-if="item.IEMRTempElementData !== '' && item.disable !== 'Y'" 
                    name="cross"
                    slot="right-icon" 
                    custom-class="delicon" 
                    :data-dataindex="index"
                    @tap.stop.prevent="(e) => deleteData(e, { dataindex: index })"
                  ></van-icon>
                </van-cell>
              </view>
              
              <view v-if="item.elementTypeCode === 'MultipleSelect'" class="selectclass">
                <van-cell 
                  is-link 
                  arrow-direction="down" 
                  :value="getData(item.IEMRTempElementData)"
                  :border="false" 
                  :data-dataindex="index"
                  @tap="(e) => multipleSelectItem(e, { dataindex: index })" 
                />
              </view>
              
              <view v-if="item.elementTypeCode === 'Date'" class="dateclass">
                <van-field 
                  v-model="item.IEMRTempElementData" 
                  :data-dataindex="index" 
                  placeholder="请输入日期"
                  @change="(val) => handleInput(val, { dataindex: index },'data')"  
                  data-title="请输入日期"
                  :disabled="item.disable === 'Y'" 
                />
              </view>
              
              <view v-if="item.elementTypeCode === 'Time'" class="dateclass">
                <van-field 
                  v-model="item.IEMRTempElementData" 
                  :data-dataindex="index" 
                  placeholder="请输入时间"
                  @change="(val) => handleInput(val, { dataindex: index },'time')"  
                  data-title="请输入时间"
                  :disabled="item.disable === 'Y'" 
                />
              </view>
              
              <view v-if="item.elementTypeCode === 'DateTime'" class="dateclass">
                <van-field 
                  v-model="item.IEMRTempElementData"  
                  :data-dataindex="index" 
                  placeholder="请输入日期时间"
                  @change="(val) => handleInput(val, { dataindex: index },'datatime')"  
                  data-title="请输入日期时间"
                  :disabled="item.disable === 'Y'"
                />
              </view>
            </van-col>
          </van-row>
        </view>
      </view>
      
      <view class="multiBtn-content" v-if="editFlag === 'E'">
        <button class="multiBtn-right" @tap="addRecord">保存</button>
      </view>
    </view>
    
    <van-action-sheet 
      :show="actionShow" 
      :actions="selectData" 
      @close="onClose" 
      @cancel="onClose" 
      @select="onSelect"
      cancel-text="取消" 
    />
    
    <van-action-sheet 
      :show="mutilCheckshow" 
      title="请选择" 
      @close="onClose" 
      @cancel="onClose"
    >
      <view class="mutilCheck">
        <view class="checkData">
          <view 
            span="8" 
            class="checkitem"
            :style="'background:' + multicheckitem.color + '; border-color:' + multicheckitem.color + ';color:' + (multicheckitem.checked ? '#fff' : '#333')"
            :data-index="multicheckid" 
            @tap="multiItemCheck"
            v-for="(multicheckitem, multicheckid) in selectData" 
            :key="multicheckid"
          >
            {{ multicheckitem.descripts }}
          </view>
        </view>
        <view>
          <view class="multiBtn-content">
            <button class="multiBtn-left" @tap="onClose">取消</button>
            <button class="multiBtn-right" @tap="onConfirmMultiCheck">保存</button>
          </view>
        </view>
      </view>
    </van-action-sheet>
  </view>
</template>

<script setup>
import { ref, onMounted, computed, defineExpose } from 'vue';
import { $http } from '../../config/https';
import { onLoad ,onShow } from '@dcloudio/uni-app';
import navBar from '@/pages/components/navbar/index';

// 状态定义
const height = ref('');
const templateID = ref('');
const newFlag = ref('0');
const elementData = ref([]);
const selectData = ref([]);
const actionShow = ref(false);
const mutilCheckshow = ref(false);
const datetype = ref('date');
const timeActionShow = ref(false);
const timeTitle = ref('');
const clickIndex = ref('-1');
const currentDate = ref(getCurrentDateTime());
const multiCheckData = ref([]);
const admID_SM = ref('');
const patID_SM = ref('');
const editFlag = ref('');
const checkitem = ref({ descripts: [] });
const checkid = ref(false);
const multicheckitem = ref({ checked: false, color: '', descripts: '' });
const multicheckid = ref('');
const imgDomain = ref(uni.getStorageSync('appUrlAddress'));
const inputTimer = ref(null);
const navbarData = ref({
  background: '',
  title: '记录',
  height: '100',
  bottom: true,
  isGoBack: true,
  isGoHome: true,
  cleanPat: 'Y'
});
// 计算属性
const getData = (dataArray) => {
  if (dataArray !== "") {
    return dataArray.join("、");
  } else {
    return "";
  }
};

const getCheckFlag = (a, b) => {
  if (a.value) {
    return a.value.indexOf(b) === -1 ? false : true;
  } else {
    return a.indexOf(b) === -1 ? false : true;
  }
};

onLoad((options) => {
    const app = getApp();
    newFlag.value = options.newFlag;
    editFlag.value = options.editFlag;
    templateID.value = options.templateID;
    admID_SM.value = options.admID;
    patID_SM.value = options.patID;
	navbarData.value.title = options.title;
    imgDomain.value = uni.getStorageSync('appUrlAddress');
    
    if (options.newFlag === '0') {
      getTemplateElement(options.templateID);
    } else {
      getTemplateData(options.templateID, options.newFlag, options.linktemplateID, options.disable);
    }
});

onShow(() => {
  try {
    const pages = getCurrentPages()
    if (pages.length > 0) {
      const currentPage = pages[pages.length - 1]
      const currentRoute = currentPage.route // 当前页面路由
      // 更新全局变量
      if (uni.$appGlobal) {
        uni.$appGlobal.globalData.value.currentRoute = currentRoute
      }
    }
  } catch (err) {
    console.error('更新当前路由失败：', err)
  }
})

// 生命周期
onMounted(() => {
	 
});

// 方法定义
function getCurrentDateTime() {
  const now = new Date();
  const year = now.getFullYear();
  const month = String(now.getMonth() + 1).padStart(2, '0');
  const day = String(now.getDate()).padStart(2, '0');
  const hours = String(now.getHours()).padStart(2, '0');
  const minutes = String(now.getMinutes()).padStart(2, '0');
  return `${year}-${month}-${day} ${hours}:${minutes}`;
}

function getTemplateData(templateID, recordID, linktemplateID, disable) {
  const patInfo = uni.getStorageSync('patInfo');
  
  $http.post('urlDeault',this, {
    code: '10020016',
    data: {
      params: [{
        IEMRRecordID: recordID,
        IEMRTemplateID: templateID,
        status: 'Y',
        linktemplateID,
        disable,
        admID: patInfo.admInfo.admID
      }]
    },
    success: function(res) {
      if (+res.errorCode === 0) {
        elementData.value = res.result;
        addValue();
      }
    }
  });
}

function getTemplateElement(templateID) {
  const patInfo = uni.getStorageSync('patInfo');
  
  $http.post('urlDeault',this, {
    code: '10020015',
    data: {
      params: [{
        IEMRTemplateID: templateID,
        admID: patInfo.admInfo.admID
      }]
    },
    success: function(res) {
      if (+res.errorCode === 0) {
        elementData.value = res.result;
        addValue();
      }
    }
  });
}

function selectItem(e, _dataset) {
  handleDataset(e, _dataset);
  const { dataindex } = e.currentTarget.dataset;
  const item = elementData.value[dataindex];
  
  if (item.disable === 'Y') {
    showToast({
      icon: 'none',
      title: '该元素已被禁用，不可编辑'
    });
    return;
  }
  
  const newSelectData = item.elmentData.map(data => {
    const isSelected = item.IEMRTempElementData === data.descripts || item.IEMRTempElementData === data.value;
    return {
      name: data.descripts,
      color: isSelected ? '#1890FF' : '#000'
    };
  });
  
  selectData.value = newSelectData;
  actionShow.value = true;
  clickIndex.value = dataindex;
}

function multipleSelectItem(e, _dataset) {
  handleDataset(e, _dataset);
  const { dataindex } = _dataset;
  const item = elementData.value[dataindex];
  const value = item.IEMRTempElementData || [];
  
  const newSelectData = item.elmentData.map(data => {
    const isChecked = value.some(v => v === data.descripts);
    return {
      ...data,
      color: isChecked ? '#1890FF' : '#e4e5e4',
      checked: isChecked
    };
  });
  
  selectData.value = newSelectData;
  mutilCheckshow.value = true;
  clickIndex.value = dataindex;
}

function multiItemCheck(e) {
  const { index } = e.currentTarget.dataset;
  const item = selectData.value[index];
  item.checked = !item.checked;
  item.color = item.checked ? '#1890FF' : '#e4e5e4';
  selectData.value = [...selectData.value];
}

function onConfirmMultiCheck() {
  const dataindex = clickIndex.value;
  const item = elementData.value[dataindex];
  let printData = '';
  const data = [];
  
  selectData.value.forEach(selectItem => {
    if (selectItem.checked) {
      data.push(selectItem.descripts);
      printData = printData 
        ? `${printData};${item.printValue === 'Y' ? selectItem.value : selectItem.descripts}`
        : `${item.printValue === 'Y' ? selectItem.value : selectItem.descripts}`;
    }
  });
  
  item.IEMRTempElementData = data;
  item.IEMRTempElementPrintData = printData;
  elementData.value = [...elementData.value];
  mutilCheckshow.value = false;
  addValue();
}

function onSelect(e) {
  const dataindex = clickIndex.value;
  const item = elementData.value[dataindex];
  const data = e.name;
  let printData = data;
  
  if (item.printValue === 'Y') {
    const found = item.elmentData.find(d => d.descripts === data);
    if (found) printData = found.value;
  }
  
  item.IEMRTempElementData = data;
  item.IEMRTempElementPrintData = printData;
  elementData.value = [...elementData.value];
  onClose();
  addValue();
}

function onClose() {
  mutilCheckshow.value = false;
  actionShow.value = false;
  selectData.value = [];
  clickIndex.value = '-1';
}

function handleInput(event, { dataindex }, type) {
  if (inputTimer.value) {
    clearTimeout(inputTimer.value);
  }
  
  inputTimer.value = setTimeout(() => {
    timeInputOnChange(event, { dataindex }, type);
  }, 2000);
}

function timeInputOnChange(e, { dataindex }, type) {
  handleDataset(e, { dataindex });
  let dateRegex = '';
  
  if (type === 'datatime') {
    dateRegex = /^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$/;
  } else if (type === 'data') {
    dateRegex = /^\d{4}-\d{2}-\d{2}$/;
  } else {
    dateRegex = /^\d{2}:\d{2}$/;
  }
  
  if (dateRegex.test(e.detail)) {
    const item = elementData.value[dataindex];
    item.IEMRTempElementData = e.detail;
    item.IEMRTempElementPrintData = e.detail;
    elementData.value = [...elementData.value];
    addValue();
    uni.showToast({
      title: '格式正确',
      icon: 'none',
      duration: 1000
    });
  } else {
    uni.showToast({
      title: '输入格式错误，请输入正确格式',
      icon: 'none',
      duration: 2000
    });
  }
}

//暴露给外部函数，获取PDA扫码反馈
const getPDAScanInfo = (code) => {
  console.log('接收参数:', code)
  // 处理参数的逻辑...
}

function inputScanOnChange(e, _dataset) {
  const patInfo = uni.getStorageSync('patInfo');
  const { dataindex } = e.currentTarget.dataset;
  uni.scanCode({
    success(res) {
      const item = elementData.value[dataindex];
      const result = res.result === patInfo.basicInfo.patNo 
        ? '腕带核对正确' 
        : '腕带核对不正确';
        
      item.IEMRTempElementData = result;
      item.IEMRTempElementPrintData = result;
      elementData.value = [...elementData.value];
      addValue();
    }
  });
}

// v-model绑定了变量 item.IEMRTempElementData,绑定的变量已自动更新输入框内容
function inputOnChange(e, { dataindex }) {
  const item = elementData.value[dataindex];
  item.IEMRTempElementPrintData = item.IEMRTempElementData;
  elementData.value = [...elementData.value];
  addValue();
}

function inputOnBlur(e, { dataindex }) {
  const item = elementData.value[dataindex];
  let value = item.IEMRTempElementData.replace(item.unit, '');
  if (item.unit && !isNaN(value) && value !== '') {
    value += item.unit;
  }
  
  item.IEMRTempElementData = value;
  item.IEMRTempElementPrintData = value;
  elementData.value = [...elementData.value];
  addValue();
}

function deleteData(e, { dataindex }) {
  handleDataset(e, { dataindex });
  const item = elementData.value[dataindex];
  item.IEMRTempElementData = '';
  item.IEMRTempElementPrintData = '';
  elementData.value = [...elementData.value];
  addValue();
}

function checkChange(e, _dataset) {
  handleDataset(e, _dataset);
  const { dataindex } = e.currentTarget.dataset;
  const item = elementData.value[dataindex];
  const data = e.detail.value;
  const printData = [];
  if (item.printValue === 'Y') {
    item.elmentData.forEach(el => {
      data.forEach(d => {
        if (el.descripts === d) {
          printData.push(el.value);
        }
      });
    });
  } else {
    item.elmentData.forEach(el => {
		if (Array.isArray(data)) {
		  data.forEach(d => {
		    if (el.descripts === d) {
		      printData.push(el.descripts);
		    }
		  });
		}
    });
  }
  if (Array.isArray(data) && data.length > 1) {
    item.IEMRTempElementData = printData;
    item.IEMRTempElementPrintData = printData;
  } else {
    item.IEMRTempElementData = e.detail.value;
    item.IEMRTempElementPrintData = e.detail.value;
  }
  
  elementData.value = [...elementData.value];
  addValue();
}

function addRecord() {
  addValue();
  const patInfo = uni.getStorageSync('patInfo');
  const userData = uni.getStorageSync('userData');
  const recordID = newFlag.value !== '0' ? newFlag.value : '';
  
  $http.post('urlDeault',this, {
    code: '10020003',
    data: {
      params: [{
        IEMRTemplateID: templateID.value,
        admID: admID_SM.value || patInfo.admInfo?.admID,
        patID: patID_SM.value || patInfo.basicInfo?.patID,
        updateUserID: userData.userID,
        IEMRRecordID: recordID,
        detailData: elementData.value
      }]
    },
    success: function(res) {
      if (+res.errorCode === 0) {
        uni.showToast({
          icon: 'none',
          title: '保存成功！',
          success: () => {
			uni.navigateBack();
          }
        });
      } else {
        uni.showToast({
          icon: 'none',
          title: res.errorMessage
        });
      }
    }
  });
}

function addValue() {
  var addElement = [];
  let elementDataN = elementData.value;
  elementData.value.map((item, index) => {
  	if (item.addItemFlag == 'Y') {
  		item.index = index;
  		addElement[item.IEMRTempElementID] = item;
  		elementData.value[index].IEMRTempElementData = elementData.value[index].defaultValue || 0;
  		elementData.value[index].IEMRTempElementPrintData = elementData.value[index].defaultValue || 0;
  	}
  });
  elementData.value.map((item) => {
  	if (item.addItemID != null && item.addItemID != '') {
  		var value = '';
  		var valueDesc = item.IEMRTempElementData;
  		if (Array.isArray(valueDesc)) {
  			item.elmentData.map((detail) => {
  				valueDesc.map((valueitem) => {
  					if ((detail.descripts == valueitem || detail.code ==
  							valueitem || detail.value == valueitem) &&
  						valueitem != '') {
  						if (isNaN(valueitem) && value == '0') {
  							value = '';
  						}
  						if (value != '') {
  							value = value + ';';
  						}
  						if (addElement[item.addItemID].printValue == 'Y') {
  							value = value + detail.value;
  						} else {
  							value = value + detail.descripts;
  						}
  					}
  				});
  			});
  		} else if (item.elmentData.length > 0) {
  			item.elmentData.map((detail) => {
  				if (detail.descripts == valueDesc) {
  					value = detail.value;
  				}
  			});
  		} else {
  			value = valueDesc;
  		}
  		if (value != '' && value != 0) {
  			var tempvalue = [];
  			if ((value + '').indexOf(';') < 0) {
  				tempvalue.push(value);
  			} else {
  				tempvalue = value.split(';');
  			}
  			for (var i = 0; i < tempvalue.length; i++) {
  				value = tempvalue[i];
  				if (addElement && addElement.length > 0 && item.addItemID && addElement[item
  						.addItemID] && addElement[item.addItemID].index) {
  					if (
  						addElement[item.addItemID] &&
  						addElement[item.addItemID].IEMRTempElementData != '' &&
  						addElement[item.addItemID].IEMRTempElementData != undefined
  					) {
  						if (!isNaN(value)) {
  							elementData.value[addElement[item.addItemID].index].IEMRTempElementData =
  								Number(elementData.value[addElement[item.addItemID].index]
  									.IEMRTempElementData) + Number(value);
  							elementData.value[addElement[item.addItemID].index]
  								.IEMRTempElementPrintData = elementData.value[addElement[item
  									.addItemID].index].IEMRTempElementData;
  						} else {
  							elementData.value[addElement[item.addItemID].index].IEMRTempElementData =
  								elementData.value[addElement[item.addItemID].index]
  								.IEMRTempElementData + ';' + value;
  							elementData.value[addElement[item.addItemID].index]
  								.IEMRTempElementPrintData = elementData.value[addElement[item
  									.addItemID].index].IEMRTempElementData;
  						}
  					} else {
  						if (!isNaN(value)) {
  							elementData.value[addElement[item.addItemID].index].IEMRTempElementData =
  								Number(value);
  							elementData.value[addElement[item.addItemID].index]
  								.IEMRTempElementPrintData = Number(value);
  						} else {
  							elementData.value[addElement[item.addItemID].index].IEMRTempElementData =
  								value;
  							elementData.value[addElement[item.addItemID].index]
  								.IEMRTempElementPrintData = value;
  						}
  					}
  				}
  			}
  		}
  	}
  });
  //遍历总和项
  addElement.map((item, itemIndex) => {
  	var index = item.index;
  	if (item.elementTypeCode == 'Select') {
  		var data = elementData.value[index].IEMRTempElementData;
  		var printData = elementData.value[index].IEMRTempElementPrintData;
  		elementData.value[index].elmentData.map((dataitem, dataIndex) => {
  			if (dataitem.value.indexOf('-') < 0) {
  				if (dataitem.value == data) {
  					elementData.value[index].IEMRTempElementData = dataitem.descripts;
  					if (elementData.value[index].printValue == 'Y') {
  						//打印值
  						elementData.value[index].IEMRTempElementPrintData = dataitem.value;
  					} else {
  						//打印描述
  						elementData.value[index].IEMRTempElementPrintData = dataitem
  							.descripts;
  					}
  				}
  			} else {
  				var valuerange = dataitem.value.split('-');
  				if (data >= valuerange[0] && data <= valuerange[1]) {
  					elementData.value[index].IEMRTempElementData = dataitem.descripts;
  					if (elementData.value[index].printValue == 'Y') {
  						//打印值
  						elementData.value[index].IEMRTempElementPrintData = dataitem.value;
  					} else {
  						//打印描述
  						elementData.value[index].IEMRTempElementPrintData = dataitem
  							.descripts;
  					}
  				}
  			}
  		});
  	}
  });
  
  setGradeFun();
}

function setGradeFun() {
  let totleValue;
  elementData.value.forEach(item => {
    if (item.addItemFlag === 'Y') {
      totleValue = item.IEMRTempElementData;
    }
    
    if (item.IEMRTempElementDesc === '自理能力等级') {
      item.elmentData.forEach(child => {
        const myValue = child.value.split('-');
        
        if (!myValue[1]) {
          if (Number(totleValue) === Number(myValue[0])) {
            item.IEMRTempElementData = child.descripts;
            item.IEMRTempElementPrintData = child.descripts;
          }
        } else {
          if (Number(totleValue) >= Number(myValue[0]) && Number(totleValue) <= Number(myValue[1])) {
            item.IEMRTempElementData = child.descripts;
            item.IEMRTempElementPrintData = child.descripts;
          }
        }
      });
    }
  });
  
  elementData.value = [...elementData.value];
}

function handleDataset(e, _dataset) {
  // 处理数据集合并到事件对象中
  if (_dataset) {
    Object.keys(_dataset).forEach(key => {
      if (!e.currentTarget.dataset[key]) {
        e.currentTarget.dataset[key] = _dataset[key];
      }
    });
  }
}

defineExpose({
  getPDAScanInfo
})
</script>

<style>
/* 保持原有样式不变 */
.content {
  height: calc(100% - 200rpx);
  padding: 4rpx 14rpx;
  overflow: auto;
}

.elementitem {
  border-bottom: 1px solid #e5e5e4;
}

.item .title {
  height: 85rpx;
  line-height: 85rpx;
  background: #f6f6f6;
  font-size: 28rpx;
  font-weight: 400;
  color: #333333;
  display: flex;
  flex-direction: row;
}

.title .border {
  border: 8rpx solid #007aff;
  border-radius: 4rpx;
  height: 28rpx;
  margin: 20rpx 10rpx 20rpx 0;
}

.itemtitle {
  line-height: 85rpx;
}

.itemdata {
  line-height: 85rpx;
}

.itemdata .van-cell {
  padding: 0 !important;
}

.inputclass {
  border: 1px solid #999999;
  margin: 18rpx 8rpx;
  line-height: 80rpx;
}

.inputclass .van-cell {
  padding: 0 !important;
}

.scanCodeclass {
  line-height: 80rpx;
  display: flex;
  text-align: center;
}

.scanViewColor_green {
  color: #66bb6a;
}

.scanViewColor_red {
  color: #f44336;
}

.custom-icon {
  width: 30px;
  height: 30px;
  margin-top: 10rpx;
  margin-left: 15rpx;
}

.comboboxclass {
  margin: 8rpx;
}

.radioboxclass {
  margin: 8rpx;
  line-height: 80rpx;
}

.areaclass {
  min-height: 185rpx;
  border: 1px solid #999999;
  margin: 8rpx;
}

.selectclass {
  min-height: 60rpx;
  border: 1px solid #999999;
  margin: 8rpx;
  vertical-align: middle;
}

.dateclass{
  padding-top: 18rpx;
}

.delicon {
  margin-right: 10rpx;
}

.selectclass .van-cell__right-icon-wrap {
  /* padding-top: 14rpx;
  padding-right: 10rpx; */
}

.content .van-cell__value:empty {
  display: block !important;
}

.label {
  width: 100%;
  height: 78rpx;
  background: #f6f6f6;
  display: flex;
  flex-direction: row;
}


.radio-container {
  display: flex;
  flex-wrap: wrap;
}

.rowitem {
  line-height: 50rpx;
  width: 50%;
  box-sizing: border-box;
  padding: 5px;
}
.rowitem2 {
  line-height: 50rpx;
  width: 100%;
  box-sizing: border-box;
  padding: 5px;
}

.mutilCheck {
  height: 500rpx;
  width: calc(100% - 48rpx);
  padding: 24rpx;
}

.mutilCheck .checkData {
  display: flex;
  flex-direction: row;
  flex-wrap: wrap;
  overflow: auto;
  height: 434rpx;
  font-size: 30rpx;
  font-weight: bold;
  align-content: start;
}

.checkitem {
  width: calc(33% - 26rpx);
  word-break: break-all;
  margin: 10rpx 12rpx;
  min-height: 60rpx;
  border: 1px solid #e4e5e4;
  border-radius: 5px;
  background: #e4e5e4;
  height: 90rpx;
}
</style>