addWaybill.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <template>
  2. <!-- 添加运单 -->
  3. <view>
  4. <u-navbar title="添加运单" autoBack placeholder></u-navbar>
  5. <view class="title_waybill">寄件人:</view>
  6. <x-form ref="sender" :list="list" :model="senderModel" :rules="rules"></x-form>
  7. <view class="title_waybill">收件人:</view>
  8. <x-form ref="recipients" :list="list" :model="recipientsModel" :rules="rules"></x-form>
  9. <view class="title_waybill">物品信息:</view>
  10. <x-form ref="goods" :list="goodsList" :model="goodsModel" :rules="goodsRules"></x-form>
  11. <view style="width: 100%;height: 150rpx;"></view>
  12. <view class="btn_print" @click="printWaybill">
  13. <u-button type="primary" text="添加运单"></u-button>
  14. </view>
  15. </view>
  16. </template>
  17. <script>
  18. import {
  19. formRules,
  20. pickupRulesil
  21. } from "./waybill.js";
  22. export default {
  23. name: 'addWaybill',
  24. data() {
  25. return {
  26. senderModel: {
  27. name: '',
  28. phone: '',
  29. address: '',
  30. },
  31. recipientsModel: {
  32. name: '',
  33. phone: '',
  34. address: '',
  35. },
  36. goodsModel: {
  37. temperatureInterval: '',
  38. deliveryCondition: '',
  39. cargoType: '',
  40. remark: '',
  41. customerName: '',
  42. },
  43. rules: {
  44. name: {
  45. required: true,
  46. message: '请输入姓名',
  47. trigger: ['blur', 'change']
  48. },
  49. phone: {
  50. required: true,
  51. message: '请输入电话',
  52. trigger: ['blur', 'change']
  53. },
  54. address: {
  55. required: true,
  56. message: '请输入地址',
  57. trigger: ['blur', 'change']
  58. },
  59. },
  60. goodsRules: {
  61. temperatureInterval: {
  62. required: true,
  63. message: '请选择温度需求',
  64. trigger: ['blur', 'change']
  65. },
  66. deliveryCondition: {
  67. required: true,
  68. message: '请选择配送要求',
  69. trigger: ['blur', 'change']
  70. },
  71. cargoType: {
  72. required: true,
  73. message: '请选择货物类型',
  74. trigger: ['blur', 'change']
  75. },
  76. },
  77. list: pickupRulesil(),
  78. goodsList: formRules(),
  79. userInfo: {},
  80. }
  81. },
  82. mounted() {
  83. var userInfo = this.$cache.getCache('userInfo')
  84. this.userInfo = userInfo
  85. },
  86. methods: {
  87. // 打印运单
  88. async printWaybill() {
  89. let flag = await this.$refs['sender'].validateForm();
  90. let flag1 = await this.$refs['recipients'].validateForm();
  91. let flag2 = await this.$refs['goods'].validateForm();
  92. if (flag && flag1 && flag2) {
  93. let params = {
  94. senderAddressName: this.senderModel.name,
  95. senderAddressPhone: this.senderModel.phone,
  96. senderAddressDetails: this.senderModel.address,
  97. consigneeAddressName: this.recipientsModel.name,
  98. consigneeAddressPhone: this.recipientsModel.phone,
  99. consigneeAddressDetails: this.recipientsModel.address,
  100. ...this.goodsModel,
  101. }
  102. uni.showLoading();
  103. if (this.userInfo.userType == 'sys') {
  104. this.$api.post('/api/waybill/applet', params).then(res => {
  105. if (res.code == 200) {
  106. uni.redirectTo({
  107. url: '/pages/order/index'
  108. });
  109. } else {
  110. uni.$u.toast('添加失败')
  111. }
  112. uni.hideLoading();
  113. }).catch(() => {
  114. uni.hideLoading();
  115. })
  116. } else {
  117. this.$api.post('/api/waybill/customer', params).then(res => {
  118. if (res.code == 200) {
  119. uni.redirectTo({
  120. url: '/pages/order/index'
  121. });
  122. } else {
  123. uni.$u.toast('添加失败')
  124. }
  125. uni.hideLoading();
  126. }).catch(() => {
  127. uni.hideLoading();
  128. })
  129. }
  130. } else {
  131. uni.$u.toast('请先完善表单')
  132. }
  133. }
  134. }
  135. }
  136. </script>
  137. <style lang="scss">
  138. page {
  139. background-color: #fff !important;
  140. }
  141. .title_waybill {
  142. position: relative;
  143. margin: 20rpx;
  144. border-bottom: 1rpx;
  145. padding-bottom: 20rpx;
  146. }
  147. .title_waybill:before {
  148. content: " ";
  149. position: absolute;
  150. left: 0;
  151. bottom: 0;
  152. width: 100%;
  153. height: 1px;
  154. border-top: 1px solid #e7e6e4;
  155. -webkit-transform-origin: 0 0;
  156. transform-origin: 0 0;
  157. -webkit-transform: scaleY(0.5);
  158. transform: scaleY(0.5);
  159. }
  160. </style>