<template>
  <div class="main-contain">
    <div class="position">
      <bread-crumb :crumbs='crumbs'></bread-crumb>
    </div>

    <div class="app-container">

      <div class="filter-container">
        <span style="font-size: 18px;color: #606266">商品使用明细</span>
      </div>

      <div class="cell clearfix">
        <span style="width: 300px;color: #606266">商品类型: {{userList[0].type.type_name}} </span>
        <span style="width: 300px;color: #606266">规格名称: {{userList[0].info.specification_name}}</span>
      </div>

      <el-row :gutter="12" style="margin-top: 10px">
        <el-table :data="userList" :class="signAndWeighBoxPatients" style="width: 50%"
                  border :header-cell-style="{ backgroundColor: 'rgb(245, 247, 250)'}"
        >
          <el-table-column min-width="35" align="center">
            <template slot="header" slot-scope="scope">
              <span>序号</span>
            </template>
            <template slot-scope="scope">
              <span v-if="scope.row.is_total == 0">{{scope.$index+1}}</span>
              <span v-if="scope.row.is_total == 1">{{'合计'}}</span>
            </template>
          </el-table-column>

          <el-table-column min-width="35" align="center">
            <template slot="header" slot-scope="scope">
              <span>使用人</span>
            </template>
            <template slot-scope="scope">
              <span v-if="scope.row.is_total == 0">{{scope.row.user.name}}</span>
              <span v-if="scope.row.is_total == 1"></span>
            </template>
          </el-table-column>
          <el-table-column min-width="35" align="center">
            <template slot="header" slot-scope="scope">
              <span>使用数量</span>
            </template>
            <template slot-scope="scope">
              <span v-if="scope.row.is_total == 0">{{scope.row.count}}</span>
              <span  v-if="scope.row.is_total == 1">{{scope.row.total}} </span>

            </template>
          </el-table-column>
          <el-table-column min-width="35" align="center">
            <template slot="header" slot-scope="scope">
              <span>使用时间</span>
            </template>
            <template slot-scope="scope">
              <span>{{scope.row.ctime | parseTime('{y}-{m}-{d} {h}:{i}')}} </span>

            </template>
          </el-table-column>

        </el-table>
      </el-row>
    </div>
  </div>
</template>

<script>
  import { uParseTime } from '@/utils/tools'
  import { getWarehouseOutUser } from '@/api/stock'
  import BreadCrumb from '../components/bread-crumb'

  export default {
    name: 'stockInOrderDetail',
    components: { BreadCrumb },
    created() {
      const order_id = this.$route.query.id
      this.GetOrderDetail(order_id)
    },
    data() {
      return {
        crumbs: [
          { path: false, name: '库存管理' },
          { path: false, name: '耗材出库单' },
          { path: false, name: '出库单详情' },
          { path: false, name: '使用明细' }

        ],
        signAndWeighBoxPatients: 'sign-and-weigh-box-patients',
        userList:[]
      }
    },
    methods: {
      getSpecificationName: function(id) {
        let name = ''
        for (let i = 0; i < this.goodInfo.length; i++) {
          if (this.goodInfo[i].id == id) {
            name = this.goodInfo[i].specification_name
          }
        }
        return name
      }, getTypeName: function(id) {
        let name = ''
        for (let i = 0; i < this.goodType.length; i++) {
          if (this.goodType[i].id == id) {
            name = this.goodType[i].type_name
          }
        }
        return name
      }, GetOrderDetail: function(order_id) {
        const params = {
          'id': order_id
        }
        getWarehouseOutUser(params).then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg)
            return false
          } else {
            var total = 0
            for (let i = 0; i < response.data.data.list.length; i++) {
              var obj = response.data.data.list[i]
              obj['is_total'] = 0
              this.userList.push(obj)
              total = total + response.data.data.list[i].count
            }
            this.userList.push({
              is_total: 1,
              total: total,
            })

            console.log(this.userList)
          }
        })
      }
    }
  }
</script>

<style rel="stylesheet/css" lang="scss" scoped>
  .information {
    border: 1px #dcdfe6 solid;
    padding: 30px 20px 30px 20px;

  .border {
    border-bottom: 1px #dcdfe6 solid;
    margin: 0px 0 20px 0;
  }

  }


  .edit_separater {
    border-top: 1px solid rgb(233, 233, 233);
    margin-top: 15px;
    margin-bottom: 15px;
  }

</style>

<style>
  .sign-and-weigh-box .sign-and-weigh-box-patients .cell {
    font-size: 12px;
  }

  .sign-and-weigh-box .sign-and-weigh-box-patients .current-row > td {
    background: #6fb5fa;
  }

  .count {
    color: #bd2c00;

  }

</style>
