<template>
	<el-container>
		<el-header>
			<h2>任务列表</h2>
		</el-header>
		<el-main>
			<scTable
				ref="table"
				:apiObj="apiObj"
				:query="params"
				row-key="id"
				:params="params"
			>
				<el-table-column
					label="#"
					type="index"
					width="50"
				></el-table-column>
				<el-table-column
					label="产品名称"
					prop="material_out_name"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column label="型号规格">
					<template #default="scope">
						<span v-if="scope.row.material_out_"
							>{{ scope.row.material_out_.specification }}|{{
								scope.row.material_out_.model
							}}</span
						>
					</template>
				</el-table-column>
				<el-table-column
					label="任务编号"
					prop="number"
					width="140"
					show-overflow-tooltip
				>
				</el-table-column>
				<el-table-column label="任务量" prop="count"> </el-table-column>
				<el-table-column label="开始时间" prop="start_date">
				</el-table-column>
				<el-table-column label="结束时间" prop="end_date">
				</el-table-column>
				<el-table-column label="合格数" prop="count_ok">
				</el-table-column>
				<el-table-column label="状态" prop="state">
					<template #default="scope">
						<el-tag :type="elTagType(scope.row.state)">
							{{ state_[scope.row.state] }}
						</el-tag>
					</template>
				</el-table-column>
				<el-table-column label="操作" fixed="right" width="60">
					<template #default="scope">
						<el-link
							type="primary"
							@click="mtask_submit(scope.row)"
							v-auth="'mtask.submit'"
							v-if="
								scope.row.state != 40 && scope.row.state != 34
							"
							>提交
						</el-link>
					</template>
				</el-table-column>
			</scTable>
		</el-main>
	</el-container>
</template>
<script>
export default {
	props: {
		mgroupName: {
			type: String,
			default: "",
		},
	},
	name: "mtask",
	data() {
		return {
			apiObj: null,
			params: { mgroup: "" },
			query: {},

			tableData: [],
			selection: [],
			cates_: {
				section: "工序",
				other: "其他",
			},
			type_: {
				10: "primary",
				20: "primary",
				30: "primary",
				34: "danger",
				40: "success",
			},
			state_: {
				10: "创建中",
				20: "已下达",
				30: "生产中",
				34: "已终止",
				40: "已提交",
			},
		};
	},
	mounted() {
		let that = this;
		that.$API.mtm.mgroup.list
			.req({ page: 0, search: that.mgroupName })
			.then((res) => {
				that.mgroupId = res[0].id;
				that.processId = res[0].process;
				that.processCate = res[0].process_cate;
				that.params.mgroup = res[0].id;
				that.apiObj = this.$API.pm.mtask.list;
				console.log("mgroupId", res[0].id);
			});
	},
	methods: {
		elTagType(state) {
			return this.type_[state];
		},
		//表格选择后回调事件
		selectionChange(selection) {
			this.selection = selection;
		},
		//搜索
		handleQuery() {
			this.$refs.table.queryData(this.query);
		},
		//本地更新数据
		//新增岗位后更新数据
		handleSaveSuccess(data, mode) {
			this.dialog.save = true;
			this.$refs.table.refresh();
		},
	},
};
</script>
<style scoped></style>
