search.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <!-- 追溯中心 -->
  2. <template>
  3. <div class="trace">
  4. <template v-if="!orderListVisible">
  5. <div style="margin-top: 15px;">
  6. <el-input :placeholder="codePlaceHoler" v-model.trim="code" class="input-with-select">
  7. <el-select v-model="type" slot="prepend" placeholder="请选择">
  8. <el-option label="订单" value="1"></el-option>
  9. <el-option label="产品" value="2"></el-option>
  10. </el-select>
  11. <el-button slot="append" type="primary" ref="searchBtn" :loading="searchloading" @click="search()">追溯</el-button>
  12. </el-input>
  13. </div>
  14. </template>
  15. <!-- 弹窗, 新增 / 修改 -->
  16. <order-list v-if="orderListVisible" :defaultList="defaultOrderList" :orderCode="code" :defaultTotalPage="defaultOrderTotal" ref="orderList" @onChose="onChose"/>
  17. </div>
  18. </template>
  19. <script>
  20. import orderList from './order-list'
  21. import { getOrderByCode, getProductById } from '@/api/trace'
  22. export default {
  23. name: 'trace-search',
  24. components: {
  25. orderList
  26. },
  27. data () {
  28. return {
  29. type: '1',
  30. code: '',
  31. orderListVisible: false,
  32. searchloading: false,
  33. defaultOrderList: [],
  34. defaultOrderTotal: 0
  35. }
  36. },
  37. created () {
  38. },
  39. methods: {
  40. onChose () {
  41. this.orderListVisible = false
  42. },
  43. search () {
  44. if (this.code === '') {
  45. this.$message.error('请输入订单/产品编码')
  46. return
  47. }
  48. this.searchloading = true
  49. let that = this
  50. if (this.type === '1') {
  51. let params = {orderCode: this.code}
  52. getOrderByCode(params).then(({data}) => {
  53. if (data && data.code === '200' && data.data) {
  54. console.log(data)
  55. this.defaultOrderList = data.data.records
  56. this.defaultOrderTotal = data.data.total
  57. this.orderListVisible = true
  58. } else {
  59. that.$message.error(data.msg)
  60. }
  61. }).catch(function (error) {
  62. console.log(error.response.data)
  63. that.$message.error('未找到任何数据')
  64. }).then(() => {
  65. this.searchloading = false
  66. })
  67. } else if (this.type === '2') {
  68. getProductById(this.code).then(({data}) => {
  69. if (data && data.code === '200') {
  70. }
  71. }).then(() => {
  72. this.searchloading = false
  73. })
  74. }
  75. },
  76. // 详情
  77. detailHandle (id) {
  78. this.detailVisible = true
  79. this.$nextTick(() => {
  80. this.$refs.detail.init(id)
  81. })
  82. }
  83. },
  84. computed: {
  85. codePlaceHoler () {
  86. return this.type === '1'
  87. ? '请输入订单编码'
  88. : '请输入产品编号'
  89. }
  90. }
  91. }
  92. </script>
  93. <style>
  94. .el-select .el-input {
  95. width: 130px;
  96. }
  97. .input-with-select .el-input-group__prepend {
  98. background-color: #fff;
  99. }
  100. </style>