<!--
  @description:库存管理
  @Modifier: 郝定康
  @routerPath: /procurement/procurementStock
  @date: 2021-02-23 10:00:42
-->
<template>
  <div>
    <table-crud
      ref="tableCrud"
      :menu="true"
      :search-form="searchForm"
      search-label-width="120px"
      @on-load="loadData"
    >
      <template v-slot:header>
        <span>库存管理</span>
      </template>
      <template v-slot:search="search">
        <el-form-item ref="depotSite" label="库存地址" prop="depotSite">
          <el-input
            v-model="searchForm.depotSite"
            placeholder="请输入库存地址"
            @keyup.enter.native="search.onSearch"
          />
        </el-form-item>
      </template>
      <template v-slot:menuLeft>
        <div class="mb10">
          <el-button type="primary" plain @click="addDictionary">
            库存地址录入
          </el-button>
        </div>
      </template>
      <template v-slot:GXTable>
        <el-table
          ref="multipleTable"
          v-loading="loading"
          :data="tableData"
        >
          <el-table-column
            type="index"
            label="序号"
            align="center"
            width="60"
          />
          <el-table-column
            prop="depotSite"
            label="库存地址"
          />
          <el-table-column
            prop="linkman"
            label="联系人"
          />
          <el-table-column
            prop="linkmanMobile"
            label="电话"
          />
          <el-table-column
            label="操作"
            align="center"
          >
            <template slot-scope="scope">
              <el-link
                type="primary"
                @click="handleUpdate(scope.row)"
              >
                [编辑]
              </el-link>
              <el-link
                type="primary"
                @click="handleDelete(scope.row.id,scope.$index)"
              >
                [删除]
              </el-link>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </table-crud>
    <!-- 字典分类录入 、编辑 -->
    <stockAddDialog ref="stockAddDialog" @typeGroupLoadData="result" />
  </div>
</template>
<script>
/* api*/
import { getAreaDepotMappedList, delAreaDepotMappedList } from '@/api/procurement/purchasplan'
/* 组件*/
import stockAddDialog from './stockAdd-dialog'
export default {
  name: 'StockList',
  components: {
    stockAddDialog // 库存管理录入 、编辑
  },
  data() {
    return {
      loading: true,
      tableData: [],
      searchForm: {
        depotSite: '' // 库存地址
      }
    }
  },
  methods: {
    // 初始化页面
    loadData(params, callback, tabData) {
      getAreaDepotMappedList(params).then(res => {
        this.loading = false
        const { data } = res
        this.tableData = data.records
        callback(res.data.total)
      }).catch(() => {
        this.loading = false
      })
    },
    // 库存管理录入
    addDictionary() {
      this.$refs.stockAddDialog.openStockEdit('create')
    },
    // 编辑
    handleUpdate(row) {
      this.$refs.stockAddDialog.openStockEdit('update', row)
    },

    // 删除
    handleDelete(id, index) {
      this.$confirm('确认要删除吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        confirmButtonClass: 'confirmBtn',
        cancelButtonClass: 'cancelBtn',
        type: 'warning'
      }).then(() => {
        const params = {
          id
        }
        delAreaDepotMappedList(params).then(() => {
          this.$message.success('删除成功')
          // 查询数据
          this.$refs.tableCrud.onSearchChange()
        })
      })
    },
    result() {
      // 查询数据
      this.$refs.tableCrud.onSearchChange()
    }
  }
}
</script>
<style lang="less" scoped>
</style>
