<template>
  <el-dialog
    append-to-body
    :visible.sync="dialogVisible"
    destroy-on-close
    width="1000px"
    @close="close"
    @open="open"
  >
    <span>起点点位列表:</span>
    <!--表格渲染-->
    <el-table
      ref="table"
      v-loading="crud.loading"
      :data="crud.data"
      style="width: 100%;"
      size="mini"
      border
      :cell-style="{'text-align':'center'}"
      :header-cell-style="{background:'#f5f7fa',color:'#606266','text-align':'center'}"
      @select="handleSelectionChange"
      @select-all="onSelectAll"
      @current-change="clickChange"
    >
      <el-table-column v-if="!isSingle" type="selection" width="55" />
      <el-table-column v-if="isSingle" label="选择" width="55">
        <template slot-scope="scope">
          <el-radio v-model="tableRadio" :label="scope.row"><i /></el-radio>
        </template>
      </el-table-column>
      <el-table-column prop="point_name" label="起点点位名称" min-width="110" show-overflow-tooltip />
      <el-table-column prop="area_type" label="所属区域" width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ dict.label.sch_area_type[scope.row.area_type] }}
        </template>
      </el-table-column>
      <el-table-column prop="material_name" label="物料名称" show-overflow-tooltip />
      <el-table-column prop="pcsn" label="批次" show-overflow-tooltip />
      <el-table-column prop="vehicle_code111" label="载具编码" show-overflow-tooltip />
      <el-table-column prop="canuse_qty" label="可用数" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ fun(scope.row.canuse_qty) }}
        </template>
      </el-table-column>
      <el-table-column prop="frozen_qty" label="冻结数" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ fun(scope.row.frozen_qty) }}
        </template>
      </el-table-column>
      <el-table-column prop="ivt_qty" label="库存数" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ fun(scope.row.ivt_qty) }}
        </template>
      </el-table-column>
      <el-table-column prop="warehousing_qty" label="待入数" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ fun(scope.row.warehousing_qty) }}
        </template>
      </el-table-column>
      <el-table-column prop="unit_name" label="数量单位" show-overflow-tooltip />
      <el-table-column prop="instorage_time" label="入库时间" show-overflow-tooltip />
      <el-table-column prop="point_type" label="点位类型">
        <template slot-scope="scope">
          {{ dict.label.sch_point_type[scope.row.point_type] }}
        </template>
      </el-table-column>
    </el-table>
    <!--分页组件-->
    <pagination />
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取 消</el-button>
      <el-button type="primary" @click="submit">确 定</el-button>
    </span>

  </el-dialog>
</template>

<script>

import CRUD, { presenter, header } from '@crud/crud'
import pagination from '@crud/Pagination'
import crudWorkprocedureiosOut from '@/api/wms/st/out/workprocedureiosOut'

export default {
  name: 'StartPointDialog',
  components: { pagination },
  dicts: ['sch_area_type', 'sch_point_type'],
  cruds() {
    return CRUD({ title: '起始点位', url: 'api/workprocedureiosOut/getStartPoint', crudMethod: { ...crudWorkprocedureiosOut }, optShow: {}})
  },
  mixins: [presenter(), header()],
  props: {
    dialogShow: {
      type: Boolean,
      default: false
    },
    isSingle: {
      type: Boolean,
      default: true
    },
    openParam: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      formInline: {
        search: ''
      },
      tableRadio: '',
      tableData: [],
      dialogVisible: false,
      material: {}
    }
  },
  watch: {
    dialogShow: {
      handler(newValue, oldValue) {
        this.dialogVisible = newValue
        this.material = this.openParam
      }
    }
  },
  methods: {
    fun(val) {
      return Number(val).toFixed(2)
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {
        })
    },
    open() {
      console.log(this.openParam)
      this.query.material_id = this.openParam.material_id
      this.query.is_full = this.openParam.is_full
      this.query.ivt_workprocedure_id = this.openParam.ivt_workprocedure_id
      this.crud.toQuery()
    },
    close() {
      this.crud.resetQuery(false)
      this.$emit('update:dialogShow', false)
    },
    submit() {
      // 处理单选
      if (this.isSingle && this.tableRadio) {
        this.$emit('update:dialogShow', false)
        this.$emit('tableChanged2', this.tableRadio)
        return
      }
      this.rows = this.$refs.table.selection
      if (this.rows.length <= 0) {
        this.$message('请先选择起点点位')
        return
      }
      this.crud.resetQuery(false)
      this.$emit('update:dialogShow', false)
      this.$emit('tableChanged2', this.rows)
    },
    handleSelectionChange(val, row) {
      if (val.length > 1) {
        this.$refs.table.clearSelection()
        this.$refs.table.toggleRowSelection(val.pop())
      } else {
        this.checkrow = row
      }
    },
    onSelectAll() {
      this.$refs.table.clearSelection()
    },
    clickChange(item) {
      this.tableRadio = item
    },
    hand(value) {
      this.crud.toQuery()
    }
  }
}
</script>

<style scoped>
.crud-opts2 {
  padding: 4px 0;
  display: -webkit-flex;
  display: flex;
  align-items: center;
}

.crud-opts2 .crud-opts-right2 {
  margin-left: auto;
}

.el-table_body tr.current-row>td {
  background-color: #e9e500;
}
</style>
