index.js 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. import $ from './../../utils/Tool'
  2. import router from './../../utils/router'
  3. import {gethouseKeeper,getSpaceAdjustList,submitFeedback} from '../../requests/api';
  4. let timer=null;
  5. Page({
  6. data: {
  7. debunkList:[
  8. {
  9. label:'1',
  10. name:"多次调节无效果"
  11. },
  12. {
  13. label:'2',
  14. name:"噪音大"
  15. },
  16. {
  17. label:'3',
  18. name:"吹风感强"
  19. },
  20. {
  21. label:'4',
  22. name:"有异味"
  23. },
  24. {
  25. label:'5',
  26. name:"空调设备故障"
  27. }
  28. ],
  29. debunkValue:0,
  30. fileList:[],
  31. showUpload:true,
  32. photoType:'', // 0照片 1视频
  33. houseKeeper:null,
  34. spaceId:null,
  35. spaceName:'',
  36. formSearch:false,
  37. imgbaseUrl:$.store.get('imgbaseUrl')
  38. },
  39. goBack(){
  40. router.pop()
  41. },
  42. goHome(){
  43. $.store.set('goHome',true);
  44. router.toHome()
  45. },
  46. chooseSpace(){
  47. router.push('search')
  48. },
  49. makePhoneCall(e){
  50. let phone = e.currentTarget.dataset.phone;
  51. console.log(e)
  52. wx.makePhoneCall({
  53. phoneNumber: phone,
  54. success:function(){
  55. console.log('拨打成功')
  56. },
  57. fail:function(){
  58. console.log('拨打失败')
  59. }
  60. })
  61. },
  62. debunkChange(event){
  63. if(event.detail!==this.data.debunkValue){
  64. this.setData({
  65. debunkValue: event.detail,
  66. });
  67. }else{
  68. this.setData({
  69. debunkValue: 0,
  70. });
  71. }
  72. },
  73. inputChange(e){
  74. let {value} = e.detail;
  75. if(timer){
  76. clearTimeout(timer)
  77. }
  78. timer = setTimeout(()=>{
  79. if(value==null){
  80. //这里表示 如果搜索框中没有数据的话,做的一些处理
  81. }else{
  82. this.setData({suggest:value},()=>{
  83. console.log(this.data.suggest)
  84. })
  85. }
  86. },300)
  87. console.log(e);
  88. // event.detail = {value, cursor, keyCode}
  89. },
  90. uploadVadio(){
  91. const that = this;
  92. wx.chooseMedia({
  93. count: 1,
  94. maxDuration: 15,
  95. sizeType: ['original', 'compressed'], // 可以指定是原图还是压缩图,默认二者都有
  96. sourceType: ['album', 'camera'], // 可以指定来源是相册还是相机,默认二者都有
  97. success: function(res) {
  98. let tempFilePaths = res.tempFiles[0].tempFilePath;
  99. if(tempFilePaths.split('.').pop()==="mp4"){
  100. that.setData({photoType:'1'})
  101. }else{
  102. that.setData({photoType:'0'})
  103. }
  104. let fileList = that.data.fileList.concat(tempFilePaths);
  105. if (fileList.length==1){
  106. that.setData({
  107. showUpload:false
  108. })
  109. }
  110. that.setData({
  111. fileList,
  112. })
  113. }
  114. })
  115. },
  116. uploadFile(){
  117. let fileName = new Date().getTime();
  118. let fileType = this.data.photoType=='0'?'.png':'.mp4';
  119. this.setData({fileName:`${fileName}${fileType}`})
  120. return new Promise((resolve,reject)=>{
  121. wx.uploadFile({
  122. url: `https://duoduoenv.sagacloud.cn/server/common/upload?name=${fileName}${fileType}`,
  123. filePath: this.data.fileList[0],
  124. name: 'file',
  125. success: (resp) => {
  126. console.log(resp);
  127. resolve(resp)
  128. },
  129. fail:(res)=>{
  130. reject(res)
  131. }
  132. })
  133. })
  134. },
  135. clearImg(){
  136. this.setData({fileList:[],showUpload:true,photoType:null})
  137. },
  138. getKeeper(){
  139. let data={
  140. // "criteria": {
  141. // "projectId": $.store.get('projectId'),
  142. "tenantId":$.store.get('tenantId')
  143. // }
  144. }
  145. gethouseKeeper(data).then(res=>{
  146. let {data} = res;
  147. this.setData({houseKeeper:data})
  148. })
  149. },
  150. getFirstSpace(){
  151. const data = {
  152. "criteria": {
  153. "userId": $.store.get('userId'),
  154. "projectId": $.store.get('projectId'),
  155. "tenantId": $.store.get('tenantId')
  156. }
  157. }
  158. getSpaceAdjustList(data).then((res)=>{
  159. if(res.count){
  160. let item = res.content[0];
  161. this.setData({
  162. spaceId:item.id,
  163. spaceName:item.localName
  164. })
  165. }
  166. })
  167. },
  168. async submitFeed(){
  169. if(!this.data.spaceId){
  170. wx.hideLoading();
  171. wx.showToast({
  172. title: '未选择空间',
  173. duration: 1500
  174. })
  175. return
  176. }
  177. if(!this.data.debunkValue&&!this.data.suggest&&!this.data.photoType){
  178. wx.hideLoading();
  179. wx.showToast({
  180. title: '请填写内容!',
  181. icon:'none',
  182. duration: 1500
  183. })
  184. return
  185. }
  186. let projectId = $.store.get('projectId') ||$.storage.get('projectId');
  187. let userId = $.store.get('userId') || $.storage.get('userId');
  188. let data={
  189. "projectId":projectId,
  190. "spaceId":this.data.spaceId,
  191. "userId":userId,
  192. "phone":$.store.get('phone'),//反馈人手机号
  193. "type":0,//反馈来源 0 小程序 1 app 2 pc
  194. "suggest":this.data.suggest,//反馈建议
  195. }
  196. this.data.debunkValue&&(data.item=this.data.debunkValue);
  197. console.log(this.data.photoType,"this.data.photoType")
  198. if(this.data.photoType!==''){
  199. let res = await this.uploadFile();
  200. data.photoList=[{"type":this.data.photoType,"photo":this.data.fileName}]
  201. }
  202. submitFeedback(data).then(res=>{
  203. if(res.result=="success"){
  204. wx.hideLoading();
  205. setTimeout(function () {
  206. wx.showToast({
  207. title:"提交成功",
  208. duration: 2000
  209. })
  210. }, 300)
  211. this.setData({fileList:[],debunkValue:0,suggest:'',showUpload:true,photoType:''})
  212. }
  213. })
  214. },
  215. /**
  216. * 生命周期函数--监听页面加载
  217. */
  218. onLoad: function (options) {
  219. !this.formSearch&&this.getFirstSpace();
  220. this.getKeeper();
  221. },
  222. /**
  223. * 生命周期函数--监听页面初次渲染完成
  224. */
  225. onReady: function () {
  226. },
  227. /**
  228. * 生命周期函数--监听页面显示
  229. */
  230. onShow: function () {
  231. },
  232. /**
  233. * 页面相关事件处理函数--监听用户下拉动作
  234. */
  235. onPullDownRefresh: function () {
  236. },
  237. })