<template>
  <div class="app-container">
    <div class="head-container">
      <h1>订单详情</h1>
      <h3>基本信息</h3>
      <el-descriptions class="margin-top" :column="2" border>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-user" />
            订单流水号:
          </template>
          {{ record.seq }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-mobile-phone" />
            订单创建时间:
          </template>
          {{ record.createDate }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-tickets" />
            付款时间:
          </template>
          {{ record.createDate }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building" />
            用户姓名:
          </template>
          {{ record.userName }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building" />
            卡号:
          </template>
          {{ record.cardNo }}
        </el-descriptions-item>
        <el-descriptions-item>
          <template slot="label">
            <i class="el-icon-office-building" />
            用户手机号:
          </template>
          {{ record.tel }}
        </el-descriptions-item>
      </el-descriptions>
      <!--表格渲染-->
      <h3>商品明细</h3>
      <el-table ref="table" v-loading="crud.loading" :span-method="arraySpanMethod" :data="crud.data" size="small" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
        <!-- <el-table-column type="index" :index="indexMethod" label="序号" /> -->
        <!-- <el-table-column :selectable="checkboxT" type="selection" width="55" /> -->
        <el-table-column prop="name" label="商品名称" />
        <el-table-column prop="food" label="商品编号" />
        <el-table-column prop="price" label="单价" />
        <!-- <el-table-column prop="userType" label="数量" /> -->
        <el-table-column prop="money" label="金额小计" />
      </el-table>
      <!--分页组件-->
      <pagination />
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button slot="reference" type="primary" icon="el-icon-search" size="mini" @click="toDetail">关闭</el-button>
    </div>
  </div>
</template>

<script>
import crudDetails from '@/api/details'
import CRUD, { presenter, header, form, crud } from '@crud/crud'
// import rrOperation from '@crud/RR.operation'
import pagination from '@crud/Pagination'
// import crudOperation from '@crud/CRUD.operation'

const defaultForm = { id: null, bh: null, money: null, userName: null, userType: null, phone: null, createDate: null, totalMoney: null, zkMoney: null }
export default {
  name: 'DmDetails',
  components: { pagination }, //, crudOperation rrOperation,
  mixins: [presenter(), header(), form(defaultForm), crud()],
  cruds() {
    return CRUD({ title: '消费记录详情', url: 'api/dmOrderRecord/queryDetails', idField: 'id', sort: 'id,desc', crudMethod: { ...crudDetails }, optShow: { download: true }})
  },
  data() {
    return {
      record: {}
    }
  },
  created() {
    this.getData()
  },
  methods: {
    arraySpanMethod({ row, column, rowIndex, columnIndex }) {
      const count = this.crud.data.length - 1
      // debugger
      // if (rowIndex % 3 === 0 && rowIndex!=0) {
      //   if (columnIndex === 0) {
      //     return [1, 4];
      //   } else if (columnIndex === 1) {
      //     return [0, 0];
      //   }
      // }
      if (rowIndex === count) {
        if (columnIndex === 0) {
          return [1, 3]
        } else if (columnIndex >= 1 && columnIndex <= 2) {
          return [0, 0]
        }
      }
    },
    toDetail(row) {
      this.$router.push({
        path: 'api/dmOrderRecord',
        query: {

        }
      })
      console.log(row)
    },
    getData() {
      this.crud.query.id = this.$route.query.recordId
      crudDetails.queryDetails({
        ... this.crud.form,
        ... this.crud.query
      }).then(res => {
        this.record = res.content[0] || {}
        this.getFood()
      })
    },
    getFood() {
      this.crud.query.seq = this.record.seq
      crudDetails.queryDetailsFood({
        ... this.crud.form,
        ... this.crud.query
      }).then(res => {
        this.crud.data = res.content
      })
    },
    // 钩子：在获取表格数据之前执行，false 则代表不获取数据
    [CRUD.HOOK.beforeRefresh]() {
      return false
    }
    // indexMethod(index) {
    //   return index + 1
    // }
  }
}
</script>

<style scoped>
.dialog-footer{
  margin-left:1300px;
}
</style>
