addWaybill.vue 11 KB

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