addWaybill.vue 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. <template>
  2. <!-- 添加运单 -->
  3. <view>
  4. <u-navbar :title="headline" autoBack placeholder></u-navbar>
  5. <view class="space_between card_Address">
  6. <view class="title_waybill">寄件人:</view>
  7. <view class="card_flex_il" @click="addressBook('sender')">
  8. <u-icon name="order" size="22"></u-icon>
  9. <view class="title_sou">寄件人簿</view>
  10. </view>
  11. </view>
  12. <x-form ref="sender" :list="list" :model="senderModel" :rules="rules"></x-form>
  13. <view class="space_between card_Address">
  14. <view class="title_waybill">收件人:</view>
  15. <view class="card_flex_il" @click="addressBook('consignee')">
  16. <u-icon name="order" size="22"></u-icon>
  17. <view class="title_sou">收件人簿</view>
  18. </view>
  19. </view>
  20. <x-form ref="recipients" :list="list" :model="recipientsModel" :rules="rules"></x-form>
  21. <view class="space_between card_Address">
  22. <view class="title_waybill">配送员:</view>
  23. <view class="card_flex_il" @click="deliveryBook">
  24. <u-icon name="order" size="22"></u-icon>
  25. <view class="title_sou">配送员簿</view>
  26. </view>
  27. </view>
  28. <x-form ref="recipients" :list="courierList" :model="courierModel" :rules="rules"></x-form>
  29. <view class="title_waybill1"></view>
  30. <x-form ref="goods" :list="goodsList" :model="goodsModel" :rules="goodsRules"></x-form>
  31. <view style="width: 100%;height: 150rpx;"></view>
  32. <view class="btn_print" @click="printWaybill">
  33. <u-button type="primary" shape="circle" :text="headline"></u-button>
  34. </view>
  35. <u-popup :show="courierShow" mode="bottom" closeable :round="10" :closeOnClickOverlay="false" @close="close">
  36. <view class="card_courier">
  37. <view class="headline">选择配送员</view>
  38. <view class="search_card">
  39. <u-search :showAction="false" v-model="keyword" @change="searchChange"
  40. placeholder="输入姓名、电话、地址快速查找"></u-search>
  41. </view>
  42. <scroll-view class="scroll-view" scroll-y="true" @scrolltolower="loadMore">
  43. <view class="courier" v-if="courieList.length > 0">
  44. <view class="courier_item space_between" v-for="(item,index) in courieList" :key="index"
  45. @click="bindingDistributor(item)">
  46. <view class="courier_name">
  47. <view class="title_name">{{item.nickName}}</view>
  48. <view class="title_phone">{{item.phone}}</view>
  49. </view>
  50. <view class="xd_title center_in">下单给TA</view>
  51. </view>
  52. </view>
  53. <view style="margin-top: 30rpx;" v-else>
  54. <u-empty mode="list" text="暂无配送员"></u-empty>
  55. </view>
  56. </scroll-view>
  57. </view>
  58. </u-popup>
  59. </view>
  60. </template>
  61. <script>
  62. import {
  63. formRules,
  64. pickupRulesil,
  65. printList
  66. } from "./waybill.js";
  67. export default {
  68. name: 'addWaybill',
  69. data() {
  70. return {
  71. senderModel: {
  72. name: '',
  73. phone: '',
  74. address: '',
  75. },
  76. recipientsModel: {
  77. name: '',
  78. phone: '',
  79. address: '',
  80. },
  81. courierModel: {
  82. name: '',
  83. phone: '',
  84. },
  85. goodsModel: {
  86. tamperProofLabel: '',
  87. tamperProofLabelImg: '',
  88. remark: '',
  89. },
  90. rules: {
  91. name: {
  92. required: true,
  93. message: '请输入姓名',
  94. trigger: ['blur', 'change']
  95. },
  96. phone: {
  97. required: true,
  98. message: '请输入电话',
  99. trigger: ['blur', 'change']
  100. },
  101. address: {
  102. required: true,
  103. message: '请输入地址',
  104. trigger: ['blur', 'change']
  105. },
  106. },
  107. goodsRules: {
  108. tamperProofLabel: {
  109. required: true,
  110. message: '请输入防拆标签码',
  111. trigger: ['blur', 'change']
  112. },
  113. tamperProofLabelImg: {
  114. required: true,
  115. message: '请上传防拆标签图片',
  116. trigger: ['blur', 'change']
  117. },
  118. },
  119. list: pickupRulesil(),
  120. courierList: printList(),
  121. goodsList: formRules(),
  122. userInfo: {},
  123. headline: '添加运单',
  124. type: 1,
  125. operationType: 'sender',
  126. courierShow: false,
  127. courieList: [],
  128. keyword: '',
  129. incubatorMore: true,
  130. Pagination: 1,
  131. pageSize: 10,
  132. saveSenderAddress: true,
  133. saveConsigneeAddress: true,
  134. }
  135. },
  136. onUnload() {
  137. // console.log('页面销毁')
  138. uni.removeStorageSync('selectAddress')
  139. },
  140. onShow() {
  141. let address = uni.getStorageSync('selectAddress')
  142. if (address) {
  143. if (this.operationType == 'sender') {
  144. this.senderModel = address
  145. this.saveSenderAddress = false
  146. } else {
  147. this.recipientsModel = address
  148. this.saveConsigneeAddress = false
  149. }
  150. }
  151. },
  152. onLoad(value) {
  153. this.headline = value.title
  154. this.type = Number(value.type)
  155. if (this.type == 2) {
  156. var orderList = this.$cache.getCache('orderDetails')
  157. this.senderModel.name = orderList.senderAddressName
  158. this.senderModel.phone = orderList.senderAddressPhone
  159. this.senderModel.address = orderList.senderAddressDetails
  160. this.recipientsModel.name = orderList.consigneeAddressName
  161. this.recipientsModel.phone = orderList.consigneeAddressPhone
  162. this.recipientsModel.address = orderList.consigneeAddressDetails
  163. this.courierModel.name = orderList.deliveryName
  164. this.courierModel.phone = orderList.deliveryPhone
  165. this.goodsModel.tamperProofLabel = orderList.tamperProofLabel
  166. this.goodsModel.tamperProofLabelImg = orderList.tamperProofLabelImg
  167. this.goodsModel.remark = orderList.remark
  168. this.goodsModel.id = orderList.id
  169. if (orderList.tamperProofLabelImg) {
  170. let arrImg = orderList.tamperProofLabelImg.split(',')
  171. let arrImgList = []
  172. arrImg.forEach((item) => {
  173. const arr = {
  174. url: item,
  175. }
  176. arrImgList.push(arr)
  177. })
  178. this.$nextTick(() => {
  179. this.$refs.goods.fileList1 = arrImgList
  180. })
  181. }
  182. }
  183. },
  184. mounted() {
  185. var userInfo = this.$cache.getCache('userInfo')
  186. this.userInfo = userInfo
  187. },
  188. methods: {
  189. // tianjia运单
  190. async printWaybill() {
  191. let flag = await this.$refs['sender'].validateForm();
  192. let flag1 = await this.$refs['recipients'].validateForm();
  193. let flag2 = await this.$refs['goods'].validateForm();
  194. if (flag && flag1 && flag2) {
  195. let params = {
  196. senderAddressName: this.senderModel.name,
  197. senderAddressPhone: this.senderModel.phone,
  198. senderAddressDetails: this.senderModel.address,
  199. consigneeAddressName: this.recipientsModel.name,
  200. consigneeAddressPhone: this.recipientsModel.phone,
  201. consigneeAddressDetails: this.recipientsModel.address,
  202. deliveryName: this.courierModel.name,
  203. deliveryPhone: this.courierModel.phone,
  204. saveSenderAddress: this.saveSenderAddress,
  205. saveConsigneeAddress: this.saveConsigneeAddress,
  206. ...this.goodsModel,
  207. }
  208. uni.showLoading();
  209. if (this.type == 1) {
  210. // 添加订单
  211. this.$api.post('/api/waybill', params).then(res => {
  212. if (res.code == 200) {
  213. uni.redirectTo({
  214. url: '/pages/order/index'
  215. });
  216. } else {
  217. uni.$u.toast('添加失败')
  218. }
  219. uni.hideLoading();
  220. }).catch(() => {
  221. uni.hideLoading();
  222. })
  223. } else {
  224. // 修改订单
  225. this.$api.put('/api/waybill', params).then(res => {
  226. if (res.code == 200) {
  227. // uni.$u.toast(res.msg)
  228. uni.redirectTo({
  229. url: '/pages/order/index'
  230. });
  231. } else {
  232. uni.$u.toast('修改失败')
  233. }
  234. uni.hideLoading();
  235. }).catch(() => {
  236. uni.hideLoading();
  237. })
  238. }
  239. } else {
  240. uni.$u.toast('请先完善表单')
  241. }
  242. },
  243. // 选择类型
  244. addressBook(type) {
  245. this.operationType = type
  246. uni.navigateTo({
  247. url: '/pages/order/addressBook?type=' + type
  248. });
  249. },
  250. // 配送员
  251. deliveryBook() {
  252. this.courierShow = true
  253. this.getDelivery()
  254. },
  255. // 获取配送员
  256. getDelivery() {
  257. this.$api.get('/api/sys-user', {
  258. page: this.Pagination,
  259. pageSize: this.pageSize,
  260. name: this.keyword,
  261. type: 3,
  262. }).then(res => {
  263. if (res.code == 200) {
  264. const data = res.data.list
  265. if (this.incubatorMore == true) {
  266. this.courieList = this.courieList.concat(data);
  267. }
  268. if (data.length < this.pageSize) {
  269. this.incubatorMore = false
  270. } else {
  271. this.incubatorMore = true
  272. }
  273. }
  274. })
  275. },
  276. // 配送员
  277. bindingDistributor(value) {
  278. this.courierShow = false
  279. this.courierModel.name = value.nickName
  280. this.courierModel.phone = value.phone
  281. },
  282. // 滚动加载更多
  283. loadMore() {
  284. if (this.incubatorMore) {
  285. this.Pagination++
  286. this.getDelivery()
  287. }
  288. },
  289. // 搜索配送员
  290. searchChange() {
  291. this.Pagination = 1
  292. this.incubatorMore = true
  293. this.courieList = []
  294. this.getDelivery()
  295. },
  296. close() {
  297. this.courierShow = false
  298. }
  299. }
  300. }
  301. </script>
  302. <style lang="scss">
  303. page {
  304. background-color: #fff !important;
  305. }
  306. .title_waybill {
  307. padding: 20rpx;
  308. }
  309. .title_waybill1 {
  310. position: relative;
  311. margin: 20rpx;
  312. border-bottom: 1rpx;
  313. padding-bottom: 20rpx;
  314. }
  315. .card_Address {
  316. position: relative;
  317. }
  318. .card_flex_il {
  319. display: flex;
  320. align-items: center;
  321. padding: 20rpx;
  322. }
  323. .title_sou {
  324. font-size: 30rpx;
  325. }
  326. .card_Address:before {
  327. content: " ";
  328. position: absolute;
  329. left: 0;
  330. bottom: 0;
  331. width: 100%;
  332. height: 1px;
  333. border-top: 1px solid #e7e6e4;
  334. -webkit-transform-origin: 0 0;
  335. transform-origin: 0 0;
  336. -webkit-transform: scaleY(0.5);
  337. transform: scaleY(0.5);
  338. }
  339. .card_courier {
  340. min-height: 600rpx;
  341. padding-bottom: 20rpx;
  342. }
  343. .scroll-view {
  344. max-height: 60vh;
  345. overflow: hidden;
  346. }
  347. .headline {
  348. padding: 30rpx 30rpx 0rpx 30rpx;
  349. display: flex;
  350. align-items: center;
  351. justify-content: center;
  352. padding-bottom: 30rpx;
  353. font-size: 32rpx;
  354. font-weight: 600;
  355. }
  356. .search_card {
  357. padding: 0rpx 30rpx 10rpx 30rpx;
  358. }
  359. .courier_item {
  360. margin: 20rpx 20rpx;
  361. width: calc(100% - 80rpx);
  362. padding: 20rpx;
  363. border-radius: 20rpx;
  364. box-shadow: 0 2rpx 10rpx 0 rgba(0, 0, 0, .1);
  365. }
  366. .courier_name {
  367. display: flex;
  368. flex-direction: column;
  369. }
  370. .title_name {
  371. font-weight: 600;
  372. font-size: 32rpx;
  373. margin-bottom: 10rpx;
  374. }
  375. .title_phone {
  376. font-size: 28rpx;
  377. }
  378. .xd_title {
  379. width: auto;
  380. font-size: 28rpx;
  381. font-weight: 500;
  382. padding: 10rpx 20rpx;
  383. border-radius: 35rpx;
  384. border: 3rpx solid #82848a;
  385. }
  386. </style>