<template>
  <div>
    <el-dialog title="选择资产" :visible.sync="show" width="800px" :before-close="handleClose">
      <div class="search">
        <el-input v-model="msg.Name" placeholder="请输入资产名称" @keyup.native.enter="getData" size="small"
          style="margin-right:25px"></el-input>
        <el-button type="primary" size="small" @click="getData">搜索</el-button>
      </div>
      <div>
        <el-table :data="tableData" style="width: 100%" height="50vh">
          <el-table-column width="80" label="Id" align="center" fixed>
            <template slot-scope="scope">
              <el-radio v-model="radio" :label="scope.row.Id"></el-radio>
            </template>
          </el-table-column>
          <el-table-column prop="Name" label="名称" width="180" align="center"></el-table-column>
          <el-table-column prop="SuppliesNum" label="资产编码" width="120" align="center"></el-table-column>
          <el-table-column prop="CategoryName" label="分类" width="120" align="center"></el-table-column>
          <el-table-column prop="BrandName" label="品牌" width="120" align="center">
          </el-table-column>
          <el-table-column prop="SuppliesModel" label="型号" width="120" align="center">
          </el-table-column>
          <el-table-column prop="Units" label="单位" width="80" align="center">
          </el-table-column>
          <el-table-column prop="Money" label="单价" width="120" align="center">
          </el-table-column>
          <el-table-column prop="InventoryNum" label="库存" width="80" align="center"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close">取 消</el-button>
        <el-button type="primary" @click="confirm">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    model: {
      prop: "show",
      event: "change"
    },
    props: {
      show: {
        type: Boolean,
        default: false
      }
    },
    data() {
      return {
        tableData: [],
        radio: "",
        msg: {
          RB_Group_Id: 0,
          Name: ""
        }
      };
    },
    methods: {
      close() {
        this.$emit("change", false);
      },
      confirm() {
        let res = this.tableData.find(e => e.Id === this.radio);
        if (res) {
          const obj = JSON.parse(JSON.stringify(res));
          obj.ImageList = obj.ImageList.map(e => {
            e = "http://imgfile.oytour.com" + e;
            return {
              Path: e
            };
          });
          this.close();
          this.$emit("confirm", obj);
        } else {
          this.$message.error("请选择资产");
        }
      },
      getData() {
        if (!this.msg.Name) {
          this.$message.error("请输入资产名称");
          return;
        }
        this.i_post("/api/Property/GetEduGoodsMaterialList", this.msg, res => {
          this.tableData = res.data.data;
        });
      },
      handleClose(done) {
        this.close();
      }
    },
    mounted() {
      let apiData = JSON.parse(localStorage.getItem("iframeData"));
      this.msg.RB_Group_Id = apiData.GroupId;
    }
  };

</script>
<style scoped>
  .search {
    display: flex;
    align-items: center;
    flex-wrap: nowrap;
  }

</style>
