<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>
        <template v-if="col.type == 'img'">
          <img v-for="img in model[key] && model[key].split(',')" :key="img" @click="handleView(img)" :src="img" />
        </template>
        <div v-else class="content">{{col.format ? col.format(model[key]) : (model[key] || ' ')}}</div>
      </i-col>
    </Row>
    <m-modal v-model="showImg" width="40%" title="图片">
      <img v-if="showImg" style="max-height:45vh;width:100%;" :src="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 20%
      height .5rem
      margin 0.05rem 0
      margin-right .03rem
      cursor pointer
</style>
