addWaybill.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  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. let arrImg = orderList.tamperProofLabelImg.split(',')
  93. let arrImgList = []
  94. arrImg.forEach((item) => {
  95. const arr = {
  96. url: item,
  97. }
  98. arrImgList.push(arr)
  99. })
  100. this.$nextTick(() => {
  101. this.$refs.goods.fileList1 = arrImgList
  102. })
  103. }
  104. },
  105. mounted() {
  106. var userInfo = this.$cache.getCache('userInfo')
  107. this.userInfo = userInfo
  108. },
  109. methods: {
  110. // tianjia运单
  111. async printWaybill() {
  112. let flag = await this.$refs['sender'].validateForm();
  113. let flag1 = await this.$refs['recipients'].validateForm();
  114. let flag2 = await this.$refs['goods'].validateForm();
  115. if (flag && flag1 && flag2) {
  116. let params = {
  117. senderAddressName: this.senderModel.name,
  118. senderAddressPhone: this.senderModel.phone,
  119. senderAddressDetails: this.senderModel.address,
  120. consigneeAddressName: this.recipientsModel.name,
  121. consigneeAddressPhone: this.recipientsModel.phone,
  122. consigneeAddressDetails: this.recipientsModel.address,
  123. ...this.goodsModel,
  124. }
  125. console.log(params, 222)
  126. uni.showLoading();
  127. if (this.type == 1) {
  128. // 添加订单
  129. this.$api.post('/api/waybill', params).then(res => {
  130. if (res.code == 200) {
  131. uni.redirectTo({
  132. url: '/pages/order/index'
  133. });
  134. } else {
  135. uni.$u.toast('添加失败')
  136. }
  137. uni.hideLoading();
  138. }).catch(() => {
  139. uni.hideLoading();
  140. })
  141. } else {
  142. // 修改订单
  143. this.$api.put('/api/waybill', params).then(res => {
  144. if (res.code == 200) {
  145. // uni.$u.toast(res.msg)
  146. uni.redirectTo({
  147. url: '/pages/order/index'
  148. });
  149. } else {
  150. uni.$u.toast('修改失败')
  151. }
  152. uni.hideLoading();
  153. }).catch(() => {
  154. uni.hideLoading();
  155. })
  156. }
  157. } else {
  158. uni.$u.toast('请先完善表单')
  159. }
  160. }
  161. }
  162. }
  163. </script>
  164. <style lang="scss">
  165. page {
  166. background-color: #fff !important;
  167. }
  168. .title_waybill {
  169. position: relative;
  170. margin: 20rpx;
  171. border-bottom: 1rpx;
  172. padding-bottom: 20rpx;
  173. }
  174. .title_waybill1 {
  175. position: relative;
  176. margin: 20rpx;
  177. border-bottom: 1rpx;
  178. padding-bottom: 20rpx;
  179. }
  180. .title_waybill:before {
  181. content: " ";
  182. position: absolute;
  183. left: 0;
  184. bottom: 0;
  185. width: 100%;
  186. height: 1px;
  187. border-top: 1px solid #e7e6e4;
  188. -webkit-transform-origin: 0 0;
  189. transform-origin: 0 0;
  190. -webkit-transform: scaleY(0.5);
  191. transform: scaleY(0.5);
  192. }
  193. </style>