Files
17168ERP/web/admin/activity/kind_reg.aspx
2025-08-29 01:27:25 +08:00

555 lines
28 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<%@ Page Title="後端管理" Language="C#" MasterPageFile="~/admin/Templates/TBS5ADM001/MasterPage.master" AutoEventWireup="true" CodeFile="kind_reg.aspx.cs" Inherits="admin_activity_kind_reg" %>
<%@ Register Src="~/admin/_uc/alert.ascx" TagPrefix="uc1" TagName="alert" %>
<asp:Content ID="Content1" ContentPlaceHolderID="page_header" runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="footer_script" runat="Server">
<script>
let VueApp = new Vue({
el: '#app',
vuetify: new Vuetify(vuetify_options),
data() {
return {
this_id: '<%= _this_id %>',
options: {},
optionsDetail: { multiSort: false },
search_dialog: {
controls: {
search1: {
id: 'search1',
title: '活動品項',
text_prop: 'subject',
value_prop: 'num',
keys: [
{ id: 'subject', title: '項目名稱', value: '' },
{ id: 'kindTxt', title: '項目分類' },
],
api_url: HTTP_HOST + 'api/activity/GetItemList',
columns: [
{ id: 'subject', title: '項目名稱' },
{ id: 'kindTxt', title: '項目分類' },
],
selected: {},
select(item,t) {
console.log("select search1", t);
item.actItem_num.text = t.subject
item.actItem_num.val = t.num
item.price = t.price
}
},
},
show: false,
current: {},
list: [],
count: 0,
page: 1,
loading: false,
footer: {
showFirstLastPage: true,
disableItemsPerPage: true,
itemsPerPageAllText: '',
itemsPerPageText: '',
},
},
snackbar: {
show: false,
text: "",
}//相關項目
, searchDetail: '',
headersDetail: [
{ text: '* 品項名稱', value: 'actitem_num.text', sortable: false },
{ text: '預設金額', value: 'price', sortable: false },
{ text: '數量', value: 'qty', sortable: false },
{ text: '', value: 'actions', sortable: false, width: "200px" },
],
footersDetail: {
showFirstLastPage: false,
disableItemsPerPage: false,
itemsPerPageAllText: '',
itemsPerPageText: '',
'prev-icon': null,
'next-icon': null,
'disable-pagination': true,
'items-per-page-options': []
},
desserts: [],
desserts_count: 0,
editedIndex: -1,
editedItem: {
id: 0,
num: 0,
activity_kind_num: 0,
actItem_num: {
text: '',
val: 0
},
price: 0,
qty :0,
},
defaultItem: {
id: 0,
num: 0,
activity_kind_num: 0,
actItem_num: {
text: '',
val: 0
},
price: 0,
qty: 0,
},
}
},
mounted() {
this.search_dialog.current = this.search_dialog.controls.search1
//console.log("mounted");
},
watch: {
options: {
handler() {
//console.log("watch1", this.search_dialog, this.search_dialog.page);
this.search_get()
console.log("watch2", this.search_dialog, this.search_dialog.page);
},
deep: true,
},
optionsDetail: {
handler() {
this.initialize();
},
deep: true,
},
},
methods: {
search_show(curr) {
//console.log("btn_click:", curr, curr.api_url);
this.search_dialog.current = curr;
this.search_clear()
this.search_dialog.show = true;
},
search_clear() {
if (!this.search_dialog.current.keys) return;
this.search_dialog.current.keys.forEach((t, i) => { t.value = '' })
this.search_get()
},
search_get() {
if (!this.search_dialog.current.keys) return;
let api_url = this.search_dialog.current.api_url;
let keys = this.search_dialog.current.keys;
this.search_dialog.page = this.options.page ?? 1
let params = { page: this.search_dialog.page, pageSize: 10 };//url params
var search = {};//post body
keys.forEach((t, i) => {
search[t.id] = t.value;
});
//necessary parameter===
if (this.search_dialog.current.id == 'search1') {
search['categorys'] = "1,2,4";//報名,掛單,贊助
}
console.log("search_get", api_url, search, params, this.options);
this.search_dialog.loading = true
axios.post(api_url, search, { params: params })
.then(response => {
this.search_dialog.list = response.data.list
this.search_dialog.count = response.data.count
this.search_dialog.loading = false
})
.catch(error => {
console.log(error)
this.search_dialog.list = []
this.search_dialog.count = 0
this.search_dialog.loading = false
this.snackbar.text = "錯誤:" + error
this.snackbar.show = true
})
},
search_headers() {
if (!this.search_dialog.current.columns) return;
r = [];
this.search_dialog.current.columns.forEach((t, i) => {
r.push({
text: t.title,
align: 'start',
sortable: false,
value: t.id,
})
})
return r
},
search_select(row) {
let curr = this.search_dialog.current;
let target = $(`[data-search-control=${curr.id}]`);
curr.selected = row;
target.children("input.search-text").val(curr.selected[curr.text_prop])//text
target.children("input:hidden").val(curr.selected[curr.value_prop])//value
if (curr.select instanceof Function) {
curr.select(this.editedItem,row);
}
this.search_dialog.show = false;
//console.log(row, row["u_name"], row["f_number"], curr.id, target);
},//文件
initialize() {
if (this.this_id != '') {
const { sortBy, sortDesc, page, itemsPerPage } = this.optionsDetail
const params = {
sortBy: sortBy[0], sortDesc: sortDesc[0],
page: page,
//pageSize: itemsPerPage == -1 ? this.desserts.length : itemsPerPage,
pageSize: itemsPerPage,
};
var searchItemDetail = {
activity_kind_num: this.this_id,
}
axios
.post(HTTP_HOST + 'api/activity/GetKindDetail',
searchItemDetail, { params: params })
.then(response => {
this.desserts = response.data.list
this.desserts_count = response.data.count
})
.catch(
error => console.log(error)
)
}
},
editItem(item) {
this.editedIndex = this.desserts.indexOf(item);
this.editedItem = $.extend(true, {}, item);
},
deleteItem(item) {
if (confirm('確定要刪除此筆資料嗎?')) {
const index = this.desserts.indexOf(item);
if (item.num > 0) {
if (index != -1) {
axios
.delete(HTTP_HOST + 'api/activity/DeleteActKindDetail/' + item.num)
.then(response => {
console.log("del", item);
this.desserts.splice(index, 1)
this.desserts_count = this.desserts_count - 1;
})
.catch(error => console.log(error))
}
} else {
this.desserts.splice(index, 1)
}
}
},
cancel() {
//data-search-control need to return to the original value
this.spliceNullData();
this.close();
},
spliceNullData() {
//if new data ,then splice it
if (this.editedItem.num == 0) {
for (var i = 0; i < this.desserts.map(x => x.id).length; i++) {
if (this.desserts[i].id == this.editedItem.id) {
this.desserts.splice(i, 1); break;
}
}
}
},
close() {
setTimeout(() => {
this.editedItem = $.extend(true, {}, this.defaultItem);
this.editedIndex = -1;
}, 300)
},
addNew() {
this.spliceNullData();
//addObj.id = this.desserts.length + 1;
var keysArr = [];
for (var i = 0; i < this.desserts.map(x => x.id).length; i++) {
//console.log(this.desserts[i].id)
keysArr.push(parseInt(this.desserts[i].id));
}
var _c = Math.max.apply(null, keysArr);
const addObj = $.extend(true, {}, this.defaultItem);
addObj.id = (isFinite(_c) ? _c : 0) + 1;
this.desserts.unshift(addObj);
this.editItem(addObj);
},
save() {
if (this.editedIndex > -1) {
if (this.this_id != '') {
//chcck necessary params
if (this.editedItem.actItem_num.val != 0 ) {
//insert or update data
var pro_order_detail =
{
num: this.editedItem.num,
activity_kind_num: this.this_id,
actItem_num: this.editedItem.actItem_num.val,
price: this.editedItem.price,
qty: this.editedItem.qty,
}
axios
.post(HTTP_HOST + 'api/activity/SaveActKindDetail', pro_order_detail)
.then(response => {
this.editedItem.num = response.data;
Object.assign(this.desserts[this.editedIndex], this.editedItem)
this.close()
})
.catch(
error => console.log(error)
)
} else {
this.snackbar.text = "必填項目未填寫完整";
this.snackbar.show = true
}
} else {
this.snackbar.text = "單號錯誤";
this.snackbar.show = true
}
}
}, customSearch(value, item) {
console.log(value, item)
},
searchData(event) {
this.desserts = this.desserts.filter(item => item.actItem_num.text.toLowerCase().includes(event));
}
},
computed: {
},
filters: {
currency: function (value) {
return value == null || value === "" ? "" :
('$' + parseFloat(value).toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,").replace(".00", ""));
},
}
})
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="page_nav" runat="Server">
<nav class="mb-1">
<asp:LinkButton ID="ImageButton4" runat="server" CausesValidation="False" OnClick="ImageButton4_Click" CssClass="btn btn-primary"><i class="mdi mdi-plus"></i> 新增主分類</asp:LinkButton>
<asp:LinkButton ID="sortButton" runat="server" Visible="false" CssClass="btn btn-primary" OnClick="sortButton_Click">
<i class="mdi mdi-sort"></i> 排序選項</asp:LinkButton>
</nav>
<nav class="mb-1">
<asp:Button ID="edit" runat="server" Text="修改" Visible="false" OnClick="edit_Click" CssClass="btn btn-primary" />
<asp:Button ID="add" runat="server" Text="新增" Visible="false" OnClick="add_Click" CssClass="btn btn-primary" />
<asp:PlaceHolder ID="down_table" runat="server">
<asp:LinkButton ID="ImageButton5" runat="server" OnClick="ImageButton5_Click" CssClass="btn btn-outline-secondary" CausesValidation="False"><i class="mdi mdi-arrow-down-right"></i> 建立下一層選項</asp:LinkButton>
<asp:LinkButton ID="ImageButton6" runat="server" OnClientClick="return msgconfirm('是否確定刪除這筆資料?<br>注意!資料刪除後將一併刪除此資料的子選項!',this);" OnClick="ImageButton6_Click" CssClass="btn btn-outline-secondary"><i class="mdi mdi-trash-can"></i> 刪除</asp:LinkButton>
</asp:PlaceHolder>
</nav>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<uc1:alert runat="server" ID="L_msg" Text="" />
<div id="content" class="container-fluid pb-4">
<div class="row">
<div class="col-sm-4 col-lg-3">
<div class="card shadow-sm my-2" id="sec1">
<div class="card-header">選擇分類</div>
<div class="card-body">
<asp:TreeView ID="TreeView2" runat="server" CssClass="aspxTree" ImageSet="Arrows"
SkipLinkText="" ShowLines="false" EnableTheming="False" ShowExpandCollapse="True">
</asp:TreeView>
</div>
</div>
</div>
<div class="col-sm-8 col-lg-9">
<asp:Panel ID="table" runat="server" CssClass="card shadow-sm my-2">
<div class="card-header">
<div>
<asp:Label ID="start" runat="server" CssClass="text-danger" Display="Dynamic"></asp:Label>
</div>
<div>
<asp:Label ID="title_msg" runat="server" CssClass="" ForeColor=""></asp:Label>
</div>
</div>
<div class="card-body form-horizontal" role="form">
<div>
<div class="form-text text-muted">以下 * 欄位為必填欄位</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-md-3 col-form-label">* 分類名稱</label>
<div class="col-sm-10 col-md-9">
<asp:TextBox ID="item_name" runat="server" CssClass="form-control" MaxLength="100" placeholder="請輸入分類名稱"></asp:TextBox>
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="item_name" ErrorMessage="必填!" Display="Dynamic" SetFocusOnError="true"></asp:RequiredFieldValidator>
</div>
</div>
<div class="row mb-1 label-sm-right">
<label class="col-sm-2 col-md-3 col-form-label">預設起始日期 </label>
<div class="col-sm-10 col-md-9 col-lg-6">
<div class="input-group">
<asp:DropDownList ID="calendar" runat="server" CssClass="form-select">
<asp:ListItem Value="">請選擇</asp:ListItem>
<asp:ListItem Value="國曆">國曆</asp:ListItem>
<asp:ListItem Value="農曆">農曆</asp:ListItem>
</asp:DropDownList>
<input type="text" class="form-control" placeholder="月" aria-label="月" id="month" runat="server">
<span class="input-group-text">月</span>
<input type="text" class="form-control" placeholder="日" aria-label="日" id="day" runat="server">
<span class="input-group-text">日</span>
</div>
</div>
<div class="col-md-3"></div>
<div class="col-sm-2 col-md-3"></div>
<div class="col-sm-10 col-md-9">
<asp:RangeValidator ID="monthRV" runat="server" SetFocusOnError="true" Display="Dynamic" ControlToValidate="month" MinimumValue="1" MaximumValue="12" Type="Integer"
ErrorMessage="月份應為1~12的數字"></asp:RangeValidator>
<asp:RangeValidator ID="dayRV" runat="server" SetFocusOnError="true" Display="Dynamic" ControlToValidate="day" MinimumValue="1" MaximumValue="31" Type="Integer"
ErrorMessage="日期應為1~31的數字"></asp:RangeValidator>
</div>
</div>
<div class="row mb-1">
<label class="col-form-label">備註</label>
<div class="col-sm-12">
<asp:TextBox ID="demo" runat="server" CssClass="form-control" TextMode="MultiLine" Rows="3" placeholder="請輸入備註"></asp:TextBox>
</div>
</div>
<v-card class="mx-auto mt-10" outlined v-if="this_id!=''">
<v-data-table
:headers="headersDetail"
:items="desserts"
:footer-props="footersDetail"
:search="searchDetail"
<%-- :footer-props="{'items-per-page-options':[5,10,15,-1]}"每頁列數--%>
:options.sync="optionsDetail" class="elevation-1" fixed-header height="350px"
<%-- :server-items-length="desserts_count"--%>
>
<v-divider inset></v-divider>
<template v-slot:top>
<v-toolbar flat color="white">
<div class="d-flex w-100">
<v-text-field v-model="searchDetail" append-icon="mdi-magnify" label="查詢" dense outlined single-line hide-details @input="searchData"></v-text-field>
<v-btn
color="primary"
class="ml-2 white--text"
@click="addNew">
<v-icon dark>mdi-plus</v-icon>新增
</v-btn>
</div>
</v-toolbar>
</template>
<template v-slot:item.actitem_num.text="{ item }" >
<div class="input-group mb-3" data-search-control="search1" @click="search_show(search_dialog.controls.search1)" v-if="item.id === editedItem.id">
<input class="form-control search-text" type="text" readonly
placeholder="品項名稱" v-model="editedItem.actItem_num.text" >
<input type="hidden" v-model="editedItem.actItem_num.val">
<button class="btn btn-outline-secondary" type="button">
<i class="mdi mdi-view-list-outline"></i>
</button>
</div>
<span v-else>{{item.actItem_num.text}}</span>
</template>
<template v-slot:item.price="{ item }">
<v-text-field v-model="editedItem.price" :hide-details="true" dense single-line v-if="item.id === editedItem.id" ></v-text-field>
<span v-else>{{item.price | currency }}</span>
</template>
<template v-slot:item.qty="{ item }">
<v-text-field v-model="editedItem.qty" :hide-details="true" dense single-line v-if="item.id === editedItem.id" ></v-text-field>
<span v-else>{{item.qty}}</span>
</template>
<template v-slot:item.actions="{ item }">
<div v-if="item.id === editedItem.id">
<v-icon color="red" class="mr-3" @click="cancel">
mdi-window-close
</v-icon>
<v-icon color="green" @click="save">
mdi-content-save
</v-icon>
</div>
<div v-else>
<v-icon color="green" class="mr-3" @click="editItem(item);">
mdi-pencil
</v-icon>
<v-icon color="red" @click="deleteItem(item)">
mdi-delete
</v-icon>
</div>
</template>
</v-data-table>
</v-card>
<div class="form-group">
<div class="col-sm-offset-3 col-md-offset-2 col-sm-9 col-md-10">
<asp:HiddenField ID="HiddenField1" runat="server" />
</div>
</div>
</div>
</asp:Panel>
</div>
</div>
<v-dialog v-model="search_dialog.show" max-width="500px">
<v-card>
<v-card-title class="justify-space-between grey lighten-2">
查詢:{{search_dialog.current.title}}
<v-btn icon @click="search_dialog.show=false"><v-icon>mdi-close</v-icon></v-btn>
</v-card-title>
<v-card-text >
<v-row>
<v-col v-for="item in search_dialog.current.keys"
:cols="search_dialog.current.keys.length>1?6:12" >
<v-text-field v-model="item.value" :label="item.title" v-if="item.visible===undefined || item.visible==true "></v-text-field>
</v-col>
<v-col cols="12" class="text-end">
<v-btn color="primary" elevation="0" @click="search_get()">查詢</v-btn>
<v-btn elevation="0" @click="search_clear()">清除條件</v-btn>
</v-col>
</v-row>
<v-data-table
:headers="search_headers()"
:items="search_dialog.list"
:footer-props="search_dialog.footer"
:items-per-page="10"
:server-items-length="search_dialog.count"
:page.sync="search_dialog.page"
:options.sync="options"
@click:row="search_select"
></v-data-table>
</v-card-text>
<v-card-actions>
</v-card-actions>
</v-card>
</v-dialog>
<v-snackbar
v-model="snackbar.show"
timeout="2000"
>
{{ snackbar.text }}
<template v-slot:action="{ attrs }">
<v-btn
text
v-bind="attrs"
@click="snackbar.show = false"
>
關閉
</v-btn>
</template>
</v-snackbar>
</div>
</asp:Content>