 <template>
  <ai-detail>
    <template slot="title">
      <ai-title title="详情" isShowBack isShowBottomBorder @onBackClick="cancel(true)">
      </ai-title>
    </template>
    <template slot="content">
      <ai-card title="基本信息">
        <template #content>
          <ai-wrapper
            label-width="120px">
            <ai-info-item label="标题" :value="info.title" isLine></ai-info-item>
            <ai-info-item label="描述" isLine :value="info.description"></ai-info-item>
            <ai-info-item label="图片" isLine :value="info.idNumber">
              <ai-uploader v-model="info.images" :instance="instance" :limit="9" disabled/>
            </ai-info-item>
            <ai-info-item label="慰问对象" :value="info.name"></ai-info-item>
            <ai-info-item label="对象类型" :value="info.type"></ai-info-item>
            <ai-info-item label="现实状态" isLine :value="dict.getLabel('visitCondolenceReality', info.reality)"></ai-info-item>
            <ai-info-item label="走访人" :value="info.createUserName"></ai-info-item>
            <ai-info-item label="走访时间" :value="info.visitTime"></ai-info-item>
          </ai-wrapper>
        </template>
      </ai-card>
    </template>
  </ai-detail>
</template>

<script>
  export default {
    name: 'Detail',

    props: {
      instance: Function,
      dict: Object,
      params: Object
    },

    data () {
      return {
        info: {},
        id: ''
      }
    },

    created () {
      this.id = this.params.id
      this.dict.load(['visitCondolenceReality']).then(() => {
        this.getDictList()
      })
    },

    methods: {
      getInfo (id) {
        this.instance.post(`/app/appvisitvondolence/queryDetailById?id=${id}`).then(res => {
          if (res.code === 0) {
            this.info = res.data
            this.info.images = res.data.images ? JSON.parse(res.data.images) : []
            this.info.type = this.dictList.filter(v => v.dictValue === res.data.applicationId)[0].dictName
          }
        })
      },

      getDictList () {
        this.instance.post(`/app/appapplicationinfo/queryApplicationListByType`).then(res => {
          if (res.code == 0) {
            this.dictList = res.data.map(v => {
              return {
                dictValue: v.id,
                dictName: v.applicationName
              }
            })
            this.getInfo(this.params.id)
          }
        })
      },

      cancel (isRefresh) {
        this.$emit('change', {
          type: 'list',
          isRefresh: !!isRefresh
        })
      }
    }
  }
</script>

<style scoped lang="scss">
</style>
