creatOrder.vue 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. <template>
  2. <view class="pages flex flex_column">
  3. <view class="forms">
  4. <view class="flex align_center">
  5. <view class="labes">扫描唯一码:</view>
  6. <view class="inputs"><image style="width: 100%;height: 35px;background: #eaeaea;" :src="tempImg"></image></view>
  7. <view class="btns" @click="openCamera"><image src="../../static/tab/tab_scan_normal.png"></image></view>
  8. </view>
  9. <view class="flex align_center">
  10. <view class="labes">识别唯一码:</view>
  11. <view class="inputs"><u-input :focus="focusInput" v-model="uuidCode" maxlength="10" border clearable type="text" placeholder="请输入唯一码"></u-input></view>
  12. <view class="btns"><u-button :loading="loading" type="primary" size="mini" @click="addTags">添加</u-button></view>
  13. </view>
  14. </view>
  15. <view class="tags-box">
  16. <u-tag v-for="item in uuid" :key="item.id" :text="item.traceCode" closeable @close="tagClick(item)" />
  17. </view>
  18. <view class="buttons">
  19. <u-button type="primary" @click="saveForm">确定</u-button>
  20. </view>
  21. </view>
  22. </template>
  23. <script>
  24. import { getTraceCodeQueryList } from '@/api/trace'
  25. export default {
  26. data() {
  27. return {
  28. tempImg: '',
  29. uuidCode: '',
  30. uuid: [],
  31. focusInput: false,
  32. loading: false
  33. }
  34. },
  35. onShow() {
  36. const uuidTemp = this.$store.state.vuex_uuidTempData
  37. // 如果有未完成的质保单
  38. if(uuidTemp && uuidTemp.traceCodeList){
  39. this.uuid = uuidTemp.traceCodeList
  40. }
  41. // 识别结束
  42. const ret = this.$store.state.vuex_tempData
  43. if(ret&&ret.retCode){
  44. this.tempImg = ret.filePath
  45. this.uuidCode = ret.retCode
  46. }
  47. this.focusInput = ret&&ret=="inputCode"
  48. },
  49. onHide() {
  50. this.$store.state.vuex_tempData = null
  51. },
  52. methods: {
  53. tagClick(item){
  54. const index = this.uuid.findIndex(k => k.traceCode == item.traceCode)
  55. if(index>=0){
  56. this.uuid.splice(index,1)
  57. }
  58. },
  59. async addTags(){
  60. if(this.uuid.length>=4){
  61. uni.showToast({
  62. icon: 'none',
  63. title: '唯一码一次最多可添加4个,请进行删减后再添加。'
  64. })
  65. return
  66. }
  67. if(this.uuidCode){
  68. this.loading = true
  69. const hasCode = await getTraceCodeQueryList({traceCode: this.uuidCode,pageSize:1,pageNo:1}).then(res => res.data)
  70. console.log(hasCode)
  71. // 已存在,且没有使用过
  72. if(hasCode.count==0){
  73. uni.showToast({
  74. icon: 'none',
  75. title: '唯一码不存在'
  76. })
  77. this.loading = false
  78. return
  79. }
  80. if(hasCode.list && hasCode.list.length > 0 && !hasCode.list[0].warrantyState){
  81. this.uuid.push(hasCode.list[0])
  82. }
  83. this.uuidCode = ''
  84. this.loading = false
  85. }else{
  86. uni.showToast({
  87. icon: 'none',
  88. title: '请扫描或手动输入唯一码'
  89. })
  90. }
  91. },
  92. openCamera(){
  93. uni.navigateTo({
  94. url: "/pages/scan-frame/scan-frame?pageType=UUID"
  95. })
  96. },
  97. saveForm(){
  98. if(this.uuid.length){
  99. this.$store.state.vuex_uuidTempData = {traceCodeList:this.uuid}
  100. uni.redirectTo({
  101. url: "/pagesA/qualityPolicy/creatCarInfo"
  102. })
  103. }else{
  104. uni.showToast({
  105. icon: 'none',
  106. title: '请扫描或手动输入唯一码'
  107. })
  108. }
  109. }
  110. }
  111. }
  112. </script>
  113. <style lang="less">
  114. .pages{
  115. height: 100vh;
  116. background: #fff;
  117. .tags-box{
  118. flex-grow: 1;
  119. padding: 1rem;
  120. /deep/ .u-tag{
  121. margin: 0.5rem 1rem;
  122. }
  123. }
  124. .buttons{
  125. padding: 1rem 6rem 3rem;
  126. }
  127. }
  128. .forms{
  129. padding: 1rem 0 0;
  130. > view{
  131. border-bottom: 1px solid #eee;
  132. padding: 0.6rem 1rem;
  133. }
  134. .labes{
  135. width: 5rem;
  136. }
  137. .inputs{
  138. flex-grow: 1;
  139. }
  140. .btns{
  141. width: 3rem;
  142. text-align: center;
  143. image{
  144. width: 1.6rem;
  145. height: 1.6rem;
  146. }
  147. }
  148. }
  149. </style>