addWaybill.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <template>
  2. <!-- 添加运单 -->
  3. <view>
  4. <u-navbar :title="headline" 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="headline"></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. quantity: '',
  41. remark: '',
  42. customerName: '',
  43. },
  44. rules: {
  45. name: {
  46. required: true,
  47. message: '请输入姓名',
  48. trigger: ['blur', 'change']
  49. },
  50. phone: {
  51. required: true,
  52. message: '请输入电话',
  53. trigger: ['blur', 'change']
  54. },
  55. address: {
  56. required: true,
  57. message: '请输入地址',
  58. trigger: ['blur', 'change']
  59. },
  60. },
  61. goodsRules: {
  62. temperatureInterval: {
  63. required: true,
  64. message: '请选择温度需求',
  65. trigger: ['blur', 'change']
  66. },
  67. deliveryCondition: {
  68. required: true,
  69. message: '请选择配送要求',
  70. trigger: ['blur', 'change']
  71. },
  72. cargoType: {
  73. required: true,
  74. message: '请选择货物类型',
  75. trigger: ['blur', 'change']
  76. },
  77. },
  78. list: pickupRulesil(),
  79. goodsList: formRules(),
  80. userInfo: {},
  81. headline: '添加运单',
  82. type: 1,
  83. }
  84. },
  85. onLoad(value) {
  86. this.headline = value.title
  87. this.type = Number(value.type)
  88. if (this.type == 2) {
  89. var orderList = this.$cache.getCache('orderDetails')
  90. // console.log(orderList, 77)
  91. this.senderModel.name = orderList.senderAddressName
  92. this.senderModel.phone = orderList.senderAddressPhone
  93. this.senderModel.address = orderList.senderAddressDetails
  94. this.recipientsModel.name = orderList.consigneeAddressName
  95. this.recipientsModel.phone = orderList.consigneeAddressPhone
  96. this.recipientsModel.address = orderList.consigneeAddressDetails
  97. this.goodsModel.temperatureInterval = orderList.temperatureInterval
  98. this.goodsModel.deliveryCondition = orderList.deliveryCondition
  99. this.goodsModel.cargoType = orderList.cargoType
  100. this.goodsModel.quantity = orderList.quantity
  101. this.goodsModel.remark = orderList.remark
  102. this.goodsModel.customerName = orderList.customerName
  103. this.goodsModel.id = orderList.id
  104. }
  105. },
  106. mounted() {
  107. var userInfo = this.$cache.getCache('userInfo')
  108. this.userInfo = userInfo
  109. },
  110. methods: {
  111. // tianjia运单
  112. async printWaybill() {
  113. let flag = await this.$refs['sender'].validateForm();
  114. let flag1 = await this.$refs['recipients'].validateForm();
  115. let flag2 = await this.$refs['goods'].validateForm();
  116. if (flag && flag1 && flag2) {
  117. let params = {
  118. senderAddressName: this.senderModel.name,
  119. senderAddressPhone: this.senderModel.phone,
  120. senderAddressDetails: this.senderModel.address,
  121. consigneeAddressName: this.recipientsModel.name,
  122. consigneeAddressPhone: this.recipientsModel.phone,
  123. consigneeAddressDetails: this.recipientsModel.address,
  124. ...this.goodsModel,
  125. }
  126. params.quantity = Number(params.quantity)
  127. uni.showLoading();
  128. if (this.type == 1) {
  129. // 添加订单
  130. if (this.userInfo.userType == 'sys') {
  131. this.$api.post('/api/waybill/applet', params).then(res => {
  132. if (res.code == 200) {
  133. uni.redirectTo({
  134. url: '/pages/order/index'
  135. });
  136. } else {
  137. uni.$u.toast('添加失败')
  138. }
  139. uni.hideLoading();
  140. }).catch(() => {
  141. uni.hideLoading();
  142. })
  143. } else {
  144. delete params.customerName
  145. this.$api.post('/api/waybill/customer', params).then(res => {
  146. if (res.code == 200) {
  147. uni.redirectTo({
  148. url: '/pages/order/index'
  149. });
  150. } else {
  151. uni.$u.toast('添加失败')
  152. }
  153. uni.hideLoading();
  154. }).catch(() => {
  155. uni.hideLoading();
  156. })
  157. }
  158. } else {
  159. // 修改订单
  160. if (this.userInfo.userType != 'sys') {
  161. delete params.customerName
  162. }
  163. this.$api.put('/api/waybill', params).then(res => {
  164. if (res.code == 200) {
  165. // uni.$u.toast(res.msg)
  166. uni.redirectTo({
  167. url: '/pages/order/index'
  168. });
  169. } else {
  170. uni.$u.toast('修改失败')
  171. }
  172. uni.hideLoading();
  173. }).catch(() => {
  174. uni.hideLoading();
  175. })
  176. }
  177. } else {
  178. uni.$u.toast('请先完善表单')
  179. }
  180. }
  181. }
  182. }
  183. </script>
  184. <style lang="scss">
  185. page {
  186. background-color: #fff !important;
  187. }
  188. .title_waybill {
  189. position: relative;
  190. margin: 20rpx;
  191. border-bottom: 1rpx;
  192. padding-bottom: 20rpx;
  193. }
  194. .title_waybill:before {
  195. content: " ";
  196. position: absolute;
  197. left: 0;
  198. bottom: 0;
  199. width: 100%;
  200. height: 1px;
  201. border-top: 1px solid #e7e6e4;
  202. -webkit-transform-origin: 0 0;
  203. transform-origin: 0 0;
  204. -webkit-transform: scaleY(0.5);
  205. transform: scaleY(0.5);
  206. }
  207. </style>