form.vue 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448
  1. <script>
  2. import * as TranslateImage from '../../utils/imageZip.js'
  3. import '../../static/upload-imgs.css'
  4. import MxDatePicker from '@/components/mx-datepicker'
  5. export default {
  6. components: {
  7. MxDatePicker,
  8. },
  9. data() {
  10. return {
  11. imageStyles: {
  12. width: 75,
  13. height: 75,
  14. border: {
  15. color: '#ccc',
  16. width: 1,
  17. style: 'dashed',
  18. radius: '5px',
  19. },
  20. },
  21. imageList: [], //保存图片路径集合
  22. List: [],
  23. index: '',
  24. faultName: null,
  25. pickerData: '',
  26. buildId: 1,
  27. floorId: 1,
  28. roomId: 1,
  29. formData: {
  30. phone: '',
  31. inputphone: '',
  32. os: '',
  33. },
  34. showPicker: false,
  35. datetime: '',
  36. rangetime: '',
  37. type: 'rangetime',
  38. timeValue: '',
  39. imgs: null,
  40. imageValue: [],
  41. ceshiData1: [],
  42. Timer: null,
  43. room_List: [[], [], []],
  44. roomIndex: null,
  45. IdList: [],
  46. IdList2: [],
  47. count: 0,
  48. count2: 0,
  49. dormNumber: null,
  50. fontnum: 0,
  51. }
  52. },
  53. onLoad() {
  54. this.getStudentInformation()
  55. this.getTime()
  56. this.getfault()
  57. this.getbuild()
  58. this.getbuildHigh()
  59. this.getrooms()
  60. },
  61. methods: {
  62. // 获取学生数据
  63. getStudentInformation() {
  64. let res = uni.getStorageSync('student')
  65. // console.log(res)
  66. if (res) {
  67. this.formData.phone = res.studentPhone
  68. this.formData.inputphone = res.studentOtherPhone
  69. this.dormNumber = res.dormNumber
  70. }
  71. },
  72. //统计textarea字数
  73. sumfrontnum(e) {
  74. console.log(e)
  75. this.fontnum = e.detail.value.length
  76. },
  77. // 初始化时间
  78. getTime() {
  79. let date = new Date(),
  80. year = date.getFullYear(),
  81. month = date.getMonth() + 1,
  82. day = date.getDate(),
  83. hour = date.getHours() < 10 ? '0' + date.getHours() : date.getHours(),
  84. minute = date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes(),
  85. second = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds()
  86. month >= 1 && month <= 9 ? (month = '0' + month) : ''
  87. day >= 0 && day <= 9 ? (day = '0' + day) : ''
  88. let timer = year + '-' + month + '-' + day + ' ' + hour + ':' + minute + ':' + second
  89. this.datetime = timer
  90. },
  91. // 获取故障类型信息
  92. async getfault() {
  93. let res = await this.$myRequest({
  94. method: 'post',
  95. url: `/fault/queryAllFaultByStatus`,
  96. })
  97. // console.log(res)
  98. this.$nextTick(() => {
  99. this.List = res.data
  100. })
  101. },
  102. // 获取宿舍楼栋数据
  103. async getbuild() {
  104. let res = await this.$myRequest({
  105. method: 'post',
  106. url: `/build/queryAllBuild`,
  107. })
  108. // console.log(res)
  109. let tempList = []
  110. res.data.forEach((item) => {
  111. tempList.push(item.buildName)
  112. console.log('bulidid' + item.buildId)
  113. })
  114. this.$nextTick(() => {
  115. this.$set(this.room_List, 0, tempList)
  116. })
  117. },
  118. // 获取宿舍楼层数据
  119. async getbuildHigh() {
  120. let res = await this.$myRequest({
  121. method: 'post',
  122. url: `/build/queryAllFloorByBuildID?buildId=${this.buildId}`,
  123. })
  124. // console.log(res)
  125. this.room_List[1] = []
  126. this.room_List[2] = []
  127. this.IdList = []
  128. let tempList = []
  129. res.data.forEach((item) => {
  130. tempList.push(item.floorName)
  131. this.IdList.push(item.floorId)
  132. console.log('floorid' + item.floorId)
  133. })
  134. this.$nextTick(() => {
  135. this.$set(this.room_List, 1, tempList)
  136. this.floorId = this.IdList[this.count]
  137. })
  138. },
  139. // 获取宿舍房间数据
  140. async getrooms() {
  141. let res = await this.$myRequest({
  142. method: 'post',
  143. url: `/build/queryAllRoomByFloorID?floorId=${this.floorId}`,
  144. })
  145. // console.log(res)
  146. this.room_List[2] = []
  147. this.IdList2 = []
  148. let tempList = []
  149. res.data.forEach((item) => {
  150. tempList.push(item.roomName)
  151. this.IdList2.push(item.roomId)
  152. console.log('roomid' + item.roomId)
  153. })
  154. this.$nextTick(() => {
  155. this.$set(this.room_List, 2, tempList)
  156. this.roomId = this.IdList2[this.count2]
  157. })
  158. },
  159. // 时间选择框
  160. onShowDatePicker(type) {
  161. this.type = type
  162. this.showPicker = true
  163. this.timeValue = this[type]
  164. },
  165. // 时间选择框点击回调
  166. onSelected(e) {
  167. this.showPicker = false
  168. if (e) {
  169. this[this.type] = e.value
  170. this.timeValue = e.value
  171. }
  172. },
  173. //故障选择
  174. bindPickerChange(e, storage) {
  175. this.index = e.target.value
  176. this.pickerData = storage[this.index] // 这里就是选中的对象
  177. },
  178. // 提交订单
  179. getList() {
  180. console.log('ppppp' + this.buildId + '-' + this.floorId + '-' + this.roomId)
  181. // 处理图片参数数据
  182. this.imgs = this.ceshiData1.join(';')
  183. // 电话验证规则
  184. let phoneVer = /^[1][3,4,5,7,8,9][0-9]{9}$/
  185. // 简单校验
  186. if (this.pickerData.faultId == null) {
  187. uni.showToast({
  188. icon: 'none',
  189. title: '请选择故障类型',
  190. duration: 2000,
  191. })
  192. return
  193. }
  194. if (this.dormNumber == null) {
  195. uni.showToast({
  196. icon: 'none',
  197. title: '请选择楼栋和宿舍号',
  198. duration: 2000,
  199. })
  200. return
  201. }
  202. if (!this.timeValue) {
  203. uni.showToast({
  204. icon: 'none',
  205. title: '请选择预期时间',
  206. duration: 2000,
  207. })
  208. return
  209. }
  210. if (!this.formData.phone) {
  211. uni.showToast({
  212. title: '请输入联系电话',
  213. icon: 'none',
  214. })
  215. return
  216. } else if (!phoneVer.test(this.formData.phone)) {
  217. uni.showToast({
  218. title: '请输入正确的联系电话',
  219. icon: 'none',
  220. })
  221. return
  222. }
  223. uni.showLoading({
  224. title: '提交中',
  225. })
  226. if (this.Timer != null) {
  227. clearTimeout(this.Timer)
  228. }
  229. this.Timer = setTimeout(async () => {
  230. let res = await this.$myRequest({
  231. method: 'post',
  232. url: `/order/insertOrder`,
  233. data: {
  234. faultId: String(this.pickerData.faultId),
  235. dormNumber: this.dormNumber,
  236. orderExpectedTime: this.timeValue,
  237. studentDormitory: this.buildId + '-' + this.floorId + '-' + this.roomId,
  238. orderImages: this.imgs,
  239. orderNote: this.formData.os,
  240. studentPhone: this.formData.phone,
  241. otherPhone: this.formData.inputphone,
  242. },
  243. })
  244. // console.log(res)
  245. if (res.status == 200) {
  246. uni.showToast({
  247. title: '提交成功',
  248. })
  249. uni.reLaunch({
  250. url: '/pages/index/index',
  251. })
  252. } else {
  253. uni.showToast({
  254. title: '提交失败',
  255. icon: 'error',
  256. })
  257. }
  258. }, 1500)
  259. },
  260. // 选择图片压缩并上传
  261. select(e) {
  262. // console.log('选择文件:', e)
  263. e.tempFiles.forEach((item) => {
  264. TranslateImage.translate(item.path, (res) => {
  265. if (Number(res.size) > 1000000) {
  266. this.imageValue = []
  267. uni.showModal({
  268. content: `图片过大,请重新上传`,
  269. showCancel: false,
  270. success() {},
  271. })
  272. return
  273. }
  274. uni.showLoading({
  275. title: '上传中',
  276. })
  277. uni.uploadFile({
  278. url: `/baoxiu/repairApi/order/uploadImage`,
  279. filePath: res.url,
  280. name: 'orderImages',
  281. success: (uploadFileRes) => {
  282. this.ceshiData1.push(JSON.parse(uploadFileRes.data).data)
  283. const path = item.path
  284. this.imageValue.push({
  285. url: path,
  286. name: '',
  287. })
  288. uni.hideLoading()
  289. },
  290. fail: () => {
  291. uni.hideLoading()
  292. },
  293. })
  294. })
  295. })
  296. },
  297. // 删除图片回调
  298. handleDelete(e) {
  299. const num = this.imageValue.findIndex((v) => v.path === e.tempFilePath)
  300. this.imageValue.splice(num, 1)
  301. this.ceshiData1.splice(num, 1)
  302. },
  303. // 三级联动下拉框回调
  304. bindPickerChange_room(e) {
  305. console.log('picker发送选择改变,携带值为', e.detail.value)
  306. this.roomIndex = e.detail.value
  307. this.dormNumber =
  308. this.room_List[0][this.roomIndex[0]] +
  309. this.room_List[1][this.roomIndex[1]] +
  310. this.room_List[2][this.roomIndex[2]]
  311. console.log('mmmmmm' + this.buildId + '-' + this.floorId + '-' + this.roomId)
  312. },
  313. // 三级联动下拉框拖动回调
  314. handleNum(e) {
  315. console.log('第' + (e.detail.column + 1) + '列' + '第' + (e.detail.value + 1) + '行')
  316. if (e.detail.column == 0) {
  317. console.log('楼栋发生变化,当前为' + (e.detail.value + 1) + '栋')
  318. // if (e.detail.value < 4) {
  319. this.buildId = e.detail.value + 1
  320. // } else {
  321. // this.buildId = e.detail.value + 5
  322. // }
  323. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  324. } else if (e.detail.column == 1) {
  325. // console.log("层数发生变化,当前为"+(e.detail.value+1)+"层")
  326. this.floorId = this.IdList[e.detail.value]
  327. this.count = e.detail.value
  328. // console.log(this.buildId + '-' + this.floorId + '-' + this.roomId)
  329. } else {
  330. // console.log("房间数发生变化,当前为"+(e.detail.value+1)+"号")
  331. this.roomId = this.IdList2[e.detail.value]
  332. this.count2 = e.detail.value
  333. console.log('zuizong' + this.buildId + '-' + this.floorId + '-' + this.roomId)
  334. }
  335. },
  336. },
  337. // 监听属性
  338. watch: {
  339. buildId: {
  340. handler() {
  341. this.getbuildHigh()
  342. },
  343. },
  344. floorId: {
  345. handler() {
  346. this.getrooms()
  347. },
  348. },
  349. },
  350. }
  351. </script>
  352. <template>
  353. <view class="form">
  354. <view class="form_item flex items-center justify-between">
  355. <span>宿舍楼栋:</span>
  356. <span v-if="dormNumber">
  357. {{ dormNumber }}
  358. </span>
  359. <span v-else>请选择</span>
  360. <picker
  361. class="picker flex justify-end items-center"
  362. mode="multiSelector"
  363. :value="roomIndex"
  364. :range="room_List"
  365. @change="bindPickerChange_room"
  366. @columnchange="handleNum"
  367. >
  368. <image src="../../static/down.svg"></image>
  369. </picker>
  370. </view>
  371. <view class="form_item flex items-center justify-between">
  372. <span>故障分类:</span>
  373. <span v-if="List != null">
  374. {{ pickerData.faultName == undefined ? '' : pickerData.faultName }}
  375. </span>
  376. <picker
  377. class="picker flex justify-end items-center"
  378. @change="bindPickerChange($event, List)"
  379. :value="index"
  380. :range="List"
  381. :range-key="'faultName'"
  382. >
  383. <image src="../../static/down.svg"></image>
  384. </picker>
  385. </view>
  386. <view class="form_item flex items-center justify-between">
  387. <span>预约时间:</span>
  388. <span>{{ timeValue || '请选择' }}</span>
  389. <view class="picker flex justify-end items-center" @click="onShowDatePicker('datetime')">
  390. <image src="../../static/down.svg"></image>
  391. </view>
  392. </view>
  393. <mx-date-picker
  394. :show="showPicker"
  395. :type="type"
  396. :value="timeValue"
  397. :show-tips="true"
  398. :begin-text="'开始'"
  399. :end-text="'截至'"
  400. :show-seconds="true"
  401. @confirm="onSelected"
  402. @cancel="onSelected"
  403. />
  404. <view class="form_item flex items-center justify-between">
  405. <span>联系电话:</span>
  406. <input type="number" maxlength="11" class="flex-1" v-model="formData.phone" />
  407. </view>
  408. </view>
  409. </template>
  410. <style lang="scss" scoped>
  411. .form {
  412. width: 100%;
  413. padding: 20rpx;
  414. &_item {
  415. height: 80rpx;
  416. border-bottom: 1px solid rgba(166, 166, 166, 0.18);
  417. }
  418. .picker {
  419. flex: 1;
  420. width: 400rpx;
  421. }
  422. image {
  423. max-width: 40rpx;
  424. max-height: 40rpx;
  425. }
  426. }
  427. </style>