123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <template>
- <view class="table-container">
- <!-- 查询框 -->
- <view class="container">
- <view class="search-container">
- <uni-easyinput prefixIcon="search" v-model="BillNo" placeholder="请输入单号" style="margin-right: 5px;">
- </uni-easyinput>
- <button class="search-button" @click="search">查询</button>
- </view>
- <view style="padding:0 5px 2px 5px;">
- <uni-datetime-picker v-model="range" type="daterange" @maskClick="maskClick" />
- </view>
- </view>
- <!-- 表格容器 -->
- <scroll-view class="table-scroll" scroll-x scroll-y @scroll="onScroll">
- <!-- 表头 -->
- <view class="table-header" ref="tableHeader" v-if="formId === 'PUR_MRB'">
- <view class="table-cell1">单据编号</view>
- <view class="table-cell">仓管员</view>
- <view class="table-cell"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">供应商</view>
- <view class="table-cell1"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">采购员</view>
- <view class="table-cell"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">采购部门</view>
- <view class="table-cell"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
- </view>
- <!-- 表头 -->
- <view class="table-header" ref="tableHeader" v-else>
- <view class="table-cell1">工作中心</view>
- <view class="table-cell">作业申请人</view>
- <view class="table-cell"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">仓管员</view>
- <view class="table-cell1"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据编号</view>
- <view class="table-cell"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
- <view class="table-cell"
- style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">备注</view>
- </view>
- <!-- 表格内容 -->
- <view class="table-body" v-if="formId === 'PUR_MRB'">
- <checkbox-group @change="checkboxChange">
- <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
- <view class="table-cell1-1">
- <checkbox :value="item.FID" :checked="item.checked" />
- {{ item["FBillNo"]}}
- </view>
- <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
- <view class="table-cell">{{ item["FSupplierID.fname"] }}</view>
- <view class="table-cell1">{{ item["FPURCHASERID.fname"] }}</view>
- <view class="table-cell">{{ item["FPURCHASEDEPTID.fname"] }}</view>
- <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
- </view>
- </checkbox-group>
- </view>
- <view class="table-body" v-else>
- <checkbox-group @change="checkboxChange">
- <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
- <view class="table-cell1-1" v-if="formId === 'LT_PRD_PMCWorkBench'">
- <checkbox :value="item.FID" :checked="item.checked" />
- {{ item["FWorkCenterId.LT.fname"]}}
- </view>
- <view class="table-cell1-1" v-else-if="formId === 'SP_PickMtrl'">
- <checkbox :value="item.FID" :checked="item.checked" />
- {{ item["FWorkCenterId.fname"]}}
- </view>
- <view class="table-cell1-1" v-else>
- <checkbox :value="item.FID" :checked="item.checked" />
- {{ item["FWorkCenterId.LT.fname"]}}
- </view>
- <view class="table-cell">{{ item["FApplicantId.fname"] }}</view>
- <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
- <view class="table-cell1-1">{{ item["FBillNo"] }}</view>
- <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
- <view class="table-cell">{{ item["FDescription"] }}</view>
- </view>
- </checkbox-group>
- </view>
- </scroll-view>
- <!-- 底部按钮 -->
- <view class="bottom-bar">
- <button class="mini-btn button" type="primary" size="default" @click="submit">确定</button>
- <button class="mini-btn button" type="warn" size="default" @click="goBack">取消</button>
- </view>
- </view>
- </template>
- <script>
- import {
- getBillList,
- getBillDetailList
- } from '../../api/production_replenishment';
- import modal from '../../plugins/modal';
- import {
- audioUrls,
- playVoice
- } from '../../utils/audio';
- import {
- getBillDetailListParam,
- getBillDetailParam,
- getSearchParam
- } from '../../utils/newparams.js';
- export default {
- data() {
- return {
- formId: '',
- BillNo: '',
- range: [], //正式
- // range: ["2024-07-27",
- // "2024-07-27"
- // ], //测试
- selected: [], // 保存每个数据项是否被选中的状态
- // isRangeSelected: true // 标记是否选择了日期范围,默认为 true
- BillList: [],
- BillDetailList: [],
- // filteredData: [] // 过滤后的数据
- };
- },
- computed: {
- },
- created() {
- this.formId = uni.getStorageSync("formId")
- this.initialDateRange();
- },
- methods: {
- initialDateRange() {
- let today = new Date();
- let formattedDate = today.toISOString().split('T')[0]; // 格式化为 "YYYY-MM-DD"
- // 设置 range 属性为当天日期的数组
- this.range = [formattedDate, formattedDate];
- },
- maskClick(e) {
- console.log('maskClick事件:', e);
- },
- handleChange(index) {
- console.log(index)
- this.filteredData[index].checked = !this.filteredData[index].checked;
- },
- onScroll(e) {
- const scrollLeft = e.detail.scrollLeft;
- this.headerLeft = -scrollLeft; // 更新表头左侧位置,实现横向滚动时的对齐效果
- },
- checkboxChange: function(e) {
- console.log(e)
- var items = this.BillList,
- values = e.detail.value;
- console.log(values)
- this.selected = values
- console.log(this.selected)
- for (var i = 0, lenI = items.length; i < lenI; ++i) {
- const item = items[i]
- if (values.includes(item.FID)) {
- this.$set(item, 'checked', true)
- } else {
- this.$set(item, 'checked', false)
- }
- }
- console.log(items)
- },
- async submit() {
- if (this.selected.length === 0) {
- modal.msgError("请先选择")
- playVoice(audioUrls.failVoiceUrl)
- return;
- }
- try {
- // let self = this
- // 获取请求条件
- const condition = this.createSubmitCondition();
- const billDetailListParam = getBillDetailListParam(condition)
- const res = await this.fetchBillDetails(billDetailListParam)
- this.BillDetailList = res;
- this.navigateBack();
- } catch (error) {
- playVoice(audioUrls.failVoiceUrl)
- console.error('操作失败:', error);
- modal.confirm(error|| '操作失败').then(res => {
- if (res) {
- } else {
- // 用户点击取消,不执行任何操作
- }
- })
- }
- // getBillDetailList(JSON.stringify(billDetailListParam)).then(
- // res => {
- // console.log(res)
- // this.BillDetailList = res
- // uni.navigateBack({
- // success: function() {
- // // 传递数据给上一页
- // uni.$emit('search', self.BillDetailList);
- // }
- // });
- // }
- // )
- },
- // 返回上一页并传递数据
- navigateBack() {
- uni.navigateBack({
- success: () => {
- uni.$emit('search', this.BillDetailList);
- }
- });
- },
- // 获取请求条件
- createSubmitCondition() {
- return {
- FormId: uni.getStorageSync('formId'),
- selectedFID: this.selected.join(',')
- };
- },
- // 发起请求并获取数据
- fetchBillDetails(billDetailListParam) {
- return getBillDetailList(JSON.stringify(billDetailListParam));
- },
- goBack() {
- uni.navigateBack();
- },
- // 函数来创建条件
- createSearchCondition(range, billNo) {
- return {
- "FormId": uni.getStorageSync('formId'),
- "FBillType": uni.getStorageSync('fbillType'),
- "FStockOrgId": uni.getStorageSync('FStockOrgId'),
- "billNo": billNo,
- "range": range
- };
- },
- search() {
- console.log(this.range)
- // 检查是否选择了日期范围
- if (this.range.length === 0) {
- modal.msgError("请选择日期范围")
- playVoice(audioUrls.failVoiceUrl)
- return;
- }
- // const condition = {
- // "FormId": uni.getStorageSync('formId'),
- // "FBillType": uni.getStorageSync('fbillType'),
- // "FStockOrgId": uni.getStorageSync('FStockOrgId'),
- // "billNo": this.BillNo,
- // "range": this.range
- // }
- const condition = this.createSearchCondition(this.range, this.BillNo);
- const searchParam = getSearchParam(condition)
- modal.loading('获取数据中,请耐心等待...')
- getBillList(JSON.stringify(searchParam)).then(
- res => this.handleResponse(res)
- // res => {
- // modal.closeLoading()
- // console.log(res)
- // if (res.length === 0) {
- // console.log("dafafadf")
- // modal.msg("请确认输入条件有效!")
- // playVoice(audioUrls.failVoiceUrl)
- // return
- // }
- // // 使用 Set 和 JSON.stringify 进行去重,会获取到明细数据
- // let uniqueArray = Array.from(new Set(res.map(item => JSON.stringify(item)))).map(item =>
- // JSON.parse(item))
- // console.log(uniqueArray)
- // this.BillList = uniqueArray
- // }
- )
- },
- handleResponse(res) {
- // 关闭加载提示
- modal.closeLoading();
- // 检查响应是否为空
- if (res.length === 0) {
- modal.msg("请确认输入条件有效!");
- playVoice(audioUrls.failVoiceUrl);
- return;
- }
- // 处理数据去重并更新状态
- this.updateBillList(res);
- },
- updateBillList(data) {
- // 使用 Set 和 JSON.stringify 进行去重
- let uniqueArray = Array.from(new Set(data.map(item => JSON.stringify(item)))).map(item =>
- JSON.parse(item));
- console.log(uniqueArray);
- this.BillList = uniqueArray;
- },
- }
- };
- </script>
- <style>
- .table-container {
- width: 100%;
- height: 100%;
- display: flex;
- flex-direction: column;
- }
- .container {
- display: flex;
- flex-direction: column;
- }
- .search-container {
- display: flex;
- /* justify-content: flex-start; */
- flex-direction: row;
- align-items: center;
- padding: 5px;
- /* border-bottom: 1px solid #ccc; */
- flex-wrap: wrap;
- }
- .search-button {
- /* padding: 8px 16px; */
- border: none;
- border-radius: 4px;
- background-color: #007bff;
- color: #fff;
- cursor: pointer;
- }
- .search-button:hover {
- background-color: #0056b3;
- }
- .table-scroll {
- /* position: absolute; */
- flex: 1;
- overflow-x: auto;
- overflow-y: hidden;
- }
- .table-header {
- position: sticky;
- top: 0;
- background-color: #f0f0f0;
- font-weight: bold;
- border-bottom: 1px solid #ccc;
- display: flex;
- z-index: 1;
- /* 确保表头在内容之上 */
- }
- .table-cell1 {
- min-width: 150px;
- padding: 10px;
- text-align: center;
- border-right: 1px solid #ccc;
- }
- .table-cell1-1 {
- min-width: 150px;
- padding: 10px;
- text-align: left;
- border-right: 1px solid #ccc;
- }
- .table-cell {
- min-width: 100px;
- padding: 10px;
- text-align: center;
- border-right: 1px solid #ccc;
- }
- .header-cell {
- border-right: none;
- /* 取消最后一列的右边框 */
- }
- .table-body {
- flex: 1;
- width: fit-content;
- /* 使内容宽度适应内容的宽度 */
- }
- .table-row {
- display: flex;
- border-bottom: 1px solid #ccc;
- }
- .checkbox {
- width: 100%;
- height: 100%;
- display: flex;
- justify-content: center;
- align-items: center;
- }
- .bottom-bar {
- display: flex;
- /* justify-content: center; */
- justify-content: flex-end;
- /* 将按钮靠右对齐 */
- align-items: center;
- /* padding: 10px; */
- padding: 3px;
- background-color: #f0f0f0;
- }
- .button {
- margin: 0 10px;
- /* padding: 10px 20px; */
- }
- </style>
|