<template>
  <div class="main-contain">
    <div class="position">

      <bread-crumb v-if="this.$route.query.type == 1" :crumbs='crumbs'></bread-crumb>
      <bread-crumb v-if="this.$route.query.type == 2" :crumbs='crumbs2'></bread-crumb>

    </div>
  <div class="app-container">

    <div class="filter-container">
      <span style="font-size: 20px;color: #606266">退库单详情</span>
      <el-row style="float:right;">
        <span style="color: #606266">{{CancelStockInfo.cancelStock.order_number}}</span>
      </el-row>
    </div>



    <div class="cell clearfix">
      <span style="width: 300px;color: #606266">单据日期:  {{CancelStockInfo.cancelStock.return_time | parseTime('{y}-{m}-{d}')}} </span>
      <span style="width: 300px;color: #606266">厂商 {{getManufactuerName(CancelStockInfo.cancelStock.manufacturer)}}</span>
      <span style="width: 300px;color: #606266">经销商 {{getDealerName(CancelStockInfo.cancelStock.dealer)}}</span>
    </div>

    <div class="filter-container" style="margin-top: 10px">
      <el-button size="small" icon="el-icon-edit" @click="editRecord">编辑</el-button>
      <el-button size="small" icon="el-icon-delete" @click="deleteRecord">删除</el-button>
    </div>

    <el-row :gutter="12" style="margin-top: 10px">
      <el-table :data="CancelStockInfo.cancelStockInfoData" :class="signAndWeighBoxPatients" style="width: 100%" 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.drug_id != 0">{{
                scope.row.drug.drug_name
              }}</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.drug_id != 0">{{
                scope.row.drug?scope.row.drug.drug_spec:''
              }}</span>
          </template>
        </el-table-column>

        <el-table-column min-width="23" align="center">
          <template slot="header" slot-scope="scope">
            <span>退库数量</span>
          </template>
          <template slot-scope="scope">
            <span>{{scope.row.count}}</span>

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


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

</template>

<script>
  import { uParseTime } from '@/utils/tools'
  import { GetAllConfig, getDrugCancelStockInfo, deleteDrugCancelStock } from '@/api/drug/drug_stock'
  import BreadCrumb from '../../components/bread-crumb'

  export default {
    name: 'cancelStockOrderDetail',
    components: { BreadCrumb },
    created() {
      const order_id = this.$route.query.id
      this.GetConfigInfo()
      this.GetOrderDetail(order_id)
    },
    data() {
      return {
        crumbs: [
          { path: false, name: '库存管理' },
          { path: false, name: '耗材退库单' },
          { path: false, name: '退库单详情' }
        ],
        crumbs2: [
          { path: false, name: '库存管理' },
          { path: false, name: '其他退库单' },
          { path: false, name: '退库单详情' }
        ],
        isEdit: 0,
        checked: false,
        signAndWeighBoxPatients: 'sign-and-weigh-box-patients',
        goodType: [],
        goodInfo: [],
        manufacturer: [],
        dealer: [],

        CancelStockInfo: {
          loading: false,
          cancelStockInfoData: [],
          cancelStock: {}
        }
      }
    },
    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
      }, GetConfigInfo: function() {
        GetAllConfig().then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg)
            return false
          } else {
            this.manufacturer = response.data.data.manufacturer
            this.dealer = response.data.data.dealer
            this.goodInfo = response.data.data.goodInfo
            this.goodType = response.data.data.goodType
          }
        })
      }, getManufactuerName: function(manufacturer_id) {
        for (let i = 0; i < this.manufacturer.length; i++) {
          if (this.manufacturer[i].id == manufacturer_id) {
            return this.manufacturer[i].manufacturer_name
          }
        }
      }, getDealerName: function(dealer_id) {
        for (let i = 0; i < this.dealer.length; i++) {
          if (this.dealer[i].id == dealer_id) {
            return this.dealer[i].dealer_name
          }
        }
      }, calculate: function(val) {
        if (val == 0) {
          return ''
        }
        return Math.round(parseFloat(val) * 100) / 100
      }, GetOrderDetail: function(order_id) {
        const params = {
          'id': order_id
        }
        getDrugCancelStockInfo(params).then(response => {
          if (response.data.state == 0) {
            this.$message.error(response.data.msg)
            return false
          } else {
            for (let i = 0; i < response.data.data.list.length; i++) {
              this.CancelStockInfo.cancelStockInfoData.push(response.data.data.list[i])
            }
            this.CancelStockInfo.cancelStock = response.data.data.info
          }
        })
      }, deleteRecord: function() {
        const ids = []
        ids.push(this.CancelStockInfo.cancelStock.id)
        const idStr = ids.join(',')

        const params = {
          ids: idStr
        }

        this.$confirm('确认删除退货单?', '删除退货单记录', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          deleteDrugCancelStock(params).then(response => {
            if (response.data.state == 0) {
              this.$message.error(response.data.msg)
              return false
            } else {
              this.$notify({
                title: '成功',
                message: '删除成功',
                type: 'success',
                duration: 2000
              })

              this.$router.back(-1)
            }
          })
        }).catch(() => {
        })
      }, editRecord: function() {
        this.$emit('edit-record')
      }
    }
  }
</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>
