search.vue 12 KB

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