search.vue 15 KB

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