租房小程序前端代码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

478 lines
15 KiB

  1. <template>
  2. <view class="container">
  3. <view class="header">
  4. <view class="title">其他农村资源录入</view>
  5. </view>
  6. <view class="form-container">
  7. <uv-form labelPosition="left" :model="form" :rules="rules" ref="form" labelWidth="80" labelStyle="font-size:28rpx;">
  8. <!-- 必填项 -->
  9. <view class="section-title">基本信息必填</view>
  10. <!-- 1. 出租/流转 -->
  11. <uv-form-item label="类型" prop="type" required>
  12. <uv-radio-group v-model="form.type" placement="row">
  13. <uv-radio name="rent" label="出租"></uv-radio>
  14. <uv-radio name="transfer" customStyle="margin-left:30rpx;" label="流转"></uv-radio>
  15. </uv-radio-group>
  16. </uv-form-item>
  17. <!-- 2. 地址 -->
  18. <uv-form-item label="地址" prop="address" required @click="handleAddressSelect()">
  19. <uv-input v-model="form.address" @click="handleAddressSelect()" disabled disabledColor="#ffffff" placeholder="请选择资源位置" border="none">
  20. </uv-input>
  21. <template v-slot:right>
  22. <uv-icon name="arrow-right"></uv-icon>
  23. </template>
  24. </uv-form-item>
  25. <!-- 3. 联系人和电话 -->
  26. <uv-form-item label="联系人" prop="contactName" required>
  27. <uv-input v-model="form.contactName" type="text" placeholder="请输入联系人姓名" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
  28. </uv-form-item>
  29. <uv-form-item label="联系电话" prop="contactPhone" required>
  30. <uv-input v-model="form.contactPhone" type="number" placeholder="请输入联系电话" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;"></uv-input>
  31. </uv-form-item>
  32. <!-- 4. 照片和视频 -->
  33. <uv-form-item label="资源照片" labelWidth="250" prop="images" labelPosition="top" required>
  34. <view class="upload-tip">请上传资源相关照片</view>
  35. <uv-upload customStyle="margin-top:20rpx;" :fileList="form.images" @afterRead="afterImageRead" @delete="deleteImagePic" name="1"
  36. multiple :maxCount="10"></uv-upload>
  37. </uv-form-item>
  38. <uv-form-item label="资源视频" labelWidth="250" prop="videos" labelPosition="top" required>
  39. <view class="upload-tip">请上传资源视频1分钟内</view>
  40. <uv-upload customStyle="margin-top:20rpx;" accept="video" :fileList="form.videos" @afterRead="afterVideoRead" @delete="deleteVideoPic" name="1"
  41. multiple :maxCount="3"></uv-upload>
  42. </uv-form-item>
  43. <!-- 5. 价格 -->
  44. <uv-form-item label="价格" prop="price" required>
  45. <view class="price-container">
  46. <uv-input v-model="form.price" type="text" placeholder="请描述价格,如:面议、1000元/年等" customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:5px 10px;flex:1;"></uv-input>
  47. </view>
  48. <view class="input-tip">开放式填写可填写具体价格或"面议"</view>
  49. </uv-form-item>
  50. <!-- 6. 资源介绍 -->
  51. <uv-form-item label="资源介绍" prop="description" labelPosition="top" required>
  52. <uv-input
  53. v-model="form.description"
  54. type="textarea"
  55. placeholder="请详细介绍资源类型、用途、特色、优势等信息"
  56. customStyle="border-radius: 5px;margin-top:5px;background-color: #f5f5f5;padding:10px;"
  57. :autoHeight="true"
  58. :maxlength="1000"
  59. ></uv-input>
  60. <view class="char-count">{{form.description.length}}/1000</view>
  61. <view class="input-tip">请详细描述资源的类型用途特色规模优势等</view>
  62. </uv-form-item>
  63. <!-- 分类标识 -->
  64. <uv-form-item label="分类标识" prop="classId" @click="handleClass()">
  65. <uv-input v-model="form.className" @click="handleClass()" disabled disabledColor="#ffffff" placeholder="选择分类标识" border="none">
  66. </uv-input>
  67. <template v-slot:right>
  68. <uv-icon name="arrow-right"></uv-icon>
  69. </template>
  70. </uv-form-item>
  71. <!-- 代理协议 -->
  72. <view class="section-title">代理协议</view>
  73. <view class="agreement-container">
  74. <view class="agreement-content">
  75. <text class="agreement-title">代理协议</text>
  76. <text class="agreement-text">
  77. 本人同意授权我平台发布信息代理销售等本人承诺所提供的信息真实有效并同意平台进行相关推广和销售代理
  78. </text>
  79. </view>
  80. <uv-checkbox v-model="form.agreeProtocol" shape="circle" activeColor="#1EC77A">
  81. <text class="agreement-label">我已阅读并同意代理协议</text>
  82. </uv-checkbox>
  83. </view>
  84. <uv-form-item>
  85. <uv-button type="primary" text="提交信息" customStyle="margin-top: 30px;background-color: #1EC77A;border-radius: 30px;" @click="submit"></uv-button>
  86. </uv-form-item>
  87. </uv-form>
  88. </view>
  89. <!-- 分类选择器 -->
  90. <uv-picker ref="picker" :columns="columns" @confirm="confirm"></uv-picker>
  91. </view>
  92. </template>
  93. <script>
  94. import { saveOrUpdateHouse, houseType } from "@/common/api.js"
  95. export default {
  96. data() {
  97. return {
  98. commonClass: '', // 所属分类ID
  99. form: {
  100. type: '', // 出租/流转
  101. address: '', // 地址
  102. contactName: '', // 联系人
  103. contactPhone: '', // 联系电话
  104. images: [], // 资源照片
  105. videos: [], // 资源视频
  106. price: '', // 价格(开放式)
  107. description: '', // 资源介绍
  108. agreeProtocol: false, // 同意代理协议
  109. longitude: '', // 经度
  110. latitude: '', // 纬度
  111. classId: '', // 分类标识
  112. className: '' // 分类名称
  113. },
  114. columns: [], // 分类选择器数据
  115. houseTypeList: [], // 分类列表
  116. rules: {
  117. type: [
  118. { required: true, message: '请选择出租或流转', trigger: ['blur', 'change'] }
  119. ],
  120. address: [
  121. { required: true, message: '请选择资源地址', trigger: ['blur', 'change'] }
  122. ],
  123. contactName: [
  124. { required: true, message: '请输入联系人姓名', trigger: ['blur', 'change'] }
  125. ],
  126. contactPhone: [
  127. { required: true, message: '请输入联系电话', trigger: ['blur', 'change'] },
  128. { pattern: /^1[3-9]\d{9}$/, message: '请输入正确的手机号码', trigger: ['blur', 'change'] }
  129. ],
  130. price: [
  131. { required: true, message: '请输入价格信息', trigger: ['blur', 'change'] }
  132. ],
  133. description: [
  134. { required: true, message: '请输入资源介绍', trigger: ['blur', 'change'] },
  135. { min: 10, message: '资源介绍至少需要10个字符', trigger: ['blur', 'change'] }
  136. ],
  137. classId: [
  138. { required: true, message: '请选择分类标识', trigger: ['blur', 'change'] }
  139. ]
  140. }
  141. }
  142. },
  143. onReady() {
  144. this.$refs.form.setRules(this.rules)
  145. },
  146. onLoad(options) {
  147. // 设置页面标题
  148. uni.setNavigationBarTitle({
  149. title: '其他农村资源录入'
  150. })
  151. // 接收传递的commonClass参数
  152. if(options.commonClass) {
  153. this.commonClass = options.commonClass
  154. }
  155. // 如果是编辑模式,设置classId用于回显
  156. if(options.classId) {
  157. this.form.classId = options.classId
  158. }
  159. // 初始化分类数据
  160. this.onHouseType()
  161. },
  162. methods: {
  163. // 获取分类数据
  164. onHouseType(){
  165. let that = this
  166. houseType({}).then(response=>{
  167. let arr=[]
  168. that.houseTypeList = response.result
  169. response.result.forEach(items=>{
  170. arr.push(items.title)
  171. // 数据回显:如果当前classId匹配,设置className
  172. if(items.id == that.form.classId){
  173. that.form.className = items.title
  174. }
  175. })
  176. that.columns[0]=arr
  177. }).catch(error=>{
  178. })
  179. },
  180. // 地址选择
  181. handleAddressSelect() {
  182. const that = this;
  183. wx.chooseLocation({
  184. success: function (res) {
  185. console.log('选择的位置:', res);
  186. that.form.longitude = res.longitude
  187. that.form.latitude = res.latitude
  188. that.form.address = res.address
  189. }
  190. })
  191. },
  192. // 资源照片上传
  193. async afterImageRead(e) {
  194. let self = this
  195. e.file.forEach(file => {
  196. self.$Oss.ossUpload(file.url).then(url => {
  197. self.form.images.push({
  198. url
  199. })
  200. })
  201. })
  202. },
  203. deleteImagePic(event) {
  204. this.form.images.splice(event.index, 1)
  205. },
  206. // 视频上传
  207. async afterVideoRead(e) {
  208. let self = this
  209. e.file.forEach(file => {
  210. self.$Oss.ossUpload(file.url).then(url => {
  211. self.form.videos.push({
  212. url
  213. })
  214. })
  215. })
  216. },
  217. deleteVideoPic(event) {
  218. this.form.videos.splice(event.index, 1)
  219. },
  220. // 分类选择
  221. handleClass() {
  222. this.$refs.picker.open();
  223. },
  224. confirm(e) {
  225. let that = this
  226. let {indexs,value,values} = e
  227. that.form.classId = that.houseTypeList[indexs[0]].id;
  228. that.form.className = that.houseTypeList[indexs[0]].title;
  229. },
  230. // 提交表单
  231. submit() {
  232. // 检查是否同意代理协议
  233. if (!this.form.agreeProtocol) {
  234. uni.showToast({
  235. title: '请先同意代理协议',
  236. icon: 'none'
  237. });
  238. return;
  239. }
  240. this.$refs.form.validate().then(res => {
  241. // 验证必填的图片和视频
  242. if (this.form.images.length === 0) {
  243. uni.showToast({
  244. title: '请上传资源照片',
  245. icon: 'none'
  246. });
  247. return;
  248. }
  249. if (this.form.videos.length === 0) {
  250. uni.showToast({
  251. title: '请上传资源视频',
  252. icon: 'none'
  253. });
  254. return;
  255. }
  256. // 构建与index.vue兼容的提交参数
  257. const params = {
  258. userId: uni.getStorageSync('userInfo')?.id || "",
  259. id: "", // 新增数据,无ID
  260. classId: this.form.classId, // 使用分类标识
  261. commonClass: this.commonClass, // 所属分类
  262. address: this.form.address, // 地址
  263. homeAge: "", // 户主年龄 - 其他资源无此字段
  264. homeAz: "", // 是否经过安置 - 默认否
  265. homeBian: "", // 房屋周边 - 其他资源无此字段
  266. homeBjsx: "", // 报建手续 - 其他资源无此字段
  267. homeCai: "", // 菜地 - 其他资源无此字段
  268. homeCat: "", // 停车 - 其他资源无此字段
  269. homeGz: "", // 房屋主体是否改造 - 默认否
  270. homeHb: "", // 房屋朝向及海拔 - 其他资源无此字段
  271. homeBz: this.form.description, // 备注 - 使用资源介绍
  272. homeJg: "其他农村资源", // 房屋结构 - 使用固定值
  273. homeJl: "", // 距离场镇距离 - 其他资源无此字段
  274. homeJt: "", // 交通 - 其他资源无此字段
  275. homeJtzy: "", // 户主家庭职业 - 其他资源无此字段
  276. homeMi: "", // 面积 - 其他资源无此字段
  277. homeMj: "", // 房屋面积 - 其他资源无此字段
  278. homeMoney: "", // 佣金 - 其他资源无此字段
  279. homeNo: "", // 房屋编号 - 其他资源无此字段
  280. homeNum: "", // 房间数量 - 其他资源无此字段
  281. homePay: this.form.price, // 付款方式及押金 - 使用价格信息
  282. homePj: "", // 邻居对房东评价 - 其他资源无此字段
  283. homeSd: "", // 水电气网 - 其他资源无此字段
  284. homeShjl: "", // 距离成都西三环 - 其他资源无此字段
  285. homeSw: "", // 非正常死亡 - 默认无
  286. homeTf: "", // 府市民云房屋信息档案查询 - 其他资源无此字段
  287. homeTime: "", // 租期 - 其他资源无此字段
  288. homeType: this.form.type === 'rent' ? '出租' : '流转', // 户型 - 使用类型
  289. homeYs: "", // 钥匙 - 默认无
  290. homeYzmj: "", // 院子总面积 - 其他资源无此字段
  291. homeZy: "", // 坟包及电塔 工厂噪音 - 其他资源无此字段
  292. iconName: "其他农村资源", // 热点名称
  293. iconTitle: "其他资源", // 标签
  294. num: "0", // 浏览量 - 默认0
  295. price: this.form.price, // 价格
  296. timeGo: "", // 年限 - 其他资源无此字段
  297. title: `${this.form.type === 'rent' ? '出租' : '流转'}-其他农村资源-${this.form.address.split('市')[1] || this.form.address}`, // 标题 - 自动生成
  298. unit: "", // 单位 - 其他资源价格单位灵活
  299. image: this.form.images.map(item => item.url).join(','), // 图片 - 使用资源照片
  300. iconImage: "", // 左上角图标
  301. homeImage: "", // 产权证照片 - 其他资源可能无产权证
  302. homeMp4: this.form.videos.map(item => item.url).join(','), // 视频
  303. latitude: this.form.latitude,
  304. longitude: this.form.longitude,
  305. // 新增字段用于标识其他资源
  306. category: 'other',
  307. contactName: this.form.contactName,
  308. contactPhone: this.form.contactPhone
  309. };
  310. console.log('其他资源提交参数:', params);
  311. uni.showLoading({
  312. title: '提交中...'
  313. });
  314. // 调用统一API
  315. saveOrUpdateHouse(params).then(response => {
  316. uni.hideLoading();
  317. uni.showToast({
  318. title: response.message || '提交成功',
  319. icon: 'success'
  320. });
  321. setTimeout(() => {
  322. uni.redirectTo({
  323. url: "/pages_subpack/successful-apply/index"
  324. });
  325. }, 2000);
  326. }).catch(error => {
  327. uni.hideLoading();
  328. uni.showToast({
  329. title: error.message || '提交失败',
  330. icon: 'none'
  331. });
  332. console.error('其他资源提交失败:', error);
  333. });
  334. }).catch(errors => {
  335. console.log('表单验证失败:', errors);
  336. uni.showToast({
  337. title: '请补全必填项',
  338. icon: 'none'
  339. });
  340. });
  341. }
  342. }
  343. }
  344. </script>
  345. <style scoped>
  346. .container {
  347. min-height: 100vh;
  348. background-color: #f5f5f5;
  349. }
  350. .header {
  351. background: linear-gradient(135deg, #1EC77A 0%, #4CAF50 100%);
  352. padding: 40rpx 40rpx 60rpx;
  353. color: white;
  354. }
  355. .title {
  356. font-size: 36rpx;
  357. font-weight: bold;
  358. text-align: center;
  359. }
  360. .form-container {
  361. background: white;
  362. margin: -30rpx 20rpx 20rpx;
  363. border-radius: 20rpx;
  364. padding: 40rpx;
  365. box-shadow: 0 4rpx 20rpx rgba(0,0,0,0.1);
  366. }
  367. .section-title {
  368. font-size: 32rpx;
  369. font-weight: bold;
  370. color: #333;
  371. margin: 40rpx 0 30rpx;
  372. padding-left: 20rpx;
  373. border-left: 6rpx solid #1EC77A;
  374. }
  375. .section-title:first-child {
  376. margin-top: 0;
  377. }
  378. .input-tip {
  379. font-size: 22rpx;
  380. color: #999;
  381. margin-top: 10rpx;
  382. line-height: 1.4;
  383. }
  384. .upload-tip {
  385. font-size: 24rpx;
  386. color: #666;
  387. margin-bottom: 10rpx;
  388. line-height: 1.5;
  389. }
  390. .price-container {
  391. display: flex;
  392. align-items: center;
  393. gap: 10rpx;
  394. }
  395. .char-count {
  396. font-size: 22rpx;
  397. color: #999;
  398. text-align: right;
  399. margin-top: 10rpx;
  400. }
  401. .agreement-container {
  402. margin: 30rpx 0;
  403. padding: 30rpx;
  404. background: #f8f9fa;
  405. border-radius: 15rpx;
  406. border: 2rpx solid #e9ecef;
  407. }
  408. .agreement-content {
  409. margin-bottom: 30rpx;
  410. }
  411. .agreement-title {
  412. display: block;
  413. font-size: 28rpx;
  414. font-weight: bold;
  415. color: #333;
  416. margin-bottom: 20rpx;
  417. }
  418. .agreement-text {
  419. display: block;
  420. font-size: 24rpx;
  421. color: #666;
  422. line-height: 1.6;
  423. }
  424. .agreement-label {
  425. font-size: 26rpx;
  426. color: #333;
  427. margin-left: 10rpx;
  428. }
  429. </style>