<template>
  <a-spin :spinning="confirmLoading">
    <template>
      <a-descriptions :column='2' bordered title=''>
        <a-descriptions-item label='考察人员'>
          {{ model.incarceratedUserId_dictText }}
        </a-descriptions-item>
        <a-descriptions-item label='服务时间'>
          {{ model.serviceTime }}
        </a-descriptions-item>
        <a-descriptions-item :span='2' label='服务地点'>
          {{ model.serviceAddress }}
        </a-descriptions-item>
        <a-descriptions-item :span='2' label='服务类型'>
          {{ model.serviceType_dictText }}
        </a-descriptions-item>
        <a-descriptions-item :span='2' label='服务描述'>
          <div class='describe'>{{ model.serviceDescribe }}</div>
        </a-descriptions-item>
        <a-descriptions-item v-if="model.serviceImageUrl !=null && model.serviceImageUrl !=undefined && model.serviceImageUrl !=''" :span='2'
                             label='服务图片'>
          <img v-for='img in companyCut(model.serviceImageUrl)' :src='img' class='imgbox' />
          <!--          <a-upload-->
          <!--            action="https://www.mocky.io/v2/5cc8019d300000980a055e76"-->
          <!--            list-type="picture-card"-->
          <!--            :file-list="fileList"-->
          <!--            @preview="handlePreview"-->
          <!--            @change="handleChange"-->
          <!--          >-->
          <!--          </a-upload>-->
          <!--          <a-modal :visible="previewVisible" :footer="null" @cancel="handleCancel">-->
          <!--            <img alt="example" style="width: 100%" :src="previewImage" />-->
          <!--          </a-modal>-->
        </a-descriptions-item>
        <a-descriptions-item label="服务视频" :span="2" v-if="model.serviceVideoUrl !=null && model.serviceVideoUrl !=undefined && model.serviceVideoUrl !=''">
          <video v-for="item in companyCut(model.serviceVideoUrl)" :src="item" autoplay="autoplay" controls="controls"
                 width="480px" height="270px">您的浏览器不支持视频播放
          </video>
        </a-descriptions-item>
        <a-descriptions-item v-if="model.auditingUserId_dictText!=null && model.auditingUserId_dictText !=undefined "
                             label="审核人">
          {{ model.auditingUserId_dictText }}
        </a-descriptions-item>
        <a-descriptions-item v-if="model.auditingUserId_dictText!=null && model.auditingUserId_dictText !=undefined "
                             label="审核时间">
          {{ model.auditingTime }}
        </a-descriptions-item>
        <a-descriptions-item label="审核状态">
          {{ model.status_dictText }}
        </a-descriptions-item>
        <a-descriptions-item v-if="model.score!=null && model.score !=undefined && model.score !=0" label="积分">
          {{ model.score }}
        </a-descriptions-item>
      </a-descriptions>
    </template>
  </a-spin>
</template>

<script>

import { httpAction } from '@/api/manage'

export default {
  name: 'MrServiceDocumentaryForm',
  components: {},
  props: {
    //表单禁用
    disabled: {
      type: Boolean,
      default: false,
      required: false
    }
  },
  data() {
    return {
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      validatorRules: {},
      url: {
        add: '/MrServiceDocumentary/mrServiceDocumentary/add',
        edit: '/MrServiceDocumentary/mrServiceDocumentary/edit',
        queryById: '/MrServiceDocumentary/mrServiceDocumentary/queryById'
      },
      previewVisible: false,
      previewImage: '',
      fileList: [
        {
          uid: '-1',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        },
        {
          uid: '-2',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        },
        {
          uid: '-3',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        },
        {
          uid: '-4',
          name: 'image.png',
          status: 'done',
          url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
        },
        {
          uid: '-5',
          name: 'image.png',
          status: 'error'
        }
      ]
    }
  },
  computed: {
    formDisabled() {
      return this.disabled
    }
  },
  created() {
    //备份model原始值
    this.modelDefault = JSON.parse(JSON.stringify(this.model))
  },
  methods: {
    companyCut(name) {
      if (name != null && name != undefined) {
        if (name.indexOf(',') > 0) {
          let company = name.split(',')
          return company
        } else {
          let company = []
          company.push(name)
          return company
        }
      } else {
        let company = []
        return company
      }

    },
    add() {
      this.edit(this.modelDefault)
    },
    edit(record) {
      this.model = Object.assign({}, record)
      this.visible = true
    },
    // base(nickName){
    //    return  Base64(nickName)
    // },
    submitForm() {
      const that = this
      // 触发表单验证
      this.$refs.form.validate(valid => {
        if (valid) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          httpAction(httpurl, this.model, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
          })
        }

      })
    },
    handleCancel() {
      this.previewVisible = false
    },
    async handlePreview(file) {
      if (!file.url && !file.preview) {
        file.preview = await getBase64(file.originFileObj)
      }
      this.previewImage = file.url || file.preview
      this.previewVisible = true
    },
    handleChange({ fileList }) {
      this.fileList = fileList
    }
  }
}
</script>
<style scoped>
.description {
  margin-bottom: 10px;
  line-height: 2;
}

.scroll_area {
  max-height: 600px;
  max-height: 500px;
  padding-right: 10px;
  overflow-y: auto;
}

.describe {
  max-width: 580px;
}

.imgbox {
  margin-right: 20px;
  width: 120px;
  height: 120px;
  object-fit: cover;
}
</style>