<template>
  <div>
    <div class="i-layout-page-header">
      <PageHeader :title="$route.meta.title" :content="$route.meta.description" hidden-breadcrumb />
    </div>
    <Card :bordered="false" dis-hover class="ivu-mt">
      <view-table ref="table" view-code="StorageFrozen">
        <template #command="{ row }">
          <Button v-if="row.storageStatus != 'Frozen'" size="small" title="冻结" type="warning" custom-icon="fa fa-lock" @click="frozen(row)"></Button>
          <Button v-if="row.storageStatus == 'Frozen'" size="small" title="解冻" type="primary" custom-icon="fa fa-lock-open" @click="unfrozen(row)"></Button>
        </template>
      </view-table>
    </Card>
  </div>
</template>
<script>
  import { mixinPage } from 'mooho-base-admin-plus';
  import storageApi from '../../api/storage';

  export default {
    name: 'storage-storageFrozen',
    mixins: [mixinPage],
    components: {},
    data() {
      return {
        filter: {}
      };
    },
    computed: {},
    created() {},
    methods: {
      // 冻结
      frozen(row) {
        this.confirm('确定要冻结该批次物料吗？', async () => {
          await storageApi.storageStatusChange({
            warehouseID: row.warehouseID,
            materialID: row.materialID,
            batchNumber: row.batchNumber,
            supplierID: row.supplierID,
            storageStatus: 'Frozen'
          });

          this.success('冻结成功!', () => {
            this.$refs.table.loadData();
          });
        });
      },
      // 解冻
      unfrozen(row) {
        this.confirm('确定要解冻该批次物料吗？', async () => {
          await storageApi.storageStatusChange({
            warehouseID: row.warehouseID,
            materialID: row.materialID,
            batchNumber: row.batchNumber,
            supplierID: row.supplierID,
            storageStatus: 'Normal'
          });

          this.success('解冻成功!', () => {
            this.$refs.table.loadData();
          });
        });
      }
    }
  };
</script>
