{% extends "main.html" %}
{% block contents %}
<style>
.clicked {
background-color: aqua;
/* border-radius: 50%; */
color: brown;
}
ul {
cursor: pointer;
}
.btn btn-warning {
margin: 0;
padding: 0;
}
.btn btn-secondary btn-lg {
margin: 0;
padding: 0;
}
</style>
<script>
let clicked;
let idx;
$(document).ready(() => {
d_list()
hideform()
})
function mv_click(id) {
$(`#clicked> ul`).removeClass('clicked')
$(`#${id}`).addClass('clicked')
$(`#add-from`).text(String(`${id}`))
idx = String(id);
console.log(idx)
// addcotnet(idx)
}
// 본선선택 필수 강제조항
function addcotnet(idx) {
// let mv_id = dix
let msn = $('input[name=msn]').val()
let hauju = $('input[name=hauju]').val()
let offer = $('input[name = offer]').val()
let p_name = $('input[name=p_name]').val()
let gangjung = $('input[name=gangjung]').val()
let size = $('input[name=size]').val()
let bundle = $('input[name=bundle]').val()
let mt = $('input[name=mt]').val()
let storage = $('input[name=storage]').val()
let formData = new FormData()
// formData.append("mv_id_give", mv_id)
formData.append("msn_give", msn)
formData.append("hauju_give", hauju)
formData.append("offer_give", offer)
formData.append("p_name_give", p_name)
formData.append("gangjung_give", gangjung)
formData.append("size_give", size)
formData.append("bundle_give", bundle)
formData.append("mt_give", mt)
formData.append("storage_give", storage)
fetch('/d_bar/post', { method: "POST", body: formData }).then(res => res.json()).then(data => {
alert(data["msg"])
window.location.reload()
})
}
function showAddform() {
$('#add-form').show();
}
function hideform() {
$('#add-form').hide()
}
function d_list() {
// let idx = idx
// let url = `/d_bar/d_detail?data=${idx}`
// console.log(url)
fetch('/d_bar/d_detail').then(res => res.json()).then(data => {
let rows = data['result'];
// $(".list").empty()
rows.forEach((row) => {
let mv_id = row['mv_id']
let msn = row['msn']
let hauju = row['hauju']
let p_name = row['p_name']
let offer = row['offer']
let gangjung = row['gangjung']
let size = row['size']
let bundle = row['bundle']
let mt = row['mt']
let storage = row['storage']
let temp_html = `<tr id=${mv_id} class="list">
<th>${msn}</th>
<th>${hauju}</th>
<th>${p_name}</th>
<th>${offer}</th>
<th>${gangjung}</th>
<th>${size}</th>
<th >${bundle}</th>
<th>${mt}</th>
<th>${storage}</th>
</tr>`
$("#list").append(temp_html)
// if (dix == mv_id) {
// }
})
})
}
</script>
<ul class="nav" id="clicked">
{% for d_list in d_lists %}
<ul id="{{d_list._id}}" onclick="mv_click(`${id}`)">
{{d_list.date}} {{d_list.mv_name}}
</ul>
{% endfor %}
</ul>
<div class="body">
<table class="table" style="border: 8px blue;">
<thead class="table-primary ">
<tr>
<!-- <th>모선명</th> -->
<th scope="col">MSN</th>
<th scope="col">화주명</th>
<th scope="col">품명</th>
<th scope="col">제강사</th>
<th scope="col">강종</th>
<th scope="col">싸이즈</th>
<th scope="col">총수량(B/D)</th>
<th scope="col">총중량(M/T)</th>
<th scope="col">창고코드</th>
</tr>
</thead>
<tbody class="table table-striped table" id=list class="add-form">
<tr class="add-form" id="add-form">
<th><input type="text" placeholder="MSN" name="msn"></th>
<td><input type="text" placeholder="화주명" name="hauju"></td>
<td><input type="text" placeholder="세부품명" value="d_bar" name="p_name"></td>
<td><input type="text" placeholder="제강사" name="offer"></td>
<td><input type="text" placeholder="강 종" name="gangjung"></td>
<td><input type="text" placeholder="싸이즈" name="size"></td>
<td><input type="text" placeholder="수 량" name="bundle"></td>
<td><input type="text" placeholder="톤수" name="mt"></td>
<td><input type="text" placeholder="창고코드" name="storage"></td>
<td><button onclick="addcotnet()" class="btn btn-warning">저장</button></td>
<td><button class="btn btn-info">삭제</button></td>
</tr>
</tbody>
</table>
<div class="add-btn">
<td><button onclick="showAddform()" class="btn btn-primary btn-lg">추가</button></td>
<td><button onclick="hideform()" class="btn btn-secondary btn-lg">취소</button></td>
</div>
</div>
{% endblock %}
from main import *
from flask import Blueprint
bp = Blueprint("d_bar", __name__, url_prefix='/d_bar')
@bp.route('/d_list')
def d_list():
d_lists = list(db.mv.find({"cago_name": "철근"}))
return render_template("d_list.html",d_lists=d_lists,title="철근상세")
@bp.route('/d_detail',methods=['GET'])
def d_detail():
data = request.args.get('idx')
print(data)
d_details = list(db.d_list.find({}))
for d_detail in d_details:
d_detail["_id"] = str(d_detail['_id'])
return jsonify({"result": d_details})
@bp.route('/post', methods=["POST"])
def post_todo():
# mv_id_receive = request.form["mv_id_give"]
msn_receive = request.form["msn_give"]
hauju_receive = request.form["hauju_give"]
p_name_receive = request.form["p_name_give"]
offer_receive = request.form["offer_give"]
gangjung_receive = request.form["gangjung_give"]
size_receive = request.form["size_give"]
bundle_receive = request.form["bundle_give"]
mt_receive = request.form["mt_give"]
storage_receive = request.form["storage_give"]
print(offer_receive)
doc = {
# "mv_id":mv_id_receive,
"msn":msn_receive,
"hauju":hauju_receive,
"p_name":p_name_receive,
"offer":offer_receive,
"gangjung":gangjung_receive,
"size":size_receive,
"bundle":bundle_receive,
"mt":mt_receive,
"storage":storage_receive,
}
db.d_list.insert_one(doc)
return jsonify({"msg": "저장 완료!"})
# @bp.route('/d_detail/<idx>',method=["GET"])
# def d_datail(idx):
# contents =list(db.d_bar_list.find({"mv_list":{idx}},{"_id":False}))
# print(contents)
# return jsonify({"result":"조회완료"})