<template>
  <div>
    <div class="title_box rx-bc mt6">
      <div class="name">副产品回收 </div>

      <div class="rx-bc"> </div>
    </div>

    <ele-pro-table
      ref="table"
      :needPage="false"
      :columns="columns"
      :datasource="list"
      class="time-form"
      max-height="600"
      @columns-change="handleColumnChange"
      :cache-key="cacheKeyUrl"
      :selection.sync="selection"
      @selection-change="handleSelectionChange"
      row-key="id"
    >
      <template v-slot:recycleQuantity="{ row, $index }">
        <el-input
          size="mini"
          class="content_num"
          v-model="row.recycleQuantity"
          placeholder="请输入重量"
        />
      </template>

      <template v-slot:action="{ row, $index }">
        <el-link type="text" @click="penalize($index)" v-if="!isDetails"
          >处置</el-link
        >
        <el-link
          type="text"
          @click="handleView(item.warehouseName)"
          v-if="isDetails"
          >查看</el-link
        >
      </template>
    </ele-pro-table>

    <!-- <div class="material">
      <div class="content_table2">
        <div class="head row rx-sc">
          <div class="item ww30">物料编码</div>
          <div class="item ww30">物料名称</div>
          <div class="item ww40">重量</div>
        </div>

        <div class="table">
          <div class="tr row rx-sc" v-for="(item, index) in list" :key="index">
            <div class="item ww30">{{ item.code }}</div>
            <div class="item ww30">{{
              isDetails ? item.categoryName : item.name
            }}</div>
            <div class="item ww40 content_num">
              <el-input
                v-model="item.recycleQuantity"
                type="digit"
                v-if="!isDetails"
              ></el-input>
              <div v-if="isDetails">{{ item.quantity }}</div>
              <div class="unit">{{ item.unit }}</div>
            </div>

            <div
              class="penalize"
              v-if="!isDetails"
              :style="{ background: item.warehouseId ? '#FFA07A' : '' }"
              @click="penalize(index)"
              >处置</div
            >
            <div
              v-if="isDetails"
              class="penalize"
              :style="{ background: item.warehouseId ? '#FFA07A' : '' }"
              @click="handleView(item.warehouseName)"
              >查看</div
            >
          </div>
        </div>
      </div>
    </div> -->

    <el-dialog
      title="仓库处置"
      :visible.sync="visible"
      :before-close="handleClose"
      :close-on-click-modal="false"
      :close-on-press-escape="false"
      append-to-body
      width="500px"
    >
      <el-form size="mini" :model="form" label-width="96px">
        <el-form-item label="仓库" prop="warehouseList">
          <el-select
            v-model="form.warehouseId"
            filterable
            placeholder="请选择仓库"
          >
            <el-option
              v-for="item in warehouseList"
              :label="item.name"
              :value="item.id"
              :key="item.id"
            >
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>

      <template slot="footer">
        <el-button size="mini" @click="visible = false">取 消</el-button>
        <el-button size="mini" type="primary" @click="warehouseSave"
          >保 存</el-button
        >
      </template>
    </el-dialog>
  </div>
</template>

<script>
  import {
    getWarehouseList

    // queryKilnXCH
  } from '@/api/mes';
  import tabMixins from '@/mixins/tableColumnsMixin';
  export default {
    name: 'semiProductJobBom',
    mixins: [tabMixins],
    props: {
      list: {
        type: Array,
        default: () => []
      },

      isDetails: {
        type: Boolean,
        default: false
      }

      // warehouseList: {
      //   type: Array,
      //   default: () => []
      // }
    },

    created() {
      this.getWarehouseFn();
    },

    computed: {
      columns() {
        let name = {
          width: 120,
          show: false
        };
        let categoryName = {
          width: 120,
          show: false
        };

        let recycleQuantity = {
          width: 120,
          show: false
        };

        let quantity = {
          width: 120,
          show: false
        };

        if (this.isDetails) {
          categoryName = {
            minWidth: 120,
            prop: 'categoryName',
            label: '物料名称',
            align: 'center',
            showOverflowTooltip: true,
            show: true
          };
          quantity = {
            minWidth: 120,
            prop: 'quantity',
            label: '重量',
            align: 'center',
            showOverflowTooltip: true,
            show: true
          };
        } else {
          name = {
            minWidth: 120,
            prop: 'name',
            label: '物料名称',
            align: 'center',
            showOverflowTooltip: true,
            show: true
          };
          recycleQuantity = {
            minWidth: 120,
            prop: 'recycleQuantity',
            slot: 'recycleQuantity',
            label: '重量',
            align: 'center',
            showOverflowTooltip: true,
            show: true
          };
        }

        return [
          {
            width: 45,
            type: 'selection',
            columnKey: 'selection',
            align: 'center',
            fixed: 'left',
            reserveSelection: true
          },
          {
            width: 55,
            type: 'index',
            columnKey: 'index',
            align: 'center',
            label: '序号',
            fixed: 'left'
          },
          {
            minWidth: 120,
            prop: 'code',
            label: '编码',
            align: 'center',
            showOverflowTooltip: true
          },
          categoryName,
          name,
          quantity,
          recycleQuantity,
          {
            minWidth: 120,
            prop: 'unit',
            label: '单位',
            align: 'center',
            showOverflowTooltip: true
          },
          {
            columnKey: 'action',
            label: '操作',
            width: 120,
            align: 'center',
            resizable: false,
            slot: 'action',
            fixed: 'right',
            showOverflowTooltip: true
          }
        ];
      }
    },

    data() {
      return {
        form: {
          warehouseId: null
        },
        penalizeIndex: null,
        visible: false,
        selection: [],
        cacheKeyUrl: 'produce-job-booking-by-product-bom',
        warehouseList: []
      };
    },

    methods: {
      handleClose() {
        this.penalizeIndex = null;

        this.visible = false;
      },

      penalize(index) {
        this.penalizeIndex = index;
        this.visible = true;
      },

      handleSelectionChange(data) {},

      warehouseSave() {
        this.$set(
          this.list[penalizeIndex],
          'warehouseId',
          this.form.warehouseId || null
        );

        this.handleClose();
        this.$forceUpdate();
      },
      handleView(name) {
        this.$message.info(name || '未设置');
      },
      getWarehouseFn() {
        getWarehouseList().then((res) => {
          this.warehouseList = res;
        });
      }
    }
  };
</script>

<style lang="scss" scoped>
  .materialBor {
    border: 1rpx solid #157a2c;
  }
</style>
