details.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <template>
  2. <view class="container">
  3. <view class="form-section" @click="openPicker">
  4. <view class="section-title">选择客户</view>
  5. <u-input
  6. v-model="formData.customerName"
  7. type="select"
  8. placeholder="请选择客户"
  9. border="bottom"
  10. readonly
  11. ></u-input>
  12. </view>
  13. <u-popup :show="showCustomerPicker" mode="bottom" @close="closePicker">
  14. <!-- 顶部操作栏(渐变背景) -->
  15. <view class="picker-header">
  16. <text class="header-btn" @click="closePicker">取消</text>
  17. <text class="header-title">选择客户</text>
  18. <text class="header-btn confirm" @click="confirmSelection">确定</text>
  19. </view>
  20. <!-- 搜索框(带防抖) -->
  21. <view class="search-box">
  22. <u-search
  23. v-model="searchKeyword"
  24. placeholder="输入客户姓名搜索"
  25. shape="round"
  26. clearable
  27. :showAction="true" actionText="搜索"
  28. @search="handleSearch"
  29. @custom="handleSearch"
  30. @clear="resetSearch"
  31. ></u-search>
  32. </view>
  33. <!-- 客户列表 -->
  34. <scroll-view
  35. scroll-y
  36. class="customer-list"
  37. :style="{height: listHeight + 'px'}"
  38. @scrolltolower="loadMore"
  39. >
  40. <view
  41. v-for="(item, index) in dataList"
  42. :key="index"
  43. class="customer-card"
  44. :class="{active: selectedIndex === index}"
  45. @click="selectItem(index)"
  46. >
  47. <text class="customer-name">{{ item.cname }}</text>
  48. <u-icon
  49. v-if="selectedIndex === index"
  50. name="checkmark-circle-fill"
  51. color="#2979ff"
  52. size="36"
  53. ></u-icon>
  54. </view>
  55. <!-- 加载状态 -->
  56. <u-loadmore
  57. :status="loading ? 'loading' : (isLastPage ? 'nomore' : 'loadmore')"
  58. marginTop="20"
  59. marginBottom="20"
  60. />
  61. </scroll-view>
  62. </u-popup>
  63. <scroll-view scroll-y class="goods-list">
  64. <view v-for="(item, index) in goodsList" :key="index" class="goods-item">
  65. <view class="goods-info">
  66. <text class="goods-name">{{ item.productName }}</text>
  67. <text class="goods-price">¥{{ item.productPrice }}</text>
  68. </view>
  69. <view class="quantity-section">
  70. <u-number-box
  71. v-model="item.productQuantity"
  72. :min="0"
  73. integer
  74. class="quantity-box"
  75. ></u-number-box>
  76. <view class="amount-box">
  77. <text class="amount-symbol">¥</text>
  78. <text class="amount-number">{{ (item.productPrice * item.productQuantity).toFixed(2) }}</text>
  79. </view>
  80. </view>
  81. </view>
  82. </scroll-view>
  83. <view class="total-section">
  84. <text class="total-label">总金额:</text>
  85. <view class="total-amount-box">
  86. <text class="total-symbol">¥</text>
  87. <text class="total-number">{{ totalAmount.toFixed(2) }}</text>
  88. </view>
  89. </view>
  90. <view class="form-section">
  91. <view class="section-title">备注信息</view>
  92. <u-textarea
  93. v-model="formData.remark"
  94. placeholder="请输入备注(最多200字)"
  95. :maxlength="200"
  96. auto-height
  97. confirm-type="done"
  98. :count="true"
  99. :height="180"
  100. class="remark-textarea"
  101. placeholder-class="placeholder-style"
  102. ></u-textarea>
  103. </view>
  104. <view class="form-section">
  105. <view class="section-title">上传图片(最多3张)</view>
  106. <u-upload
  107. :fileList="fileList"
  108. @afterRead="afterRead"
  109. @delete="deletePic"
  110. multiple
  111. maxCount="3"
  112. :previewFullImage="true"
  113. uploadIcon="plus"
  114. uploadIconColor="#999"
  115. deletable
  116. :previewImage="true"
  117. class="upload-area"
  118. >
  119. <template #default>
  120. <view class="upload-tip">点击或拖拽上传图片</view>
  121. </template>
  122. </u-upload>
  123. </view>
  124. <view class="submit-section" v-if="!this.formData.status || this.formData.status !== 2">
  125. <button
  126. class="submit-btn"
  127. :disabled="totalAmount <= 0 || !formData.customerId"
  128. @click="clickSubmit"
  129. >
  130. {{this.formData.id ? '修改回收单' : '提交回收单'}}
  131. </button>
  132. </view>
  133. </view>
  134. </template>
  135. <script>
  136. import {
  137. submitRecycling,
  138. updateRecycling,
  139. getDetail,
  140. getCustomerPageList,
  141. greenRecyclingGoods
  142. } from '@/api/views/recycling/index.js'
  143. import http from '@/http/api.js'
  144. import {
  145. clientId,
  146. clientSecret
  147. } from '@/common/setting'
  148. export default {
  149. onLoad(options) {
  150. this.formData.id = options.id
  151. this.getGoodsList()
  152. console.log(options.id);
  153. },
  154. data() {
  155. return {
  156. showCustomerPicker: false,
  157. searchKeyword: '',
  158. dataList: [], // 当前页数据
  159. currentPage: 1, // 当前页码
  160. loading: false, // 加载状态
  161. isLastPage: false, // 是否最后一页
  162. selectedIndex: -1, // 选中项索引
  163. listHeight: 500, // 滚动区域高度,
  164. goodsList: [],
  165. fileList: [],
  166. formData: {
  167. id: null,
  168. quantity: null,
  169. amount: null,
  170. customerId: null,
  171. customerName: null,
  172. remark: '',
  173. imgs: [],
  174. greenRecyclingItemList: []
  175. },
  176. }
  177. },
  178. computed: {
  179. totalAmount() {
  180. return this.goodsList.reduce((total, item) => {
  181. return total + (item.productPrice * item.productQuantity)
  182. }, 0)
  183. }
  184. },
  185. methods: {
  186. selectItem(index) {
  187. this.selectedIndex = index;
  188. },
  189. async fetchData(reset = false) {
  190. if (this.loading) return;
  191. this.loading = true;
  192. try {
  193. const params = {
  194. current: reset ? 1 : this.currentPage,
  195. size: 10,
  196. cname: this.searchKeyword,
  197. corpType: 'KH'
  198. };
  199. getCustomerPageList(params).then(res => {
  200. console.info('获取数据成功:', res)
  201. if (reset) {
  202. this.dataList = res.data.records;
  203. this.currentPage = 1;
  204. } else {
  205. this.dataList = [...this.dataList, ...res.data.records];
  206. }
  207. this.isLastPage = this.currentPage * 10 >= res.data.total;
  208. })
  209. } catch (error) {
  210. console.error('获取数据失败:', error);
  211. } finally {
  212. this.loading = false;
  213. }
  214. },
  215. // 搜索处理(带防抖)
  216. handleSearch() {
  217. clearTimeout(this.timer);
  218. this.timer = setTimeout(() => {
  219. this.fetchData(true);
  220. }, 500);
  221. },
  222. // 加载更多
  223. loadMore() {
  224. if (!this.isLastPage && !this.loading) {
  225. this.currentPage++;
  226. this.fetchData();
  227. }
  228. },
  229. calcListHeight() {
  230. uni.getSystemInfo({
  231. success: (res) => {
  232. // 顶部操作栏88 + 搜索框60 + 底部安全区30
  233. this.listHeight = res.windowHeight - 88 - 60 - 30;
  234. }
  235. });
  236. },
  237. // 重置搜索
  238. resetSearch() {
  239. this.searchKeyword = '';
  240. },
  241. openPicker() {
  242. this.showCustomerPicker = true;
  243. this.calcListHeight();
  244. this.fetchData(true)
  245. },
  246. confirmSelection() {
  247. if (this.selectedIndex >= 0) {
  248. const selected = this.dataList[this.selectedIndex];
  249. console.info('selected----', selected)
  250. this.formData.customerId = selected.id
  251. this.formData.customerName = selected.cname
  252. this.$emit('selected', selected);
  253. }
  254. this.closePicker();
  255. },
  256. closePicker() {
  257. this.showCustomerPicker = false;
  258. },
  259. async afterRead(event) {
  260. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  261. let lists = [].concat(event.file)
  262. let fileListLen = this[`fileList${event.name}`].length
  263. lists.map((item) => {
  264. this[`fileList${event.name}`].push({
  265. ...item,
  266. })
  267. })
  268. for (let i = 0; i < lists.length; i++) {
  269. const result = await this.uploadFilePromise(lists[i].url)
  270. let item = this[`fileList${event.name}`][fileListLen]
  271. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  272. sort: this.fileList.length,
  273. fileName: JSON.parse(result).data.originalName,
  274. url: JSON.parse(result).data.link
  275. }))
  276. fileListLen++
  277. }
  278. },
  279. deletePic(event) {
  280. this.fileList.splice(event.index, 1)
  281. },
  282. orderDetail(){
  283. if (!this.formData.id) {
  284. return
  285. }
  286. getDetail(this.formData.id).then(res => {
  287. this.formData = res.data
  288. this.fileList = JSON.parse(this.formData.imgs)
  289. for (let itemNum in res.data.greenRecyclingItemList) {
  290. let nowItem = res.data.greenRecyclingItemList[itemNum]
  291. console.info(nowItem)
  292. let nowGoods = this.goodsList.findIndex(item => item.productName === nowItem.productName)
  293. console.info(nowGoods)
  294. if (nowGoods !== -1) {
  295. this.goodsList[nowGoods].productQuantity = nowItem.productQuantity
  296. this.goodsList[nowGoods].productPrice = nowItem.productPrice
  297. continue
  298. }
  299. this.goodsList.push(nowItem)
  300. }
  301. })
  302. },
  303. clickSubmit() {
  304. if (this.totalAmount <= 0) return;
  305. this.formData.quantity = this.goodsList.reduce((sum, item) => sum + item.productQuantity, 0);
  306. this.formData.amount = this.totalAmount
  307. this.formData.greenRecyclingItemList = this.goodsList.filter(item => item.productQuantity > 0)
  308. this.formData.imgs = JSON.stringify(this.fileList)
  309. if (this.formData.id) {
  310. this.handleUpdate()
  311. return;
  312. }
  313. this.handleSubmit()
  314. },
  315. handleSubmit() {
  316. uni.showLoading({title: '提交中...'});
  317. submitRecycling(this.formData).then(res => {
  318. console.info(res)
  319. this.formData.id = res.data
  320. uni.showToast({title: '提交成功'});
  321. }).finally(() => {
  322. uni.hideLoading();
  323. })
  324. },
  325. handleUpdate() {
  326. uni.showLoading({title: '提交中...'});
  327. this.formData.greenRecyclingItemList = this.goodsList.filter(item => item.productQuantity > 0)
  328. updateRecycling(this.formData).then(res => {
  329. console.info(res)
  330. // this.formData.id = res.data
  331. uni.showToast({title: '修改成功'});
  332. }).finally(() => {
  333. uni.hideLoading();
  334. })
  335. },
  336. uploadFilePromise(url) {
  337. return new Promise((resolve, reject) => {
  338. let a = uni.uploadFile({
  339. url: http.config.baseURL +
  340. '/blade-resource/oss/endpoint/put-file', // 仅为示例,非真实的接口地址
  341. filePath: url,
  342. name: 'file',
  343. formData: {
  344. user: 'test'
  345. },
  346. header: {
  347. // 客户端认证参数
  348. 'Authorization': 'Basic ' + Base64.encode(clientId + ':' +
  349. clientSecret),
  350. 'Blade-Auth': 'bearer ' + uni.getStorageSync('accessToken')
  351. },
  352. success: (res) => {
  353. setTimeout(() => {
  354. resolve(res.data)
  355. }, 1000)
  356. }
  357. });
  358. })
  359. },
  360. getGoodsList(){
  361. greenRecyclingGoods().then(res => {
  362. for(let num in res.data){
  363. this.goodsList.push( {
  364. productName: res.data[num].dictValue,
  365. productPrice: res.data[num].dictKey,
  366. productQuantity: 0
  367. })
  368. }
  369. this.orderDetail()
  370. })
  371. }
  372. }
  373. }
  374. </script>
  375. <style lang="scss" scoped>
  376. .container {
  377. padding: 20rpx;
  378. background-color: #f8f8f8;
  379. /* 按钮高度 + 边距 */
  380. padding-bottom: 120rpx;
  381. }
  382. .goods-list {
  383. height: 30vh;
  384. margin-bottom: 20rpx;
  385. background-color: #fff;
  386. border-radius: 16rpx;
  387. padding: 20rpx;
  388. }
  389. .goods-list::-webkit-scrollbar {
  390. display: none;
  391. width: 0;
  392. height: 0;
  393. }
  394. .goods-item {
  395. display: flex;
  396. justify-content: space-between;
  397. align-items: center;
  398. padding: 20rpx 0;
  399. border-bottom: 1rpx solid #eee;
  400. }
  401. .goods-info {
  402. flex: 1;
  403. display: flex;
  404. flex-direction: column;
  405. }
  406. .goods-name {
  407. font-size: 28rpx;
  408. color: #333;
  409. }
  410. .goods-price {
  411. font-size: 32rpx;
  412. color: #f56c6c;
  413. margin-top: 10rpx;
  414. }
  415. .quantity-box {
  416. width: 200rpx;
  417. }
  418. .form-section {
  419. background-color: #fff;
  420. border-radius: 16rpx;
  421. padding: 30rpx;
  422. margin-top: 20rpx;
  423. margin-bottom: 20rpx;
  424. }
  425. .section-title {
  426. font-size: 28rpx;
  427. color: #333;
  428. font-weight: 500;
  429. margin-bottom: 20rpx;
  430. position: relative;
  431. padding-left: 16rpx;
  432. }
  433. .section-title::before {
  434. content: "";
  435. position: absolute;
  436. left: 0;
  437. top: 50%;
  438. transform: translateY(-50%);
  439. width: 4rpx;
  440. height: 24rpx;
  441. background-color: #2979ff;
  442. border-radius: 2rpx;
  443. }
  444. .remark-textarea {
  445. background-color: #f8f8f8;
  446. border-radius: 12rpx;
  447. padding: 20rpx;
  448. font-size: 28rpx;
  449. }
  450. .placeholder-style {
  451. color: #b2b2b2;
  452. font-size: 26rpx;
  453. }
  454. .upload-area {
  455. margin-top: 20rpx;
  456. }
  457. .upload-tip {
  458. color: #999;
  459. font-size: 26rpx;
  460. text-align: center;
  461. padding: 20rpx 0;
  462. }
  463. /* 调整计数器样式 */
  464. /deep/ .u-textarea__count {
  465. color: #999;
  466. font-size: 24rpx;
  467. }
  468. /* 美化已上传图片的样式 */
  469. /deep/ .u-upload__wrap__preview__image {
  470. border-radius: 8rpx;
  471. }
  472. /deep/ .u-upload__wrap__preview__mask {
  473. background-color: rgba(0, 0, 0, 0.3);
  474. border-radius: 8rpx;
  475. }
  476. .quantity-section {
  477. display: flex;
  478. align-items: center;
  479. gap: 20rpx;
  480. }
  481. .amount-box {
  482. display: flex;
  483. align-items: baseline;
  484. min-width: 140rpx;
  485. padding: 10rpx 20rpx;
  486. background-color: #f8f8f8;
  487. border-radius: 8rpx;
  488. justify-content: flex-end;
  489. }
  490. .amount-symbol {
  491. font-size: 24rpx;
  492. color: #f56c6c;
  493. margin-right: 4rpx;
  494. }
  495. .amount-number {
  496. font-size: 28rpx;
  497. color: #f56c6c;
  498. font-weight: 500;
  499. }
  500. .total-section {
  501. background-color: #fff;
  502. border-radius: 16rpx;
  503. padding: 30rpx;
  504. margin-top: 20rpx;
  505. display: flex;
  506. justify-content: space-between;
  507. align-items: center;
  508. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  509. }
  510. .total-amount-box {
  511. display: flex;
  512. align-items: baseline;
  513. }
  514. .total-symbol {
  515. font-size: 28rpx;
  516. color: #f56c6c;
  517. margin-right: 6rpx;
  518. }
  519. .total-number {
  520. font-size: 36rpx;
  521. color: #f56c6c;
  522. font-weight: bold;
  523. }
  524. .total-label {
  525. font-size: 28rpx;
  526. color: #333;
  527. font-weight: 500;
  528. }
  529. .submit-section {
  530. position: fixed;
  531. bottom: 30rpx;
  532. left: 0;
  533. right: 0;
  534. padding: 0 30rpx;
  535. }
  536. .submit-btn {
  537. width: 100%;
  538. height: 80rpx;
  539. background: linear-gradient(90deg, #2979ff, #4facfe);
  540. color: white;
  541. font-size: 32rpx;
  542. border-radius: 40rpx;
  543. display: flex;
  544. align-items: center;
  545. justify-content: center;
  546. box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.3);
  547. &[disabled] {
  548. background: #c8c9cc;
  549. box-shadow: none;
  550. }
  551. }
  552. /* 调整输入框样式 */
  553. /deep/ .u-input__content__field-wrapper__field {
  554. font-size: 28rpx !important;
  555. color: #333 !important;
  556. }
  557. /* 搜索框区域样式 */
  558. .search-box {
  559. padding: 20rpx;
  560. background: #fff;
  561. border-bottom: 1rpx solid #f0f0f0;
  562. }
  563. /* 空状态提示 */
  564. .empty-tip {
  565. padding-top: 100rpx;
  566. }
  567. /* 顶部操作栏(渐变背景) */
  568. .picker-header {
  569. display: flex;
  570. justify-content: space-between;
  571. align-items: center;
  572. padding: 24rpx 32rpx;
  573. background: linear-gradient(135deg, #2979ff 0%, #4facfe 100%);
  574. box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.2);
  575. .header-title {
  576. font-size: 34rpx;
  577. font-weight: 500;
  578. color: #fff;
  579. letter-spacing: 1rpx;
  580. }
  581. .header-btn {
  582. font-size: 30rpx;
  583. color: rgba(255,255,255,0.9);
  584. padding: 8rpx 16rpx;
  585. border-radius: 40rpx;
  586. &.confirm {
  587. background: rgba(255,255,255,0.2);
  588. }
  589. }
  590. }
  591. /* 客户列表(卡片式设计) */
  592. .customer-list {
  593. background-color: #f8f8f8;
  594. padding: 20rpx;
  595. }
  596. .customer-card {
  597. display: flex;
  598. justify-content: space-between;
  599. align-items: center;
  600. padding: 28rpx 32rpx;
  601. margin: 0 20rpx 20rpx;
  602. background: #fff;
  603. border-radius: 16rpx;
  604. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  605. transition: all 0.3s ease;
  606. &:active {
  607. transform: scale(0.98);
  608. }
  609. &.active {
  610. border: 1rpx solid #2979ff;
  611. box-shadow: 0 4rpx 16rpx rgba(41, 121, 255, 0.3);
  612. }
  613. .customer-name {
  614. font-size: 32rpx;
  615. color: #333;
  616. flex: 1;
  617. }
  618. .check-mark {
  619. width: 44rpx;
  620. height: 44rpx;
  621. display: flex;
  622. align-items: center;
  623. justify-content: center;
  624. background: rgba(41, 121, 255, 0.1);
  625. border-radius: 50%;
  626. }
  627. }
  628. .card-content {
  629. display: flex;
  630. justify-content: space-between;
  631. align-items: center;
  632. padding: 28rpx 32rpx;
  633. .customer-name {
  634. font-size: 32rpx;
  635. color: #333;
  636. font-weight: 500;
  637. letter-spacing: 0.5rpx;
  638. }
  639. .check-mark {
  640. width: 44rpx;
  641. height: 44rpx;
  642. display: flex;
  643. align-items: center;
  644. justify-content: center;
  645. background: rgba(41, 121, 255, 0.1);
  646. border-radius: 50%;
  647. }
  648. }
  649. .card-divider {
  650. height: 1rpx;
  651. background: linear-gradient(90deg, transparent, rgba(0,0,0,0.08), transparent);
  652. margin: 0 32rpx;
  653. }
  654. </style>