<template>
  <div>
    <el-dialog
      title="选择委外物品"
      width="70%"
      :close-on-click-modal="false"
      :visible.sync="visible">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="search()">
        <el-form-item label="物品名称">
          <el-input v-model="dataForm.productName" placeholder="物品名称" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-button @click="search()">查询</el-button>
          <el-button type="primary" @click="addItems()">添加</el-button>
  <!--          <el-button @click="visible = false" type="primary">返回</el-button>-->
        </el-form-item>
      </el-form>
      <el-table
        :data="dataList"
        border
        v-loading="dataListLoading"
        @selection-change="selectionChangeHandle"
        style="width: 100%;">
        <el-table-column
          type="selection">
        </el-table-column>
        <el-table-column
          label="序号"
          type="index"
          width="50"
          align="center">
        </el-table-column>
        <el-table-column
          prop="purchaseCode"
          header-align="center"
          align="center"
          min-width="180"
          :show-tooltip-when-overflow="true"
          label="采购编码">
        </el-table-column>
        <el-table-column
          prop="productName"
          header-align="center"
          align="center"
          width="160"
          :show-tooltip-when-overflow="true"
          label="产品名称">
        </el-table-column>
        <el-table-column
          prop="specificationExplian"
          header-align="center"
          align="center"
          width="160"
          :show-tooltip-when-overflow="true"
          label="要求说明">
        </el-table-column>
        <el-table-column
          prop="cnt"
          header-align="center"
          align="center"
          label="数量">
        </el-table-column>
        <el-table-column
          prop="unitName"
          header-align="center"
          align="center"
          min-width="100"
          :show-tooltip-when-overflow="true"
          label="单位">
        </el-table-column>
        <el-table-column
          prop="deadline"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="委外期限">
        </el-table-column>
        <el-table-column
          prop="arrivedTime"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="到料时间">
        </el-table-column>
        <el-table-column
          prop="batchNumber"
          header-align="center"
          align="center"
          min-width="160"
          :show-tooltip-when-overflow="true"
          label="批次号/用途">
        </el-table-column>
        <el-table-column
          prop="notes"
          header-align="center"
          align="center"
          min-width="180"
          :show-overflow-tooltip="true"
          label="备注">
        </el-table-column>
      </el-table>
      <el-pagination
        @size-change="sizeChangeHandle"
        @current-change="currentChangeHandle"
        :current-page="pageIndex"
        :page-sizes="[10, 20, 50, 100]"
        :page-size="pageSize"
        :total="totalPage"
        layout="total, sizes, prev, pager, next, jumper">
      </el-pagination>
    </el-dialog>
  </div>
</template>

<script>
  export default {
    name: 'outsource-chose',
    data () {
      return {
        visible: false,
        dataForm: {},
        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: []
      }
    },
    methods: {
      init () {
        this.visible = true
        this.getDataList()
      },
      search () {
        this.pageIndex = 1
        this.getDataList()
      },
      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/biz-service/purCommDetail/listDetail'),
          method: 'get',
          params: this.$http.adornParams({
            'current': this.pageIndex,
            'size': this.pageSize,
            'productName': this.dataForm.productName ? this.dataForm.productName : null,
            'purchaseState': 3
          })
        }).then(({data}) => {
          if (data && data.code === '200') {
            this.dataList = data.data.records
            this.totalPage = Number(data.data.total)
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 添加
      exportItem (item) {
        this.$emit('addItem', item)
      },
      addItems () {
        if (this.dataListSelections.length === 0) {
          this.$message.warning('请选择物品')
          return
        }
        this.visible = false
        this.$emit('addItems', this.dataListSelections)
      }
    }
  }
</script>

<style scoped>

</style>
