sureCombine.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. <template>
  2. <div class="container">
  3. <div style="padding: 20px 0;">合并签收以下快件:</div>
  4. <van-form @submit="onSubmit">
  5. <van-field name="checkboxGroup">
  6. <template #input>
  7. <van-checkbox-group v-model="checkboxGroup">
  8. <van-checkbox disabled style="margin-bottom: 10px;" :name="item.id" shape="square"
  9. v-for="item in goodsList" :key="item.id"> {{ item.expressNo }} & {{ item.expressType
  10. }} & {{ item.expressQuantity }}件 &{{ item.isPayOnDelivery == '否' ? '非到付' : '到付' }}
  11. </van-checkbox>
  12. </van-checkbox-group>
  13. </template>
  14. </van-field>
  15. <van-field name="uploader" label="上传照片" :rules="[{ required: true, message: '请上传图片' }]">
  16. <template #input>
  17. <van-uploader v-model="uploader" :after-read="afterRead" :before-read="beforeRead" :max-count="1" />
  18. </template>
  19. </van-field>
  20. <van-button style="height: 40px; width: 150px; border-radius: 8px; margin-right: 20px;" type="info"
  21. native-type="submit">确定签收</van-button>
  22. <van-button style="height: 40px; width: 150px; border-radius: 8px;" type="default"
  23. @click="back">返回上一级</van-button>
  24. </van-form>
  25. </div>
  26. </template>
  27. <script>
  28. import { appDelivery, appUploadTheSignature } from '@/api/index'
  29. import axios from 'axios';
  30. export default {
  31. name: 'sureCombine',
  32. props: ['isCombine', 'goodsList'],
  33. data() {
  34. return {
  35. checkbox: false,
  36. checkboxGroup: [],
  37. uploader: [],//图片
  38. };
  39. },
  40. mounted() {
  41. // 在组件挂载后,设置默认选中的值
  42. this.checkboxGroup = this.goodsList.map(item => item.id);
  43. },
  44. methods: {
  45. beforeRead(file) {
  46. // 在这里可以添加对文件的校验逻辑
  47. // 如果返回 true, 则继续读取文件
  48. return true;
  49. },
  50. // 文件读取完成后的钩子
  51. async afterRead(file) {
  52. console.log(file)
  53. const formData = new FormData();
  54. formData.append('file', file.file); // 这里的 'file' 是后端接收文件的字段名
  55. const res = await appUploadTheSignature(formData)
  56. this.getFileUrl = res.data
  57. },
  58. async onSubmit(values) {
  59. let data = []
  60. this.goodsList.forEach((item) => {
  61. if (values.checkboxGroup.find((itemA) => itemA === item.id)) {
  62. data.push(item.expressNo)
  63. }
  64. })
  65. const params = {
  66. signEnclosureImg: this.getFileUrl,//签署图片
  67. deliveryId: data.join(','),//快递单号逗号隔开
  68. deliveryPeopleId: localStorage.getItem('courierId'),// 派件员id
  69. }
  70. const res = await appDelivery({ ...params }, { emulateJSON: true, loading: true, message: '签收中' })
  71. if (res.code == 0) {
  72. this.$toast('签收成功')
  73. this.$router.push('/')
  74. } else {
  75. this.$toast('签收失败')
  76. }
  77. },
  78. back() {
  79. this.$emit('isCombine', true)
  80. },
  81. }
  82. };
  83. </script>
  84. <style lang="less" scoped>
  85. * {
  86. font-size: 16px;
  87. }
  88. .van-field__label {
  89. width: 4rem;
  90. }
  91. .container {
  92. padding: 2px 10px 0 10px;
  93. background-color: #fff;
  94. }
  95. </style>