<template>
  <view>
    <uni-nav-bar
      fixed="true"
      statusBar="true"
      left-icon="back"
      title="设备台账"
      @clickLeft="back"
      rightText="待处理"
      @clickRight="toProcessed"
      :rightNum="num"
    >
    </uni-nav-bar>
    <view class="main">
      <view class="title">
        <view class="">{{ info.assetName }}</view>
        <view class="sub">{{ info.assetCode }}</view>
      </view>
      <view class="img-box">
        <image
          mode="widthFix"
          class="main-img"
          :src="apiUrl + info.imageUrl.accessUrl"
          v-if="info.imageUrl"
        ></image>
        <image
          mode="widthFix"
          class="main-img"
          src="./upload-placeholder.svg"
          v-else
        ></image>
      </view>

      <view class="main-list">
        <view
          class="list-item"
          v-for="(item, index) in jumpList"
          :key="index"
          @click="toJump(item)"
        >
          <image
            class="item-img"
            :src="`../../static/ledger/icon${index + 1}.png`"
          ></image>
          <view class="item-name">{{ item.name }}</view>
        </view>
      </view>
    </view>
    <Assign
      ref="assignRef"
      @total="handlNum"
      :qrContent="qrContent"
      :list="AssignList"
    />
  </view>
</template>

<script>
import Assign from '@/pages/equipment_ledger/components/Assign.vue'
import { get, postJ } from '@/utils/api.js'
export default {
  components: {
    Assign
  },
  data () {
    return {
      jumpList: [
        {
          id: 0,
          name: '基本信息',
          url: '/pages/equipment_ledger/basic_info/basic_info?info='
        },
        {
          id: 1,
          name: '关联模具',
          url: '/pages/equipment_ledger/correlation_model/correlation_model?info='
        },
        {
          id: 2,
          name: '巡点检记录',
          url: '/pages/equipment_ledger/patrol_record/patrol_record?info='
        },
        {
          id: 3,
          name: '保养记录',
          url: '/pages/equipment_ledger/patrol_record/patrol_record?info='
        },
        {
          id: 4,
          name: '维修记录',
          url: '/pages/equipment_ledger/patrol_record/patrol_record?info='
        },
        {
          id: 5,
          name: '故障记录',
          url: '/pages/equipment_ledger/malfunction/malfunction?info='
        },
        {
          id: 6,
          name: '盘点记录',
          url: '/pages/equipment_ledger/check/check?info='
        },
        // { id: 7, name: '设备运行记录' },
        {
          id: 8,
          name: '物联数据',
          url: '/pages/equipment_ledger/lot_data/lot_data?info='
        }
      ],
      info: '',
      num: '0',
      qrContent: '',
      // 待处理工单
      AssignList: []
    }
  },
  async onLoad (option) {
    console.log('option', option)
    this.qrContent = option.qrContent
    this.info = JSON.parse(decodeURIComponent(option.info))

    console.log(this.info)
  },
  onShow () {
    if (this.info) {
      this.getAssign()
    }
  },
  computed: {},
  methods: {
    toProcessed () {
      this.$refs.assignRef.open(this.info.assetCode)
      console.log('点击待处理')
    },
    toJump (item) {
      if (item.url) {
        uni.navigateTo({
          url:
            item.url +
            encodeURIComponent(JSON.stringify(this.info)) +
            '&pageTitle=' +
            item.name
        })
      }
    },
    assignSuccess () {
      // this.back()
    },
    handlNum (num) {
      this.num = String(num)
    },
    // 获取待处理数量
    getAssign () {
      let par = {
        equiCode: this.info.assetCode,
        orderTypeList: [1, 2, 3]
      }
      let _par = this.URLSearchParams(par)
      postJ(
        this.apiUrl + '/workOrder/getEquiAndWorkOrder?' + _par,
        par,
        true
      ).then(res => {
        if (res?.success) {
          this.AssignList = res.data
          this.num = String(res.data.length)
          if (res.data.length > 0) {
            this.$refs.assignRef.open()
          }
        }
      })
    },
    // 设置barType
    setBarType (val) {
      let index = val.indexOf('@_@')
      let result = 0
      if (index !== -1) {
        let item = val.substr(index + 3, 1)
        if (item) {
          result = Number(item)
        }
      }
      return result
    }
  }
}
</script>

<style scoped lang="scss">
.main {
  .title {
    padding-top: 20rpx;
    text-align: center;
    font-weight: bold;
    .sub {
      font-weight: normal;
      font-size: $uni-font-size-ssm;
      color: $uni-color-subtitle;
    }
  }
  .img-box {
  }
  .main-img {
    display: block;
    margin: 40rpx auto;
    width: 500rpx;
  }
  .main-list {
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    .list-item {
      border: 1rpx solid #47975a;
      border-radius: 14rpx;
      width: 205rpx;
      height: 160rpx;
      margin: 0 20rpx 30rpx;
      .item-img {
        display: block;
        margin: 15rpx auto;
        width: 80rpx;
        height: 80rpx;
      }
      .item-name {
        width: 100%;
        color: #47975a;
        font-size: 28rpx;
        text-align: center;
      }
    }
  }
}
</style>
