126 lines
5.4 KiB
JavaScript
126 lines
5.4 KiB
JavaScript
// 获取表格数据
|
|
function getDomData() {
|
|
const dom = $('div[name=cutting_speed_ids]')
|
|
if (!dom.length) return
|
|
const table = dom.find('.o_list_table')
|
|
const thead = table.children('thead')
|
|
const tbody = table.children('tbody')
|
|
const tbody_child = tbody.children()
|
|
const hideTheadDom = thead.find('[data-name=process_capability]')
|
|
hideTheadDom.hide().next().hide()
|
|
hideTheadDom.before('<th customTh>精加工</th><th customTh>粗加工</th>')
|
|
tbody_child.each(function () {
|
|
const dom = $(this).children('[name=process_capability]')
|
|
if(!dom.length) return
|
|
dom.css('cssText', 'display: none!important').next().css('cssText', 'display: none!important')
|
|
const isCu = dom.text() == '粗加工' // 是否粗加工
|
|
const v = dom.next().text() // 切削速度
|
|
dom.after(`<td customSpeed="1" name="process_capability" is="精加工" val="${ v }">${!isCu ? v : ''}</td><td customSpeed="1" name="process_capability" is="粗加工" val="${ v }">${isCu ? v : ''}</td>`)
|
|
setListenClick()
|
|
})
|
|
return;
|
|
handleTbody(tbody, newTableData, ΦList, table)
|
|
}
|
|
|
|
// 监听点击
|
|
function setListenClick() {
|
|
$(document).click(function (e) {
|
|
if ($(e.target).attr('customSpeed')) {
|
|
const orginV = $('[customInput=1]').children('input').val()
|
|
$('[customInput=1]').parent().html(orginV)
|
|
const v = $(e.target).attr('val')
|
|
const is = $(e.target).attr('is')
|
|
$(e.target).html('')
|
|
const input = $('<div customInput="1" is="' + is + '" class="o_field_widget o_field_char"><input class="o_input" type="text" autocomplete="off" maxlength="20"></div>')
|
|
input.children('input').val(v)
|
|
$(e.target).append(input)
|
|
input.children('input').focus()
|
|
input.children('input').select()
|
|
} else if ($(e.target).attr('customInput')) {
|
|
|
|
} else {
|
|
const orginV = $('[customInput=1]').children('input').val()
|
|
$('[customInput=1]').parent().html(orginV)
|
|
const v = $(e.target).attr('val')
|
|
}
|
|
})
|
|
$(document).off('change') // 防止重复绑定
|
|
$(document).on('change', '[customInput] input', async function () {
|
|
$(this).parents('td').attr('val', $(this).val())
|
|
$(this).parents('td').siblings('[customspeed]').attr('val', $(this).val())
|
|
var eve1 = new Event('change')
|
|
var eve2 = new Event('input')
|
|
var eve3 = new Event('click')
|
|
let patchSpeedDom = $(this).parents('td').siblings('[name=cutting_speed]')
|
|
let patchProcessDom = $(this).parents('td').siblings('[name=process_capability]')
|
|
$(this).parents('td').siblings('[customspeed]').text('') // 清空其他加工类型的数据
|
|
await timeOut(500)
|
|
patchProcessDom[0].dispatchEvent(eve3)
|
|
await timeOut(200)
|
|
const processVal = $(this).parent().attr('is')
|
|
patchProcessDom.find('select').val(`"${processVal}"`) // 设置源select的val为“加工类型 is”、
|
|
patchProcessDom.attr("data-tooltip", `${processVal}`)
|
|
patchProcessDom.find('select')[0].dispatchEvent(eve1)
|
|
|
|
patchSpeedDom[0].dispatchEvent(eve3)
|
|
await timeOut(200)
|
|
patchSpeedDom.find('input').val($(this).val())
|
|
await timeOut(50)
|
|
patchSpeedDom.find('input')[0].dispatchEvent(eve2)
|
|
patchSpeedDom.find('input')[0].dispatchEvent(eve1)
|
|
})
|
|
$(document).off('blur') // 防止重复绑定
|
|
$(document).on('blur', '[customInput] input', async function () {
|
|
if(!$(this).length) return
|
|
|
|
$(this).parents('td').siblings('[customspeed]').text('') // 清空其他加工类型的数据
|
|
let patchProcessDom = $(this).parents('td').siblings('[name=process_capability]')
|
|
try {
|
|
patchProcessDom[0].dispatchEvent(new Event('click'))
|
|
const processVal = $(this).parent().attr('is')
|
|
patchProcessDom.find('select').val(`"${processVal}"`) // 设置源select的val为“加工类型 is”、
|
|
patchProcessDom.attr("data-tooltip", `${processVal}`)
|
|
patchProcessDom.find('select')[0].dispatchEvent(new Event('change'))
|
|
} catch {
|
|
|
|
}
|
|
|
|
})
|
|
}
|
|
function timeOut(time) {
|
|
return new Promise(resolve => {
|
|
setTimeout(() => {
|
|
resolve()
|
|
}, time)
|
|
})
|
|
}
|
|
|
|
function listenAdd() {
|
|
$('td.o_field_x2many_list_row_add a').click(async function () {
|
|
await timeOut(500)
|
|
const tr = $('.o_list_table').children('tbody').children('tr').eq(-2)
|
|
if(tr.children('td').eq(2).text() == '') {
|
|
const dom = tr.children('[name=process_capability]')
|
|
if(!dom.length) return
|
|
dom.css('cssText', 'display: none!important').next().css('cssText', 'display: none!important')
|
|
const isCu = dom.text() == '粗加工' // 是否粗加工
|
|
const v = dom.next().text() // 切削速度
|
|
dom.after(`<td customSpeed="1" name="process_capability" is="精加工" val="${ v }">${!isCu ? v : ''}</td><td customSpeed="1" name="process_capability" is="粗加工" val="${ v }">${isCu ? v : ''}</td>`)
|
|
}
|
|
})
|
|
}
|
|
|
|
function listenSave() {
|
|
$('.o_form_button_save').click( async function () {
|
|
await timeOut(1000)
|
|
if($(this).parent().next().length) return
|
|
$('th[customTh],td[cusomSpeed]').remove()
|
|
getDomData()
|
|
|
|
})
|
|
}
|
|
|
|
listenAdd()
|
|
listenSave()
|
|
getDomData()
|