<template>
  <div class="app-container">
    <div class="tab-header webtop">
      <div>调拨详情</div>
      <div>
        <el-button type="info" size="small" @click="handleReturn()">关闭</el-button>
      </div>
    </div>
    <div class="listconadd">
      <el-form ref="form_obj" :model="formobj" class="formaddcopy02">
        <el-row class="first_row">
          <el-col :span="8">
            <div class="span-sty">申请人</div>
            <el-form-item><span class="addinputInfo">{{ formobj.createByName }}</span></el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="span-sty">申请部门</div>
            <el-form-item><span class="addinputInfo">{{ formobj.deptName }}</span></el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="span-sty">申请日期</div>
            <el-form-item><span class="addinputInfo">{{ formobj.createTime }}</span></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="8">
            <div class="span-sty">调出站</div>
            <el-form-item><span class="addinputInfo">{{ formobj.outPlatName }}</span></el-form-item>
          </el-col>
          <el-col :span="5">
            <div class="span-sty">调入站</div>
            <el-form-item><span class="addinputInfo">{{ formobj.inOrgName }}</span></el-form-item>
          </el-col>
          <el-col :span="3">
            <el-form-item><span style="width: 100%;">{{ formobj.inPlatName }}</span></el-form-item>
          </el-col>
          <el-col :span="8">
            <div class="span-sty">经办人</div>
            <el-form-item><span class="addinputInfo">{{ formobj.confirmName }}</span></el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="24">
            <div class="span-sty">备注</div>
            <el-form-item><span class="addinputInfo">{{ formobj.remarks }}</span></el-form-item>
          </el-col>
        </el-row>
        <div class="title">调拨商品列表</div>
        <el-table :data="formobj.wmsInventoryAllocateBillDetailNewList" :index="index" border style="width: 100%;" show-summary :summary-method="getSummaries">
          <el-table-column fixed width="60" label="序号" type="index" :index="index + 1" align="center"/>
          <el-table-column prop="goodsID" label="商品ID" align="center"/>
          <el-table-column prop="goodsSpuName" label="商品名称" align="center"/>
          <el-table-column prop="goodsSkuCode" label="商品编码" align="center"/>
          <el-table-column prop="goodsSkuOwnSpec" label="型号" align="center"/>
          <el-table-column prop="unit" label="单位" align="center"/>
          <el-table-column prop="warehouseName" label="仓库" width="150" align="center"/>
          <el-table-column prop="warehouseZoneName" label="区域" width="150" align="center"/>
          <el-table-column prop="warehouseArea" label="库区" width="150" align="center"/>
          <el-table-column prop="warehouseRackCode" label="库位" align="center"/>
          <el-table-column prop="stockCount" label="库存数量" align="center"/>
          <el-table-column prop="markUpRatio" label="加价比例" align="center"/>
          <el-table-column prop="requAmount" label="调拨单价" align="center"/>
          <el-table-column prop="count" label="调拨数量" align="center"/>
          <el-table-column prop="amount" label="调拨金额" align="center" width="100"/>
        </el-table>
      </el-form>
    </div>
  </div>
</template>

<script>
import req from '@/api/storage/allocation.js'

export default {
  data() {
    return {
      index: 0,
      formobj: {}
    }
  },

  methods: {
    // 合计
    getSummaries(param) {
      const {
        columns,
        data
      } = param
      const sums = []
      columns.forEach((column, index) => {
        if (index === 0) {
          sums[index] = '合计'
          return
        }
        const values = data.map(item => Number(item[column.property]))
        if (column.property === 'count') {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          sums[index] += ''
        } else if (column.property === 'amount') {
          sums[index] = values.reduce((prev, curr) => {
            const value = Number(curr)
            if (!isNaN(value)) {
              return prev + curr
            } else {
              return prev
            }
          }, 0)
          sums[index] += ''
        }
      })
      return sums
    },
    showAdd(sid) {
      this.$nextTick(() => {
        this.$refs['form_obj'].clearValidate()
      })
      req.init(sid).then((res) => {
        if (res.success) {
          this.formobj = res.data
        }
      })
    },
    handleReturn(isreload) {
      if (isreload === 'true') this.$emit('reloadlist')
      this.formobj = {}
      this.$emit('doback')
    }
  }
}
</script>

<style scoped>
.span-sty {
  width: 130px !important;
}
.addinputInfo {
  margin-left: 120px !important;
}
.first_row {
  border-top: 1px solid #E0E3EB;
}
</style>
