<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" />
		<meta name="viewport" content="width=device-width, initial-scale=1.0" />
		<title>工程明细列表</title>
		<link rel="stylesheet" href="{{ url_for('static', filename='styles.css') }}" />
		<style>

		</style>
		<script src="{{ url_for('static', filename='utils.js') }}"></script>
		<script src="{{ url_for('static', filename='sub_project_item_list.js') }}"></script>
		<script>
			function searchData() {
				const process_status = document.getElementById('process_status_select').value
				const send_status = document.getElementById('send_status_select').value
				const keyword = document.getElementById('search_input').value
				window.location.href = `{{ url_for('project.project_item_list', sub_project_id=sub_project.id) }}?k=${keyword}&p_s=${process_status}&s_s=${send_status}`
			}
			function reSearchData() {
				window.location.href = `{{ url_for('project.project_item_list', sub_project_id=sub_project.id) }}`
			}
			function jumpToPage(page) {
				window.location.href = `{{ url_for('project.project_item_list', sub_project_id=sub_project.id) }}?p_s={{process_status}}&s_s={{send_status}}&k={{keyword}}&pp={{per_page}}&p=${page}`
			}
		</script>
	</head>
	<body>
		<div class="box">
			<div class="box_header">
				<div class="project_info">
					<button class="btn btn-info btn-large" onclick="goTo(`{{ url_for('project.sub_project_list',project_id=sub_project.project_id) }}`)">返回</button>
					<h3 class="box_title">工程明细列表</h3>
					<span class="separator">|</span>
					<dl>
						<dt>工程名称:</dt>
						<dd>{{ sub_project.sub_project_name }}</dd>
					</dl>
					<!--<dl>
						<dt>标准版本:</dt>
						<dd>
							{% if sub_project.standard_version == '1' %}
							<span class="label label-warning">旧版</span>
							{% elif sub_project.standard_version == '2' %}
							<span class="label label-info">新版</span>
							{% endif %}
						</dd>
					</dl>-->
				</div>
				{% include 'base/user_info.html' %}
			</div>
			<div class="box_header">
				<div class="btn_box">
					<button class="btn btn-success btn-large" onclick="addSubProjectItem()">新建工程明细</button>
				</div>
				<div class="search_box">
					<select id="process_status_select" class="form-control form-select" title="处理状态选择">
						<option value="-1" {% if process_status == -1 %}selected{% endif %}>请选择处理状态</option>
						<option value="2" {% if process_status == 2 %}selected{% endif %}>已处理</option>
						<option value="3" {% if process_status == 3 %}selected{% endif %}>处理失败</option>
						<option value="0" {% if process_status == 0 %}selected{% endif %}>未处理</option>
						<option value="1" {% if process_status == 1 %}selected{% endif %}>处理中</option>
					</select>
					<select id="send_status_select" class="form-control form-select" title="推送状态选择">
						<option value="-1" {% if send_status == -1 %}selected{% endif %}>请选择推送状态</option>
						<option value="2" {% if send_status == 2 %}selected{% endif %}>已推送</option>
						<option value="3" {% if send_status == 3 %}selected{% endif %}>推送失败</option>
						<option value="0" {% if send_status == 0 %}selected{% endif %}>未推送</option>
						<option value="1" {% if send_status == 1 %}selected{% endif %}>推送中</option>
					</select>
					<input type="text" id="search_input" title="" class="form-control" placeholder="请输入查询关键字" value="{{ keyword }}" />
					<button type="button" class="btn btn-info btn-large" onclick="searchData()">查询</button>
					<button type="button" class="btn btn-warning btn-large" onclick="reSearchData()">重置</button>
				</div>
			</div>

			<div class="box_body">
				<table class="table">
					<thead>
						<tr>
							<th width="300px">名称</th>
							<th>规格型号</th>
							<th width="150px">数量</th>
							<th width="120px">单位</th>
							<th width="120">定额编号</th>
							<th width="120px">处理状态</th>
							<th width="120px">发送状态</th>
							<th width="360px">操作</th>
						</tr>
					</thead>
					<tbody>
						{% if items %} {% for item in items %}
						<tr data-id="{{item.id}}">
							<td class="device_name">
								{{ item.device_name if item.device_name else '-' }}
								<input type="hidden" class="form-control" title="设备名称" value="{{ item.device_name if item.device_name else '' }}" />
							</td>
							<td class="device_model">
								{{ item.device_model if item.device_model else '-' }}
								<input type="hidden" class="form-control" title="设备规格型号" value="{{ item.device_model if item.device_model else '' }}" />
							</td>
							<td class="device_count">
								{{ item.device_count if item.device_count else '-' }}
								<input type="hidden" class="form-control" title="设备数量" value="{{ item.device_count if item.device_count else '' }}" />
							</td>
							<td class="device_unit">
								{{ item.device_unit if item.device_unit else '-' }}
								<input type="hidden" class="form-control" title="设备单位" value="{{ item.device_unit if item.device_unit else '' }}" />
							</td>
							<td class="standard_no">
								{{ item.standard_no if item.standard_no else '-' }}
								<input type="hidden" class="form-control" title="设备定额编号" value="{{ item.standard_no if item.standard_no else '' }}" />
							</td>
							<td class="process_status">
								{% if item.process_status == 1 %}
								<span class="label label-warning">处理中...</span>
								{% elif item.process_status == 2 %}
								<span class="label label-success">已处理</span>
								{% elif item.process_status == 3 %}
								<span class="label label-danger">处理失败</span>
								{% else %}
								<span class="label label-default">未处理</span>
								{% endif %}
							</td>
							<td class="send_status">
								{% if item.send_status == 1 %}
								<span class="label label-warning">推送中...</span>
								{% elif item.send_status == 2 %}
								<span class="label label-success">已推送</span>
								{% elif item.send_status == 3 %}
								<span class="label label-danger">推送失败</span>
								{% else %}
								<span class="label label-default">未推送</span>
								{% endif %}
							</td>
							<td class="tool">
								{% if item.process_status == 0 %}
								<button class="btn btn-success" onclick="startProcessItem('{{ item.id }}')">开始处理</button>
								{% elif item.process_status == 2 %}
								<button class="btn btn-warning" onclick="startProcessItem('{{ item.id }}')">重新处理</button>
								{% elif item.process_status == 3 %}
								<button class="btn btn-danger" onclick="startProcessItem('{{ item.id }}')">重新处理</button>
								{% endif %}
								{% if item.send_status == 0 and item.process_status != 1 %}
								<button class="btn btn-success" onclick="startSendItem('{{ item.id }}')">开始发送</button>
								{% elif item.send_status == 2 and item.process_status != 1 %}
								<button class="btn btn-warning" onclick="startSendItem('{{ item.id }}')">重新发送</button>
								{% elif item.send_status == 3 and item.process_status != 1 %}
								<button class="btn btn-danger" onclick="startSendItem('{{ item.id }}')">重新发送</button>
								{% endif %}
								<button class="btn btn-info" onclick="editSubProjectItem('{{ item.id }}')">编辑</button>
								<button class="btn btn-danger" onclick="deleteSubProjectItem('{{ item.id }}')">删除</button>
							</td>
						</tr>
						{% endfor %} {% else %}
						<tr>
							<td colspan="15">没有明细数据</td>
						</tr>
						{% endif %}
					</tbody>
				</table>
				<div class="pagination">
					<div class="pagination-info">
						{% set total_pages = (total_count|int + per_page|int - 1)//per_page %}
						<span class="page"> 总共 {{ total_count }} 条数据，每页 {{ per_page }} 条，当前第 {{ page }} 页 / 共 {{ total_pages }} 页 </span>
					</div>
					<div class="pagination-links">
						{% if page > 1 %}
						<span class="page page-link" onclick="jumpToPage(1)">首页</span>
						{% endif %} {% if page > 1 %}
						<span class="page page-link" onclick="jumpToPage(`{{page - 1}}`)">上一页</span>
						{% endif %} {% set start_page = [1, page - 2]|max %} {% set end_page = [total_pages, page + 2]|min %} {% if start_page > 1 %}
						<span class="page page-link" onclick="jumpToPage(1)">1</span>
						{% if start_page > 2 %}
						<span class="page">...</span>
						{% endif %} {% endif %} {% for p in range(start_page, end_page + 1) %} {% if p == page %}
						<span class="page page-link active" onclick="jumpToPage(`{{ p }}`)">{{ p }}</span>
						{% else %}
						<span class="page page-link" onclick="jumpToPage(`{{ p }}`)">{{ p }}</span>
						{% endif %} {% endfor %} {% if end_page < total_pages %} {% if end_page < total_pages - 1 %}
						<span class="page">...</span>
						{% endif %}
						<span class="page page-link" onclick="jumpToPage(`{{ total_pages }}`)">{{ total_pages }}</span>
						{% endif %} {% if page < total_pages %}
						<span class="page page-link" onclick="jumpToPage(`{{ page+1 }}`)">下一页</span>
						{% endif %} {% if page < total_pages %}
						<span class="page page-link" onclick="jumpToPage(`{{ total_pages }}`)">末页</span>
						{% endif %}
					</div>
				</div>
			</div>
		</div>
	<div class="modal" id="modal-sub_project_item">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<h3 class="modal-title"><span></span>工程明细</h3>
				<span class="close-btn" onclick="hide_modal('#modal-sub_project_item')">&times;</span>
			</div>
			<div class="modal-body">
				<div class="form-group">
					<input type="hidden" id="item_id">
					<div>
						<label>设备名称：</label>
						<input type="text" title="" id="device_name" class="form-control" placeholder="请输入设备名称">
					</div>
					<div>
						<label>规格型号：</label>
						<input type="text" title="" id="device_model" class="form-control" placeholder="请输入规格型号">
					</div>
					<div>
						<label>数量：</label>
						<input type="text" title="" id="device_count" class="form-control" placeholder="请输入数量">
					</div>
					<div>
						<label>单位：</label>
						<input type="text" title="" id="device_unit" class="form-control" placeholder="请输入单位">
					</div>
					<div>
						<label>定额编号：</label>
						<input type="text" title="" id="standard_no" class="form-control" placeholder="请输入定额编号">
					</div>
					<div style="display: block;">
                        <label for="is_query">是否查询知识库：</label>
                        <input type="checkbox" id="is_query" class="form-control" style="width: auto;flex: 0;">
                    </div>
				</div>
			</div>
			<div class="modal-footer">
				<button class="btn btn-success" onclick="saveSubProjectItem('{{sub_project.id}}')">保存</button>
				<button class="btn btn-warning" onclick="hide_modal('#modal-sub_project_item')">取消</button>
			</div>
		</div>
	</div>
</div>
</body>
</html>
