展品维保小程序前端代码接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

762 lines
20 KiB

5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
5 days ago
  1. <template>
  2. <view class="maintenance-submit">
  3. <!-- 保养基本信息 -->
  4. <view class="maintenance-info">
  5. <view class="info-header">
  6. <view class="red-line"></view>
  7. <text class="info-title">保养项目</text>
  8. </view>
  9. <!-- 保养人 -->
  10. <view class="form-item">
  11. <text class="label">保养人</text>
  12. <view class="input-area" >
  13. <input
  14. v-model="maintenanceName"
  15. placeholder="请填写"
  16. class="input-field"
  17. ref="maintainerInput"
  18. />
  19. </view>
  20. </view>
  21. <!-- 保养日期 -->
  22. <view class="form-item" @click="showDatePicker">
  23. <text class="label">保养日期</text>
  24. <view class="select-area">
  25. <text class="value" :class="{ placeholder: !maintenanceDate }">{{ maintenanceDate || '请选择' }}</text>
  26. <uv-icon name="arrow-down" size="18" color="#000"></uv-icon>
  27. </view>
  28. </view>
  29. <!-- 保养前状态 -->
  30. <view class="form-item">
  31. <text class="label">保养前状态</text>
  32. </view>
  33. <view class="textarea-container">
  34. <uv-textarea
  35. v-model="stateFrontText"
  36. placeholder="请填写保养前的设备内容"
  37. :maxlength="200"
  38. :show-confirm-bar="false"
  39. height="60"
  40. border="none"
  41. :custom-style="{ backgroundColor: '#f5f5f5' }"
  42. ></uv-textarea>
  43. </view>
  44. <!-- 保养前图片 -->
  45. <view class="image-upload">
  46. <view v-for="(img, index) in stateFrontImage" :key="index" class="image-item">
  47. <image :src="img" mode="aspectFill" @click="previewImage(img, stateFrontImage)"></image>
  48. <view class="delete-btn" @click="deleteBeforeImage(index)">
  49. <uv-icon name="close" size="12" color="#fff"></uv-icon>
  50. </view>
  51. </view>
  52. <view class="upload-btn" @click="uploadBeforeImage">
  53. <uv-icon name="camera" size="34" color="#C70019"></uv-icon>
  54. </view>
  55. </view>
  56. <!-- 保养后状态 -->
  57. <view class="form-item">
  58. <text class="label">保养后状态</text>
  59. </view>
  60. <view class="textarea-container">
  61. <uv-textarea
  62. v-model="stateBackText"
  63. placeholder="请填写保养后的设备内容"
  64. :maxlength="200"
  65. :show-confirm-bar="false"
  66. height="60"
  67. border="none"
  68. :custom-style="{ backgroundColor: '#f5f5f5' }"
  69. ></uv-textarea>
  70. </view>
  71. <!-- 保养后图片 -->
  72. <view class="image-upload">
  73. <view v-for="(img, index) in stateBackImage" :key="index" class="image-item">
  74. <image :src="img" mode="aspectFill" @click="previewImage(img, stateBackImage)"></image>
  75. <view class="delete-btn" @click="deleteAfterImage(index)">
  76. <uv-icon name="close" size="12" color="#fff"></uv-icon>
  77. </view>
  78. </view>
  79. <view class="upload-btn" @click="uploadAfterImage">
  80. <uv-icon name="camera" size="34" color="#C70019"></uv-icon>
  81. </view>
  82. </view>
  83. <!-- 是否产生费用 -->
  84. <view class="form-item">
  85. <text class="label">是否产生费用</text>
  86. <view class="radio-options">
  87. <view
  88. class="radio-item"
  89. :class="{ active: isExpend === '1' }"
  90. @click="selectCost('1')"
  91. >
  92. <view class="radio-dot" :class="{ active: isExpend === '1' }"></view>
  93. <text :class="{ active: isExpend === '1' }"></text>
  94. </view>
  95. <view
  96. class="radio-item"
  97. :class="{ active: isExpend === '0' }"
  98. @click="selectCost('0')"
  99. >
  100. <view class="radio-dot" :class="{ active: isExpend === '0' }"></view>
  101. <text :class="{ active: isExpend === '0' }"></text>
  102. </view>
  103. </view>
  104. </view>
  105. <!-- 产生费用 -->
  106. <view class="form-item" v-if="isExpend === '1'">
  107. <text class="label">产生费用</text>
  108. <view class="input-area" >
  109. <input
  110. v-model="amount"
  111. placeholder="请输入费用"
  112. disabled
  113. class="input-field"
  114. />
  115. </view>
  116. </view>
  117. <!-- 费用详情表格 -->
  118. <view class="cost-table" v-if="isExpend === '1'">
  119. <view class="table-header">
  120. <text class="header-cell">费用名称</text>
  121. <text class="header-cell">数量</text>
  122. <text class="header-cell">金额</text>
  123. <text class="header-cell"></text>
  124. </view>
  125. <view class="table-row" v-for="(item, index) in costList" :key="index">
  126. <view class="cell-input">
  127. <uv-input
  128. v-model="item.name"
  129. placeholder="费用名称"
  130. border="none"
  131. :custom-style="{ backgroundColor: 'transparent', fontSize: '28rpx' }"
  132. ></uv-input>
  133. </view>
  134. <view class="cell-input">
  135. <uv-input
  136. v-model="item.quantity"
  137. placeholder="数量"
  138. border="none"
  139. :custom-style="{ backgroundColor: 'transparent', fontSize: '28rpx' }"
  140. ></uv-input>
  141. </view>
  142. <view class="cell-input">
  143. <uv-input
  144. v-model="item.amount"
  145. placeholder="金额"
  146. type="digit"
  147. border="none"
  148. :custom-style="{ backgroundColor: 'transparent', fontSize: '28rpx' }"
  149. ></uv-input>
  150. </view>
  151. <view class="cell-action">
  152. <view class="action-btn delete-btn" @click="removeCostItem(index)" v-if="costList.length > 1">
  153. <uv-icon name="close" size="14" color="#fff"></uv-icon>
  154. </view>
  155. <view class="action-btn add-btn" @click="addCostItem" v-if="index === costList.length - 1">
  156. <uv-icon name="plus" size="14" color="#fff"></uv-icon>
  157. </view>
  158. </view>
  159. </view>
  160. </view>
  161. <!-- 附件信息 -->
  162. <view class="form-item form-item-header">
  163. <text class="label active">附件信息</text>
  164. </view>
  165. <!-- 保养备注 -->
  166. <view class="form-item">
  167. <text class="label">保养备注</text>
  168. </view>
  169. <view class="textarea-container">
  170. <uv-textarea
  171. v-model="remarkText"
  172. placeholder="请填写备注"
  173. :maxlength="200"
  174. :show-confirm-bar="false"
  175. height="60"
  176. border="none"
  177. :custom-style="{ backgroundColor: '#f5f5f5' }"
  178. ></uv-textarea>
  179. </view>
  180. <!-- 附件图片 -->
  181. <view class="image-upload">
  182. <view v-for="(img, index) in remarkImage" :key="index" class="image-item">
  183. <image :src="img" mode="aspectFill" @click="previewImage(img, remarkImage)"></image>
  184. <view class="delete-btn" @click="deleteAttachment(index)">
  185. <uv-icon name="close" size="12" color="#fff"></uv-icon>
  186. </view>
  187. </view>
  188. <view class="upload-btn" @click="uploadAttachment">
  189. <uv-icon name="camera" size="34" color="#C70019"></uv-icon>
  190. </view>
  191. </view>
  192. <!-- 下次保养日期 -->
  193. <view class="form-item" @click="showNextDatePicker">
  194. <text class="label">下次保养日期</text>
  195. <view class="select-area">
  196. <text class="value" :class="{ placeholder: !nextMaintenanceDate }">{{ nextMaintenanceDate || '请选择' }}</text>
  197. <uv-icon name="arrow-down" size="18" color="#000"></uv-icon>
  198. </view>
  199. </view>
  200. <!-- 备注 -->
  201. <view class="form-item">
  202. <text class="label">备注</text>
  203. </view>
  204. <view class="textarea-container">
  205. <uv-textarea
  206. v-model="remark"
  207. placeholder="请填写备注"
  208. :maxlength="200"
  209. :show-confirm-bar="false"
  210. height="60"
  211. border="none"
  212. :custom-style="{ backgroundColor: '#f5f5f5' }"
  213. ></uv-textarea>
  214. </view>
  215. </view>
  216. <!-- 提交按钮 -->
  217. <view class="submit-container">
  218. <uv-button
  219. type="primary"
  220. text="立即提交"
  221. :disabled="submiting"
  222. :custom-style="{ backgroundColor: '#C70019', borderRadius: '25px' }"
  223. @click="submitMaintenance"
  224. ></uv-button>
  225. </view>
  226. <!-- 日期选择器 -->
  227. <uv-datetime-picker
  228. confirm-color="#C70019"
  229. ref="datePicker"
  230. mode="date"
  231. v-model="timeValue"
  232. @confirm="confirmDate"
  233. ></uv-datetime-picker>
  234. <uv-datetime-picker
  235. confirm-color="#C70019"
  236. ref="nextDatePicker"
  237. mode="date"
  238. v-model="nextTimeValue"
  239. @confirm="confirmNextDate"
  240. ></uv-datetime-picker>
  241. </view>
  242. </template>
  243. <script>
  244. export default {
  245. data() {
  246. return {
  247. timeValue: Number(new Date()),
  248. nextTimeValue: Number(new Date()),
  249. // 表单数据
  250. maintenanceName: '',
  251. maintenanceDate: '',
  252. stateFrontText: '',
  253. stateFrontImage: [],
  254. stateBackText: '',
  255. stateBackImage: [],
  256. isExpend: '0',
  257. costList: [{ name: '', quantity: '', amount: '' }],
  258. remarkText: '',
  259. remarkImage: [],
  260. nextMaintenanceDate: '',
  261. remark: '',
  262. showpieceId: '',
  263. submiting: false
  264. }
  265. },
  266. computed: {
  267. // 计算总金额
  268. amount() {
  269. return this.costList.reduce((sum, item) => {
  270. return sum + (Number(item.quantity) * parseFloat(item.amount || 0))
  271. }, 0)
  272. }
  273. },
  274. methods: {
  275. // 显示日期选择器
  276. showDatePicker() {
  277. this.$refs.datePicker.open()
  278. },
  279. // 确认日期
  280. confirmDate(e) {
  281. // uv-datetime-picker返回的是时间戳,需要转换为日期格式
  282. this.maintenanceDate = this.$utils.formatTime(e.value)
  283. },
  284. // 显示下次保养日期选择器
  285. showNextDatePicker() {
  286. this.$refs.nextDatePicker.open()
  287. },
  288. // 确认下次保养日期
  289. confirmNextDate(e) {
  290. // uv-datetime-picker返回的是时间戳,需要转换为日期格式
  291. this.nextMaintenanceDate = this.$utils.formatTime(e.value)
  292. },
  293. // 选择是否产生费用
  294. selectCost(value) {
  295. this.isExpend = value
  296. if (value === '0') {
  297. this.costList = [{ name: '', quantity: '', amount: '' }]
  298. } else if (this.costList.length === 0) {
  299. this.costList = [{ name: '', quantity: '', amount: '' }]
  300. }
  301. },
  302. // 添加费用项目
  303. addCostItem() {
  304. this.costList.push({ name: '', quantity: '', amount: '' })
  305. },
  306. // 删除费用项目
  307. removeCostItem(index) {
  308. if (this.costList.length > 1) {
  309. this.costList.splice(index, 1)
  310. } else {
  311. uni.showToast({ title: '至少保留一个费用项目', icon: 'none' })
  312. }
  313. },
  314. // 上传保养前图片
  315. async uploadBeforeImage() {
  316. try {
  317. const result = await this.$utils.chooseAndUpload()
  318. if (result && result.success) {
  319. console.log(result);
  320. this.stateFrontImage.push(result.url)
  321. }
  322. } catch (error) {
  323. console.error('图片上传失败:', error)
  324. uni.showToast({
  325. title: '图片上传失败',
  326. icon: 'error'
  327. })
  328. }
  329. },
  330. // 删除保养前图片
  331. deleteBeforeImage(index) {
  332. this.stateFrontImage.splice(index, 1)
  333. },
  334. // 上传保养后图片
  335. async uploadAfterImage() {
  336. try {
  337. const result = await this.$utils.chooseAndUpload()
  338. if (result && result.success) {
  339. console.log(result);
  340. this.stateBackImage.push(result.url)
  341. }
  342. } catch (error) {
  343. console.error('头像上传失败:', error)
  344. uni.showToast({
  345. title: '头像上传失败',
  346. icon: 'error'
  347. })
  348. }
  349. },
  350. // 删除保养后图片
  351. deleteAfterImage(index) {
  352. this.stateBackImage.splice(index, 1)
  353. },
  354. // 上传附件
  355. async uploadAttachment() {
  356. try {
  357. const result = await this.$utils.chooseAndUpload()
  358. if (result && result.success) {
  359. console.log(result);
  360. this.remarkImage.push(result.url)
  361. }
  362. } catch (error) {
  363. console.error('头像上传失败:', error)
  364. uni.showToast({
  365. title: '头像上传失败',
  366. icon: 'error'
  367. })
  368. }
  369. },
  370. // 删除附件
  371. deleteAttachment(index) {
  372. this.remarkImage.splice(index, 1)
  373. },
  374. // 预览图片
  375. previewImage(url, imageList) {
  376. uni.previewImage({
  377. urls: imageList,
  378. current: url
  379. })
  380. },
  381. // 提交保养
  382. async submitMaintenance() {
  383. // 表单验证
  384. if (!this.maintenanceName.trim()) {
  385. uni.showToast({ title: '请填写保养人', icon: 'none' })
  386. return
  387. }
  388. if (!this.stateFrontText.trim()) {
  389. uni.showToast({ title: '请填写保养前状态', icon: 'none' })
  390. return
  391. }
  392. if (!this.stateBackText.trim()) {
  393. uni.showToast({ title: '请填写保养后状态', icon: 'none' })
  394. return
  395. }
  396. if (this.isExpend === '1' && !this.amount){
  397. uni.showToast({ title: '请填写消费', icon: 'none' })
  398. return
  399. }
  400. // 把costList切换成字符串并用,,;分割
  401. // 提交数据
  402. const formData = {
  403. maintenanceName: this.maintenanceName,
  404. maintenanceDate: this.maintenanceDate,
  405. stateFrontText: this.stateFrontText,
  406. stateFrontImage: this.stateFrontImage?.join(',') || '',
  407. stateBackText: this.stateBackText,
  408. stateBackImage: this.stateBackImage?.join(',') || '',
  409. expenseList: this.costList.map(item => {
  410. return `${item.name},${item.quantity},${item.amount}`
  411. }).join(';'),
  412. isExpend: this.isExpend,
  413. amount: this.amount,
  414. remarkText: this.remarkText,
  415. remarkImage: this.remarkImage?.join(',') || '',
  416. nextMaintenanceDate: this.nextMaintenanceDate,
  417. remark: this.remark,
  418. showpieceId: this.showpieceId
  419. }
  420. this.submiting = true
  421. try{
  422. const subRes = await this.$api.exhibit.addMaintenance(formData)
  423. if(subRes.code == 200){
  424. uni.showToast({ title: subRes.message, icon: 'success' })
  425. // 返回上一页
  426. setTimeout(() => {
  427. uni.navigateBack()
  428. }, 1000)
  429. }else{
  430. uni.showToast({ title: subRes.message, icon: 'none' })
  431. }
  432. }catch(err){
  433. // uni.showToast({ title: err.message, icon: 'none' })
  434. this.submiting = false
  435. }
  436. }
  437. },
  438. onLoad(options) {
  439. this.showpieceId = options.id
  440. }
  441. }
  442. </script>
  443. <style lang="scss" scoped>
  444. .maintenance-submit {
  445. min-height: 100vh;
  446. background-color: #f5f5f5;
  447. padding-bottom: 200rpx;
  448. }
  449. .maintenance-info {
  450. margin: 18rpx;
  451. background: #ffffff;
  452. border-radius: 15rpx;
  453. box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  454. padding: 40rpx;
  455. .info-header {
  456. display: flex;
  457. align-items: center;
  458. margin-bottom: 40rpx;
  459. .red-line {
  460. width: 9rpx;
  461. height: 33rpx;
  462. background-color: $primary-color;
  463. margin-right: 7rpx;
  464. border-radius: 5rpx;
  465. }
  466. .info-title {
  467. font-size: 30rpx;
  468. font-weight: bold;
  469. color: $primary-text-color;
  470. }
  471. }
  472. .form-item-header {
  473. border-bottom: none;
  474. margin-top: 20rpx;
  475. }
  476. .form-item {
  477. display: flex;
  478. align-items: center;
  479. justify-content: space-between;
  480. padding: 24rpx 0;
  481. border-bottom: 2rpx solid #f0f0f0;
  482. &:last-child {
  483. border-bottom: none;
  484. }
  485. .label {
  486. font-size: 30rpx;
  487. color: $primary-text-color;
  488. flex-shrink: 0;
  489. &.active {
  490. font-weight: bold;
  491. }
  492. }
  493. .value {
  494. font-size: 30rpx;
  495. color: $secondary-text-color;
  496. &.placeholder {
  497. color: $secondary-text-color;
  498. }
  499. }
  500. .select-area {
  501. display: flex;
  502. align-items: center;
  503. gap: 16rpx;
  504. }
  505. .input-area {
  506. flex: 1;
  507. // background-color: #f5f5f5;
  508. border-radius: 8rpx;
  509. padding: 16rpx 24rpx;
  510. margin-left: 24rpx;
  511. .input-field {
  512. width: 100%;
  513. font-size: 30rpx;
  514. color: $primary-text-color;
  515. background: transparent;
  516. border: none;
  517. outline: none;
  518. text-align: right;
  519. &::placeholder {
  520. color: $secondary-text-color;
  521. }
  522. }
  523. }
  524. .radio-options {
  525. display: flex;
  526. gap: 60rpx;
  527. .radio-item {
  528. display: flex;
  529. align-items: center;
  530. gap: 16rpx;
  531. .radio-dot {
  532. width: 32rpx;
  533. height: 32rpx;
  534. border: 4rpx solid #ddd;
  535. border-radius: 50%;
  536. position: relative;
  537. &.active {
  538. border-color: $primary-color;
  539. &::after {
  540. content: '';
  541. position: absolute;
  542. top: 50%;
  543. left: 50%;
  544. transform: translate(-50%, -50%);
  545. width: 16rpx;
  546. height: 16rpx;
  547. background-color: $primary-color;
  548. border-radius: 50%;
  549. }
  550. }
  551. }
  552. text {
  553. font-size: 30rpx;
  554. color: $secondary-text-color;
  555. &.active {
  556. color: $primary-color;
  557. }
  558. }
  559. }
  560. }
  561. }
  562. .textarea-container {
  563. border-radius: 8rpx;
  564. }
  565. .image-upload {
  566. display: flex;
  567. flex-wrap: wrap;
  568. gap: 24rpx;
  569. margin: 16rpx 0;
  570. .upload-btn {
  571. width: 160rpx;
  572. height: 160rpx;
  573. border: 2rpx dashed $primary-color;
  574. display: flex;
  575. align-items: center;
  576. justify-content: center;
  577. background-color: #fff;
  578. }
  579. .image-item {
  580. position: relative;
  581. width: 160rpx;
  582. height: 160rpx;
  583. image {
  584. width: 100%;
  585. height: 100%;
  586. border-radius: 8rpx;
  587. }
  588. .delete-btn {
  589. position: absolute;
  590. top: -12rpx;
  591. right: -12rpx;
  592. width: 40rpx;
  593. height: 40rpx;
  594. background-color: #ff4757;
  595. border-radius: 50%;
  596. display: flex;
  597. align-items: center;
  598. justify-content: center;
  599. }
  600. }
  601. }
  602. // 费用表格样式
  603. .cost-table {
  604. margin-top: 24rpx;
  605. border: 2rpx solid #f0f0f0;
  606. border-radius: 8rpx;
  607. overflow: hidden;
  608. .table-header {
  609. display: flex;
  610. background-color: #f5f5f5;
  611. padding: 16rpx 0;
  612. .header-cell {
  613. flex: 1;
  614. text-align: center;
  615. font-size: 28rpx;
  616. font-weight: bold;
  617. color: $primary-text-color;
  618. &:first-child {
  619. flex: 2;
  620. }
  621. &:last-child {
  622. width: 120rpx;
  623. flex: none;
  624. }
  625. }
  626. }
  627. .table-row {
  628. display: flex;
  629. border-top: 2rpx solid #f0f0f0;
  630. .cell-input {
  631. flex: 1;
  632. padding: 8rpx;
  633. border-right: 2rpx solid #f0f0f0;
  634. &:first-child {
  635. flex: 2;
  636. }
  637. &:last-child {
  638. border-right: none;
  639. }
  640. }
  641. .cell-action {
  642. width: 120rpx;
  643. display: flex;
  644. align-items: center;
  645. justify-content: center;
  646. gap: 8rpx;
  647. padding: 8rpx;
  648. .action-btn {
  649. width: 36rpx;
  650. height: 36rpx;
  651. padding: 4rpx;
  652. border-radius: 50%;
  653. display: flex;
  654. align-items: center;
  655. justify-content: center;
  656. &.add-btn {
  657. background-color: #1a9c10;
  658. }
  659. &.delete-btn {
  660. background-color: $primary-color;
  661. }
  662. }
  663. }
  664. }
  665. }
  666. }
  667. .submit-container {
  668. position: fixed;
  669. bottom: 0;
  670. left: 0;
  671. right: 0;
  672. padding: 32rpx;
  673. background-color: #fff;
  674. border-top: 2rpx solid #f0f0f0;
  675. }
  676. </style>