creatOrder.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 && hasCode.count==0){
  83. uni.showToast({
  84. icon: 'none',
  85. title: '唯一码不存在'
  86. })
  87. this.loading = false
  88. return
  89. }
  90. if(hasCode && 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. if(!hasCode){
  101. uni.showToast({
  102. icon: 'none',
  103. title: '系统异常,请联系管理员!'
  104. })
  105. }
  106. this.uuidCode = ''
  107. this.loading = false
  108. }else{
  109. uni.showToast({
  110. icon: 'none',
  111. title: '请扫描或手动输入唯一码'
  112. })
  113. }
  114. },
  115. openCamera(){
  116. const _this = this
  117. uni.scanCode({
  118. scanType: ['barCode','datamatrix','pdf417'],
  119. success: function (res) {
  120. // console.log('条码类型:' + res.scanType);
  121. // console.log('条码内容:' + res.result);
  122. // _this.tempImg = ret.filePath
  123. _this.uuidCode = res.result
  124. _this.focusInput = true
  125. }
  126. });
  127. },
  128. saveForm(){
  129. if(this.uuid.length){
  130. if(this.$store.state.vuex_uuidTempData){
  131. this.$store.state.vuex_uuidTempData.traceCodeList = this.uuid
  132. }else{
  133. this.$store.state.vuex_uuidTempData = {traceCodeList: this.uuid}
  134. }
  135. uni.redirectTo({
  136. url: "/pagesA/qualityPolicy/creatCarInfo"
  137. })
  138. }else{
  139. uni.showToast({
  140. icon: 'none',
  141. title: '请先添加唯一码'
  142. })
  143. }
  144. }
  145. }
  146. }
  147. </script>
  148. <style lang="less">
  149. .pages{
  150. height: 100vh;
  151. background: #fff;
  152. .tags-box{
  153. flex-grow: 1;
  154. padding: 1rem;
  155. /deep/ .u-tag{
  156. margin: 0.5rem 1rem;
  157. }
  158. }
  159. .buttons{
  160. padding: 1rem 6rem 3rem;
  161. }
  162. }
  163. .forms{
  164. padding: 1rem 0 0;
  165. > view{
  166. border-bottom: 1px solid #eee;
  167. padding: 0.6rem 1rem;
  168. }
  169. .labes{
  170. width: 5rem;
  171. }
  172. .inputs{
  173. flex-grow: 1;
  174. button{
  175. width: 100%;
  176. }
  177. }
  178. .btns{
  179. width: 3rem;
  180. text-align: center;
  181. image{
  182. width: 1.6rem;
  183. height: 1.6rem;
  184. }
  185. }
  186. }
  187. </style>