creatOrder.vue 4.0 KB

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