car-manager.vue 3.9 KB

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