car-manager.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <template>
  2. <view>
  3. <view class="box">
  4. <view class="top">
  5. <text class="title">业务车辆</text>
  6. </view>
  7. <view class="item">
  8. <view class="l"><text style="color: red;">*</text>车牌号:</view>
  9. <view class="r">
  10. <u-input placeholder="输入车牌号" v-model="form.carNo">
  11. </u-input>
  12. </view>
  13. </view>
  14. <view class="item">
  15. <view class="l"><text style="color: red;" v-if="needCarSize==1">*</text>规格(米):</view>
  16. <view class="r">
  17. <u-input placeholder="输入规格" type="number" v-model="form.carSize">
  18. </u-input>
  19. </view>
  20. </view>
  21. <view class="item">
  22. <view class="l">车辆类型:</view>
  23. <view class="r" style="flex: 12;">
  24. <picker v-if="carType.list.length>0" class="p-picker" @change="carTypeChange($event)"
  25. :value="carType.index" :range="carType.list" range-key="name">
  26. <text class="p-text">{{carType.list[carType.index].name}}</text>
  27. </picker>
  28. </view>
  29. </view>
  30. <view class="item" v-if="carType.index==1">
  31. <view class="l"><text style="color: red;" >*</text>载重(kg):</view>
  32. <view class="r">
  33. <u-input placeholder="车辆载重" v-model="form.netWeight">
  34. </u-input>
  35. </view>
  36. </view>
  37. </view>
  38. <view style="margin-top: 50px;">
  39. <u-button type="primary" text="确定" @click="saveFn"></u-button>
  40. <u-button type="info" text="返回" @click="backFn" style="margin-top: 20rpx;"></u-button>
  41. </view>
  42. <!-- ---------------------------------------------------------- -->
  43. <view class="bottom-safety"></view>
  44. </view>
  45. </template>
  46. <script>
  47. export default {
  48. data() {
  49. return {
  50. carType: {
  51. index: 0,
  52. list: []
  53. },
  54. needCarSize: 0,
  55. needWeight: 0,
  56. form: {
  57. carNo: '',
  58. carType: '',
  59. netWeight: '',
  60. carSize: ''
  61. }
  62. }
  63. },
  64. onLoad(options) {
  65. this.form = JSON.parse(options.carJson);
  66. this.needCarSize = options.needCarSize;
  67. this.needWeight = options.needWeight;
  68. this.getCarType();
  69. },
  70. methods: {
  71. getCarType() {
  72. this.$api.getCarType().then(resp => {
  73. let list = resp.data;
  74. this.carType.list = list;
  75. let form=this.form;
  76. let carType=this.form.carType;
  77. if(carType){
  78. this.carType.index=this.carType.list.map(obj=>obj.name).indexOf(carType);
  79. }
  80. })
  81. },
  82. carTypeChange(e) {
  83. var value = e.detail.value; //当前picker选中的值
  84. this.carType.index = value;
  85. },
  86. backFn(){
  87. this.$common.back();
  88. },
  89. saveFn() {
  90. let data = this.form;
  91. if (!data.carNo) {
  92. this.$common.toast('请填写车牌号')
  93. return false;
  94. }
  95. let needCarSize = this.needCarSize;
  96. if (!data.carSize&&needCarSize==1) {
  97. this.$common.toast('请填写车辆规格')
  98. return false;
  99. }
  100. let needWeight = this.needWeight;
  101. if (this.carType.index==1&&(!data.netWeight||data.netWeight<=0)) {
  102. this.$common.toast('请填写车辆载重')
  103. return false;
  104. }
  105. if(this.carType.index==0){
  106. data.netWeight=0;
  107. }
  108. data.carType=this.carType.list[this.carType.index].name;
  109. data.carNo=data.carNo.toUpperCase();
  110. uni.navigateBack({
  111. delta: 1,
  112. success: function(resp) {
  113. uni.$emit('getCar', data) //触发事件
  114. }
  115. })
  116. }
  117. },
  118. }
  119. </script>
  120. <style lang="scss">
  121. page {
  122. background-color: #fff;
  123. }
  124. .save-btn {
  125. background-color: #ff4200;
  126. height: 88rpx;
  127. display: flex;
  128. justify-content: center;
  129. align-items: center;
  130. margin: 60rpx;
  131. color: #fff;
  132. font-size: 30rpx;
  133. font-weight: bold;
  134. border-radius: 10rpx;
  135. }
  136. @import '@/common/common.scss'
  137. </style>