租房小程序前端代码
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.

497 lines
15 KiB

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