addWaybill.vue 13 KB

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