distributionOrder.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  1. <template>
  2. <!-- 分配订单 -->
  3. <view>
  4. <u-navbar title="分配订单" 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" :addloading="addloading"
  14. :productData="productData" @getSweep="getSweep"></x-form>
  15. <view class="safeBottom" style="width: 100%;height: 180rpx;"></view>
  16. <view class="btn_print" @click="printWaybill">
  17. <u-button type="primary" text="确定"></u-button>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import {
  23. allocationRulesil,
  24. allocationList
  25. } from "./waybill.js";
  26. export default {
  27. data() {
  28. return {
  29. list: allocationRulesil(),
  30. recipientsModel: {
  31. name: '',
  32. phone: '',
  33. address: '',
  34. },
  35. rules: {
  36. name: {
  37. required: false,
  38. message: '请输入姓名',
  39. trigger: ['blur', 'change']
  40. },
  41. phone: [{
  42. required: true,
  43. message: '请输入电话',
  44. trigger: ['blur', 'change']
  45. }, {
  46. validator: (rule, value, callback) => {
  47. return uni.$u.test.mobile(value);
  48. },
  49. message: '请输入正确手机号码',
  50. trigger: ['change', 'blur'],
  51. }],
  52. address: {
  53. required: false,
  54. message: '请输入地址',
  55. trigger: ['blur', 'change']
  56. },
  57. },
  58. goodsModel: {
  59. drugBarCode: '',
  60. prescription: [],
  61. },
  62. productData: [],
  63. goodsRules: {},
  64. goodsList: allocationList(),
  65. addloading: false,
  66. allocationSuccess: false,
  67. waybillNo: '',
  68. }
  69. },
  70. onUnload() {
  71. uni.$off('success')
  72. // console.log('页面销毁')
  73. uni.removeStorageSync('selectAddress')
  74. },
  75. onLoad(option) {
  76. if (option.flag == 'true') {
  77. this.allocationSuccess = true
  78. }
  79. this.waybillNo = option.waybillNo
  80. },
  81. onShow() {
  82. let address = uni.getStorageSync('selectAddress')
  83. if (address) {
  84. this.$nextTick(() => {
  85. this.$refs['recipients'].validateForm();
  86. })
  87. this.recipientsModel = address
  88. this.saveConsigneeAddress = false
  89. }
  90. },
  91. methods: {
  92. // 选择类型
  93. addressBook(type) {
  94. this.operationType = type
  95. uni.navigateTo({
  96. url: '/pages/order/addressBook?type=' + type
  97. });
  98. },
  99. // 确定分配订单
  100. async printWaybill() {
  101. let flag1 = await this.$refs['recipients'].validateForm();
  102. if (flag1) {
  103. if (this.productData.length > 0) {
  104. let params = {
  105. consigneeAddressName: this.recipientsModel.name,
  106. consigneeAddressPhone: this.recipientsModel.phone,
  107. consigneeAddressDetails: this.recipientsModel.address,
  108. drugs: this.productData,
  109. waybillNo: this.waybillNo,
  110. prescription: this.goodsModel.prescription,
  111. }
  112. uni.showLoading({
  113. mask: true
  114. });
  115. this.$api.post('/api/waybill/assignment', params).then(res => {
  116. if (res.code == 200) {
  117. if (this.allocationSuccess) {
  118. uni.$emit('success', '成功');
  119. uni.navigateBack({
  120. delta: 1
  121. });
  122. } else {
  123. uni.$emit('success', '成功');
  124. uni.navigateBack({
  125. delta: 2
  126. });
  127. }
  128. } else {
  129. uni.$u.toast(res.msg)
  130. }
  131. uni.hideLoading();
  132. })
  133. } else {
  134. uni.$u.toast('请扫描分配药品条形码')
  135. }
  136. }
  137. },
  138. // 获取药品信息码上放心
  139. getSweep(event) {
  140. let idExists = this.productData.some(obj => obj.code === event);
  141. if (!idExists) {
  142. this.addloading = true
  143. uni.request({
  144. url: 'https://public.coldbaozhida.com/Ali_msfx/codedetail', //仅为示例,并非真实接口地址。
  145. method: 'GET',
  146. header: {
  147. 'content-type': 'application/x-www-form-urlencoded', // 默认值
  148. },
  149. data: {
  150. code: event,
  151. },
  152. success: (res) => {
  153. if (res.data.status == 200) {
  154. let arr = JSON.parse(res.data.data)
  155. if (arr.result.models.length > 0) {
  156. let drugList = {
  157. code: '',
  158. physic_name: '',
  159. physic_type_desc: '',
  160. pkg_spec_crit: '',
  161. ent_name: '',
  162. }
  163. drugList.code = arr.result.models[0].code
  164. drugList.physic_name = arr.result.models[0].drug_ent_base_d_t_o.physic_name
  165. drugList.physic_type_desc = arr.result.models[0].drug_ent_base_d_t_o
  166. .physic_type_desc
  167. drugList.pkg_spec_crit = arr.result.models[0].drug_ent_base_d_t_o
  168. .pkg_spec_crit
  169. drugList.ent_name = arr.result.models[0].p_user_ent_d_t_o.ent_name
  170. this.productData.push(drugList)
  171. this.productData = this.uniqueArray(this.productData)
  172. } else {
  173. uni.$u.toast('该商品不存在')
  174. }
  175. }
  176. this.addloading = false
  177. }
  178. });
  179. } else {
  180. uni.$u.toast('该商品已存在')
  181. }
  182. },
  183. // 去重
  184. uniqueArray(arr) {
  185. return [...new Set(arr)];
  186. },
  187. }
  188. }
  189. </script>
  190. <style lang="scss">
  191. page {
  192. background-color: #fff !important;
  193. }
  194. .card_Address {
  195. position: relative;
  196. }
  197. .card_flex_il {
  198. display: flex;
  199. align-items: center;
  200. padding: 20rpx;
  201. }
  202. .title_waybill {
  203. font-size: 32rpx;
  204. padding: 20rpx;
  205. }
  206. .title_sou {
  207. font-size: 32rpx;
  208. }
  209. .card_Address:before {
  210. content: " ";
  211. position: absolute;
  212. left: 0;
  213. bottom: 0;
  214. width: 100%;
  215. height: 1px;
  216. border-top: 1px solid #e7e6e4;
  217. -webkit-transform-origin: 0 0;
  218. transform-origin: 0 0;
  219. -webkit-transform: scaleY(0.5);
  220. transform: scaleY(0.5);
  221. }
  222. </style>