<template>
  <el-dialog
    :visible.sync="visible"
    v-bind="modalOptions"
    append-to-body
  >
    <el-form
      ref="formData"
      :model="formData"
      size="mini"
      label-position="left"
      label-suffix=":"
      label-width="200px"
    >
      <!-- 用户详情信息 -->
      <el-form-item label="用户ID" prop="buyerUserId">
        {{ formData.buyerUserId || '--' }}
      </el-form-item>
      <el-form-item label="头像" prop="headImage">
        <el-image
          v-if="formData.headImage" lazy :src="common.seamingImgUrl(formData.headImage)"
          style="width:40px;height:40px;" fit="cover"
          :preview-src-list="[ common.seamingImgUrl(formData.headImage) ]"
        />
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="注册来源" prop="terminal">
        <span v-if="formData.terminal === 1">APP</span>
        <span v-else-if="formData.terminal === 2">小程序</span>
        <span v-else-if="formData.terminal === 3">H5</span>
        <span v-else-if="formData.terminal === 4">支付宝小程序</span>
        <span v-else-if="formData.terminal === 5">PC</span>
        <span v-else>未知</span>
      </el-form-item>
      <el-form-item label="生日" prop="birthday">
        {{ formData.birthday || '--' }}
      </el-form-item>
      <el-form-item label="性别" prop="sex">
        {{ formData.sex || '--' }}
      </el-form-item>
      <el-form-item label="用户昵称" prop="name">
        {{ formData.name || '--' }}
      </el-form-item>
      <el-form-item label="用户手机号" prop="phone">
        {{ formData.phone || '--' }}
      </el-form-item>
      <el-form-item label="微信名称" prop="wechatName">
        {{ formData.wechatName || '--' }}
      </el-form-item>
      <!-- <el-form-item label="渠道编码" prop="channelCode">
        {{ formData.channelCode || '--' }}
        </el-form-item>
        <el-form-item label="积分" prop="credit">
        {{ formData.credit || '--' }}
        </el-form-item>
        <el-form-item label="成长值" prop="growth">
        {{ formData.growth || '--' }}
        </el-form-item> -->
      <el-form-item label="是否黑名单" prop="ifBlack">
        <el-tag v-if="formData.ifBlack === 0" effect="plain" type="info">否</el-tag>
        <el-tag v-else-if="formData.ifBlack === 1" effect="plain" type="danger">是</el-tag>
        <span v-else>--</span>
      </el-form-item>
      <!-- <el-form-item label="状态" prop="state">
        {{ formData.state || '--' }}
        </el-form-item> -->
      <el-form-item label="创建时间" prop="createTime">
        {{ formData.createTime || '--' }}
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>

export default {
  name: 'DetailModal',
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '800px',
        title: '查看用户详情'
      },
      visible: false,
      formData: {
        buyerUserId: '',
        headImage: '',
        terminal: '',
        birthday: '',
        sex: '',
        name: '',
        phone: '',
        wechatName: '',
        channelCode: '',
        credit: '',
        growth: '',
        ifBlack: '',
        state: '',
        createTime: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      if (params.buyerUserId) {
        // this.getInfo(params.buyerUserId)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await xxxx({ id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

