search.vue 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <template>
  2. <view class="table-container">
  3. <!-- 查询框 -->
  4. <view class="container">
  5. <view class="search-container">
  6. <uni-easyinput prefixIcon="search" v-model="stockLocNum" 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-y @scroll="onScroll">
  16. <!-- 表头 -->
  17. <view class="table-header" ref="tableHeader">
  18. <view class="table-cell1">仓位编号</view>
  19. </view>
  20. <!-- 表格内容 -->
  21. <view class="table-body">
  22. <!-- <checkbox-group @change="checkboxChange"> -->
  23. <view class="table-row" v-for="(item, index) in stockList" :key="item.FStockLocNum">
  24. <!-- <view class="table-cell1"> -->
  25. <!-- <checkbox :value="item.FID" :checked="item.checked" />{{ item.FBillNo}} -->
  26. <view class="checkbox-container">
  27. <checkbox :value="item.FStockLocNum" :checked="item.checked"
  28. @tap="handleCheckboxClick(item.FStockLocNum)" />
  29. <view style="display: flex; justify-content: center; align-items: center;">
  30. {{ item.FStockLocNum}}
  31. </view>
  32. </view>
  33. <!-- </view> -->
  34. </view>
  35. <!-- </checkbox-group> -->
  36. </view>
  37. </scroll-view>
  38. <!-- 底部按钮 -->
  39. <view class="bottom-bar">
  40. <button class="mini-btn button" type="primary" size="default" @click="submit">确定</button>
  41. <button class="mini-btn button" type="warn" size="default" @click="goBack">取消</button>
  42. </view>
  43. </view>
  44. </template>
  45. <script>
  46. import {
  47. getBillList,
  48. getBillDetailList,
  49. Querylocation
  50. } from '../../api/production_replenishment';
  51. import modal from '../../plugins/modal';
  52. import {
  53. audioUrls,
  54. playVoice
  55. } from '../../utils/audio';
  56. import {
  57. getBillDetailListParam,
  58. getBillDetailParam,
  59. getSearchParam
  60. } from '../../utils/newparams.js';
  61. export default {
  62. data() {
  63. return {
  64. formId: '',
  65. stockLocNum: '',
  66. selectedItemId: null,
  67. range: [], //正式
  68. // range: ["2024-07-27",
  69. // "2024-07-27"
  70. // ], //测试
  71. selected: [], // 保存每个数据项是否被选中的状态
  72. // isRangeSelected: true // 标记是否选择了日期范围,默认为 true
  73. stockList: [],
  74. BillDetailList: [],
  75. stockNum: ''
  76. // filteredData: [] // 过滤后的数据
  77. };
  78. },
  79. onLoad(option) {
  80. console.log(option)
  81. this.stockNum = option.stockNum
  82. // this.stageLists = JSON.parse(decodeURIComponent(option.stageInfo))
  83. console.log(this.stockNum)
  84. },
  85. computed: {
  86. },
  87. created() {
  88. this.formId = uni.getStorageSync("formId")
  89. this.initialDateRange();
  90. },
  91. methods: {
  92. initialDateRange() {
  93. let today = new Date();
  94. let formattedDate = today.toISOString().split('T')[0]; // 格式化为 "YYYY-MM-DD"
  95. // 设置 range 属性为当天日期的数组
  96. this.range = [formattedDate, formattedDate];
  97. },
  98. maskClick(e) {
  99. console.log('maskClick事件:', e);
  100. },
  101. handleChange(index) {
  102. console.log(index)
  103. this.filteredData[index].checked = !this.filteredData[index].checked;
  104. },
  105. onScroll(e) {
  106. const scrollLeft = e.detail.scrollLeft;
  107. this.headerLeft = -scrollLeft; // 更新表头左侧位置,实现横向滚动时的对齐效果
  108. },
  109. checkboxChange: function(e) {
  110. console.log(e)
  111. var items = this.BillList,
  112. values = e.detail.value;
  113. console.log(values)
  114. this.selected = values
  115. console.log(this.selected)
  116. for (var i = 0, lenI = items.length; i < lenI; ++i) {
  117. const item = items[i]
  118. if (values.includes(item.FID)) {
  119. this.$set(item, 'checked', true)
  120. } else {
  121. this.$set(item, 'checked', false)
  122. }
  123. }
  124. console.log(items)
  125. },
  126. async submit() {
  127. if (this.selectedItemId == null) {
  128. modal.msgError("请选择仓位")
  129. playVoice(audioUrls.failVoiceUrl)
  130. return
  131. }
  132. this.navigateBack();
  133. },
  134. // 返回上一页并传递数据
  135. navigateBack() {
  136. uni.navigateBack({
  137. success: () => {
  138. uni.$emit('search', this.selectedItemId);
  139. }
  140. });
  141. },
  142. // 获取请求条件
  143. createSubmitCondition() {
  144. return {
  145. FormId: uni.getStorageSync('formId'),
  146. selectedFID: this.selected.join(',')
  147. };
  148. },
  149. // 发起请求并获取数据
  150. fetchBillDetails(billDetailListParam) {
  151. return getBillDetailList(JSON.stringify(billDetailListParam));
  152. },
  153. goBack() {
  154. uni.navigateBack();
  155. },
  156. // 函数来创建条件
  157. createSearchCondition(range, billNo) {
  158. return {
  159. "FormId": uni.getStorageSync('formId'),
  160. "FBillType": uni.getStorageSync('fbillType'),
  161. "FStockOrgId": uni.getStorageSync('FStockOrgId'),
  162. "billNo": billNo,
  163. "range": range
  164. };
  165. },
  166. search() {
  167. modal.loading('获取数据中,请耐心等待...')
  168. let data = {
  169. usertoken: "99302b4923aa42298c5922b7b68bcff9",
  170. stockNum: this.stockNum,
  171. stockLocNum: this.stockLocNum
  172. }
  173. Querylocation(data).then(res => {
  174. console.log(res);
  175. this.handleResponse(res)
  176. })
  177. // console.log(this.range)
  178. // const condition = this.createSearchCondition(this.range, this.BillNo);
  179. // const searchParam = getSearchParam(condition)
  180. // modal.loading('获取数据中,请耐心等待...')
  181. // getBillList(JSON.stringify(searchParam)).then(
  182. // res => this.handleResponse(res)
  183. // )
  184. },
  185. handleResponse(res) {
  186. // 关闭加载提示
  187. modal.closeLoading();
  188. // 检查响应是否为空
  189. if (res.length === 0) {
  190. modal.msg("请确认输入条件有效!");
  191. playVoice(audioUrls.failVoiceUrl);
  192. return;
  193. }
  194. // 处理数据去重并更新状态
  195. this.updateStockList(res);
  196. },
  197. updateStockList(data) {
  198. // 使用 Set 和 JSON.stringify 进行去重
  199. // let uniqueArray = Array.from(new Set(data.map(item => JSON.stringify(item)))).map(item =>
  200. // JSON.parse(item));
  201. // console.log(uniqueArray);
  202. console.log(data)
  203. this.stockList = data.results;
  204. console.log(this.stockList)
  205. },
  206. handleCheckboxClick(itemId) {
  207. console.log(itemId)
  208. // 取消之前选中的项
  209. if (this.selectedItemId === itemId) {
  210. this.selectedItemId = null;
  211. this.stockList.forEach(item => {
  212. item.checked = false;
  213. });
  214. console.log(this.stockList)
  215. } else {
  216. // 更新选中项
  217. this.selectedItemId = itemId;
  218. this.stockList.forEach(item => {
  219. item.checked = (item.FStockLocNum === itemId);
  220. });
  221. console.log(this.stockList)
  222. }
  223. console.log(this.selectedItemId)
  224. this.$forceUpdate()
  225. },
  226. }
  227. };
  228. </script>
  229. <style>
  230. .table-container {
  231. width: 100%;
  232. height: 100%;
  233. display: flex;
  234. flex-direction: column;
  235. }
  236. .container {
  237. display: flex;
  238. flex-direction: column;
  239. }
  240. .search-container {
  241. display: flex;
  242. /* justify-content: flex-start; */
  243. flex-direction: row;
  244. align-items: center;
  245. padding: 5px;
  246. /* border-bottom: 1px solid #ccc; */
  247. flex-wrap: wrap;
  248. }
  249. .search-button {
  250. /* padding: 8px 16px; */
  251. border: none;
  252. border-radius: 4px;
  253. background-color: #007bff;
  254. color: #fff;
  255. cursor: pointer;
  256. }
  257. .search-button:hover {
  258. background-color: #0056b3;
  259. }
  260. .table-scroll {
  261. /* position: absolute; */
  262. flex: 1;
  263. overflow-x: auto;
  264. overflow-y: hidden;
  265. }
  266. .table-header {
  267. position: sticky;
  268. top: 0;
  269. background-color: #f0f0f0;
  270. font-weight: bold;
  271. border-bottom: 1px solid #ccc;
  272. display: flex;
  273. z-index: 1;
  274. /* 确保表头在内容之上 */
  275. }
  276. .table-cell1 {
  277. width: 100%;
  278. padding: 10px;
  279. text-align: center;
  280. border-right: 1px solid #ccc;
  281. }
  282. .table-cell1-1 {
  283. min-width: 150px;
  284. padding: 10px;
  285. text-align: left;
  286. border-right: 1px solid #ccc;
  287. }
  288. .table-cell {
  289. min-width: 100px;
  290. padding: 10px;
  291. text-align: center;
  292. border-right: 1px solid #ccc;
  293. }
  294. .header-cell {
  295. border-right: none;
  296. /* 取消最后一列的右边框 */
  297. }
  298. .table-body {
  299. flex: 1;
  300. /* width: fit-content; */
  301. /* 使内容宽度适应内容的宽度 */
  302. }
  303. .table-row {
  304. width: 100%;
  305. /* display: flex; */
  306. border-bottom: 1px solid #ccc;
  307. }
  308. .checkbox {
  309. width: 100%;
  310. height: 100%;
  311. display: flex;
  312. justify-content: center;
  313. align-items: center;
  314. }
  315. .bottom-bar {
  316. display: flex;
  317. /* justify-content: center; */
  318. justify-content: flex-end;
  319. /* 将按钮靠右对齐 */
  320. align-items: center;
  321. /* padding: 10px; */
  322. padding: 3px;
  323. background-color: #f0f0f0;
  324. }
  325. .button {
  326. margin: 0 10px;
  327. /* padding: 10px 20px; */
  328. }
  329. .checkbox-container {
  330. width: 100%;
  331. padding: 10px;
  332. /* text-align: center; */
  333. border-right: 1px solid #ccc;
  334. display: flex;
  335. align-items: center;
  336. /* margin-left: 10px;
  337. margin-right: 10px; */
  338. /* 可根据需要调整间距 */
  339. }
  340. </style>