<template>
  <div class="monitor-form">
    <p v-if="title" class="title">{{title}}</p>
    <Row class="row" v-for="(row, rowIndex) in layout" :key="rowIndex">
      <i-col class="col" v-for="(col, key) in row" :key="key" :span="col.width" :offset="col.offset || 0">
        <div :style="`text-align: ${col.align || 'right'}; width:${labelWidth}rem;`">{{col.label}}：</div>
        <img v-if="col.type == 'img'" @click="handleView(model[key])" :src="require(`@/assets/images/${model[key]}`)"/>
        <div v-else class="content">{{col.format ? col.format(model[key]) : (model[key] || ' ')}}</div>
      </i-col>
    </Row>
    <m-modal v-model="showImg">
      <img v-if="showImg" style="width: 100%;" :src="require(`@/assets/images/${curSrc}`)"/>
    </m-modal>
  </div>
</template>

<script>
export default {
  name: 'MonitorForm',
  props: {
    title: {
      type: String,
      default: '',
    },
    labelWidth: {
      type: Number,
      default: 1,
    },
    layout: {
      type: Array,
      default() {
        return []
      }
    },
    model: {
      type: Object,
      default() {
        return {}
      }
    }
  },
  data() {
    return {
      showImg: false,
      curSrc: null,
    }
  },
  methods: {
    handleView(src) {
      this.curSrc = src
      this.showImg = true
    }
  }
}
</script>

<style lang="stylus" scoped>
.monitor-form
  font-size .1rem
  color #fff
  margin-bottom .1rem
  .title
    font-size .12rem
    font-weight bold
    color $edgeColor
    padding-bottom 0.05rem
    margin-bottom .1rem
    border-bottom 0.01rem solid rgba(51,145,255,.2)
  .row
    line-height .3rem
    &:nth-child(2n+1)
      background-color rgba(51,145,255,.2)
  .col
    display flex
    align-items center
    padding 0 .1rem
    // &:nth-child(2n+1)
    //   background-color $section-bg
    .content
      flex 1
    img
      width 25%
      height .5rem
      margin 0.05rem 0
      cursor pointer
</style>
