details.vue 17 KB

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