<template>
  <el-container>
    <el-header>
      <div class="left-panel">
        <el-input
            v-model="query.search"
            placeholder="名称"
            clearable
            style="margin-right: 5px;"
          ></el-input>
          <el-button
            type="primary"
            icon="el-icon-search"
            @click="handleQuery"
          ></el-button>
      </div>
      <div class="right-panel">
			  <el-button type="primary" icon="el-icon-plus" @click="table_add" v-auth="'mpoint.create'"></el-button>
      </div>
    </el-header>
    <el-main class="nopadding">
			<scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" hidePagination>
				<el-table-column label="#" type="index" width="50"></el-table-column>
				<el-table-column label="名称" prop="name" min-width="100"></el-table-column>
				<el-table-column label="计量物料" prop="material_name" min-width="150"></el-table-column>
				<el-table-column label="所属部门" prop="belong_dept_name" min-width="150"></el-table-column>
				<el-table-column label="所属工段" prop="mgroup_name" min-width="150"></el-table-column>
				<el-table-column label="创建时间" prop="create_time" min-width="150"></el-table-column>
				<el-table-column label="操作" fixed="right" align="center" width="140">
					<template #default="scope">
						<el-button link size="small" @click="table_edit(scope.row)" v-auth="'mpoint.update'" type="primary">编辑</el-button>
						<el-divider direction="vertical"></el-divider>
						<el-popconfirm title="确定删除吗？" @confirm="table_del(scope.row, scope.$index)">
							<template #reference>
								<el-button link size="small" v-auth="'mpoint.delete'" type="danger">删除</el-button>
							</template>
						</el-popconfirm>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
  </el-container>
  <save-dialog
    v-if="dialog.save"
    ref="saveDialog"
    @success="handleSaveSuccess"
    @closed="dialog.save = false"
  ></save-dialog>
  <el-drawer
    title="测点原始记录"
    v-model="logShow"
    :size="1000"
    destroy-on-close
  >
   1111
  </el-drawer>
</template>
<script>
import saveDialog from "./mpoint_form.vue";
export default {
  name: "rparty",
  components: {
    saveDialog,
  },
  data() {
    return {
      logShow:false,
      dialog: {
        save: false,
        permission: false,
      },
      apiObj: this.$API.enm.mpoint.list,
      query: {},
      selection: [],
    };
  },
  methods: {
    //添加
    table_add() {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("add");
      });
    },
    //编辑
    table_edit(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("edit").setData(row);
      });
    },
    //原始测点记录
    mplog(row){
      this.logShow = true;
    },
    //查看
    table_show(row) {
      this.dialog.save = true;
      this.$nextTick(() => {
        this.$refs.saveDialog.open("show").setData(row);
      });
    },
    //删除
    table_del(row) {
      var id = row.id;
      this.$API.mtm.team.delete.req(id).then(res=>{
        if(res.err_msg){
          this.$message.error(res.err_msg)
        }else{
          this.$refs.table.refresh();
          this.$message.success("删除成功")
        }
      })
    },

    //本地更新数据
    handleSaveSuccess(data, mode) {
      this.$refs.table.refresh();
    },
    handleQuery() {
				this.$refs.table.queryData(this.query)
			},
    resetQuery() {
      this.query = {};
    },
  },
};
</script>