addEditOrder.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. <template>
  2. <div>
  3. <el-dialog top="5vh" :title="staffTitle" :visible.sync="staffDialogVisible" width="900px"
  4. :close-on-click-modal="false" @close="closePopup">
  5. <div class="waybill_item">
  6. <waybillForm ref="recipients" title="患者信息" :conserveFlag="conserveFlag" thinTitle="患者簿"
  7. :ruleForm="recipientsForm" @addressBook="getAddressBook('recipients')" @conserveSelect="conserveSelectil">
  8. </waybillForm>
  9. </div>
  10. <forms ref="childRules" :formNewList="formRuleList" :ruleForm="ruleForm" :delDrug="true" labelWidth="80px">
  11. </forms>
  12. <el-dialog width="60%" title="地址簿" :visible.sync="innerVisible" append-to-body>
  13. <div class="space_between_in" style="margin-bottom: 15px;">
  14. <div style="display: flex;align-items: center;width: 100%;">
  15. <h3 style="margin-left: 10px;flex: none;">搜索:</h3>
  16. <el-input v-model="bookInput" style="width: 100%;" placeholder="请输入姓名、电话、地址快速查找"
  17. @input="fastSearch()"></el-input>
  18. </div>
  19. </div>
  20. <div class="card_book_list">
  21. <!-- 表单 -->
  22. <tables :suspension="true" :tableList="bookTableList" :tableData="bookTableData" @cellClick="cellClick">
  23. </tables>
  24. <!-- 分页 -->
  25. <div v-if="bookTotal">
  26. <pagination :total="bookTotal" :currentPage="bookPagination.PageIndex" @changeSize="bookChangeSize"
  27. @changeCurrent="bookChangeCurrent">
  28. </pagination>
  29. </div>
  30. </div>
  31. </el-dialog>
  32. <span slot="footer" class="dialog-footer">
  33. <el-button plain @click="staffDialogVisible = false">取 消</el-button>
  34. <el-button type="primary" :loading="confirmLoading" @click="handleAdd">确 定</el-button>
  35. </span>
  36. </el-dialog>
  37. </div>
  38. </template>
  39. <script>
  40. import {
  41. addWaybill,
  42. putWaybill,
  43. } from '@/api/waybill'
  44. import {
  45. getAddress
  46. } from '@/api/address'
  47. import {
  48. getUser
  49. } from '@/api/user'
  50. import tables from '@/components/tables'
  51. import pagination from '@/components/pagination'
  52. import waybillForm from '@/components/waybillForm'
  53. import forms from '@/components/forms'
  54. import {
  55. formRules,
  56. addressBook,
  57. } from "../views/OrderManagement/uncertain.js";
  58. export default {
  59. name: 'addEditOrder',
  60. components: {
  61. tables,
  62. pagination,
  63. waybillForm,
  64. forms,
  65. },
  66. props: {
  67. staffTitle: {
  68. type: String,
  69. default: () => '添加',
  70. },
  71. operationType: {
  72. type: String,
  73. default: () => 'add',
  74. },
  75. orderInformation: {
  76. type: Object,
  77. default: () => {},
  78. },
  79. orderId: {
  80. type: Number,
  81. default: () => null,
  82. },
  83. },
  84. data() {
  85. return {
  86. staffDialogVisible: false,
  87. recipientsForm: {
  88. name: '',
  89. phone: '',
  90. region: '',
  91. address: '',
  92. },
  93. conserveFlag: true,
  94. saveConsigneeAddress: true,
  95. delivererName: '',
  96. ruleForm: {
  97. deliveryType: '现在配送',
  98. askForTime: null,
  99. is_secondary_distribution: false,
  100. tamperProofLabel: '',
  101. tamperProofLabelImg: '',
  102. remark: '',
  103. fileList: [],
  104. drugCode: [],
  105. },
  106. formRuleList: [],
  107. conserveFlag: true,
  108. saveConsigneeAddress: true,
  109. innerVisible: false,
  110. bookInput: '',
  111. bookTableList: [],
  112. bookTableData: [],
  113. bookType: '',
  114. bookPagination: {
  115. PageIndex: 1,
  116. PageSize: 10,
  117. },
  118. bookTotal: 0,
  119. confirmLoading: false,
  120. }
  121. },
  122. watch: {
  123. orderInformation: {
  124. handler(newVal, oldVal) {
  125. // console.log(newVal, 'val')
  126. setTimeout(() => {
  127. this.$nextTick(() => {
  128. if (newVal.id) {
  129. this.recipientsForm.name = newVal.consigneeAddressName
  130. this.recipientsForm.phone = newVal.consigneeAddressPhone
  131. this.recipientsForm.address = newVal.consigneeAddressDetails
  132. this.ruleForm.tamperProofLabel = newVal.tamperProofLabel
  133. this.ruleForm.drugCode = newVal.drugs
  134. if (newVal.deliveryType) {
  135. this.ruleForm.deliveryType = newVal.deliveryType
  136. }
  137. if (newVal.askForTime) {
  138. this.ruleForm.askForTime = newVal.askForTime
  139. }
  140. this.ruleForm.is_secondary_distribution = newVal.is_secondary_distribution
  141. if (newVal.tamperProofLabelImg) {
  142. var arr = newVal.tamperProofLabelImg.split(',')
  143. var arr3 = []
  144. arr.forEach((item, index) => {
  145. var arr1 = {
  146. url: '',
  147. }
  148. arr1.url = item
  149. arr3.push(arr1)
  150. })
  151. this.ruleForm.fileList = arr3
  152. this.ruleForm.tamperProofLabelImg = newVal.tamperProofLabelImg
  153. }
  154. if (newVal.drugs && newVal.drugs.length > 0) {
  155. this.$refs.childRules.commodityList = newVal.drugs
  156. }
  157. this.ruleForm.remark = newVal.remark
  158. }
  159. })
  160. })
  161. },
  162. immediate: true,
  163. deep: true
  164. }
  165. },
  166. mounted() {
  167. const dataList = formRules();
  168. this.formRuleList = dataList;
  169. },
  170. methods: {
  171. // 弹窗表单添加
  172. async handleAdd() {
  173. let recipientsFlag = this.$refs['recipients'].validateForm();
  174. let childRulesFlag = this.$refs['childRules'].validateForm();
  175. if (recipientsFlag && childRulesFlag) {
  176. // if (this.ruleForm.drugCode.length > 0) {
  177. this.confirmLoading = true
  178. var params = {
  179. consigneeAddressName: this.recipientsForm.name,
  180. consigneeAddressPhone: this.recipientsForm.phone,
  181. consigneeAddressDetails: this.recipientsForm.address,
  182. saveConsigneeAddress: this.saveConsigneeAddress,
  183. // deliveryId: Number(this.personnelForm.deliveryId),
  184. // reCheckId: Number(this.personnelForm.reCheckId),
  185. ...this.ruleForm,
  186. drugs: this.ruleForm.drugCode
  187. }
  188. if (this.ruleForm.fileList) {
  189. var fileImage = this.picture(this.ruleForm.fileList)
  190. params.tamperProofLabelImg = fileImage
  191. }
  192. if (!params.askForTime) {
  193. delete params.askForTime
  194. }
  195. if (this.operationType == 'add') {
  196. delete params.fileList
  197. delete params.drugCode
  198. delete params.code
  199. await addWaybill(params).then(res => {
  200. if (res.code == 200) {
  201. this.$message({
  202. message: '操作成功',
  203. type: 'success'
  204. });
  205. // this.getList()
  206. this.$emit('refreshList')
  207. }
  208. this.staffDialogVisible = false
  209. this.confirmLoading = false
  210. }).catch(() => {
  211. this.confirmLoading = false
  212. })
  213. } else if (this.operationType == 'edit') {
  214. delete params.fileList
  215. delete params.drugCode
  216. delete params.code
  217. params.id = this.orderId
  218. await putWaybill(params).then(res => {
  219. if (res.code == 200) {
  220. this.$message({
  221. message: '操作成功',
  222. type: 'success'
  223. });
  224. // this.getList()
  225. this.$emit('refreshList')
  226. }
  227. this.staffDialogVisible = false
  228. this.confirmLoading = false
  229. }).catch(() => {
  230. this.confirmLoading = false
  231. })
  232. }
  233. // } else {
  234. // this.$message.error('请扫码添加商品');
  235. // }
  236. } else {
  237. this.$message.error('表单信息不完整,请继续填写完整');
  238. }
  239. },
  240. picture(arr) {
  241. var imgList = JSON.parse(JSON.stringify(arr))
  242. var imgArr = []
  243. imgList.forEach((item, index) => {
  244. imgArr.push(item.url)
  245. })
  246. var imgString = imgArr.join()
  247. return imgString
  248. },
  249. // 获取地址簿
  250. getAddressBook(type) {
  251. this.bookTableList = addressBook()
  252. this.bookType = type
  253. this.innerVisible = true
  254. this.getSenderSend()
  255. },
  256. conserveSelectil(type) {
  257. if (type) {
  258. this.saveConsigneeAddress = true
  259. } else {
  260. this.saveConsigneeAddress = false
  261. }
  262. },
  263. // 快速搜索
  264. fastSearch() {
  265. this.bookPagination.PageIndex = 1
  266. if (this.bookType == 'deliverer') {
  267. this.getDelivererList()
  268. }
  269. },
  270. // 获取寄/收列表
  271. getSenderSend() {
  272. let address = ''
  273. if (this.bookType == 'recipients') {
  274. address = 'consignee'
  275. } else {
  276. address = this.bookType
  277. }
  278. getAddress({
  279. page: this.bookPagination.PageIndex,
  280. pageSize: this.bookPagination.PageSize,
  281. name: this.bookInput,
  282. addressType: address,
  283. }).then(res => {
  284. if (res.code == 200) {
  285. this.bookTableData = res.data.list
  286. this.bookTotal = res.data.count
  287. }
  288. })
  289. },
  290. getDelivererList() {
  291. var params = {
  292. page: 1,
  293. pageSize: 999,
  294. // type: 3,
  295. name: this.delivererName,
  296. }
  297. getUser(params).then(res => {
  298. if (res.code == 200) {
  299. let arr = res.data.list
  300. let arrList = []
  301. arr.forEach(item1 => {
  302. var arrData = {
  303. label: null,
  304. value: null,
  305. }
  306. arrData.label = item1.nickName
  307. arrData.value = item1.id
  308. arrList.push(arrData)
  309. })
  310. this.personnelList.forEach(item => {
  311. if (item.field == 'deliveryId') {
  312. item.options = item.options.concat(arrList)
  313. }
  314. })
  315. }
  316. })
  317. },
  318. // 地址簿
  319. bookChangeSize(val) {
  320. this.bookPagination.PageSize = val
  321. if (this.bookType == 'deliverer') {
  322. this.getDelivererList()
  323. } else {
  324. this.getSenderSend()
  325. }
  326. },
  327. bookChangeCurrent(val) {
  328. this.bookPagination.PageIndex = val
  329. if (this.bookType == 'deliverer') {
  330. this.getDelivererList()
  331. } else {
  332. this.getSenderSend()
  333. }
  334. },
  335. // 选择table其中某一项
  336. cellClick(row) {
  337. this.innerVisible = false
  338. const param = {
  339. ...row
  340. }
  341. if (this.bookType == 'recipients') {
  342. this.recipientsForm = param
  343. this.$nextTick(() => {
  344. this.$refs.recipients.radio = ''
  345. // this.$refs['recipients'].clickitem('1')
  346. this.$refs['recipients'].validateForm();
  347. })
  348. } else if (this.bookType == 'deliverer') {
  349. this.delivererForm.name = param.nickName
  350. this.delivererForm.phone = param.phone
  351. this.$nextTick(() => {
  352. this.$refs['deliverer'].validateForm();
  353. })
  354. }
  355. },
  356. // 关闭清空表单
  357. closePopup() {
  358. this.ruleForm.fileList = []
  359. this.$refs.childRules.commodityList = []
  360. // this.$refs.sender.resetForm()
  361. this.$refs.recipients.resetForm()
  362. // this.$refs.deliverer.resetForm()
  363. this.$refs.childRules.resetCheck()
  364. }
  365. }
  366. }
  367. </script>
  368. <style lang="scss" scoped>
  369. </style>