search.vue 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  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. },
  144. // 返回上一页并传递数据
  145. navigateBack() {
  146. uni.navigateBack({
  147. success: () => {
  148. uni.$emit('search', this.BillDetailList);
  149. }
  150. });
  151. },
  152. // 获取请求条件
  153. createSubmitCondition() {
  154. return {
  155. FormId: uni.getStorageSync('formId'),
  156. selectedFID: this.selected.join(',')
  157. };
  158. },
  159. // 发起请求并获取数据
  160. fetchBillDetails(billDetailListParam) {
  161. return getBillDetailList(JSON.stringify(billDetailListParam));
  162. },
  163. goBack() {
  164. uni.navigateBack();
  165. },
  166. // 函数来创建条件
  167. createSearchCondition(range, billNo) {
  168. return {
  169. "FormId": uni.getStorageSync('formId'),
  170. "FBillType": uni.getStorageSync('fbillType'),
  171. // "FStockOrgId": uni.getStorageSync('FStockOrgId'),
  172. "billNo": billNo,
  173. "range": range
  174. };
  175. },
  176. search() {
  177. console.log(this.range)
  178. // 检查是否选择了日期范围
  179. if (this.range.length === 0) {
  180. modal.msgError("请选择日期范围")
  181. playVoice(audioUrls.failVoiceUrl)
  182. return;
  183. }
  184. const condition = this.createSearchCondition(this.range, this.BillNo);
  185. console.log(condition)
  186. const searchParam = getSearchParam(condition)
  187. modal.loadingMask('获取数据中,请耐心等待...')
  188. getBillList(JSON.stringify(searchParam)).then(
  189. res => this.handleResponse(res)
  190. // res => {
  191. // modal.closeLoading()
  192. // console.log(res)
  193. // if (res.length === 0) {
  194. // console.log("dafafadf")
  195. // modal.msg("请确认输入条件有效!")
  196. // playVoice(audioUrls.failVoiceUrl)
  197. // return
  198. // }
  199. // // 使用 Set 和 JSON.stringify 进行去重,会获取到明细数据
  200. // let uniqueArray = Array.from(new Set(res.map(item => JSON.stringify(item)))).map(item =>
  201. // JSON.parse(item))
  202. // console.log(uniqueArray)
  203. // this.BillList = uniqueArray
  204. // }
  205. )
  206. },
  207. handleResponse(res) {
  208. // 关闭加载提示
  209. modal.closeLoading();
  210. // 检查响应是否为空
  211. if (res.length === 0) {
  212. modal.msg("请确认输入条件有效!");
  213. playVoice(audioUrls.failVoiceUrl);
  214. return;
  215. }
  216. // 处理数据去重并更新状态
  217. this.updateBillList(res);
  218. },
  219. updateBillList(data) {
  220. // 使用 Set 和 JSON.stringify 进行去重
  221. let uniqueArray = Array.from(new Set(data.map(item => JSON.stringify(item)))).map(item =>
  222. JSON.parse(item));
  223. console.log(uniqueArray);
  224. this.BillList = uniqueArray;
  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. min-width: 150px;
  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. display: flex;
  305. border-bottom: 1px solid #ccc;
  306. }
  307. .checkbox {
  308. width: 100%;
  309. height: 100%;
  310. display: flex;
  311. justify-content: center;
  312. align-items: center;
  313. }
  314. .bottom-bar {
  315. display: flex;
  316. /* justify-content: center; */
  317. justify-content: flex-end;
  318. /* 将按钮靠右对齐 */
  319. align-items: center;
  320. /* padding: 10px; */
  321. padding: 3px;
  322. background-color: #f0f0f0;
  323. }
  324. .button {
  325. margin: 0 10px;
  326. /* padding: 10px 20px; */
  327. }
  328. </style>