addWaybill.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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"
  11. @incubatorClick="incubatorClick"></x-form>
  12. <view style="width: 100%;height: 150rpx;"></view>
  13. <view class="btn_print" @click="printWaybill">
  14. <u-button type="primary" :text="headline"></u-button>
  15. </view>
  16. </view>
  17. </template>
  18. <script>
  19. import {
  20. formRules,
  21. pickupRulesil
  22. } from "./waybill.js";
  23. export default {
  24. name: 'addWaybill',
  25. data() {
  26. return {
  27. senderModel: {
  28. name: '',
  29. phone: '',
  30. address: '',
  31. },
  32. recipientsModel: {
  33. name: '',
  34. phone: '',
  35. address: '',
  36. },
  37. goodsModel: {
  38. temperatureInterval: '',
  39. deliveryCondition: '',
  40. coolerBoxId: 0,
  41. coolerBoxIdname: '',
  42. cargoType: '',
  43. quantity: '',
  44. remark: '',
  45. customerName: '',
  46. },
  47. rules: {
  48. name: {
  49. required: true,
  50. message: '请输入姓名',
  51. trigger: ['blur', 'change']
  52. },
  53. phone: [{
  54. required: true,
  55. message: '请输入电话',
  56. trigger: ['blur', 'change']
  57. }, {
  58. validator: (rule, value, callback) => {
  59. return uni.$u.test.mobile(value);
  60. },
  61. message: '电话号码不正确',
  62. trigger: ['change', 'blur'],
  63. }],
  64. address: {
  65. required: true,
  66. message: '请输入地址',
  67. trigger: ['blur', 'change']
  68. },
  69. },
  70. goodsRules: {
  71. temperatureInterval: {
  72. required: true,
  73. message: '请选择温度需求',
  74. trigger: ['blur', 'change']
  75. },
  76. deliveryCondition: {
  77. required: true,
  78. message: '请选择配送要求',
  79. trigger: ['blur', 'change']
  80. },
  81. cargoType: {
  82. required: true,
  83. message: '请选择货物类型',
  84. trigger: ['blur', 'change']
  85. },
  86. coolerBoxId: {
  87. type: 'number',
  88. required: true,
  89. message: '请选择保温箱',
  90. trigger: ['blur', 'change']
  91. },
  92. quantity: {
  93. required: true,
  94. message: '请输入数量',
  95. trigger: ['blur', 'change']
  96. },
  97. },
  98. list: pickupRulesil(),
  99. goodsList: formRules(),
  100. userInfo: {},
  101. headline: '添加运单',
  102. type: 1,
  103. }
  104. },
  105. onLoad(value) {
  106. this.headline = value.title
  107. this.type = Number(value.type)
  108. if (this.type == 2) {
  109. var orderList = this.$cache.getCache('orderDetails')
  110. // console.log(orderList, 77)
  111. this.senderModel.name = orderList.senderAddressName
  112. this.senderModel.phone = orderList.senderAddressPhone
  113. this.senderModel.address = orderList.senderAddressDetails
  114. this.recipientsModel.name = orderList.consigneeAddressName
  115. this.recipientsModel.phone = orderList.consigneeAddressPhone
  116. this.recipientsModel.address = orderList.consigneeAddressDetails
  117. this.goodsModel.temperatureInterval = orderList.temperatureInterval
  118. this.goodsModel.deliveryCondition = orderList.deliveryCondition
  119. this.goodsModel.cargoType = orderList.cargoType
  120. this.goodsModel.quantity = orderList.quantity
  121. this.goodsModel.remark = orderList.remark
  122. this.goodsModel.customerName = orderList.customerName
  123. this.goodsModel.id = orderList.id
  124. this.goodsModel.coolerBoxId = orderList.coolerBox.id
  125. this.goodsModel.coolerBoxIdname = orderList.coolerBox.name
  126. }
  127. },
  128. mounted() {
  129. var userInfo = this.$cache.getCache('userInfo')
  130. this.userInfo = userInfo
  131. },
  132. methods: {
  133. // 添加运单
  134. async printWaybill() {
  135. let flag = await this.$refs['sender'].validateForm();
  136. let flag1 = await this.$refs['recipients'].validateForm();
  137. let flag2 = await this.$refs['goods'].validateForm();
  138. if (flag && flag1 && flag2) {
  139. let params = {
  140. senderAddressName: this.senderModel.name,
  141. senderAddressPhone: this.senderModel.phone,
  142. senderAddressDetails: this.senderModel.address,
  143. consigneeAddressName: this.recipientsModel.name,
  144. consigneeAddressPhone: this.recipientsModel.phone,
  145. consigneeAddressDetails: this.recipientsModel.address,
  146. ...this.goodsModel,
  147. }
  148. delete params.coolerBoxIdname
  149. params.quantity = Number(params.quantity)
  150. uni.showLoading();
  151. if (this.type == 1) {
  152. // 添加订单
  153. if (this.userInfo.userType == 'sys') {
  154. this.$api.post('/api/waybill/applet', params).then(res => {
  155. if (res.code == 200) {
  156. uni.redirectTo({
  157. url: '/pages/order/index'
  158. });
  159. } else {
  160. uni.$u.toast('添加失败')
  161. }
  162. uni.hideLoading();
  163. }).catch(() => {
  164. uni.hideLoading();
  165. })
  166. } else {
  167. delete params.customerName
  168. this.$api.post('/api/waybill/customer', params).then(res => {
  169. if (res.code == 200) {
  170. uni.redirectTo({
  171. url: '/pages/order/index'
  172. });
  173. } else {
  174. uni.$u.toast('添加失败')
  175. }
  176. uni.hideLoading();
  177. }).catch(() => {
  178. uni.hideLoading();
  179. })
  180. }
  181. } else {
  182. // 修改订单
  183. if (this.userInfo.userType != 'sys') {
  184. delete params.customerName
  185. }
  186. this.$api.put('/api/waybill', params).then(res => {
  187. if (res.code == 200) {
  188. // uni.$u.toast(res.msg)
  189. uni.redirectTo({
  190. url: '/pages/order/index'
  191. });
  192. } else {
  193. uni.$u.toast('修改失败')
  194. }
  195. uni.hideLoading();
  196. }).catch(() => {
  197. uni.hideLoading();
  198. })
  199. }
  200. } else {
  201. uni.$u.toast('请先完善表单')
  202. }
  203. },
  204. // 保温箱
  205. incubatorClick(value) {
  206. this.goodsModel.coolerBoxId = value.id
  207. this.goodsModel.coolerBoxIdname = value.name
  208. this.$forceUpdate()
  209. }
  210. }
  211. }
  212. </script>
  213. <style lang="scss">
  214. page {
  215. background-color: #fff !important;
  216. }
  217. .title_waybill {
  218. position: relative;
  219. margin: 20rpx;
  220. border-bottom: 1rpx;
  221. padding-bottom: 20rpx;
  222. }
  223. .title_waybill:before {
  224. content: " ";
  225. position: absolute;
  226. left: 0;
  227. bottom: 0;
  228. width: 100%;
  229. height: 1px;
  230. border-top: 1px solid #e7e6e4;
  231. -webkit-transform-origin: 0 0;
  232. transform-origin: 0 0;
  233. -webkit-transform: scaleY(0.5);
  234. transform: scaleY(0.5);
  235. }
  236. </style>