creatOrder.vue 4.4 KB

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