<script setup>
import { Select } from '@element-plus/icons-vue'
import { useExperiment } from '../composables/useData'
const { experiment } = useExperiment()
import { getRecords } from '../api'

const typeArr = ['营销背景分析', '营销渠道选择', '用户分析', '用户标签体系设计', '用户精准分群', '自动化营销旅程设计', '营销物料设计', '营销策划报告']

// 列表配置
const listOptions = {
  remote: {
    httpRequest: getRecords,
    callback({ items }) {
      return { list: items }
    }
  },
  columns: [
    { label: '序号', type: 'index', width: 60 },
    {
      label: '步骤名称',
      prop: 'type',
      computed({ row }) {
        return typeArr[row.type - 1]
      }
    },
    { label: '步骤状态', prop: 'is_complete', slots: 'table-complete' },
    { label: '开始时间', prop: 'start_time' },
    { label: '更新时间', prop: 'update_time' },
    { label: '评分', prop: 'score' },
    { label: '操作', slots: 'table-x', width: 140 }
  ]
}

const currentRow = ref()
const dialogVisible = ref(false)
// 查看评语
const handleView = row => {
  currentRow.value = row
  dialogVisible.value = true
}
</script>

<template>
  <AppCard>
    <el-form label-suffix=":" inline class="info">
      <el-form-item label="实验名称">{{ experiment.name }}</el-form-item>
      <el-form-item label="课程名称">{{ experiment.course_name }}</el-form-item>
      <el-form-item label="指导教师">{{ experiment.teacher_name }}</el-form-item>
      <el-form-item label="实验学时">{{ experiment.length }}学时</el-form-item>
    </el-form>
    <el-divider />
    <h2 class="h2-title">营销策划</h2>
    <AppList v-bind="listOptions">
      <template #table-complete="{ row }">
        <el-icon v-if="row.is_complete"><Select color="green" /></el-icon>
      </template>
      <template #table-x="{ row }">
        <el-button text type="primary">
          <router-link :to="{ path: '/market/my/update', query: { experiment_id: $route.query.experiment_id, step: row.type } }">编辑</router-link>
        </el-button>
        <el-button text type="primary" @click="handleView(row)" v-if="row.comment">查看评语</el-button>
      </template>
    </AppList>
    <el-dialog v-model="dialogVisible" title="查看评语" width="600">
      <div v-html="currentRow.comment"></div>
      <template #footer>
        <el-row justify="center">
          <el-button plain auto-insert-space round @click="dialogVisible = false">关闭</el-button>
        </el-row>
      </template>
    </el-dialog>
  </AppCard>
</template>

<style lang="scss" scoped>
.info {
  display: flex;
  justify-content: space-between;
}
</style>
