addWaybill.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  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. this.printLoading = true
  221. if (this.type == 1) {
  222. // 添加运单
  223. this.$api.post('/api/waybill', params).then(res => {
  224. if (res.code == 200) {
  225. uni.redirectTo({
  226. url: '/pages/order/index'
  227. });
  228. } else {
  229. uni.$u.toast(res.msg)
  230. }
  231. uni.hideLoading();
  232. this.printLoading = false
  233. }).catch(() => {
  234. uni.hideLoading();
  235. this.printLoading = false
  236. })
  237. } else {
  238. // 修改运单
  239. this.$api.put('/api/waybill', params).then(res => {
  240. if (res.code == 200) {
  241. // uni.$u.toast(res.msg)
  242. uni.redirectTo({
  243. url: '/pages/order/index'
  244. });
  245. } else {
  246. uni.$u.toast('修改失败')
  247. }
  248. uni.hideLoading();
  249. this.printLoading = false
  250. }).catch(() => {
  251. uni.hideLoading();
  252. this.printLoading = false
  253. })
  254. }
  255. } else {
  256. uni.$u.toast('请扫码添加商品')
  257. }
  258. } else {
  259. uni.$u.toast('请先完善表单')
  260. }
  261. },
  262. // 选择类型
  263. addressBook(type) {
  264. this.operationType = type
  265. uni.navigateTo({
  266. url: '/pages/order/addressBook?type=' + type
  267. });
  268. },
  269. // 配送员
  270. deliveryBook() {
  271. this.courierShow = true
  272. this.courierHeadline = '选择配送员'
  273. this.textEmpty = '暂无配送员'
  274. this.getDelivery()
  275. },
  276. // 复核人
  277. selector(value) {
  278. this.selectiveType = value.field
  279. this.courieList = []
  280. this.incubatorMore = true
  281. this.Pagination = 1
  282. if (value.field == 'deliveryName') {
  283. this.courierHeadline = '选择配送人'
  284. this.textEmpty = '暂无配送人'
  285. this.getDelivery(value.field)
  286. } else if (value.field == 'reCheckName') {
  287. this.courierHeadline = '选择复核人'
  288. this.textEmpty = '暂无复核人'
  289. this.getDelivery(value.field)
  290. }
  291. this.courierShow = true
  292. },
  293. // 获取药品信息码上放心
  294. getSweep(event) {
  295. let idExists = this.productData.some(obj => obj.code === event);
  296. if (!idExists) {
  297. this.addloading = true
  298. uni.request({
  299. url: 'https://public.coldbaozhida.com/Ali_msfx/codedetail', //仅为示例,并非真实接口地址。
  300. method: 'GET',
  301. header: {
  302. 'content-type': 'application/x-www-form-urlencoded', // 默认值
  303. },
  304. data: {
  305. code: event,
  306. },
  307. success: (res) => {
  308. if (res.data.status == 200) {
  309. let arr = JSON.parse(res.data.data)
  310. if (arr.result.models.length > 0) {
  311. let drugList = {
  312. code: '',
  313. physic_name: '',
  314. physic_type_desc: '',
  315. pkg_spec_crit: '',
  316. ent_name: '',
  317. }
  318. drugList.code = arr.result.models[0].code
  319. drugList.physic_name = arr.result.models[0].drug_ent_base_d_t_o.physic_name
  320. drugList.physic_type_desc = arr.result.models[0].drug_ent_base_d_t_o
  321. .physic_type_desc
  322. drugList.pkg_spec_crit = arr.result.models[0].drug_ent_base_d_t_o
  323. .pkg_spec_crit
  324. drugList.ent_name = arr.result.models[0].p_user_ent_d_t_o.ent_name
  325. this.productData.push(drugList)
  326. this.productData = this.uniqueArray(this.productData)
  327. } else {
  328. uni.$u.toast('该商品不存在')
  329. }
  330. this.addloading = false
  331. }
  332. }
  333. });
  334. } else {
  335. uni.$u.toast('该商品已存在')
  336. }
  337. },
  338. // 去重
  339. uniqueArray(arr) {
  340. return [...new Set(arr)];
  341. },
  342. // 获取配送员
  343. getDelivery(field) {
  344. if (field == 'deliveryName') {
  345. // 配送人
  346. this.$api.get('/api/sys-user', {
  347. page: this.Pagination,
  348. pageSize: this.pageSize,
  349. name: this.keyword,
  350. // type: 3,
  351. }).then(res => {
  352. if (res.code == 200) {
  353. const data = res.data.list
  354. if (this.incubatorMore == true) {
  355. this.courieList = this.courieList.concat(data);
  356. }
  357. if (data.length < this.pageSize) {
  358. this.incubatorMore = false
  359. } else {
  360. this.incubatorMore = true
  361. }
  362. }
  363. })
  364. } else if (field == 'reCheckName') {
  365. // 复核人
  366. this.$api.get('/api/sys-user', {
  367. page: this.Pagination,
  368. pageSize: this.pageSize,
  369. name: this.keyword,
  370. }).then(res => {
  371. if (res.code == 200) {
  372. const data = res.data.list
  373. if (this.incubatorMore == true) {
  374. this.courieList = this.courieList.concat(data);
  375. }
  376. if (data.length < this.pageSize) {
  377. this.incubatorMore = false
  378. } else {
  379. this.incubatorMore = true
  380. }
  381. }
  382. })
  383. }
  384. },
  385. // 选择
  386. bindingDistributor(value) {
  387. // this.$refs['courier'].validateForm();
  388. if (this.selectiveType == 'deliveryName') {
  389. this.goodsModel.deliveryId = value.id
  390. this.goodsModel.deliveryName = value.nickName
  391. this.$refs['goods'].formValidation('deliveryName')
  392. } else if (this.selectiveType == 'reCheckName') {
  393. this.goodsModel.reCheckId = value.id
  394. this.goodsModel.reCheckName = value.nickName
  395. this.$refs['goods'].formValidation('reCheckName')
  396. }
  397. this.courierShow = false
  398. },
  399. // 滚动加载更多
  400. loadMore() {
  401. if (this.incubatorMore) {
  402. this.Pagination++
  403. this.getDelivery(this.selectiveType)
  404. }
  405. },
  406. // 搜索配送员
  407. searchChange() {
  408. this.Pagination = 1
  409. this.incubatorMore = true
  410. this.courieList = []
  411. this.getDelivery(this.selectiveType)
  412. },
  413. close() {
  414. this.courierShow = false
  415. }
  416. }
  417. }
  418. </script>
  419. <style lang="scss">
  420. page {
  421. background-color: #fff !important;
  422. }
  423. .title_waybill {
  424. font-size: 32rpx;
  425. padding: 20rpx;
  426. }
  427. .card_Address {
  428. position: relative;
  429. }
  430. .card_flex_il {
  431. display: flex;
  432. align-items: center;
  433. padding: 20rpx;
  434. }
  435. .title_sou {
  436. font-size: 32rpx;
  437. }
  438. .icon_bottom {
  439. font-size: 36rpx;
  440. margin-right: 10rpx;
  441. }
  442. .card_Address:before {
  443. content: " ";
  444. position: absolute;
  445. left: 0;
  446. bottom: 0;
  447. width: 100%;
  448. height: 1px;
  449. border-top: 1px solid #e7e6e4;
  450. -webkit-transform-origin: 0 0;
  451. transform-origin: 0 0;
  452. -webkit-transform: scaleY(0.5);
  453. transform: scaleY(0.5);
  454. }
  455. .card_courier {
  456. min-height: 600rpx;
  457. padding-bottom: 20rpx;
  458. }
  459. .scroll-view {
  460. max-height: 60vh;
  461. overflow: hidden;
  462. }
  463. .headline {
  464. padding: 30rpx 30rpx 0rpx 30rpx;
  465. display: flex;
  466. align-items: center;
  467. justify-content: center;
  468. padding-bottom: 30rpx;
  469. font-size: 32rpx;
  470. font-weight: 600;
  471. }
  472. .search_card {
  473. padding: 0rpx 30rpx 10rpx 30rpx;
  474. }
  475. .courier_item {
  476. margin: 20rpx 20rpx;
  477. width: calc(100% - 80rpx);
  478. padding: 20rpx;
  479. border-radius: 20rpx;
  480. // box-shadow: 0 2rpx 10rpx 0 rgba(0, 0, 0, .1);
  481. border: 1rpx solid #e7e6e4;
  482. }
  483. .courier_name {
  484. display: flex;
  485. flex-direction: column;
  486. }
  487. .title_name {
  488. font-weight: 600;
  489. font-size: 32rpx;
  490. margin-bottom: 10rpx;
  491. }
  492. .title_phone {
  493. font-size: 28rpx;
  494. }
  495. .xd_title {
  496. width: auto;
  497. font-size: 28rpx;
  498. font-weight: 500;
  499. padding: 15rpx 30rpx;
  500. border-radius: 35rpx;
  501. // border: 3rpx solid #82848a;
  502. background-color: #E4E7ED;
  503. }
  504. </style>