<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="priceId">
        {{ formData.priceId || '--' }}
      </el-form-item>
      <el-form-item label="店铺ID" prop="shopId">
        {{ formData.shopId || '--' }}
      </el-form-item>
      <el-form-item label="方案名称" prop="programmeName">
        {{ formData.programmeName || '--' }}
      </el-form-item>
      <el-form-item label="优惠定价系数" prop="preferentialPrice">
        {{ formData.preferentialPrice || '--' }}
      </el-form-item>
      <el-form-item label="市场价定价系数" prop="marketPrice">
        {{ formData.marketPrice || '--' }}
      </el-form-item>
      <el-form-item label="供货价定价系数" prop="supplyPrice">
        {{ formData.supplyPrice || '--' }}
      </el-form-item>
      <el-form-item label="渠道价定价系数" prop="channelPrice">
        {{ formData.channelPrice || '--' }}
      </el-form-item>
      <el-form-item label="活动开始时间" prop="startTime">
        {{ formData.startTime || '--' }}
      </el-form-item>
      <el-form-item label="活动结束时间" prop="endTime">
        {{ formData.endTime || '--' }}
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <span v-if="formData.status === 0">未开始</span>
        <span v-else-if="formData.status === 1">进行中</span>
        <span v-else-if="formData.status === 2">已结束</span>
        <span v-else-if="formData.status === 3">已停用</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="类型" prop="type">
        <span v-if="formData.type === 0">平台</span>
        <span v-else-if="formData.type === 1">团长</span>
        <span v-else-if="formData.type === 2">合伙人</span>
        <span v-else-if="formData.type === 3">加盟商</span>
        <span v-else-if="formData.type === 4">代理商</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="是否默认选择" prop="isDefault">
        <span v-if="formData.isDefault === 0">否</span>
        <span v-else-if="formData.isDefault === 1">是</span>
        <span v-else>--</span>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        {{ formData.createTime || '--' }}
      </el-form-item>
      <el-form-item label="更新时间" prop="updateTime">
        {{ formData.updateTime || '--' }}
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import { priceControlGetById } from '@/api/selectionCenter/selectionCenter'

export default {
  name: 'DetailModal',
  data() {
    return {
      modalOptions: {
        closeOnClickModal: false,
        width: '800px',
        title: '查看定价方案详情'
      },
      visible: false,
      formData: {
        priceId: '',
        shopId: '',
        programmeName: '',
        preferentialPrice: '',
        marketPrice: '',
        supplyPrice: '',
        channelPrice: '',
        startTime: '',
        endTime: '',
        status: '',
        type: '',
        isDefault: '',
        createTime: '',
        updateTime: ''
      }
    }
  },
  methods: {
    handleClose() {
      this.visible = false
    },
    handleOpen(params = {}) {
      this.formData = Object.assign(this.$options.data().formData, params)
      if (params.priceId) {
        this.getInfo(params.priceId)
      }
      this.visible = true
    },
    async getInfo(id) {
      const loading = this.$loading({ text: '加载中' })
      try {
        const res = await priceControlGetById({ id })
        this.formData = Object.assign(this.$options.data().formData, res.data, {
          priceId: res.data.priceId || '',
          shopId: res.data.shopId || '',
          programmeName: res.data.programmeName || '',
          preferentialPrice: res.data.preferentialPrice || '',
          marketPrice: res.data.marketPrice || '',
          supplyPrice: res.data.supplyPrice || '',
          channelPrice: res.data.channelPrice || '',
          startTime: res.data.startTime || '',
          endTime: res.data.endTime || '',
          status: res.data.status,
          type: res.data.type,
          isDefault: res.data.isDefault,
          createTime: res.data.createTime || '',
          updateTime: res.data.updateTime || ''
        })
      } finally {
        loading.close()
      }
    }
  }
}
</script>

