details.vue 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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">{{ itemAmount(item) }}</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. itemAmount(row) {
  197. let amount = (row.productPrice * row.productQuantity).toFixed(2)
  198. row.productAmount = amount
  199. return amount
  200. },
  201. async fetchData(reset = false) {
  202. if (this.loading) return;
  203. this.loading = true;
  204. try {
  205. const params = {
  206. current: reset ? 1 : this.currentPage,
  207. size: 10,
  208. cname: this.searchKeyword,
  209. corpType: 'KH'
  210. };
  211. getCustomerPageList(params).then(res => {
  212. console.info('获取数据成功:', res)
  213. if (reset) {
  214. this.dataList = res.data.records;
  215. this.currentPage = 1;
  216. } else {
  217. this.dataList = [...this.dataList, ...res.data.records];
  218. }
  219. this.isLastPage = this.currentPage * 10 >= res.data.total;
  220. })
  221. } catch (error) {
  222. console.error('获取数据失败:', error);
  223. } finally {
  224. this.loading = false;
  225. }
  226. },
  227. // 搜索处理(带防抖)
  228. handleSearch() {
  229. clearTimeout(this.timer);
  230. this.timer = setTimeout(() => {
  231. this.fetchData(true);
  232. }, 500);
  233. },
  234. // 加载更多
  235. loadMore() {
  236. if (!this.isLastPage && !this.loading) {
  237. this.currentPage++;
  238. this.fetchData();
  239. }
  240. },
  241. calcListHeight() {
  242. uni.getSystemInfo({
  243. success: (res) => {
  244. // 顶部操作栏88 + 搜索框60 + 底部安全区30
  245. this.listHeight = res.windowHeight - 88 - 60 - 30;
  246. }
  247. });
  248. },
  249. // 重置搜索
  250. resetSearch() {
  251. this.searchKeyword = '';
  252. },
  253. openPicker() {
  254. this.showCustomerPicker = true;
  255. this.calcListHeight();
  256. this.fetchData(true)
  257. },
  258. confirmSelection() {
  259. if (this.selectedIndex >= 0) {
  260. const selected = this.dataList[this.selectedIndex];
  261. console.info('selected----', selected)
  262. this.formData.customerId = selected.id
  263. this.formData.customerName = selected.cname
  264. this.$emit('selected', selected);
  265. }
  266. this.closePicker();
  267. },
  268. closePicker() {
  269. this.showCustomerPicker = false;
  270. },
  271. async afterRead(event) {
  272. // 当设置 mutiple 为 true 时, file 为数组格式,否则为对象格式
  273. let lists = [].concat(event.file)
  274. let fileListLen = this[`fileList${event.name}`].length
  275. lists.map((item) => {
  276. this[`fileList${event.name}`].push({
  277. ...item,
  278. })
  279. })
  280. for (let i = 0; i < lists.length; i++) {
  281. const result = await this.uploadFilePromise(lists[i].url)
  282. let item = this[`fileList${event.name}`][fileListLen]
  283. this[`fileList${event.name}`].splice(fileListLen, 1, Object.assign(item, {
  284. sort: this.fileList.length,
  285. fileName: JSON.parse(result).data.originalName,
  286. url: JSON.parse(result).data.link
  287. }))
  288. fileListLen++
  289. }
  290. },
  291. deletePic(event) {
  292. this.fileList.splice(event.index, 1)
  293. },
  294. orderDetail(){
  295. if (!this.formData.id) {
  296. return
  297. }
  298. getDetail(this.formData.id).then(res => {
  299. this.formData = res.data
  300. this.fileList = JSON.parse(this.formData.imgs)
  301. for (let itemNum in res.data.greenRecyclingItemList) {
  302. let nowItem = res.data.greenRecyclingItemList[itemNum]
  303. console.info(nowItem)
  304. let nowGoods = this.goodsList.findIndex(item => item.productName === nowItem.productName)
  305. console.info(nowGoods)
  306. if (nowGoods !== -1) {
  307. this.goodsList[nowGoods].productQuantity = nowItem.productQuantity
  308. this.goodsList[nowGoods].productPrice = nowItem.productPrice
  309. continue
  310. }
  311. this.goodsList.push(nowItem)
  312. }
  313. })
  314. },
  315. clickSubmit() {
  316. if (this.totalAmount <= 0) return;
  317. this.formData.quantity = this.goodsList.reduce((sum, item) => sum + item.productQuantity, 0);
  318. this.formData.amount = this.totalAmount
  319. this.formData.greenRecyclingItemList = this.goodsList.filter(item => item.productQuantity > 0)
  320. this.formData.imgs = JSON.stringify(this.fileList)
  321. if (this.formData.id) {
  322. this.handleUpdate()
  323. return;
  324. }
  325. this.handleSubmit()
  326. },
  327. handleSubmit() {
  328. uni.showLoading({title: '提交中...'});
  329. submitRecycling(this.formData).then(res => {
  330. console.info(res)
  331. this.formData.id = res.data
  332. uni.showToast({title: '提交成功'});
  333. this.backPage()
  334. }).finally(() => {
  335. uni.hideLoading();
  336. })
  337. },
  338. backPage(){
  339. setTimeout(() => {
  340. uni.navigateBack({
  341. delta: 1
  342. });
  343. }, 500)
  344. },
  345. handleUpdate() {
  346. uni.showLoading({title: '提交中...'});
  347. this.formData.greenRecyclingItemList = this.goodsList.filter(item => item.productQuantity > 0)
  348. updateRecycling(this.formData).then(res => {
  349. console.info(res)
  350. // this.formData.id = res.data
  351. uni.showToast({title: '修改成功'});
  352. this.backPage()
  353. }).finally(() => {
  354. uni.hideLoading();
  355. })
  356. },
  357. uploadFilePromise(url) {
  358. return new Promise((resolve, reject) => {
  359. let a = uni.uploadFile({
  360. url: http.config.baseURL +
  361. '/blade-resource/oss/endpoint/put-file', // 仅为示例,非真实的接口地址
  362. filePath: url,
  363. name: 'file',
  364. formData: {
  365. user: 'test'
  366. },
  367. header: {
  368. // 客户端认证参数
  369. 'Authorization': 'Basic ' + Base64.encode(clientId + ':' +
  370. clientSecret),
  371. 'Blade-Auth': 'bearer ' + uni.getStorageSync('accessToken')
  372. },
  373. success: (res) => {
  374. setTimeout(() => {
  375. resolve(res.data)
  376. }, 1000)
  377. }
  378. });
  379. })
  380. },
  381. getGoodsList(){
  382. greenRecyclingGoods().then(res => {
  383. for(let num in res.data){
  384. this.goodsList.push( {
  385. productName: res.data[num].dictValue,
  386. productPrice: res.data[num].dictKey,
  387. productQuantity: 0,
  388. productAmount: 0
  389. })
  390. }
  391. this.orderDetail()
  392. })
  393. }
  394. }
  395. }
  396. </script>
  397. <style lang="scss" scoped>
  398. .container {
  399. padding: 20rpx;
  400. background-color: #f8f8f8;
  401. /* 按钮高度 + 边距 */
  402. padding-bottom: 120rpx;
  403. }
  404. .goods-list {
  405. height: 30vh;
  406. margin-bottom: 20rpx;
  407. background-color: #fff;
  408. border-radius: 16rpx;
  409. padding: 20rpx;
  410. }
  411. .goods-list::-webkit-scrollbar {
  412. display: none;
  413. width: 0;
  414. height: 0;
  415. }
  416. .goods-item {
  417. display: flex;
  418. justify-content: space-between;
  419. align-items: center;
  420. padding: 20rpx 0;
  421. border-bottom: 1rpx solid #eee;
  422. }
  423. .goods-info {
  424. flex: 1;
  425. display: flex;
  426. flex-direction: column;
  427. }
  428. .goods-name {
  429. font-size: 28rpx;
  430. color: #333;
  431. }
  432. .goods-price {
  433. font-size: 32rpx;
  434. color: #f56c6c;
  435. margin-top: 10rpx;
  436. }
  437. .quantity-box {
  438. width: 200rpx;
  439. }
  440. .form-section {
  441. background-color: #fff;
  442. border-radius: 16rpx;
  443. padding: 30rpx;
  444. margin-top: 20rpx;
  445. margin-bottom: 20rpx;
  446. }
  447. .section-title {
  448. font-size: 28rpx;
  449. color: #333;
  450. font-weight: 500;
  451. margin-bottom: 20rpx;
  452. position: relative;
  453. padding-left: 16rpx;
  454. }
  455. .section-title::before {
  456. content: "";
  457. position: absolute;
  458. left: 0;
  459. top: 50%;
  460. transform: translateY(-50%);
  461. width: 4rpx;
  462. height: 24rpx;
  463. background-color: #2979ff;
  464. border-radius: 2rpx;
  465. }
  466. .remark-textarea {
  467. background-color: #f8f8f8;
  468. border-radius: 12rpx;
  469. padding: 20rpx;
  470. font-size: 28rpx;
  471. }
  472. .placeholder-style {
  473. color: #b2b2b2;
  474. font-size: 26rpx;
  475. }
  476. .upload-area {
  477. margin-top: 20rpx;
  478. }
  479. .upload-tip {
  480. color: #999;
  481. font-size: 26rpx;
  482. text-align: center;
  483. padding: 20rpx 0;
  484. }
  485. /* 调整计数器样式 */
  486. /deep/ .u-textarea__count {
  487. color: #999;
  488. font-size: 24rpx;
  489. }
  490. /* 美化已上传图片的样式 */
  491. /deep/ .u-upload__wrap__preview__image {
  492. border-radius: 8rpx;
  493. }
  494. /deep/ .u-upload__wrap__preview__mask {
  495. background-color: rgba(0, 0, 0, 0.3);
  496. border-radius: 8rpx;
  497. }
  498. .quantity-section {
  499. display: flex;
  500. align-items: center;
  501. gap: 20rpx;
  502. }
  503. .amount-box {
  504. display: flex;
  505. align-items: baseline;
  506. min-width: 140rpx;
  507. padding: 10rpx 20rpx;
  508. background-color: #f8f8f8;
  509. border-radius: 8rpx;
  510. justify-content: flex-end;
  511. }
  512. .amount-symbol {
  513. font-size: 24rpx;
  514. color: #f56c6c;
  515. margin-right: 4rpx;
  516. }
  517. .amount-number {
  518. font-size: 28rpx;
  519. color: #f56c6c;
  520. font-weight: 500;
  521. }
  522. .total-section {
  523. background-color: #fff;
  524. border-radius: 16rpx;
  525. padding: 30rpx;
  526. margin-top: 20rpx;
  527. display: flex;
  528. justify-content: space-between;
  529. align-items: center;
  530. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  531. }
  532. .total-amount-box {
  533. display: flex;
  534. align-items: baseline;
  535. }
  536. .total-symbol {
  537. font-size: 28rpx;
  538. color: #f56c6c;
  539. margin-right: 6rpx;
  540. }
  541. .total-number {
  542. font-size: 36rpx;
  543. color: #f56c6c;
  544. font-weight: bold;
  545. }
  546. .total-label {
  547. font-size: 28rpx;
  548. color: #333;
  549. font-weight: 500;
  550. }
  551. .submit-section {
  552. position: fixed;
  553. bottom: 30rpx;
  554. left: 0;
  555. right: 0;
  556. padding: 0 30rpx;
  557. }
  558. .submit-btn {
  559. width: 100%;
  560. height: 80rpx;
  561. background: linear-gradient(90deg, #2979ff, #4facfe);
  562. color: white;
  563. font-size: 32rpx;
  564. border-radius: 40rpx;
  565. display: flex;
  566. align-items: center;
  567. justify-content: center;
  568. box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.3);
  569. &[disabled] {
  570. background: #c8c9cc;
  571. box-shadow: none;
  572. }
  573. }
  574. /* 调整输入框样式 */
  575. /deep/ .u-input__content__field-wrapper__field {
  576. font-size: 28rpx !important;
  577. color: #333 !important;
  578. }
  579. /* 搜索框区域样式 */
  580. .search-box {
  581. padding: 20rpx;
  582. background: #fff;
  583. border-bottom: 1rpx solid #f0f0f0;
  584. }
  585. /* 空状态提示 */
  586. .empty-tip {
  587. padding-top: 100rpx;
  588. }
  589. /* 顶部操作栏(渐变背景) */
  590. .picker-header {
  591. display: flex;
  592. justify-content: space-between;
  593. align-items: center;
  594. padding: 24rpx 32rpx;
  595. background: linear-gradient(135deg, #2979ff 0%, #4facfe 100%);
  596. box-shadow: 0 4rpx 12rpx rgba(41, 121, 255, 0.2);
  597. .header-title {
  598. font-size: 34rpx;
  599. font-weight: 500;
  600. color: #fff;
  601. letter-spacing: 1rpx;
  602. }
  603. .header-btn {
  604. font-size: 30rpx;
  605. color: rgba(255,255,255,0.9);
  606. padding: 8rpx 16rpx;
  607. border-radius: 40rpx;
  608. &.confirm {
  609. background: rgba(255,255,255,0.2);
  610. }
  611. }
  612. }
  613. /* 客户列表(卡片式设计) */
  614. .customer-list {
  615. background-color: #f8f8f8;
  616. padding: 20rpx;
  617. }
  618. .customer-card {
  619. display: flex;
  620. justify-content: space-between;
  621. align-items: center;
  622. padding: 28rpx 32rpx;
  623. margin: 0 20rpx 20rpx;
  624. background: #fff;
  625. border-radius: 16rpx;
  626. box-shadow: 0 4rpx 12rpx rgba(0, 0, 0, 0.05);
  627. transition: all 0.3s ease;
  628. &:active {
  629. transform: scale(0.98);
  630. }
  631. &.active {
  632. border: 1rpx solid #2979ff;
  633. box-shadow: 0 4rpx 16rpx rgba(41, 121, 255, 0.3);
  634. }
  635. .customer-name {
  636. font-size: 32rpx;
  637. color: #333;
  638. flex: 1;
  639. }
  640. .check-mark {
  641. width: 44rpx;
  642. height: 44rpx;
  643. display: flex;
  644. align-items: center;
  645. justify-content: center;
  646. background: rgba(41, 121, 255, 0.1);
  647. border-radius: 50%;
  648. }
  649. }
  650. .card-content {
  651. display: flex;
  652. justify-content: space-between;
  653. align-items: center;
  654. padding: 28rpx 32rpx;
  655. .customer-name {
  656. font-size: 32rpx;
  657. color: #333;
  658. font-weight: 500;
  659. letter-spacing: 0.5rpx;
  660. }
  661. .check-mark {
  662. width: 44rpx;
  663. height: 44rpx;
  664. display: flex;
  665. align-items: center;
  666. justify-content: center;
  667. background: rgba(41, 121, 255, 0.1);
  668. border-radius: 50%;
  669. }
  670. }
  671. .card-divider {
  672. height: 1rpx;
  673. background: linear-gradient(90deg, transparent, rgba(0,0,0,0.08), transparent);
  674. margin: 0 32rpx;
  675. }
  676. </style>