search.vue 9.1 KB

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