add.vue 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  1. <template>
  2. <view class="" >
  3. <u-toast ref="uToast"/>
  4. <view class="bg-white" style="padding: 10rpx 30rpx;margin: 20rpx;border-radius: 12rpx;">
  5. <u-form :label-style="labelStyle" label-width="150" :model="form" ref="uForm">
  6. <u-form-item label="车主姓名" :required="true"><u-input v-model="form.personName" placeholder="车主姓名"/></u-form-item>
  7. <u-form-item v-if="!$isEmpty(form.id)" label="手机号码" :required="true"><u-input type="number" v-model="form.personPhone" placeholder="请输入手机号码"/></u-form-item>
  8. <u-form-item label="所属小区" :required="true">
  9. <u-input v-if="$isEmpty(form.id)" type="select" :select-open="residentialShow" v-model="residentialName" placeholder="请选择小区" @click="residentialShow=true"></u-input>
  10. <u-input v-else disabled v-model="form.residentialName" ></u-input>
  11. </u-form-item>
  12. <u-form-item label="车牌号" :required="true">
  13. <u-input v-model="form.number" placeholder="请填写车牌号"></u-input>
  14. </u-form-item>
  15. <u-form-item label="车辆型号">
  16. <u-input v-model="form.model" placeholder="请填写车辆型号"></u-input>
  17. </u-form-item>
  18. <u-form-item label="燃油类别">
  19. <u-input v-model="form.fuelCategory" placeholder="请填写燃油类别"></u-input>
  20. </u-form-item>
  21. <u-form-item label="车身颜色">
  22. <u-input v-model="form.color" placeholder="请填写车身颜色"></u-input>
  23. </u-form-item>
  24. <u-form-item label="车辆照片">
  25. <u-input v-model="form.carImg" placeholder="车辆照片"></u-input>
  26. </u-form-item>
  27. </u-form>
  28. </view>
  29. <!-- 小区 -->
  30. <u-popup border-radius="60" height="60%" mode="bottom" v-model="residentialShow">
  31. <view class="fixed cu-bar search bg-white">
  32. <view class="search-form round">
  33. <text class="cuIcon-search"></text>
  34. <u-input style="width: 90%;" v-model="residentialKeyword" type="text" :adjust-position="false" placeholder="请输入关键字搜索" confirm-type="search"/>
  35. </view>
  36. </view>
  37. <scroll-view v-if="!$isEmpty(residentialList)" style="padding-top: 110rpx;height: 100%;" :scroll-y="true" >
  38. <view @click="residentialConfirm(item)" hover-class="hoverClass" class="text-center padding-30 solid-bottom" v-for="(item,index) in residentialList" :key="index">
  39. <text>{{item.name}}</text>
  40. </view>
  41. <u-divider v-if="residentialList.length>=10" height="80">只显示十条数据</u-divider>
  42. </scroll-view>
  43. <u-empty v-else name="search"></u-empty>
  44. </u-popup>
  45. <view @click="confirm" class="bottom-bar" >
  46. <view class="cu-btn bg-blue radius" style="width: 70%;height: 84rpx;">
  47. 提交
  48. </view>
  49. </view>
  50. </view>
  51. </template>
  52. <script>
  53. export default {
  54. name: '',
  55. data() {
  56. return {
  57. labelStyle:{
  58. "fontWeight":"600"
  59. },
  60. form:{
  61. personName:'',
  62. residentialId:'',
  63. personPhone:'',
  64. fuelCategory:'',
  65. number:'',
  66. model:'',
  67. carImg:'',
  68. color:''
  69. },
  70. //小区
  71. residentialName:'',
  72. residentialShow:false,
  73. residentialKeyword:'',
  74. residentialList:[],
  75. };
  76. },
  77. onLoad(options) {
  78. //加载小区数据
  79. this.fetchResidentialList()
  80. if (!this.$isEmpty(options.id)) {
  81. this.form.id=options.id
  82. this.fetchDataDetail()
  83. uni.setNavigationBarTitle({
  84. title:"修改车辆信息"
  85. })
  86. }
  87. },
  88. watch:{
  89. //小区
  90. residentialKeyword(){
  91. let that=this
  92. if (this.timer){
  93. clearTimeout(this.timer)
  94. }
  95. this.timer = setTimeout(() => {
  96. that.residentialList=[]
  97. that.getResidentailList()
  98. }, 500)
  99. },
  100. },
  101. methods:{
  102. fetchDataDetail(){
  103. this.$api.room.pageBycondition({id:this.form.id}).then(res=>{
  104. this.form=res.list[0]
  105. })
  106. },
  107. /**
  108. * 获取小区数据列表
  109. */
  110. fetchResidentialList(){
  111. let params={
  112. isSelect: true,
  113. name:this.residentialKeyword
  114. }
  115. this.$api.residential.page(params).then(res=>{
  116. this.residentialList = res.list
  117. })
  118. },
  119. //点击选择小区时
  120. residentialConfirm(item){
  121. //赋值给提交的数据
  122. this.form.residentialId=item.id
  123. //赋值给回显的名称
  124. this.residentialName=item.name
  125. let params={
  126. residentialId:item.id
  127. }
  128. this.residentialShow=false
  129. },
  130. showBuilding(){
  131. if (this.$isEmpty(this.residentialName)) {
  132. this.$showToast('请先选择小区','warning')
  133. return
  134. }
  135. this.buildingShow=true
  136. },
  137. confirm(){
  138. if (this.$isEmpty(this.form.personName)) {
  139. this.$u.toast('请输入车主姓名')
  140. return
  141. }
  142. if (this.$isEmpty(this.form.residentialId)) {
  143. this.$u.toast("请选择小区")
  144. return
  145. }
  146. console.log(this.form);
  147. if (this.$isEmpty(this.form.id)) {
  148. return
  149. this.$api.room.add(this.form).then(res=>{
  150. if (res.data) {
  151. this.$dialog.showModal('操作成功',false).then(res=>{
  152. uni.navigateBack()
  153. })
  154. }else{
  155. this.$u.toast('操作失败')
  156. }
  157. })
  158. //新增
  159. }else{
  160. let {oldId,orgPosition,...params}=this.form
  161. //修改
  162. this.$api.room.update(params).then(res=>{
  163. if (res.data==true) {
  164. this.$dialog.showModal('操作成功',false).then(res=>{
  165. uni.navigateBack()
  166. })
  167. }else{
  168. this.$u.toast('操作失败')
  169. }
  170. })
  171. }
  172. }
  173. }
  174. };
  175. </script>
  176. <style lang="scss" scoped>
  177. page{
  178. background-color: #FFFFFF;
  179. }
  180. </style>