<template>
  <div class="padding-20">
    <div class="search-box">
      <el-form ref="form"
               :inline="true"
               :model="searchForm"
               clearable
               class="mt-10">
        <el-form-item label="订单编号:">
          <el-input v-model="searchForm.storage_number" placeholder="请输入订单编号" clearable></el-input>
        </el-form-item>
        <el-form-item label="存入时间:">
          <el-date-picker
            :editable="false"
            v-model="time"
            @change="timearr => {timearr ? (searchForm.start_time = timearr[0] + ' 00:00:00', searchForm.end_time = timearr[1] + ' 23:59:59') : searchForm.start_time = searchForm.end_time = undefined}"
            type="daterange"
            value-format="yyyy-MM-dd"
            start-placeholder="开始时间"
            end-placeholder="结束时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item class="ml-10">
          <el-button icon="el-icon-search" type="primary" @click="searchSubmit">查询</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="tableData"
              stripe
              v-loading="tableLoading"
              class="marginT-10 order-table"
              border
              :max-height="vheight">
      <el-table-column label="ID" prop="id" width="80"></el-table-column>
      <el-table-column label="订单编号" prop="storage_number" width="160"></el-table-column>
      <el-table-column label="酒名" prop="storage_name" width="200"></el-table-column>
      <el-table-column label="存酒图片" width="140">
        <template slot-scope="scope">
          <el-image style="width: 100px; height: 100px"
                    :src="scope.row.storage_img_url"
                    :preview-src-list="[scope.row.storage_img_url]">
          </el-image>
        </template>
      </el-table-column>
      <el-table-column label="用户昵称" prop="user_name" width="120"></el-table-column>
      <el-table-column label="用户手机" prop="user_phone" width="120"></el-table-column>
      <el-table-column label="存储状态">
        <template slot-scope="scope">
          <p>{{ ['存储中', '已取走'][scope.row.storage_status] }}</p>
        </template>
      </el-table-column>
      <el-table-column label="存酒时间" prop="created_at" width="160"></el-table-column>
      <el-table-column label="取酒时间" prop="storage_out_at" width="160"></el-table-column>
      <el-table-column label="录入人" prop="operation_in_name" width="120"></el-table-column>
      <el-table-column label="取酒人" prop="operation_out_name" width="120"></el-table-column>
      <el-table-column label="备注" prop="storage_remark" width="300"></el-table-column>
      <el-table-column label="操作" fixed="right">
        <template slot-scope="scope">
          <el-button type="text"
                     v-permission="'business_saveWine_edit'"
                     @click="edit(scope.row)">编辑
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      class="marginT-20"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      :hide-on-single-page="true"
      :current-page="page"
      :page-size="page_size"
      :page-sizes="[10, 20, 100, 200, 300, 400]"
      background
      layout="total, sizes, prev, pager, next, jumper"
      :total="totalCount"/>
    <detail v-if="detailsDialog.show"
            v-model="detailsDialog.show"
            :exData="detailsDialog.exData"
            @success="init"></detail>
  </div>
</template>

<script>
import page from '@/mixin/page'
import detail from './details'
import axios from 'axios'

export default {
  mixins: [page],
  components: {
    detail,
  },
  data () {
    return {
      detailsDialog: {
        show: false,
        exData: {}
      },
      time: [],
      searchForm: {},
      tableData: [],
      tableUrl: '/v1/user/storage/list'
    }
  },
  methods: {
    edit (row) {
      this.detailsDialog.exData = row
      this.detailsDialog.show = true
    }
  },
  mounted () {
    this.init()
  }
}
</script>

<style lang="scss" scoped>
.el-dropdown {
  margin: 0 10px;

  .el-dropdown-link {
    cursor: pointer;
    color: #409EFF;
  }
}
</style>
