|
```
2. 調用插件 ```
// 調用插件,商品子視窗
$(".prodWin").click(function(){
var vTr = $(this).parents("tr:first");//得到父tr对象;
var sn = vTr.attr("data-prod");//取得商品流水號
var id = vTr.attr("id");//取得id
var url = 'purchase.php?op=prodWin&sn='+sn+'&id='+id;
var wH = 350;
var wW = 600;
var wL = 0;
var wT = 0;
childWin(url,wH,wW,wL,wT);
});
```
3. 子視窗函數 ```
//子視窗函數
function childWin(url,wH,wW,wL,wT)
{
mywin=window.open("","","height=" + wH + ",width=" + wW + ",left="+ wL + ",top=" + wT );
mywin.location.href = url ;
}
```
4. 程式流程
purchase.php ```
#----- 商品子視窗
case "prodWin":
echo prodWin($sn);
exit;
```
5. 程式函數 ```
function prodWin($sn=""){
global $xoopsDB;
#---- 過濾資料 --------------------------
$myts = &MyTextSanitizer::getInstance();
$id = system_CleanVars($_REQUEST, 'id', '', 'string');
$sql = "select a.sn,a.title,b.title as kind_title
from " . $xoopsDB->prefix("ugm_stk_prod") . " as a
left join ". $xoopsDB->prefix("ugm_stk_kind") ." as b on a.kind = b.sn
where a.enable='1'
order by a.sort desc"; //die($sql);
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error($sql));
$rows = "";
while ($row = $xoopsDB->fetchArray($result)) {
$row['sn'] = intval($row['sn']);
$row['title'] = $myts->htmlSpecialChars($row['title']);//
$row['kind_title'] = $myts->htmlSpecialChars($row['kind_title']);//
$checked = ($row['sn'] == $sn) ? "":"";
$rows .= "{$checked} | {$row['sn']} | {$row['title']} | {$row['kind_title']} |
";
}
$title = "商品資料";
$content = "
";
$main = show_lytebox_html_b4($content,$title);
return $main;
}
```
6. 傳回商品sn,由母視窗AJAX
templates/ugm\_stk\_purchase.tpl ```
//用廠商流水號,取得廠商資料
function getAjaxProd(sn,id)
{
$.ajax({
type: 'GET',
url: '<{xoAppUrl}>modules/ugm_stk/purchase.php?op=getAjaxProd&id=' + id + '&sn=' + sn,
dataType: 'json',
success: function(data) {
var target = $('#'+data.id);
target.find('.prod').val(data.sn);//商品編號
target.find('.prod_title').html(data.title);//商品名稱
target.find('.price').val(data.price);//商品進價
target.find('.amount').focus();//聚焦數量
},
error: function(jqXHR) {
alert('發生錯誤:(templates/ugm_stk_purchase.tpl/getAjaxProd) ' + jqXHR.status);
}
})
}
```
7. 程式
流程 ```
case "getAjaxProd":
echo getAjaxProd($sn);
exit;
```
函數 ```
################################
# 用流水號取得廠商資料
#################################
function getAjaxProd($sn){
global $xoopsDB;
#---- 過濾資料 --------------------------
$myts = &MyTextSanitizer::getInstance();
$id = system_CleanVars($_REQUEST, 'id', '', 'string');
#外鍵
$sql = "select a.*
from " . $xoopsDB->prefix("ugm_stk_prod") . " as a
where a.sn='$sn'"; //die($sql);
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error($sql));
$row = $xoopsDB->fetchArray($result);
$rows['sn'] = intval($row['sn']);//商品流水號
$rows['title'] = $myts->htmlSpecialChars($row['title']);//商品名稱
$rows['price'] = intval($row['price']);//名稱
$rows['id'] = $id ;
return json_encode($rows, JSON_UNESCAPED_UNICODE) ;
}
```
8.
9.