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 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.code" :text="item.code" 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. }
  33. },
  34. onShow() {
  35. const uuidTemp = this.$store.state.vuex_uuidTempData
  36. // 如果有未完成的质保单
  37. if(uuidTemp && uuidTemp.traceCodeList){
  38. this.uuid = uuidTemp.traceCodeList
  39. }
  40. // 识别结束
  41. const ret = this.$store.state.vuex_tempData
  42. if(ret&&ret.retCode){
  43. this.tempImg = ret.filePath
  44. this.uuidCode = ret.retCode
  45. }
  46. this.focusInput = ret&&ret=="inputCode"
  47. },
  48. onHide() {
  49. this.$store.state.vuex_tempData = null
  50. },
  51. methods: {
  52. tagClick(item){
  53. const index = this.uuid.findIndex(k => k.code == item.code)
  54. if(index>=0){
  55. this.uuid.splice(index,1)
  56. }
  57. },
  58. async addTags(){
  59. if(this.uuid.length>=4){
  60. uni.showToast({
  61. icon: 'none',
  62. title: '唯一码一次最多可添加4个,请进行删减后再添加。'
  63. })
  64. return
  65. }
  66. if(this.uuidCode){
  67. const hasCode = await getTraceCodeQueryList({traceCode: this.uuidCode,pageSize:1,pageNo:1}).then(res => res.data)
  68. console.log(hasCode)
  69. // 已存在,且没有使用过
  70. if(hasCode.count==0){
  71. uni.showToast({
  72. icon: 'none',
  73. title: '唯一码不存在'
  74. })
  75. return
  76. }
  77. if(hasCode.list && hasCode.list.length > 0 && !hasCode.list[0].warrantyState){
  78. this.uuid.push({
  79. code: this.uuidCode,
  80. name: '箭冠轮胎雪胎RT-8000',
  81. state: ['inhand','outof'][Math.random() < 0.5 ? 0 : 1]
  82. })
  83. }
  84. this.uuidCode = ''
  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>