展品维保小程序前端代码接口
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.

766 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. if (formData.isExpend === '0'){
  421. delete formData.expenseList
  422. }
  423. this.submiting = true
  424. try{
  425. const subRes = await this.$api.exhibit.addMaintenance(formData)
  426. if(subRes.code == 200){
  427. uni.showToast({ title: subRes.message, icon: 'success' })
  428. // 返回上一页
  429. setTimeout(() => {
  430. uni.navigateBack()
  431. }, 1000)
  432. }else{
  433. uni.showToast({ title: subRes.message, icon: 'none' })
  434. }
  435. }catch(err){
  436. // uni.showToast({ title: err.message, icon: 'none' })
  437. this.submiting = false
  438. }
  439. }
  440. },
  441. onLoad(options) {
  442. this.showpieceId = options.id
  443. }
  444. }
  445. </script>
  446. <style lang="scss" scoped>
  447. .maintenance-submit {
  448. min-height: 100vh;
  449. background-color: #f5f5f5;
  450. padding-bottom: 200rpx;
  451. }
  452. .maintenance-info {
  453. margin: 18rpx;
  454. background: #ffffff;
  455. border-radius: 15rpx;
  456. box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  457. padding: 40rpx;
  458. .info-header {
  459. display: flex;
  460. align-items: center;
  461. margin-bottom: 40rpx;
  462. .red-line {
  463. width: 9rpx;
  464. height: 33rpx;
  465. background-color: $primary-color;
  466. margin-right: 7rpx;
  467. border-radius: 5rpx;
  468. }
  469. .info-title {
  470. font-size: 30rpx;
  471. font-weight: bold;
  472. color: $primary-text-color;
  473. }
  474. }
  475. .form-item-header {
  476. border-bottom: none;
  477. margin-top: 20rpx;
  478. }
  479. .form-item {
  480. display: flex;
  481. align-items: center;
  482. justify-content: space-between;
  483. padding: 24rpx 0;
  484. border-bottom: 2rpx solid #f0f0f0;
  485. &:last-child {
  486. border-bottom: none;
  487. }
  488. .label {
  489. font-size: 30rpx;
  490. color: $primary-text-color;
  491. flex-shrink: 0;
  492. &.active {
  493. font-weight: bold;
  494. }
  495. }
  496. .value {
  497. font-size: 30rpx;
  498. color: $secondary-text-color;
  499. &.placeholder {
  500. color: $secondary-text-color;
  501. }
  502. }
  503. .select-area {
  504. display: flex;
  505. align-items: center;
  506. gap: 16rpx;
  507. }
  508. .input-area {
  509. flex: 1;
  510. // background-color: #f5f5f5;
  511. border-radius: 8rpx;
  512. padding: 16rpx 24rpx;
  513. margin-left: 24rpx;
  514. .input-field {
  515. width: 100%;
  516. font-size: 30rpx;
  517. color: $primary-text-color;
  518. background: transparent;
  519. border: none;
  520. outline: none;
  521. text-align: right;
  522. &::placeholder {
  523. color: $secondary-text-color;
  524. }
  525. }
  526. }
  527. .radio-options {
  528. display: flex;
  529. gap: 60rpx;
  530. .radio-item {
  531. display: flex;
  532. align-items: center;
  533. gap: 16rpx;
  534. .radio-dot {
  535. width: 32rpx;
  536. height: 32rpx;
  537. border: 4rpx solid #ddd;
  538. border-radius: 50%;
  539. position: relative;
  540. &.active {
  541. border-color: $primary-color;
  542. &::after {
  543. content: '';
  544. position: absolute;
  545. top: 50%;
  546. left: 50%;
  547. transform: translate(-50%, -50%);
  548. width: 16rpx;
  549. height: 16rpx;
  550. background-color: $primary-color;
  551. border-radius: 50%;
  552. }
  553. }
  554. }
  555. text {
  556. font-size: 30rpx;
  557. color: $secondary-text-color;
  558. &.active {
  559. color: $primary-color;
  560. }
  561. }
  562. }
  563. }
  564. }
  565. .textarea-container {
  566. border-radius: 8rpx;
  567. }
  568. .image-upload {
  569. display: flex;
  570. flex-wrap: wrap;
  571. gap: 24rpx;
  572. margin: 16rpx 0;
  573. .upload-btn {
  574. width: 160rpx;
  575. height: 160rpx;
  576. border: 2rpx dashed $primary-color;
  577. display: flex;
  578. align-items: center;
  579. justify-content: center;
  580. background-color: #fff;
  581. }
  582. .image-item {
  583. position: relative;
  584. width: 160rpx;
  585. height: 160rpx;
  586. image {
  587. width: 100%;
  588. height: 100%;
  589. border-radius: 8rpx;
  590. }
  591. .delete-btn {
  592. position: absolute;
  593. top: -12rpx;
  594. right: -12rpx;
  595. width: 40rpx;
  596. height: 40rpx;
  597. background-color: #ff4757;
  598. border-radius: 50%;
  599. display: flex;
  600. align-items: center;
  601. justify-content: center;
  602. }
  603. }
  604. }
  605. // 费用表格样式
  606. .cost-table {
  607. margin-top: 24rpx;
  608. border: 2rpx solid #f0f0f0;
  609. border-radius: 8rpx;
  610. overflow: hidden;
  611. .table-header {
  612. display: flex;
  613. background-color: #f5f5f5;
  614. padding: 16rpx 0;
  615. .header-cell {
  616. flex: 1;
  617. text-align: center;
  618. font-size: 28rpx;
  619. font-weight: bold;
  620. color: $primary-text-color;
  621. &:first-child {
  622. flex: 2;
  623. }
  624. &:last-child {
  625. width: 120rpx;
  626. flex: none;
  627. }
  628. }
  629. }
  630. .table-row {
  631. display: flex;
  632. border-top: 2rpx solid #f0f0f0;
  633. .cell-input {
  634. flex: 1;
  635. padding: 8rpx;
  636. border-right: 2rpx solid #f0f0f0;
  637. &:first-child {
  638. flex: 2;
  639. }
  640. &:last-child {
  641. border-right: none;
  642. }
  643. }
  644. .cell-action {
  645. width: 120rpx;
  646. display: flex;
  647. align-items: center;
  648. justify-content: center;
  649. gap: 8rpx;
  650. padding: 8rpx;
  651. .action-btn {
  652. width: 36rpx;
  653. height: 36rpx;
  654. padding: 4rpx;
  655. border-radius: 50%;
  656. display: flex;
  657. align-items: center;
  658. justify-content: center;
  659. &.add-btn {
  660. background-color: #1a9c10;
  661. }
  662. &.delete-btn {
  663. background-color: $primary-color;
  664. }
  665. }
  666. }
  667. }
  668. }
  669. }
  670. .submit-container {
  671. position: fixed;
  672. bottom: 0;
  673. left: 0;
  674. right: 0;
  675. padding: 32rpx;
  676. background-color: #fff;
  677. border-top: 2rpx solid #f0f0f0;
  678. }
  679. </style>