Effect:
Segment parsing code
Paging function implementation:
1. Label
1. Search bar - fuzzy query
<!-- 搜索框-->
<form action="" @submit="search_wip_name">
<view class="search_position">
<view class="search">
<view class="search_left">
工单名称:
</view>
<view class="search_right">
<input name="wip_entity_name" type="text" />
</view>
</view>
</view>
<view class="search_position">
<view class="search">
<view class="search_left">
料号:
</view>
<view class="search_right">
<input name="ItemNo" type="text" />
</view>
</view>
</view>
<view class="search_position">
<view class="search">
<view class="search_left">
名称:
</view>
<view class="search_right">
<input name="ItemName" type="text" />
</view>
</view>
</view>
<view class="search_position">
<view class="btn_position">
<button class="button" form-type="submit">查询</button>
<button class="button1">确认</button>
</view>
</view>
</form>
<form action="" @submit="search_wip_name"> : For form information, @submit = "search_wip_name" form submission method
name="wip_entity_name" sets the value of name, which is convenient for the js side to obtain data
<button class="button" form-type="submit" >query</button>, set form-type="submit" , bind the submit button of the form
2. Form information
<!-- 表格 -->
<scroll-view scroll-x="true" style="overflow-x: scroll; white-space: nowrap;">
<view class="table">
<view class="table-tr">
<view class="table-th1">工单名称</view>
<view class="table-th1">料号</view>
<view class="table-th1">料号名称</view>
<view class="table-th1">规格型号</view>
<view class="table-th1">预计开工日</view>
<view class="table-th1">开工量</view>
</view>
<!-- :class="{ selected: selectedIndex === index,'selected-row':selectedRow ===index }" -->
<view class="table-tr" v-for="(item, index) in dataList" :key="index"
:class="{ selected: item.selectedIndex === index, 'selected-row': item.selectedRow }"
@click="selectRow(index,item.wip_entity_name)">
<view class="table-td1">{
{item.wip_entity_name}}</view>
<view class="table-td2">{
{item.primary_item}}</view>
<view class="table-td2">{
{item.item_name}}</view>
<view class="table-td2">{
{item.item_desc}}</view>
<view class="table-td2">{
{item.plan_start_date}}</view>
<view class="table-td2">{
{item.start_quantity}}</view>
</view>
</view>
</scroll-view>
scroll-view
Implements a scrollable view area. In this code,scroll-view
the component is used to achieve the effect of horizontal scrolling, that is, it can scroll horizontally.
scroll-x="true"
: Setscroll-view
the component to scroll horizontally.
style="overflow-x: scroll; white-space: nowrap;"
: Add a style, set the horizontal scroll bar to be visible, and the content will not wrap.v-for="(item, index) in dataList" :key="index" : Through
v-for
the instruction, traversedataList
the array to generate multiple rows, and each row corresponds to a data item in the array.:key="index"
Used to specify a unique ID for each row.
:class="{ selected: item.selectedIndex === index, 'selected-row': item.selectedRow }"
: Whenitem.selectedIndex
the sum is equal, add a style classindex
to the current line ; when true, add a style class to the current line. (Here is the code to realize the click to get the data, and the code to change the row style by clicking)selected
item.selectedRow
selected-row
3. Pagination implementation
<!-- 分页 -->
<view class="pagination">
<view class="up_page" :class="{ 'first-page': isFirstPage }" :disabled="currentPage === 1"
@click="prevPage"><</view>
<view class="now_page">
<text style="color:#2979ff">{
{ currentPage }} </text><text
style="color:#4b4b4b">/{
{ totalPage }}</text>
</view>
<view class="down_page" :class="{ 'last-page': isLastPage }" :disabled="currentPage === totalPage"
@click="nextPage">></view>
</view>
</view>
<view class="up_page" :class="{ 'first-page': isFirstPage }" :disabled="currentPage === 1" @click="prevPage"><</view>
: This is a view element that displays a previous page button.
:class="{ 'first-page': isFirstPage }"
The bound class name condition judges, if the current page number is the first page, addfirst-page
the class name, which can be used for custom styles. According toisFirstPage
the value of the variable to determine whether to addfirst-page
the class name. Added when theisFirstPage
value of is .true
class="first-page"
:disabled="currentPage === 1"
Determine whether the button is clickable by judging whether the current page number is 1, so as to achieve the effect of disabling the button. This sentence means whencurrentPage的值===1时,disabled="true"那么就被禁用,反之则反
@click="prevPage"
The click event is bound, and the method will be executed when the button is clickedprevPage
.
<text style="color:#2979ff">{ { currentPage }} </text><text style="color:#4b4b4b">/{ { totalPage }}</text>
: Use two<text>
labels to display the current page number and the total number of pages respectively.
{ { currentPage }}
is an interpolation expression used to render the current page number.
{ { totalPage }}
Also an interpolation expression used to render the total number of pages. Style the text by settingstyle
properties, such as color.
<view class="down_page" :class="{ 'last-page': isLastPage }" :disabled="currentPage === totalPage" @click="nextPage">></view>
: This is a view element that displays a next page button, similar to a previous page button.
:class="{ 'last-page': isLastPage }"
The bound class name condition judges, if the current page number is the last page, addlast-page
the class name, which can be used for custom styles.
:disabled="currentPage === totalPage"
Determine whether the button can be clicked by judging whether the current page number is equal to the total number of pages, so as to achieve the effect of disabling the button.
@click="nextPage"
The click event is bound, and the method will be executed when the button is clickednextPage
.
Two, JS
1. Variable setting
data() {
return {
dataList: [],//查询出的数据
currentPage: 1,//当前页码
pageSize: 10,//每页显示数量
totalPage: 0,//总页数默认值
selectedIndex: -1,//selectedIndex 默认为 -1 是为了表示列表项未被选中的状态。
isFirstPage: '',//是否是第一页
isLastPage: '',//是否是最后一页
selectedRow: '',//选择行
wip_entity_name: '',//工单(模糊查询使用)
ItemNo: '',//料号
ItemName: '',//料号名称
};
},
2. Automatically calculate the current page information
computed: {
getCurrentPageData() {
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
return this.dataList.slice(startIndex, endIndex);
}
},
computed
It is a computed property feature provided by the vue.js framework. Usecomputed
to define some properties that are automatically calculated based on data changes in Vue components.In the given code,
getCurrentPageData
that is a computed property. It relies on the two data attributes ofcurrentPage
andpageSize
, and when these two attributes change,getCurrentPageData
it will automatically recalculate and return the data of the current page.
getCurrentPageData
is the name of a computed property.- Computed properties are defined by using
computed
keywords.- Code logic in computed properties is automatically executed when the associated reactive dependencies change.
const startIndex = (this.currentPage - 1) * this.pageSize;
: Calculate the starting index of the current page, usingcurrentPage
thesepageSize
two responsive data.
currentPage
Indicates the current page number.pageSize
Indicates the number of data bars displayed on each page.- The starting index calculation formula is
(当前页数 - 1) * 每页数据条数
.const endIndex = startIndex + this.pageSize;
: Calculate the end index of the current page.
- The calculation formula for the end index is
起始索引 + 每页数据条数
.return this.dataList.slice(startIndex, endIndex);
: According to the start index and end index, useslice()
the methoddataList
to extract the data of the current page from the array, and use it as the return value of the calculated property.
3. Click the search button to get the value of the fuzzy query
//模糊查询
search_wip_name(e) {
this.wip_entity_name = e.detail.value.wip_entity_name //工单号
this.ItemNo = e.detail.value.ItemNo //料号
this.ItemName = e.detail.value.ItemName //料号名称
this.getData(1); // 调用getData方法重新获取数据
},
4. Select row function
//选择行
selectRow(index, wipEntityName) {
const selectedItem = this.dataList[index];
if (selectedItem.selectedIndex === index && selectedItem.selectedRow) {
// 取消选中状态并清空wip_entity_name的值
this.dataList = this.dataList.map(item => ({
...item,
selectedIndex: -1,
selectedRow: false
}));
this.wip_entity_name = '';
} else {
// 选中当前行并获取wip_entity_name的值
this.dataList = this.dataList.map((item, i) => ({
...item,
selectedIndex: i === index ? index : -1,
selectedRow: i === index ? !item.selectedRow : false
}));
this.wip_entity_name = wipEntityName;
}
},
The selectRow(index, wipEntityName) method accepts two parameters
index
andwipEntityName
, respectively, the index of the selected row and the corresponding wip_entity_name attribute value.
const selectedItem = this.dataList[index];
: Obtain the data item object of the selected row according to the index and store it inselectedItem
the variable.
if (selectedItem.selectedIndex === index && selectedItem.selectedRow) { ... }
: Determine whether the currently selected row is already selected.
- If it is, it means that the user wants to uncheck the row and go
if
inside the code block.- Otherwise, it means that the user wants to select the line and enter
else
the code block.If a code block is entered
else
:this.dataList = this.dataList.map(item => ({
...item,
selectedIndex: -1,
selectedRow: false
}));this.wip_entity_name = '';
- Use
map()
the method to traversedataList
the array, set each rowselectedIndex
to -1 (indicates unselected), andselectedRow
set it to false (indicates unselected state).- Assign the updated
dataList
value back to the originaldataList
array to update the data.- Setting
wip_entity_name
the property to an empty string clears its value.If a code block is entered
else
:// Select the current row and get the value of wip_entity_name
this.dataList = this.dataList.map((item, i) => ({ ...item, selectedIndex: i === index ? index : -1, selectedRow: i === index ? !item.selectedRow : false })); this.wip_entity_name = wipEntityName;
- Use
map()
the method to traversedataList
the array, set each rowselectedIndex
as the index of the current row (indicating the selected row), andselectedRow
set it to true (indicating the selected state).- Assign the updated
dataList
value back to the originaldataList
array to update the data.- Set
wip_entity_name
the attribute towipEntityName
the value of the parameter, which is the value of wip_entity_name corresponding to the selected row.
5. Previous page, next page function realization
//上一页
prevPage() {
if (this.currentPage > 1) {
this.currentPage--;
this.getData(this.currentPage); // 调用getData方法获取上一页数据
}
},
//下一页
nextPage() {
if (this.currentPage < this.totalPage) {
this.currentPage++;
this.getData(this.currentPage); // 调用getData方法获取下一页数据
}
},
prevPage
Is the name of a method used to get the data of the previous page.
if (this.currentPage > 1)
Make sure that the current page number is greater than 1, that is, it is not the first page.If the conditions are met, do the following:
- Decrease the current page number
currentPage
by one, that is, jump to the previous page.- Call
getData
the method and pass in the updatedcurrentPage
as a parameter to get the data of the previous page.
nextPage
Is the name of a method used to get the next page of data.
if (this.currentPage < this.totalPage)
Make sure that the current page number is less than the total number of pages, that is, it is not the last page.
- Add one to the current page number
currentPage
to jump to the next page.- Call
getData
the method and pass in the updated onecurrentPage
as a parameter to get the data of the next page.
6. Get data
front-end code
//获取数据
getData(page) {
uni.request({
url: getApp().globalData.position + 'Produce/search_wip_name',
data: {
page: page,
pageSize: this.pageSize,
wip_entity_name: this.wip_entity_name, // 添加工单号参数
ItemNo: this.ItemNo, // 添加料号参数
ItemName: this.ItemName, // 添加料号名称参数
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: 'POST',
dataType: 'json',
success: res => {
// this.dataList = res.data.info;
this.dataList = res.data.info.map(item => ({
...item,
selectedIndex: -1,
selectedRow: false
}));
this.totalPage = Math.ceil(parseInt(res.data.total) / this.pageSize);
this.currentPage = page;
// 更新 isFirstPage 和 isLastPage 的值
this.isFirstPage = (page === 1);
this.isLastPage = (page === this.totalPage);
},
fail(res) {
console.log("查询失败");
}
});
}
},
Use
uni.request
the method to send a request, passing in the following parameters:
url
: The address of the request,getApp().globalData.position + 'Produce/search_wip_name'
indicating that the attribute values in the global dataposition
are concatenated'Produce/search_wip_name'
.data
: The parameter object of the request, includingpage
,pageSize
,wip_entity_name
,ItemNo
andItemName
header
: Request header information, set"Content-Type": "application/x-www-form-urlencoded"
.method
: Request method, set to'POST'
, means to use the POST method to send the request.dataType
: The data type of the response, set it'json'
to indicate that data in JSON format is expected to be returned.success
: The callback function when the request is successful, perform the operation:
- Assign the response data
res.data.info
tothis.dataList(设置页面需要展示的数据)
, andmap()
add attributesselectedIndex
and to each data item through the methodselectedRow
, and initialize it to-1
andfalse
.- Calculate the total number of pages based on the total amount of data
res.data.total
and the number displayed on each page , and assign it to .this.pageSize
this.totalPage
- Assign the current page number
page
tothis.currentPage
.- Update the value of sum,
this.isFirstPage
andthis.isLastPage
judge whether it is the first page or the last page according to the current page number and the total number of pages.fail
: The callback function when the request fails, print out"查询失败"
Backend code (thinkphp)
public function search_wip_name()
{
//从前端传入当前页码和每页总数
$page = input('post.page', 1); // 当前页码,默认为1
$pageSize = input('post.pageSize', 10); // 每页显示的数据条数,默认为10
//从前端传入模糊查询的条件
$wip_entity_name = input('post.wip_entity_name', '');
$ItemNo = input('post.ItemNo', '');
$ItemName = input('post.ItemName', '');
//进行数据库查询
$data['info'] = Db::table('wip_jobs_all')
->alias('a')
->join(['sf_item_no' => 'b'], 'a.primary_item=b.item_no')
->field('a.plan_start_date, a.start_quantity, a.wip_entity_name, a.quantity_completed, a.primary_item, b.item_desc, b.item_name, a.creation_date')
->where([
'a.status_type' => ['<>', '关闭'],
'a.wip_entity_name' => ['not in', function ($query) {
$query->table('wip_material_requierments')->where('quantity_issued', '>', 0)->field('wip_entity_name');
}]
])
//模糊查询条件
->where([
'a.wip_entity_name' => ['like', '%' . $wip_entity_name . '%'],
'a.primary_item' => ['like', '%' . $ItemNo . '%'],
'b.item_name' => ['like', '%' . $ItemName . '%'],
])
->order('a.wip_entity_name DESC')
//加入页码和每页数量的限制
->limit(($page - 1) * $pageSize, $pageSize)
->select();
// 格式化时间
foreach ($data['info'] as &$item) {
$item['creation_date'] = date('Y-m-d H:i:s', $item['creation_date']);
}
//计算查询总数
$total = Db::table('wip_jobs_all')
->alias('a')
->join(['sf_item_no' => 'b'], 'a.primary_item=b.item_no')
->where([
'a.status_type' => ['<>', '关闭'],
'a.wip_entity_name' => ['not in', function ($query) {
$query->table('wip_material_requierments')->where('quantity_issued', '>', 0)->field('wip_entity_name');
}]
])
->where([
'a.wip_entity_name' => ['like', '%' . $wip_entity_name . '%'],
'a.primary_item' => ['like', '%' . $ItemNo . '%'],
'b.item_name' => ['like', '%' . $ItemName . '%'],
])
->count();
$data['total'] = strval($total); // 将总数转换为字符串类型
//输出数据
echo json_encode($data);
}
7. The component has been mounted into the DOM
mounted() {
this.getData(1);
}
mounted
: "The component has been mounted into the DOM" means that the instance of the Vue component has been created and successfully inserted into the DOM structure of the page, and the template content of the component has been rendered on the page.In
mounted
the hook function, the method is calledgetData
and parameters are passed in1
. The specific analysis is as follows:
mounted
is a lifecycle hook function, indicating that the component has been mounted into the DOM.- In this function, call is called
this.getData(1)
, that is, the method named is calledgetData
, and the parameters are passed in1
.- This means that after the component is mounted,
getData
the method will be called immediately, and the parameter is1
to get the data of the first page.- Through this code, the operation of obtaining data will be executed immediately after the component is loaded, and the data of the first page will be obtained and displayed
full code
front end
<template>
<view>
<!-- 搜索框-->
<form action="" @submit="search_wip_name">
<view class="search_position">
<view class="search">
<view class="search_left">
工单名称:
</view>
<view class="search_right">
<input name="wip_entity_name" type="text" />
</view>
</view>
</view>
<view class="search_position">
<view class="search">
<view class="search_left">
料号:
</view>
<view class="search_right">
<input name="ItemNo" type="text" />
</view>
</view>
</view>
<view class="search_position">
<view class="search">
<view class="search_left">
名称:
</view>
<view class="search_right">
<input name="ItemName" type="text" />
</view>
</view>
</view>
<view class="search_position">
<view class="btn_position">
<button class="button" form-type="submit">查询</button>
<button class="button1" >确认</button>
</view>
</view>
</form>
<!-- 表格 -->
<scroll-view scroll-x="true" style="overflow-x: scroll; white-space: nowrap;" lower-threshold="50">
<view class="table">
<view class="table-tr">
<view class="table-th1">工单名称</view>
<view class="table-th1">料号</view>
<view class="table-th1">料号名称</view>
<view class="table-th1">规格型号</view>
<view class="table-th1">预计开工日</view>
<view class="table-th1">开工量</view>
</view>
<!-- :class="{ selected: selectedIndex === index,'selected-row':selectedRow ===index }" -->
<view class="table-tr" v-for="(item, index) in dataList" :key="index"
:class="{ selected: item.selectedIndex === index, 'selected-row': item.selectedRow }"
@click="selectRow(index,item.wip_entity_name)">
<view class="table-td1">{
{item.wip_entity_name}}</view>
<view class="table-td2">{
{item.primary_item}}</view>
<view class="table-td2">{
{item.item_name}}</view>
<view class="table-td2">{
{item.item_desc}}</view>
<view class="table-td2">{
{item.plan_start_date}}</view>
<view class="table-td2">{
{item.start_quantity}}</view>
</view>
</view>
</scroll-view>
<!-- 分页 -->
<view class="pagination">
<view class="up_page" :class="{ 'first-page': isFirstPage }" :disabled="currentPage === 1"
@click="prevPage">
<</view>
<view class="now_page">
<text style="color:#2979ff">{
{ currentPage }} </text><text
style="color:#4b4b4b">/{
{ totalPage }}</text>
</view>
<view class="down_page" :class="{ 'last-page': isLastPage }" :disabled="currentPage === totalPage"
@click="nextPage">></view>
</view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
dataList: [],
currentPage: 1,
pageSize: 10,
totalPage: 0,
selectedIndex: -1,
isFirstPage: '',
isLastPage: '',
selectedRow: '',
wip_entity_name: '',
ItemNo: '',
ItemName: '',
};
},
computed: {
getCurrentPageData() {
const startIndex = (this.currentPage - 1) * this.pageSize;
const endIndex = startIndex + this.pageSize;
return this.dataList.slice(startIndex, endIndex);
}
},
methods: {
//模糊查询
search_wip_name(e) {
this.wip_entity_name = e.detail.value.wip_entity_name //工单号
this.ItemNo = e.detail.value.ItemNo //料号
this.ItemName = e.detail.value.ItemName //料号名称
this.getData(1); // 调用getData方法重新获取数据
},
//选择行
selectRow(index, wipEntityName) {
const selectedItem = this.dataList[index];
if (selectedItem.selectedIndex === index && selectedItem.selectedRow) {
// 取消选中状态并清空wip_entity_name的值
this.dataList = this.dataList.map(item => ({
...item,
selectedIndex: -1,
selectedRow: false
}));
this.wip_entity_name = '';
} else {
// 选中当前行并获取wip_entity_name的值
this.dataList = this.dataList.map((item, i) => ({
...item,
selectedIndex: i === index ? index : -1,
selectedRow: i === index ? !item.selectedRow : false
}));
this.wip_entity_name = wipEntityName;
}
},
//上一页
prevPage() {
if (this.currentPage > 1) {
this.currentPage--;
this.getData(this.currentPage); // 调用getData方法获取上一页数据
}
},
//下一页
nextPage() {
if (this.currentPage < this.totalPage) {
this.currentPage++;
this.getData(this.currentPage); // 调用getData方法获取下一页数据
}
},
//获取数据
getData(page) {
uni.request({
url: getApp().globalData.position + 'Produce/search_wip_name',
data: {
page: page,
pageSize: this.pageSize,
wip_entity_name: this.wip_entity_name, // 添加工单号参数
ItemNo: this.ItemNo, // 添加料号参数
ItemName: this.ItemName, // 添加料号名称参数
},
header: {
"Content-Type": "application/x-www-form-urlencoded"
},
method: 'POST',
dataType: 'json',
success: res => {
// this.dataList = res.data.info;
this.dataList = res.data.info.map(item => ({
...item,
selectedIndex: -1,
selectedRow: false
}));
this.totalPage = Math.ceil(parseInt(res.data.total) / this.pageSize);
this.currentPage = page;
// 更新 isFirstPage 和 isLastPage 的值
this.isFirstPage = (page === 1);
this.isLastPage = (page === this.totalPage);
},
fail(res) {
console.log("查询失败");
}
});
}
},
mounted() {
this.getData(1);
}
};
</script>
<style>
/* 行选择样式 */
.selected-row {
background-color: #74bfe7;
}
/* 第一页和最后一页,按钮的样式 */
.up_page.first-page {
color: #afafaf;
}
.down_page.last-page {
color: #afafaf;
}
/* 翻页样式 */
.pagination {
display: flex;
width: 100%;
background-color: #f5f5f5;
align-items: center;
justify-items: center;
justify-content: center;
height: 60rpx;
border: 1rpx solid gray;
border-top: none;
}
.up_page {
width: 10%;
text-align: center;
color: #4b4b4b;
}
.down_page {
width: 10%;
text-align: center;
color: #4b4b4b;
}
.now_page {
width: 80%;
text-align: center;
}
/* 表格样式 */
.table {
margin-top: 5%;
font-size: 85%;
display: table;
width: 200%;
border-collapse: collapse;
box-sizing: border-box;
}
.table-tr {
display: table-row;
}
.table-th1 {
width: 20%;
display: table-cell;
font-weight: bold;
border: 1rpx solid gray;
background-color: #51aad6;
text-align: center;
vertical-align: middle;
padding: 10rpx 0;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
.table-th2 {
width: 30%;
display: table-cell;
font-weight: bold;
border: 1rpx solid gray;
background-color: #51aad6;
text-align: center;
vertical-align: middle;
padding: 10rpx 0;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
.table-th3 {
width: 50%;
display: table-cell;
font-weight: bold;
border: 1rpx solid gray;
background-color: #51aad6;
text-align: center;
vertical-align: middle;
padding: 10rpx 0;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
.table-td1 {
width: 20%;
display: table-cell;
border: 1rpx solid gray;
text-align: center;
vertical-align: middle;
padding: 10rpx 0;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
.table-td2 {
width: 30%;
display: table-cell;
border: 1rpx solid gray;
text-align: center;
vertical-align: middle;
padding: 10rpx 0;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
}
.table-td3 {
width: 50%;
display: table-cell;
border: 1rpx solid gray;
text-align: center;
vertical-align: middle;
overflow: hidden;
text-overflow: ellipsis;
word-break: break-all;
/* padding: 5px 0; */
}
/* 搜索框 */
.search_position {
display: flex;
align-items: center;
justify-content: center;
width: 100%;
margin: 5% 0;
/* border:1px solid black; */
}
.search {
width: 90%;
/* border:1px solid black; */
display: flex;
}
.search_left {
font-size: 105%;
font-weight: bold;
color: rgb(90, 90, 90);
width: 30%;
}
.search_right {
border-bottom: 1px solid rgb(95, 95, 95);
width: 70%;
}
.btn_position {
display: flex;
align-items: center;
justify-content: center;
width: 60%;
margin: 2% 0;
/* border: 1px solid black; */
}
.button {
margin-top: 5%;
background-color: #40A4D6;
color: #fff;
font-size: 30rpx;
/* border: 1px solid black; */
}
.button1 {
margin-top: 5%;
background-color: #fff ;
color: #40A4D6;
font-size: 30rpx;
border: 1px solid #40A4D6;
}
</style>
rear end
//模糊查询工单
public function search_wip_name()
{
//获取前台传来的页码和每页显示数
$page = input('post.page', 1); // 当前页码,默认为1
$pageSize = input('post.pageSize', 10); // 每页显示的数据条数,默认为10
//获取模糊查询的条件
$wip_entity_name = input('post.wip_entity_name', '');//工单
$ItemNo = input('post.ItemNo', '');//料号
$ItemName = input('post.ItemName', ''); //料号名称
//查询数据,代入分页的限制条件->limit(($page - 1) * $pageSize, $pageSize)
$data['info'] = Db::table('wip_jobs_all')
->alias('a')
->join(['sf_item_no' => 'b'], 'a.primary_item=b.item_no')
->field('a.plan_start_date, a.start_quantity, a.wip_entity_name, a.quantity_completed, a.primary_item, b.item_desc, b.item_name, a.creation_date')
->where([
'a.status_type' => ['<>', '关闭'],
'a.wip_entity_name' => ['not in', function ($query) {
$query->table('wip_material_requierments')->where('quantity_issued', '>', 0)->field('wip_entity_name');
}]
])
->where([
'a.wip_entity_name' => ['like', '%' . $wip_entity_name . '%'],
'a.primary_item' => ['like', '%' . $ItemNo . '%'],
'b.item_name' => ['like', '%' . $ItemName . '%'],
])
->order('a.wip_entity_name DESC')
->limit(($page - 1) * $pageSize, $pageSize)
->select();
// 格式化时间
foreach ($data['info'] as &$item) {
$item['creation_date'] = date('Y-m-d H:i:s', $item['creation_date']);
}
//计算总条数
$total = Db::table('wip_jobs_all')
->alias('a')
->join(['sf_item_no' => 'b'], 'a.primary_item=b.item_no')
->where([
'a.status_type' => ['<>', '关闭'],
'a.wip_entity_name' => ['not in', function ($query) {
$query->table('wip_material_requierments')->where('quantity_issued', '>', 0)->field('wip_entity_name');
}]
])
->where([
'a.wip_entity_name' => ['like', '%' . $wip_entity_name . '%'],
'a.primary_item' => ['like', '%' . $ItemNo . '%'],
'b.item_name' => ['like', '%' . $ItemName . '%'],
])
->count();
$data['total'] = strval($total); // 将总数转换为字符串类型
//输出数据
echo json_encode($data);
}