<template>
  <view>
    <uv-form-item
      :labelWidth="100"
      :label="item?.taskFiledValue"
      :borderBottom="false"
      labelPosition="left"
      :required="item?.isMustfill == '1'"
      @click="autoSelectFn"
    >
      <uv-input
        input-align="right"
        v-model="propsMessage"
        disabled
        disabledColor="#ffffff"
        :placeholder="`请选择${item?.taskFiledValue}`"
        border="none"
      />
      <template v-slot:right>
        <uv-icon name="arrow-right"></uv-icon>
      </template>
    </uv-form-item>
  </view>
</template>

<script setup lang="ts">
import { computed } from 'vue'

const emmits = defineEmits(['update:autoSelecValue'])

let props = defineProps({
  item: Object,
  index: Number,
  autoSelecValue: String,
  sendParams: Object
})

// 选择商业公司或者医院 模糊搜索
const autoSelectFn = () => {
  // 库存调查14
  const taskTypeIds = ['14', '31', '37']
  if (taskTypeIds.includes(props?.item?.taskTypeId)) {
    // 调查对象temp26  先选择调查类别
    if (props?.item?.taskFiledKey === 'temp26') {
      if (!props?.sendParams?.temp23) {
        return uni.showToast({
          title: '请选择调查类别',
          icon: 'none'
        })
      }
    }
    //
    let activeId = props.sendParams?.temp28 || 1
    let sendVal = ''
    let firstInvestigation = ''
    // 首次调查
    if (props?.sendParams?.temp23 === '0') {
      firstInvestigation = 'first'
      activeId = 1
    }
    // 关联执行包id
    let packageId = props?.sendParams?.temp32 || ''
    // 选中的是调查品种
    let investigateDrug = ''
    // 点击调查品种
    if (props?.item?.taskFiledKey === 'temp24') {
      investigateDrug = 'drug'
      if (!props?.sendParams?.temp32) {
        return uni.showToast({
          title: '请选择关联执行包',
          icon: 'none'
        })
      }
      sendVal = props?.sendParams?.temp24 || ''
      uni.navigateTo({
        url: `/pages-sub-task/investigate-varieties/index?sendParamsKey=${props?.item?.taskFiledKey}&sendVal=${sendVal}&investigateDrug=${investigateDrug}&packageId=${packageId}`
      })
      return
    }
    if (props?.sendParams && props?.item && props?.sendParams[props?.item.taskFiledKey]) {
      sendVal = props?.sendParams[props?.item.taskFiledKey]
    }

    uni.navigateTo({
      url: `/pages-sub-task/hospital-drugstore-company/index?sendParamsKey=${props?.item?.taskFiledKey}&activeId=${activeId}&sendVal=${sendVal}&firstInvestigation=${firstInvestigation}`
    })
    return
  }
  let sendVal =
    (props?.sendParams && props.item && props?.sendParams[props.item.taskFiledKey]) || ''
  uni.navigateTo({
    url: `/pages-sub-task/single-select/index?taskTypeId=${props?.item?.taskTypeId}&sendParamsKey=${props?.item?.taskFiledKey}&sendVal=${sendVal}`
  })
}

const propsMessage = computed({
  get: () => {
    return props.autoSelecValue
  },
  set: (val) => {
    emmits('update:autoSelecValue', val)
  }
})
</script>

<style lang="scss" scoped></style>
