creatOrder.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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){
  81. if(!hasCode.list[0].warrantyState){
  82. this.uuid.push(hasCode.list[0])
  83. }else{
  84. uni.showToast({
  85. icon: 'none',
  86. title: '唯一码已使用'
  87. })
  88. }
  89. }
  90. this.uuidCode = ''
  91. this.loading = false
  92. }else{
  93. uni.showToast({
  94. icon: 'none',
  95. title: '请扫描或手动输入唯一码'
  96. })
  97. }
  98. },
  99. openCamera(){
  100. uni.navigateTo({
  101. url: "/pages/scan-frame/scan-frame?pageType=UUID"
  102. })
  103. },
  104. saveForm(){
  105. if(this.uuid.length){
  106. if(this.$store.state.vuex_uuidTempData){
  107. this.$store.state.vuex_uuidTempData.traceCodeList = this.uuid
  108. }else{
  109. this.$store.state.vuex_uuidTempData = {traceCodeList: this.uuid}
  110. }
  111. uni.redirectTo({
  112. url: "/pagesA/qualityPolicy/creatCarInfo"
  113. })
  114. }else{
  115. uni.showToast({
  116. icon: 'none',
  117. title: '请扫描或手动输入唯一码'
  118. })
  119. }
  120. }
  121. }
  122. }
  123. </script>
  124. <style lang="less">
  125. .pages{
  126. height: 100vh;
  127. background: #fff;
  128. .tags-box{
  129. flex-grow: 1;
  130. padding: 1rem;
  131. /deep/ .u-tag{
  132. margin: 0.5rem 1rem;
  133. }
  134. }
  135. .buttons{
  136. padding: 1rem 6rem 3rem;
  137. }
  138. }
  139. .forms{
  140. padding: 1rem 0 0;
  141. > view{
  142. border-bottom: 1px solid #eee;
  143. padding: 0.6rem 1rem;
  144. }
  145. .labes{
  146. width: 5rem;
  147. }
  148. .inputs{
  149. flex-grow: 1;
  150. }
  151. .btns{
  152. width: 3rem;
  153. text-align: center;
  154. image{
  155. width: 1.6rem;
  156. height: 1.6rem;
  157. }
  158. }
  159. }
  160. </style>