<template>
  <el-dialog
    :visible.sync="visible"
    v-bind="modalOptions"
  >
    <el-form
      ref="formData"
      :model="formData"
      size="mini"
      label-position="left"
      label-suffix=":"
      label-width="200px"
    >
      <!-- 桌号二维码 -->
      <el-form-item label="桌号ID" prop="deskId">
        {{ formData.deskId || '--' }}
      </el-form-item>
      <el-form-item label="桌号二维码" prop="codeImage">
        <el-image v-if="formData.codeImage" :src="formData.codeImage" style="width:380px; height:380px" fit="fill" :preview-src-list="[ formData.codeImage ]" />
        <span v-else>--</span>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { createQRShopAuthDept } from '@/api/mealManagement/TableNumberSetting'

export default {
  name: 'MealCodeCreate',
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '800px',
        title: '查看桌号二维码详情'
      },
      visible: false,
      formData: {
        deskId: '',
        codeImage: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData.deskId = params.id
      // this.formData = Object.assign(this.$options.data().formData, params)
      if (params.id) {
        this.getInfo(params.id)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await createQRShopAuthDept({ id })
        // this.formData = Object.assign(this.$options.data().formData, res.data, {
        //   id: res.data.id || ''
        // })
        this.formData.codeImage = res.data
      } finally {
        loading.close()
      }
    }
  }
}
</script>

