// 調整插件,商品子視窗
$(".prodWin").click(function(){
var vTr = $(this).parents("tr:first");//得到父tr对象;
var sn = vTr.attr("data-prod");//取得商品流水號
var id = vTr.attr("id");//取得id
childWin('purchase.php?op=prodWin&sn='+sn+'&id='+id,300,300);
});
```
3. purchase.php
流程 ```
#----- 商品子視窗
case "prodWin":
echo prodWin($sn);
exit;
```
函數
```
function prodWin($sn=""){
global $xoopsDB;
#---- 過濾資料 --------------------------
$myts = &MyTextSanitizer::getInstance();
$id = system_CleanVars($_REQUEST, 'id', '', 'string');
#外鍵
$sql = "select sn,title
from " . $xoopsDB->prefix("ugm_stk_prod") . "
where enable='1'
order by sort desc"; //die($sql);
$result = $xoopsDB->query($sql) or redirect_header($_SERVER['PHP_SELF'], 3, web_error($sql));
$option = $selected = $defaultTitle = "";
while ($row = $xoopsDB->fetchArray($result)) {
//以下會產生這些變數: $sn , $ofsn , $title , $enable ,$sort url target
$row['sn'] = intval($row['sn']);
$row['title'] = $myts->htmlSpecialChars($row['title']);//
$selected = "";
if ($row['sn'] == $sn) {
$selected = " selected";
}
$option .= "";
}
$main="
商品資料
";
return $main;
}
```
4. 母視窗的方法
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);
}
})
}
```
purchase.php
流程
```
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) ;
}
```
5.