<template>
  <view>
    <navbar-back
      title="样品库管理"
      titleWidth="800"
      :autoBack="false"
      leftIcon=""
      :leftText="`您好！${userInfo.nickname}`"
    >
      <u-icon @click="popupShow = true" size="28" color="#FFF" name="setting-fill" />
    </navbar-back>

    <up-grid :col="gridCol" :border="false">
      <up-grid-item class="mb20 mt20" v-for="item in menuItemList" :key="item.url" @click="goTo(item.url)">
        <u-icon :name="item.otherConf.icon" color="#0055A2" size="80" />
        <view class="grid-text">{{ item.name }}</view>
      </up-grid-item>
    </up-grid>

    <mePopup :show="popupShow" @update:show="val => (popupShow = val)" />
  </view>
</template>

<script setup>
import { ref, computed, onMounted } from 'vue'
import nx from '@/nx'
import { onLoad, onShow } from '@dcloudio/uni-app'
import { useGridCol } from '@/nx/hooks/useGridCol'
import mePopup from '@/pages/index/me-popup.vue'

// 响应式数据
const popupShow = ref(false)

const menuItemList = ref([
  {
    url: '/pages/sampleWarehouse/sampleSearch/index',
    otherConf: { icon: '/static/images/menus/记录.png' },
    name: '样品查询'
  },
  {
    url: '/pages/sampleWarehouse/returnToStock/index',
    otherConf: { icon: '/static/images/menus/样品归库.png' },
    name: '样品归库'
  },
  {
    url: '/pages/sampleWarehouse/execChangeLocation/index',
    otherConf: { icon: '/static/images/menus/库位变更.png' },
    name: '库位变更'
  },
  {
    url: '/pages/sampleWarehouse/sampleDispatchInternal/index',
    otherConf: { icon: '/static/images/menus/内部调拨.png' },
    name: '内部调拨'
  },
  {
    url: '/pages/sampleWarehouse/sampleDispatchExternal/index',
    otherConf: { icon: '/static/images/menus/外部调拨.png' },
    name: '外部调拨'
  },
  {
    url: '/pages/sampleWarehouse/dispatchGiveBack/index',
    otherConf: { icon: '/static/images/menus/调拨归还.png' },
    name: '调拨归还'
  },
  {
    url: '/pages/sampleWarehouse/sampleTakeOff/index',
    otherConf: { icon: '/static/images/menus/样品下架.png' },
    name: '样品下架'
  }
])

// 计算属性
const userInfo = computed(() => nx.$store('user').userInfo)

// 方法
const goTo = url => {
  nx.$router.go(url)
}
// onShow(() => {
//   //连接打印服务
//   let printList = uni.getStorageSync('KEY_PRINT_LIST')
//   if (printList && printList.length > 0) {
//     for (let print of printList) {
//       nx.$print.open(print.printIp, print.printPort)
//     }
//   } else {
//     uni.showModal({
//       title: '提示',
//       showCancel: false,
//       content: '打印服务未配置，请在系统设置中配置打印服务',
//       success: function (res) {
//         uni.navigateTo({
//           url: '/pages/setting/print'
//         })
//       }
//     })
//   }
// })
// 生命周期
onMounted(() => {})
// 动态设置 grid 列数
const { gridCol } = useGridCol([400], [2, 3])
</script>

<style scoped lang="scss">
.grid-text {
  font-size: 24px;
}
</style>
