addWaybill.vue 14 KB

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