addWaybill.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_waybill1"></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. tamperProofLabel: '',
  38. tamperProofLabelImg: '',
  39. remark: '',
  40. },
  41. rules: {
  42. name: {
  43. required: true,
  44. message: '请输入姓名',
  45. trigger: ['blur', 'change']
  46. },
  47. phone: {
  48. required: true,
  49. message: '请输入电话',
  50. trigger: ['blur', 'change']
  51. },
  52. address: {
  53. required: true,
  54. message: '请输入地址',
  55. trigger: ['blur', 'change']
  56. },
  57. },
  58. goodsRules: {
  59. tamperProofLabel: {
  60. required: true,
  61. message: '请输入防拆标签码',
  62. trigger: ['blur', 'change']
  63. },
  64. tamperProofLabelImg: {
  65. required: true,
  66. message: '请上传防拆标签图片',
  67. trigger: ['blur', 'change']
  68. },
  69. },
  70. list: pickupRulesil(),
  71. goodsList: formRules(),
  72. userInfo: {},
  73. headline: '添加运单',
  74. type: 1,
  75. }
  76. },
  77. onLoad(value) {
  78. this.headline = value.title
  79. this.type = Number(value.type)
  80. if (this.type == 2) {
  81. var orderList = this.$cache.getCache('orderDetails')
  82. this.senderModel.name = orderList.senderAddressName
  83. this.senderModel.phone = orderList.senderAddressPhone
  84. this.senderModel.address = orderList.senderAddressDetails
  85. this.recipientsModel.name = orderList.consigneeAddressName
  86. this.recipientsModel.phone = orderList.consigneeAddressPhone
  87. this.recipientsModel.address = orderList.consigneeAddressDetails
  88. this.goodsModel.tamperProofLabel = orderList.tamperProofLabel
  89. this.goodsModel.tamperProofLabelImg = orderList.tamperProofLabelImg
  90. this.goodsModel.remark = orderList.remark
  91. this.goodsModel.id = orderList.id
  92. if (orderList.tamperProofLabelImg) {
  93. let arrImg = orderList.tamperProofLabelImg.split(',')
  94. let arrImgList = []
  95. arrImg.forEach((item) => {
  96. const arr = {
  97. url: item,
  98. }
  99. arrImgList.push(arr)
  100. })
  101. this.$nextTick(() => {
  102. this.$refs.goods.fileList1 = arrImgList
  103. })
  104. }
  105. }
  106. },
  107. mounted() {
  108. var userInfo = this.$cache.getCache('userInfo')
  109. this.userInfo = userInfo
  110. },
  111. methods: {
  112. // tianjia运单
  113. async printWaybill() {
  114. let flag = await this.$refs['sender'].validateForm();
  115. let flag1 = await this.$refs['recipients'].validateForm();
  116. let flag2 = await this.$refs['goods'].validateForm();
  117. if (flag && flag1 && flag2) {
  118. let params = {
  119. senderAddressName: this.senderModel.name,
  120. senderAddressPhone: this.senderModel.phone,
  121. senderAddressDetails: this.senderModel.address,
  122. consigneeAddressName: this.recipientsModel.name,
  123. consigneeAddressPhone: this.recipientsModel.phone,
  124. consigneeAddressDetails: this.recipientsModel.address,
  125. ...this.goodsModel,
  126. }
  127. uni.showLoading();
  128. if (this.type == 1) {
  129. // 添加订单
  130. this.$api.post('/api/waybill', params).then(res => {
  131. if (res.code == 200) {
  132. uni.redirectTo({
  133. url: '/pages/order/index'
  134. });
  135. } else {
  136. uni.$u.toast('添加失败')
  137. }
  138. uni.hideLoading();
  139. }).catch(() => {
  140. uni.hideLoading();
  141. })
  142. } else {
  143. // 修改订单
  144. this.$api.put('/api/waybill', params).then(res => {
  145. if (res.code == 200) {
  146. // uni.$u.toast(res.msg)
  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. uni.$u.toast('请先完善表单')
  160. }
  161. }
  162. }
  163. }
  164. </script>
  165. <style lang="scss">
  166. page {
  167. background-color: #fff !important;
  168. }
  169. .title_waybill {
  170. position: relative;
  171. margin: 20rpx;
  172. border-bottom: 1rpx;
  173. padding-bottom: 20rpx;
  174. }
  175. .title_waybill1 {
  176. position: relative;
  177. margin: 20rpx;
  178. border-bottom: 1rpx;
  179. padding-bottom: 20rpx;
  180. }
  181. .title_waybill:before {
  182. content: " ";
  183. position: absolute;
  184. left: 0;
  185. bottom: 0;
  186. width: 100%;
  187. height: 1px;
  188. border-top: 1px solid #e7e6e4;
  189. -webkit-transform-origin: 0 0;
  190. transform-origin: 0 0;
  191. -webkit-transform: scaleY(0.5);
  192. transform: scaleY(0.5);
  193. }
  194. </style>