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

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

    <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>
  export default {
    name: 'semiProductJobBom',

    props: {
      list: {
        type: Array,
        default: () => []
      },

      isDetails: {
        type: Boolean,
        default: false
      },

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

    data() {
      return {
        form: {
          warehouseId: null
        },
        penalizeIndex: null,
        visible: false
      };
    },

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

        this.visible = false;
      },

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

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

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

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