search.vue 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498
  1. <template>
  2. <view class="table-container">
  3. <!-- 查询框 -->
  4. <view class="container">
  5. <view class="search-container">
  6. <uni-easyinput prefixIcon="search" v-model="BillNo" placeholder="请输入单号" style="margin-right: 5px;">
  7. </uni-easyinput>
  8. <button class="search-button" @click="search">查询</button>
  9. </view>
  10. <view style="padding:0 5px 2px 5px;">
  11. <uni-datetime-picker v-model="range" type="daterange" @maskClick="maskClick" />
  12. </view>
  13. </view>
  14. <!-- 表格容器 -->
  15. <scroll-view class="table-scroll" scroll-x scroll-y @scroll="onScroll">
  16. <!-- 表头 -->
  17. <view class="table-header" ref="tableHeader" v-if="formId === 'PUR_MRB'">
  18. <view class="table-cell1">单据编号</view>
  19. <view class="table-cell">仓管员</view>
  20. <view class="table-cell"
  21. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">供应商</view>
  22. <view class="table-cell1"
  23. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">采购员</view>
  24. <view class="table-cell"
  25. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">采购部门</view>
  26. <view class="table-cell"
  27. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
  28. </view>
  29. <view class="table-header" ref="tableHeader" v-else-if="formId === 'STK_OEMInStockRETURN'">
  30. <view class="table-cell1">单据编号</view>
  31. <view class="table-cell">仓管员</view>
  32. <view class="table-cell"
  33. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">客户</view>
  34. <view class="table-cell1"
  35. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">部门</view>
  36. <view class="table-cell"
  37. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
  38. </view>
  39. <view class="table-header" ref="tableHeader" v-else-if="formId === 'SAL_OUTSTOCK'">
  40. <view class="table-cell1">单据编号</view>
  41. <view class="table-cell">仓管员</view>
  42. <view class="table-cell1"
  43. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">客户</view>
  44. <view class="table-cell1"
  45. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">销售员</view>
  46. <view class="table-cell"
  47. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">销售部门</view>
  48. <view class="table-cell"
  49. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
  50. </view>
  51. <view class="table-header" ref="tableHeader" v-else-if="formId === 'STK_MisDelivery'">
  52. <view class="table-cell1">领料部门</view>
  53. <view class="table-cell">领料人</view>
  54. <view class="table-cell"
  55. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">仓管员</view>
  56. <view class="table-cell1"
  57. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据编号</view>
  58. <view class="table-cell"
  59. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
  60. <view class="table-cell"
  61. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">备注</view>
  62. </view>
  63. <!-- 表头 -->
  64. <view class="table-header" ref="tableHeader" v-else>
  65. <view class="table-cell1">工作中心</view>
  66. <view class="table-cell" v-if="formId === 'SP_PickMtrl'">领料人</view>
  67. <view class="table-cell" v-else>作业申请人</view>
  68. <view class="table-cell"
  69. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">仓管员</view>
  70. <view class="table-cell1"
  71. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据编号</view>
  72. <view class="table-cell"
  73. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">单据日期</view>
  74. <view class="table-cell"
  75. style="background-color: #f0f0f0;font-weight: bold;border-bottom: 1px solid #ccc;">备注</view>
  76. </view>
  77. <!-- 表格内容 -->
  78. <view class="table-body" v-if="formId === 'PUR_MRB'">
  79. <checkbox-group @change="checkboxChange">
  80. <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
  81. <view class="table-cell1-1">
  82. <checkbox :value="item.FID" :checked="item.checked" />
  83. {{ item["FBillNo"]}}
  84. </view>
  85. <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
  86. <view class="table-cell">{{ item["FSupplierID.fname"] }}</view>
  87. <view class="table-cell1">{{ item["FPURCHASERID.fname"] }}</view>
  88. <view class="table-cell">{{ item["FPURCHASEDEPTID.fname"] }}</view>
  89. <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
  90. </view>
  91. </checkbox-group>
  92. </view>
  93. <view class="table-body" v-else-if="formId === 'STK_OEMInStockRETURN'">
  94. <checkbox-group @change="checkboxChange">
  95. <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
  96. <view class="table-cell1-1">
  97. <checkbox :value="item.FID" :checked="item.checked" />
  98. {{ item["FBillNo"]}}
  99. </view>
  100. <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
  101. <view class="table-cell">{{ item["FCustId.FName"] }}</view>
  102. <view class="table-cell1">{{ item["FDeptId.LT.FName"] }}</view>
  103. <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
  104. </view>
  105. </checkbox-group>
  106. </view>
  107. <view class="table-body" v-else-if="formId === 'SAL_OUTSTOCK'">
  108. <checkbox-group @change="checkboxChange">
  109. <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
  110. <view class="table-cell1-1">
  111. <checkbox :value="item.FID" :checked="item.checked" />
  112. {{ item["FBillNo"]}}
  113. </view>
  114. <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
  115. <view class="table-cell1">{{ item["FCustomerID.FName"] }}</view>
  116. <view class="table-cell1">{{ item["FSalesManID.FName"] }}</view>
  117. <view class="table-cell">{{ item["FSaleDeptID.FName"] }}</view>
  118. <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
  119. </view>
  120. </checkbox-group>
  121. </view>
  122. <view class="table-body" v-else-if="formId === 'STK_MisDelivery'">
  123. <checkbox-group @change="checkboxChange">
  124. <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
  125. <view class="table-cell1-1">
  126. <checkbox :value="item.FID" :checked="item.checked" />
  127. {{ item["FDeptId.FName"]}}
  128. </view>
  129. <view class="table-cell">{{ item["FPickerId.FName"] }}</view>
  130. <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
  131. <view class="table-cell1-1">{{ item["FBillNo"] }}</view>
  132. <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
  133. <view class="table-cell">{{ item["FDescription"] }}</view>
  134. </view>
  135. </checkbox-group>
  136. </view>
  137. <view class="table-body" v-else>
  138. <checkbox-group @change="checkboxChange">
  139. <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
  140. <view class="table-cell1-1" v-if="formId === 'LT_PRD_PMCWorkBench'">
  141. <checkbox :value="item.FID" :checked="item.checked" />
  142. {{ item["FWorkCenterId.LT.fname"]}}
  143. </view>
  144. <view class="table-cell1-1" v-else-if="formId === 'SP_PickMtrl'">
  145. <checkbox :value="item.FID" :checked="item.checked" />
  146. {{ item["FWorkCenterId.fname"]}}
  147. </view>
  148. <view class="table-cell1-1" v-else>
  149. <checkbox :value="item.FID" :checked="item.checked" />
  150. {{ item["FWorkCenterId.LT.fname"]}}
  151. </view>
  152. <view class="table-cell" v-if="formId === 'SP_PickMtrl'">{{ item["FPickingPeople.LT.FName"] }}
  153. </view>
  154. <view class="table-cell" v-else>{{ item["FApplicantId.fname"] }}</view>
  155. <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
  156. <view class="table-cell1-1">{{ item["FBillNo"] }}</view>
  157. <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
  158. <view class="table-cell">{{ item["FDescription"] }}</view>
  159. </view>
  160. </checkbox-group>
  161. </view>
  162. </scroll-view>
  163. <!-- 底部按钮 -->
  164. <view class="bottom-bar">
  165. <button class="mini-btn button" type="primary" size="default" @click="submit">确定</button>
  166. <button class="mini-btn button" type="warn" size="default" @click="goBack">取消</button>
  167. </view>
  168. </view>
  169. </template>
  170. <script>
  171. import {
  172. getBillList,
  173. getBillDetailList
  174. } from '../../api/production_replenishment';
  175. import modal from '../../plugins/modal';
  176. import {
  177. audioUrls,
  178. playVoice
  179. } from '../../utils/audio';
  180. import {
  181. getBillDetailListParam,
  182. getBillDetailParam,
  183. getSearchParam
  184. } from '../../utils/newparams.js';
  185. export default {
  186. data() {
  187. return {
  188. formId: '',
  189. BillNo: '',
  190. range: [], //正式
  191. // range: ["2024-07-27",
  192. // "2024-07-27"
  193. // ], //测试
  194. selected: [], // 保存每个数据项是否被选中的状态
  195. // isRangeSelected: true // 标记是否选择了日期范围,默认为 true
  196. BillList: [],
  197. BillDetailList: [],
  198. // filteredData: [] // 过滤后的数据
  199. };
  200. },
  201. computed: {
  202. },
  203. created() {
  204. this.formId = uni.getStorageSync("formId")
  205. this.initialDateRange();
  206. },
  207. methods: {
  208. initialDateRange() {
  209. let today = new Date();
  210. let formattedDate = today.toISOString().split('T')[0]; // 格式化为 "YYYY-MM-DD"
  211. // 设置 range 属性为当天日期的数组
  212. this.range = [formattedDate, formattedDate];
  213. },
  214. maskClick(e) {
  215. console.log('maskClick事件:', e);
  216. },
  217. handleChange(index) {
  218. console.log(index)
  219. this.filteredData[index].checked = !this.filteredData[index].checked;
  220. },
  221. onScroll(e) {
  222. const scrollLeft = e.detail.scrollLeft;
  223. this.headerLeft = -scrollLeft; // 更新表头左侧位置,实现横向滚动时的对齐效果
  224. },
  225. checkboxChange: function(e) {
  226. console.log(e)
  227. var items = this.BillList,
  228. values = e.detail.value;
  229. console.log(values)
  230. this.selected = values
  231. console.log(this.selected)
  232. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  233. const item = items[i]
  234. if (values.includes(item.FID)) {
  235. this.$set(item, 'checked', true)
  236. } else {
  237. this.$set(item, 'checked', false)
  238. }
  239. }
  240. console.log(items)
  241. },
  242. async submit() {
  243. if (this.selected.length === 0) {
  244. modal.msgError("请先选择")
  245. playVoice(audioUrls.failVoiceUrl)
  246. return;
  247. }
  248. try {
  249. // let self = this
  250. // 获取请求条件
  251. const condition = this.createSubmitCondition();
  252. const billDetailListParam = getBillDetailListParam(condition)
  253. const res = await this.fetchBillDetails(billDetailListParam)
  254. this.BillDetailList = res;
  255. this.navigateBack();
  256. } catch (error) {
  257. playVoice(audioUrls.failVoiceUrl)
  258. console.error('操作失败:', error);
  259. modal.confirm(error || '操作失败').then(res => {
  260. if (res) {
  261. } else {
  262. // 用户点击取消,不执行任何操作
  263. }
  264. })
  265. }
  266. // getBillDetailList(JSON.stringify(billDetailListParam)).then(
  267. // res => {
  268. // console.log(res)
  269. // this.BillDetailList = res
  270. // uni.navigateBack({
  271. // success: function() {
  272. // // 传递数据给上一页
  273. // uni.$emit('search', self.BillDetailList);
  274. // }
  275. // });
  276. // }
  277. // )
  278. },
  279. // 返回上一页并传递数据
  280. navigateBack() {
  281. uni.navigateBack({
  282. success: () => {
  283. uni.$emit('search', this.BillDetailList);
  284. }
  285. });
  286. },
  287. // 获取请求条件
  288. createSubmitCondition() {
  289. return {
  290. FormId: uni.getStorageSync('formId'),
  291. selectedFID: this.selected.join(','),
  292. FBillType:uni.getStorageSync('fbillType')
  293. };
  294. },
  295. // 发起请求并获取数据
  296. fetchBillDetails(billDetailListParam) {
  297. return getBillDetailList(JSON.stringify(billDetailListParam));
  298. },
  299. goBack() {
  300. uni.navigateBack();
  301. },
  302. // 函数来创建条件
  303. createSearchCondition(range, billNo) {
  304. return {
  305. "FormId": uni.getStorageSync('formId'),
  306. "FBillType": uni.getStorageSync('fbillType'),
  307. "FStockOrgId": uni.getStorageSync('FStockOrgId'),
  308. "billNo": billNo,
  309. "range": range
  310. };
  311. },
  312. search() {
  313. console.log(this.range)
  314. // 检查是否选择了日期范围
  315. if (this.range.length === 0) {
  316. modal.msgError("请选择日期范围")
  317. playVoice(audioUrls.failVoiceUrl)
  318. return;
  319. }
  320. // const condition = {
  321. // "FormId": uni.getStorageSync('formId'),
  322. // "FBillType": uni.getStorageSync('fbillType'),
  323. // "FStockOrgId": uni.getStorageSync('FStockOrgId'),
  324. // "billNo": this.BillNo,
  325. // "range": this.range
  326. // }
  327. const condition = this.createSearchCondition(this.range, this.BillNo);
  328. const searchParam = getSearchParam(condition)
  329. modal.loading('获取数据中,请耐心等待...')
  330. getBillList(JSON.stringify(searchParam)).then(
  331. res => this.handleResponse(res)
  332. // res => {
  333. // modal.closeLoading()
  334. // console.log(res)
  335. // if (res.length === 0) {
  336. // console.log("dafafadf")
  337. // modal.msg("请确认输入条件有效!")
  338. // playVoice(audioUrls.failVoiceUrl)
  339. // return
  340. // }
  341. // // 使用 Set 和 JSON.stringify 进行去重,会获取到明细数据
  342. // let uniqueArray = Array.from(new Set(res.map(item => JSON.stringify(item)))).map(item =>
  343. // JSON.parse(item))
  344. // console.log(uniqueArray)
  345. // this.BillList = uniqueArray
  346. // }
  347. )
  348. },
  349. handleResponse(res) {
  350. // 关闭加载提示
  351. modal.closeLoading();
  352. // 检查响应是否为空
  353. if (res.length === 0) {
  354. modal.msg("请确认输入条件有效!");
  355. playVoice(audioUrls.failVoiceUrl);
  356. return;
  357. }
  358. // 处理数据去重并更新状态
  359. this.updateBillList(res);
  360. },
  361. updateBillList(data) {
  362. // 使用 Set 和 JSON.stringify 进行去重
  363. let uniqueArray = Array.from(new Set(data.map(item => JSON.stringify(item)))).map(item =>
  364. JSON.parse(item));
  365. console.log(uniqueArray);
  366. this.BillList = uniqueArray;
  367. },
  368. }
  369. };
  370. </script>
  371. <style>
  372. .table-container {
  373. width: 100%;
  374. height: 100%;
  375. display: flex;
  376. flex-direction: column;
  377. }
  378. .container {
  379. display: flex;
  380. flex-direction: column;
  381. }
  382. .search-container {
  383. display: flex;
  384. /* justify-content: flex-start; */
  385. flex-direction: row;
  386. align-items: center;
  387. padding: 5px;
  388. /* border-bottom: 1px solid #ccc; */
  389. flex-wrap: wrap;
  390. }
  391. .search-button {
  392. /* padding: 8px 16px; */
  393. border: none;
  394. border-radius: 4px;
  395. background-color: #007bff;
  396. color: #fff;
  397. cursor: pointer;
  398. }
  399. .search-button:hover {
  400. background-color: #0056b3;
  401. }
  402. .table-scroll {
  403. /* position: absolute; */
  404. flex: 1;
  405. overflow-x: auto;
  406. overflow-y: hidden;
  407. }
  408. .table-header {
  409. position: sticky;
  410. top: 0;
  411. background-color: #f0f0f0;
  412. font-weight: bold;
  413. border-bottom: 1px solid #ccc;
  414. display: flex;
  415. z-index: 1;
  416. /* 确保表头在内容之上 */
  417. }
  418. .table-cell1 {
  419. min-width: 150px;
  420. padding: 10px;
  421. text-align: center;
  422. border-right: 1px solid #ccc;
  423. }
  424. .table-cell1-1 {
  425. min-width: 150px;
  426. padding: 10px;
  427. text-align: left;
  428. border-right: 1px solid #ccc;
  429. }
  430. .table-cell {
  431. min-width: 100px;
  432. padding: 10px;
  433. text-align: center;
  434. border-right: 1px solid #ccc;
  435. }
  436. .header-cell {
  437. border-right: none;
  438. /* 取消最后一列的右边框 */
  439. }
  440. .table-body {
  441. flex: 1;
  442. width: fit-content;
  443. /* 使内容宽度适应内容的宽度 */
  444. }
  445. .table-row {
  446. display: flex;
  447. border-bottom: 1px solid #ccc;
  448. }
  449. .checkbox {
  450. width: 100%;
  451. height: 100%;
  452. display: flex;
  453. justify-content: center;
  454. align-items: center;
  455. }
  456. .bottom-bar {
  457. display: flex;
  458. /* justify-content: center; */
  459. justify-content: flex-end;
  460. /* 将按钮靠右对齐 */
  461. align-items: center;
  462. /* padding: 10px; */
  463. padding: 3px;
  464. background-color: #f0f0f0;
  465. }
  466. .button {
  467. margin: 0 10px;
  468. /* padding: 10px 20px; */
  469. }
  470. </style>