creatOrder.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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="20" 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. uuidTemp.traceCodeList.map(item => {
  41. this.addTags(item.traceCode)
  42. })
  43. }
  44. },
  45. onHide() {
  46. this.$store.state.vuex_tempData = null
  47. },
  48. methods: {
  49. tagClick(item){
  50. const index = this.uuid.findIndex(k => k.traceCode == item.traceCode)
  51. if(index>=0){
  52. this.uuid.splice(index,1)
  53. }
  54. },
  55. async addTags(){
  56. if(this.uuid.length>=4){
  57. uni.showToast({
  58. icon: 'none',
  59. title: '唯一码一次最多可添加4个,请进行删减后再添加。'
  60. })
  61. return
  62. }
  63. if(this.uuidCode){
  64. this.loading = true
  65. const hasCode = await getTraceCodeQueryList({traceCode: this.uuidCode,pageSize:1,pageNo:1}).then(res => res.data)
  66. console.log(hasCode)
  67. // 已存在,且没有使用过
  68. if(hasCode.count==0){
  69. uni.showToast({
  70. icon: 'none',
  71. title: '唯一码不存在'
  72. })
  73. this.loading = false
  74. return
  75. }
  76. if(hasCode.list && hasCode.list.length > 0){
  77. if(!hasCode.list[0].warrantyState){
  78. this.uuid.push(hasCode.list[0])
  79. }else{
  80. uni.showToast({
  81. icon: 'none',
  82. title: '唯一码已使用'
  83. })
  84. }
  85. }
  86. this.uuidCode = ''
  87. this.loading = false
  88. }else{
  89. uni.showToast({
  90. icon: 'none',
  91. title: '请扫描或手动输入唯一码'
  92. })
  93. }
  94. },
  95. openCamera(){
  96. const _this = this
  97. uni.scanCode({
  98. scanType: ['barCode','datamatrix','pdf417'],
  99. success: function (res) {
  100. // console.log('条码类型:' + res.scanType);
  101. // console.log('条码内容:' + res.result);
  102. // _this.tempImg = ret.filePath
  103. _this.uuidCode = res.result
  104. _this.focusInput = true
  105. }
  106. });
  107. },
  108. saveForm(){
  109. if(this.uuid.length){
  110. if(this.$store.state.vuex_uuidTempData){
  111. this.$store.state.vuex_uuidTempData.traceCodeList = this.uuid
  112. }else{
  113. this.$store.state.vuex_uuidTempData = {traceCodeList: this.uuid}
  114. }
  115. uni.redirectTo({
  116. url: "/pagesA/qualityPolicy/creatCarInfo"
  117. })
  118. }else{
  119. uni.showToast({
  120. icon: 'none',
  121. title: '请先添加唯一码'
  122. })
  123. }
  124. }
  125. }
  126. }
  127. </script>
  128. <style lang="less">
  129. .pages{
  130. height: 100vh;
  131. background: #fff;
  132. .tags-box{
  133. flex-grow: 1;
  134. padding: 1rem;
  135. /deep/ .u-tag{
  136. margin: 0.5rem 1rem;
  137. }
  138. }
  139. .buttons{
  140. padding: 1rem 6rem 3rem;
  141. }
  142. }
  143. .forms{
  144. padding: 1rem 0 0;
  145. > view{
  146. border-bottom: 1px solid #eee;
  147. padding: 0.6rem 1rem;
  148. }
  149. .labes{
  150. width: 5rem;
  151. }
  152. .inputs{
  153. flex-grow: 1;
  154. button{
  155. width: 100%;
  156. }
  157. }
  158. .btns{
  159. width: 3rem;
  160. text-align: center;
  161. image{
  162. width: 1.6rem;
  163. height: 1.6rem;
  164. }
  165. }
  166. }
  167. </style>