addWaybill.vue 13 KB

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