<template>
  <el-dialog
    title="操作记录"
    :visible.sync="visible"
    width="80%"
    @close="handleClose">
    <div
      style="padding:20px"
      v-loading="loading">
      <el-table
        border
        :data="tableData"
        stripe>
        <el-table-column
          prop="manager_name"
          label="操作人">
          <template slot-scope="scope">
            {{ getNickName(scope.row.managerId) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="update_column"
          label="更新字段">
          <template slot-scope="scope">
            {{ getUpdateType(scope.row.update_column) }}
          </template>
        </el-table-column>
        <el-table-column
          prop="old_value"
          label="原数据">
        </el-table-column>
        <el-table-column
          prop="new_value"
          label="新数据">
        </el-table-column>
        <el-table-column
          prop="update_time"
          label="更新时间">
          <template slot-scope="scope">
            {{ scope.row.update_time | formatTime }}
          </template>
        </el-table-column>
      </el-table>
    </div>

    <span slot="footer">
      <el-button
        type="primary"
        @click="visible = false">关闭</el-button>
    </span>
  </el-dialog>
</template>

<script>
import { getTravelAgencyPreorderUpdateLog } from '@/api/travelAgency'
export default {
  computed: {
    salesList () {
      return this.$store.state.user.salesList
    }
  },
  data () {
    return {
      loading: false,
      visible: false,
      tableData: []
    }
  },
  methods: {
    show (num) {
      this.visible = true
      this.loading = true
      getTravelAgencyPreorderUpdateLog(num).then(res => {
        this.tableData = res.list
      }).finally(() => {
        this.loading = false
      })
    },
    getNickName (id) {
      return this.salesList.find(i => i.id === id).nickName
    },
    getUpdateType (str) {
      let type
      switch (str) {
        case 'number':
          type = '数量'
          break
        case 'play_date':
          type = '游玩日期'
          break
      }
      return type
    },
    handleClose () {
      this.visible = false
    }
  }
}
</script>

<style lang="scss" scoped>

</style>
