search.vue 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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">
  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. <!-- 表格内容 -->
  30. <view class="table-body">
  31. <checkbox-group @change="checkboxChange">
  32. <view class="table-row" v-for="(item, index) in BillList" :key="item.FID">
  33. <view class="table-cell1-1">
  34. <checkbox :value="item.FID" :checked="item.checked" />
  35. {{ item["FWorkCenterId.LT.fname"]}}
  36. </view>
  37. <view class="table-cell">{{ item["FApplicantId.fname"] }}</view>
  38. <view class="table-cell">{{ item["FSTOCKERID.fname"] }}</view>
  39. <view class="table-cell1-1">{{ item["FBillNo"] }}</view>
  40. <view class="table-cell">{{ item["FDate"].substring(0, 10) }}</view>
  41. <view class="table-cell">{{ item["FDescription"] }}</view>
  42. </view>
  43. </checkbox-group>
  44. </view>
  45. </scroll-view>
  46. <!-- 底部按钮 -->
  47. <view class="bottom-bar">
  48. <button class="mini-btn button" type="primary" size="default" @click="submit">确定</button>
  49. <button class="mini-btn button" type="warn" size="default" @click="goBack">取消</button>
  50. </view>
  51. </view>
  52. </template>
  53. <script>
  54. import {
  55. getBillList,
  56. getBillDetailList
  57. } from '../../api/production_replenishment';
  58. import modal from '../../plugins/modal';
  59. import {
  60. audioUrls,
  61. playVoice
  62. } from '../../utils/audio';
  63. import {
  64. getBillDetailListParam,
  65. getBillDetailParam,
  66. getSearchParam
  67. } from '../../utils/params';
  68. export default {
  69. data() {
  70. return {
  71. BillNo: '',
  72. range: [], //正式
  73. // range: ["2024-07-27",
  74. // "2024-07-27"
  75. // ], //测试
  76. selected: [], // 保存每个数据项是否被选中的状态
  77. // isRangeSelected: true // 标记是否选择了日期范围,默认为 true
  78. BillList: [],
  79. BillDetailList: [],
  80. // filteredData: [] // 过滤后的数据
  81. };
  82. },
  83. computed: {
  84. },
  85. created() {
  86. this.initializeRange();
  87. },
  88. methods: {
  89. initializeRange() {
  90. let today = new Date();
  91. let formattedDate = today.toISOString().split('T')[0]; // 格式化为 "YYYY-MM-DD"
  92. // 设置 range 属性为当天日期的数组
  93. this.range = [formattedDate, formattedDate];
  94. },
  95. maskClick(e) {
  96. console.log('maskClick事件:', e);
  97. },
  98. handleChange(index) {
  99. console.log(index)
  100. this.filteredData[index].checked = !this.filteredData[index].checked;
  101. },
  102. onScroll(e) {
  103. const scrollLeft = e.detail.scrollLeft;
  104. this.headerLeft = -scrollLeft; // 更新表头左侧位置,实现横向滚动时的对齐效果
  105. },
  106. checkboxChange: function(e) {
  107. console.log(e)
  108. var items = this.BillList,
  109. values = e.detail.value;
  110. console.log(values)
  111. this.selected = values
  112. console.log(this.selected)
  113. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  114. const item = items[i]
  115. if (values.includes(item.FID)) {
  116. this.$set(item, 'checked', true)
  117. } else {
  118. this.$set(item, 'checked', false)
  119. }
  120. }
  121. console.log(items)
  122. },
  123. submit() {
  124. if (this.selected.length === 0) {
  125. modal.msgError("请先选择")
  126. playVoice(audioUrls.failVoiceUrl)
  127. return;
  128. }
  129. let self = this
  130. const selectedFID = this.selected.join(',')
  131. const condition = {
  132. "selectedFID": selectedFID
  133. }
  134. const billDetailListParam = getBillDetailListParam(condition)
  135. getBillDetailList(JSON.stringify(billDetailListParam)).then(
  136. res => {
  137. console.log(res)
  138. this.BillDetailList = res
  139. uni.navigateBack({
  140. success: function() {
  141. // 传递数据给上一页
  142. uni.$emit('search', self.BillDetailList);
  143. }
  144. });
  145. }
  146. )
  147. },
  148. goBack() {
  149. uni.navigateBack();
  150. },
  151. search() {
  152. console.log(this.range)
  153. // 检查是否选择了日期范围
  154. if (this.range.length === 0) {
  155. modal.msgError("请选择日期范围")
  156. playVoice(audioUrls.failVoiceUrl)
  157. return;
  158. }
  159. const condition = {
  160. "FStockOrgId": uni.getStorageSync('FStockOrgId'),
  161. "billNo": this.BillNo,
  162. "range": this.range
  163. }
  164. console.log(condition)
  165. const searchParam = getSearchParam(condition)
  166. console.log(searchParam)
  167. modal.loading('获取数据中,请耐心等待...')
  168. getBillList(JSON.stringify(searchParam)).then(
  169. res => {
  170. modal.closeLoading()
  171. console.log(res)
  172. if (res.length === 0) {
  173. console.log("dafafadf")
  174. modal.msg("请确认输入条件有效!")
  175. playVoice(audioUrls.failVoiceUrl)
  176. return
  177. }
  178. // 使用 Set 和 JSON.stringify 进行去重,会获取到明细数据
  179. let uniqueArray = Array.from(new Set(res.map(item => JSON.stringify(item)))).map(item =>
  180. JSON.parse(item))
  181. console.log(uniqueArray)
  182. this.BillList = uniqueArray
  183. }
  184. )
  185. }
  186. }
  187. };
  188. </script>
  189. <style>
  190. .table-container {
  191. width: 100%;
  192. height: 100%;
  193. display: flex;
  194. flex-direction: column;
  195. }
  196. .container {
  197. display: flex;
  198. flex-direction: column;
  199. }
  200. .search-container {
  201. display: flex;
  202. /* justify-content: flex-start; */
  203. flex-direction: row;
  204. align-items: center;
  205. padding: 5px;
  206. /* border-bottom: 1px solid #ccc; */
  207. flex-wrap: wrap;
  208. }
  209. .search-button {
  210. /* padding: 8px 16px; */
  211. border: none;
  212. border-radius: 4px;
  213. background-color: #007bff;
  214. color: #fff;
  215. cursor: pointer;
  216. }
  217. .search-button:hover {
  218. background-color: #0056b3;
  219. }
  220. .table-scroll {
  221. /* position: absolute; */
  222. flex: 1;
  223. overflow-x: auto;
  224. overflow-y: hidden;
  225. }
  226. .table-header {
  227. position: sticky;
  228. top: 0;
  229. background-color: #f0f0f0;
  230. font-weight: bold;
  231. border-bottom: 1px solid #ccc;
  232. display: flex;
  233. z-index: 1;
  234. /* 确保表头在内容之上 */
  235. }
  236. .table-cell1 {
  237. min-width: 150px;
  238. padding: 10px;
  239. text-align: center;
  240. border-right: 1px solid #ccc;
  241. }
  242. .table-cell1-1 {
  243. min-width: 150px;
  244. padding: 10px;
  245. text-align: left;
  246. border-right: 1px solid #ccc;
  247. }
  248. .table-cell {
  249. min-width: 100px;
  250. padding: 10px;
  251. text-align: center;
  252. border-right: 1px solid #ccc;
  253. }
  254. .header-cell {
  255. border-right: none;
  256. /* 取消最后一列的右边框 */
  257. }
  258. .table-body {
  259. flex: 1;
  260. width: fit-content;
  261. /* 使内容宽度适应内容的宽度 */
  262. }
  263. .table-row {
  264. display: flex;
  265. border-bottom: 1px solid #ccc;
  266. }
  267. .checkbox {
  268. width: 100%;
  269. height: 100%;
  270. display: flex;
  271. justify-content: center;
  272. align-items: center;
  273. }
  274. .bottom-bar {
  275. display: flex;
  276. /* justify-content: center; */
  277. justify-content: flex-end;
  278. /* 将按钮靠右对齐 */
  279. align-items: center;
  280. /* padding: 10px; */
  281. padding: 3px;
  282. background-color: #f0f0f0;
  283. }
  284. .button {
  285. margin: 0 10px;
  286. /* padding: 10px 20px; */
  287. }
  288. </style>