property.vue 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <template>
  2. <view>
  3. <view class="card">
  4. <view class="form">
  5. <view class="flex">
  6. <view class="need">*</view>
  7. <view>所在小区</view>
  8. </view>
  9. <view class="bg-gray padding-20">
  10. <input disabled type="text" placeholder="请选择您所在的小区" v-model="data.residentialName" />
  11. </view>
  12. </view>
  13. <view class="form">
  14. <view class="flex">
  15. <view class="need">*</view>
  16. <view>报修地点</view>
  17. </view>
  18. <view class="bg-gray padding-20 margin-top-20" style="position: relative;">
  19. <input placeholder="报修地点" v-model="data.reportPosition" />
  20. <view @click.stop="roomShow=true" class="cu-btn df bg-blue radius"
  21. style="position: absolute;right: 10rpx;top: 0;bottom: 0;margin:auto;z-index: 99;">
  22. 选择我的房屋
  23. </view>
  24. </view>
  25. </view>
  26. <view class="form ">
  27. <view class="flex">
  28. <view class="need">*</view>
  29. <view>联系方式</view>
  30. </view>
  31. <view class="bg-gray padding-20 " style="position: relative;">
  32. <input maxlength="11" type="number" placeholder="请输入您的联系方式" v-model="data.reportorPhone" />
  33. <button class="cu-btn df bg-blue radius" @getphonenumber="getPhoneNumber" open-type="getPhoneNumber"
  34. style="position: absolute;right: 10rpx;top: 0;bottom: 0;margin:auto;z-index: 99;">
  35. 获取微信电话
  36. </button>
  37. </view>
  38. </view>
  39. <view class="form">
  40. <view class="flex">
  41. <view class="need">*</view>
  42. <view>预约时间</view>
  43. </view>
  44. <view class="bg-gray padding-20" @click="timeShow=true">
  45. <input disabled type="number" placeholder="请选择预约时间" v-model="dateTimeStr" />
  46. </view>
  47. </view>
  48. </view>
  49. <view class="card ">
  50. <view class="form" style="height: 320rpx;">
  51. <view class="bg-gray padding-10">
  52. <u-input v-model="data.reportDetail" type="textarea" maxlength="100" height="240" placeholder="故障描述(必填)"
  53. style="width: 100%;line-height: 50rpx;" />
  54. <view class="text-right text-df text-gray padding-top-10">
  55. {{data.reportDetail.length}} / 100
  56. </view>
  57. </view>
  58. </view>
  59. </view>
  60. <view class="card">
  61. <view class="text-center padding-20">
  62. <text>上传图片(选填,最多四张)</text>
  63. </view>
  64. <view>
  65. <view class="cu-form-group" style="padding: 20rpx 30rpx">
  66. <view class="grid col-4 grid-square flex-sub padding-left-10">
  67. <view class="bg-img" v-for="(item,index) in imgList" :key="index" @click="viewImage(index)">
  68. <image :src="imgList[index]" mode="aspectFill"></image>
  69. <view class="cu-tag bg-red" @click.stop="DelImg(index)">
  70. <text class='cuIcon-close' style="font-size: 20rpx;"></text>
  71. </view>
  72. </view>
  73. <view class="solids" @click="chooseImage" v-if="imgList.length<4">
  74. <text class='cuIcon-add ' style="font-size: 60rpx;color: #c9c9c9;"></text>
  75. </view>
  76. </view>
  77. </view>
  78. </view>
  79. </view>
  80. <view style="height: 160rpx;"></view>
  81. <view style="z-index: 999;" class="footer-fixed" :style="{'margin-bottom': safeAreaBottom+'rpx'}"
  82. @click="submit">
  83. <view class="cu-btn flex text-lg bg-red-btn" style="padding: 46rpx 0;">
  84. 确定提交
  85. </view>
  86. </view>
  87. <u-mask z-index="99999" :show="maskShow" @click="maskShow = false">
  88. <view style="margin: 20rpx;" @click.stop="">
  89. <textarea @confirm="confirm" @keyboardheightchange="keyboardheightchange" v-model="data.reportDetail"
  90. value="" style="background-color: #FFFFFF;width: 100%;padding: 20rpx;box-sizing: border-box;"
  91. placeholder="请对您的问题进行描述(必填)" />
  92. <view class="bg-white text-right text-df text-gray padding-10">
  93. {{data.reportDetail.length}} / 100
  94. </view>
  95. </view>
  96. </u-mask>
  97. <u-popup v-model="timeShow" mode="bottom" border-radius="20" :closeable="true" height="55%">
  98. <time-selector @getDateTime="timeConfirm"></time-selector>
  99. </u-popup>
  100. <u-select v-model="roomShow" :list="roomList" @confirm="roomChange" label-name="fullRoomName"
  101. value-name="fullRoomName"></u-select>
  102. </view>
  103. </template>
  104. <script>
  105. import timeSelector from '@/comps/mp-time/index.vue';
  106. var app = getApp()
  107. export default {
  108. components: {
  109. timeSelector
  110. },
  111. data() {
  112. return {
  113. sessionKey:'',
  114. platform: '',
  115. maskShow: false,
  116. //图片回显
  117. imgList: [],
  118. data: {
  119. //上报人
  120. reportor: '',
  121. //保修电话
  122. reportorPhone: '',
  123. repairName: '',
  124. //故障详情描述
  125. reportDetail: '',
  126. //报事来源,1:小程序,2:后台
  127. reportSource: 1,
  128. //故障位置
  129. reportPosition: '',
  130. //处理状态:待处理
  131. handleStatus: 0,
  132. //小区id
  133. residentialId: '',
  134. //图片描述
  135. pic: '',
  136. //预约时间区间
  137. beginTime: '',
  138. endTime: '',
  139. },
  140. base64_image: [],
  141. roomList: [],
  142. roomShow: false,
  143. residentialShow: false,
  144. defaultValue: [],
  145. residentialList: [],
  146. timeShow: false,
  147. dateTimeStr: ''
  148. }
  149. },
  150. onLoad() {
  151. this.initData()
  152. },
  153. onShow() {
  154. this.data.reportorPhone = getApp().globalData.member.phone
  155. },
  156. methods: {
  157. getPhoneNumber(e) {
  158. if (e.detail.errMsg == "getPhoneNumber:ok") {
  159. let params = {
  160. sessionKey: this.sessionKey,
  161. encryptedData: e.detail.encryptedData,
  162. iv: e.detail.iv
  163. }
  164. this.$http.getOpenData(params).then(res => {
  165. this.data.reportorPhone = res.data.purePhoneNumber
  166. })
  167. return
  168. }
  169. this.$u.toast('获取手机号失败')
  170. },
  171. async getSessionKey(){
  172. let jsCode = await new Promise((resolve, reject) => {
  173. uni.login({
  174. provider: 'weixin',
  175. success: res => {
  176. resolve(res.code);
  177. },
  178. fail: err => {
  179. reject(err);
  180. }
  181. })
  182. })
  183. let params = {
  184. js_code: jsCode,
  185. name: 'community',
  186. app_type: 1
  187. };
  188. let res = await this.$http.getOpenid(params);
  189. this.sessionKey = res.data.session_key
  190. },
  191. initData() {
  192. this.getSessionKey()
  193. //判断是ios还是安卓,ios键盘上移会挤压遮挡层
  194. this.platform = this.$u.os() || "android"
  195. this.data.memberId = app.globalData.member.id
  196. if (this.$isEmpty(this.data.memberId)) {
  197. this.$dialog.showModalAndBack('系统异常')
  198. return
  199. }
  200. //获取用户的userid
  201. this.data.reportor = app.globalData.member ? app.globalData.member.name : '未知'
  202. //从缓存中获取默认的小区名字和小区id
  203. this.data.residentialName = uni.getStorageSync("plotName")
  204. this.data.residentialId = uni.getStorageSync("residentialId")
  205. //获取我的房间
  206. this.getRoomByMemberId()
  207. },
  208. roomChange(e) {
  209. this.data.reportPosition = e[0].value
  210. },
  211. getRoomByMemberId() {
  212. let memberId = this.vuex_member.id
  213. let params = {
  214. residentialId: uni.getStorageSync('residentialId'),
  215. id: memberId
  216. }
  217. this.$http.getRoomByMemberId(params).then(res => {
  218. if (res.data.success) {
  219. this.roomList = res.data.data
  220. this.roomList.forEach(item => {
  221. item.fullRoomName = item.residentialName + "-" + item.buildingName + "-" + item
  222. .unitName + "-" + item.name
  223. })
  224. }
  225. })
  226. },
  227. submit() {
  228. if (this.$isEmpty(this.data.residentialId)) {
  229. this.$u.toast("请选择小区")
  230. return
  231. }
  232. if (this.$isEmpty(this.data.reportPosition)) {
  233. this.$u.toast("请输入报修的具体地点")
  234. return
  235. }
  236. if (this.$isEmpty(this.data.reportorPhone)) {
  237. this.$u.toast("请输入联系方式")
  238. return
  239. }
  240. if (!this.$u.test.mobile(this.data.reportorPhone)) {
  241. this.$u.toast("请输入正确的联系方式")
  242. return
  243. }
  244. if (this.$isEmpty(this.data.beginTime) || this.$isEmpty(this.data.endTime)) {
  245. this.$u.toast("请选择预约时间")
  246. return
  247. }
  248. if (this.$util.createDate(this.data.beginTime).getTime() >
  249. this.$util.createDate(this.data.endTime).getTime()) {
  250. this.$u.toast("开始时间不能小于结束时间")
  251. return
  252. }
  253. if (this.$isEmpty(this.data.reportDetail)) {
  254. this.$u.toast("请对您的问题进行描述")
  255. return
  256. }
  257. this.data.pic = this.base64_image.join(",")
  258. this.$http.addEstateRepair(this.data).then(res => {
  259. if (res.data.success) {
  260. this.$dialog.showModalAndBack('提交成功')
  261. } else {
  262. app.globalData.oneFailHint("提交失败");
  263. }
  264. });
  265. },
  266. showMask() {
  267. if (this.platform != 'ios') {
  268. this.maskShow = true
  269. }
  270. },
  271. confirm() {
  272. this.maskShow = false
  273. },
  274. keyboardheightchange(e) {
  275. if (e.detail.height == 0) {
  276. this.maskShow = false
  277. }
  278. },
  279. timeConfirm(e) {
  280. this.timeShow = false
  281. this.data.beginTime = e.beginTime
  282. this.data.endTime = e.endTime
  283. this.dateTimeStr = this.data.beginTime + " 至 " + this.data.endTime
  284. },
  285. /**
  286. * 上传问题截图
  287. */
  288. async chooseImage() {
  289. let res = await this.$wxApi.chooseImage(4)
  290. if (this.$isEmpty(res)) {
  291. return
  292. }
  293. for (let path of res) {
  294. let url = (await this.$http.uploadFile(path)).data.data.link
  295. this.base64_image.push(url)
  296. this.imgList.push(url)
  297. }
  298. },
  299. /*预览图片*/
  300. viewImage(index) {
  301. uni.previewImage({
  302. urls: this.imgList,
  303. current: index
  304. });
  305. },
  306. /*删除图片*/
  307. DelImg(index) {
  308. uni.showModal({
  309. title: '提示',
  310. content: '确定要删除这张照片吗?',
  311. cancelText: '取消',
  312. confirmText: '确定',
  313. success: res => {
  314. if (res.confirm) {
  315. this.imgList.splice(index, 1)
  316. this.base64_image.splice(index, 1)
  317. }
  318. }
  319. })
  320. },
  321. }
  322. }
  323. </script>
  324. <style lang="scss">
  325. .bg-gray {
  326. background-color: #f7f7f7;
  327. }
  328. .card {
  329. margin: 18rpx;
  330. border-radius: 20rpx;
  331. box-sizing: border-box;
  332. background-color: #FFFFFF;
  333. }
  334. .card .form {
  335. padding: 23rpx;
  336. }
  337. .need {
  338. font-size: 38rpx;
  339. font-weight: 800;
  340. color: #ff0000;
  341. padding-right: 10rpx;
  342. }
  343. </style>