<template>
  <div>
    <el-card>
      <el-form :model="filterQuery" label-width="100px" size="mini">
        <el-row>
          <el-col :span="8">
            <el-form-item label="模板名称:" class="query-form-item">
              <el-input v-model="filterQuery.name" placeholder="请输入模板名称"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="模板编码:" class="query-form-item">
              <el-input v-model="filterQuery.code" placeholder="请输入模板编码"></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="8" >
            <el-form-item>
              <el-button-group>
                <el-button type="primary" icon="el-icon-refresh" @click="onReset"></el-button>
                <el-button type="primary" icon="search" @click="onSubmit">查询</el-button>
                <el-button type="primary" icon="search" @click="combine">选入</el-button>
              </el-button-group>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>

      <el-table :data="list"  border highlight-current-row   @current-change="handleChange" style="width: 100%" >
        <el-table-column width="50">
          <template slot-scope="scope">
            <el-radio v-model="radio" :label="scope.row.id" ><span></span></el-radio>
          </template>
        </el-table-column>
        <el-table-column label="序号" type="index"></el-table-column>
        <el-table-column label="模板名称" prop="name" ></el-table-column>
        <el-table-column label="模板编码" prop="code" ></el-table-column>
        <el-table-column label="规格" prop="ggxh" ></el-table-column>
        <el-table-column label="价格" prop="price" >
          <template slot-scope="scope">
            {{ scope.row.price == "null" ? "0.00":scope.row.price }}
          </template>
        </el-table-column>
<!--        <el-table-column label="备注" prop="remark" ></el-table-column>-->
        <el-table-column label="创建人" prop="createByName" ></el-table-column>
        <el-table-column label="创建时间" prop="createTime" ></el-table-column>
      </el-table>

      <pagination
          v-show="total>0"
          :total="total"
          :limit.sync="filterQuery.limit"
          :page.sync="filterQuery.page"
          @pagination="handleCurrentChange"
      ></pagination>
    </el-card>
  </div>
</template>

<script>
import {
  addModeldestiny,
  delectModeldestiny,
  filterDestinyDelect,
  getBasicDestinyfilter
} from "@/api/basic/basicDestinyRel";
import destinyModelEdit from "@/views/basic/destiny/destinyModelEdit";
import destinyModelSelectProduct from "@/views/basic/destiny/destinyModelSelectProduct";
import {isBlank} from "@/utils/strUtil";


export default {
  props: {
    closeDialog: {
      type: Function,
      required: true,
    },
  },
  data() {
    return {
      filterQuery: {
        name: "",
        code: "",
        type: 1,
        status: 3,
        page: 1,
        limit: 20
      },
      total: 0,
      destinyId:null,
      radio:null,
      currentRow:null,
      list: [],
    };
  },
  methods: {
    onReset() {
      this.$router.push({
        path: ""
      });
      this.filterQuery = {
        name: "",
        code: "",
        type: 1,
        status: 3,
        page: 1,
        limit: 20
      };
      this.getList();
      this.destinyId=null
    },
    onSubmit() {
      this.$router.push({
        path: "",
      });
      this.filterQuery.page = 1;
      this.getList();
    },
    getList() {
      this.loading = true;
      getBasicDestinyfilter(this.filterQuery).then(response => {
        this.loading = false;
        this.list = response.data.list || [];
        this.total = response.data.total || 0;
      }).catch(() => {
        this.loading = false;
        this.list = [];
        this.total = 0;
        this.roles = [];
      });
    },
    handleCurrentChange(val) {
      this.filterQuery.page = val.page;
      this.getList();
    },
    showRow (row) {
      this.destinyId= row
    },
    combine(){
      if (this.currentRow == null) {
        this.$message.error('未选择定数包');
        return;
      }
      this.closeDialog(this.currentRow.id);
    },
    handleChange(val) {
      this.radio = val.id;
      this.currentRow = val;
    },
  }
  ,
  mounted() {
  }
  ,
  created() {
    this.getList();
  }
}
;
</script>
