search.vue 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. <!-- 追溯中心 -->
  2. <template>
  3. <div class="trace">
  4. <div class="search">
  5. <template v-if="!orderListVisible && !productListVisible">
  6. <div>
  7. <el-input :placeholder="codePlaceHoler" v-model.trim="code" class="input-with-select">
  8. <el-select v-model="type" slot="prepend" placeholder="请选择">
  9. <el-option label="任务单" value="1"></el-option>
  10. <el-option label="物料" value="2"></el-option>
  11. </el-select>
  12. <el-button slot="append" type="primary" ref="searchBtn" :loading="searchloading" @click="search()">追溯</el-button>
  13. </el-input>
  14. </div>
  15. </template>
  16. </div>
  17. <!-- 弹窗, 新增 / 修改 -->
  18. <order-list v-if="orderListVisible" :defaultList="defaultOrderList" :orderCode="code" :defaultTotalPage="defaultOrderTotal" ref="orderList" @onChose="onChose"/>
  19. <product-list v-if="productListVisible" :defaultList="defaultProductList" :productCode="code" :defaultTotalPage="defaultProductTotal" ref="productList" @onChose="onChose"></product-list>
  20. </div>
  21. </template>
  22. <script>
  23. import orderList from './order-list'
  24. import ProductList from './product-list'
  25. import { getOrderByCode, getProductByCode } from '@/api/trace'
  26. export default {
  27. name: 'trace-search',
  28. components: {
  29. orderList,
  30. ProductList
  31. },
  32. data () {
  33. return {
  34. type: '1',
  35. code: '',
  36. orderListVisible: false,
  37. productListVisible: false,
  38. searchloading: false,
  39. defaultOrderList: [],
  40. defaultOrderTotal: 0
  41. }
  42. },
  43. created () {
  44. },
  45. methods: {
  46. onChose () {
  47. this.orderListVisible = false
  48. this.productListVisible = false
  49. },
  50. search () {
  51. if (this.code === '') {
  52. this.$message.error('请输入任务单/物料编码')
  53. return
  54. }
  55. this.searchloading = true
  56. let that = this
  57. // 任务单追溯
  58. if (this.type === '1') {
  59. let params = {orderCode: this.code}
  60. getOrderByCode(params).then(({data}) => {
  61. if (data && data.code === '200' && data.data) {
  62. console.log(data)
  63. this.defaultOrderList = data.data.records
  64. this.defaultOrderTotal = data.data.total
  65. this.orderListVisible = true
  66. } else {
  67. that.$message.error(data.msg)
  68. }
  69. }).catch(function (error) {
  70. console.log(error.response.data)
  71. that.$message.error('服务器异常')
  72. }).then(() => {
  73. this.searchloading = false
  74. })
  75. } else if (this.type === '2') { // 物料追溯
  76. let params = {
  77. 'prodCode': this.code
  78. }
  79. // console.log(params)
  80. getProductByCode(params).then(({data}) => {
  81. // console.log(data)
  82. if (data && data.code === '200' && data.data) {
  83. this.defaultProductList = data.data.records
  84. this.defaultProductTotal = data.data.total
  85. this.productListVisible = true
  86. } else {
  87. that.$message.error(data.msg)
  88. }
  89. }).then(() => {
  90. this.searchloading = false
  91. })
  92. }
  93. },
  94. // 详情
  95. detailHandle (id) {
  96. this.detailVisible = true
  97. this.$nextTick(() => {
  98. this.$refs.detail.init(id)
  99. })
  100. }
  101. },
  102. computed: {
  103. codePlaceHoler () {
  104. return this.type === '1'
  105. ? '请输入任务单编码'
  106. : '请输入物料编号'
  107. }
  108. }
  109. }
  110. </script>
  111. <style>
  112. .el-select .el-input {
  113. width: 130px;
  114. }
  115. .input-with-select .el-input-group__prepend {
  116. background-color: #fff;
  117. }
  118. .trace {
  119. width: 100%;
  120. min-height: 711px;
  121. position: relative;
  122. }
  123. .search {
  124. position: absolute;
  125. width: 100%;
  126. top: 50%;
  127. margin-top:-20px
  128. }
  129. </style>