运维小程序
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.js 7.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. // pages/workorder/index.js
  2. const api = require('../../api/index.js');
  3. Page({
  4. /**
  5. * 页面的初始数据
  6. */
  7. data: {
  8. array:['日常','故障','其他'],
  9. namelist:[],
  10. typelist:['日常','故障','其他'],
  11. devicedata:[],
  12. index:1,
  13. nameindex:'',
  14. typeindex:0,
  15. deviceindex:'',
  16. date:'',
  17. partnerAvite:[],
  18. priority:'1',
  19. workorderContent:'',
  20. switchtype:true,
  21. datestart:'',
  22. dateend:''
  23. },
  24. /**
  25. * 生命周期函数--监听页面加载
  26. */
  27. onLoad(options) {
  28. console.log(options.name);
  29. this.setData({
  30. index:options.name
  31. })
  32. this.getselectinformationall()
  33. this.getselectdevicelist()
  34. },
  35. onworkorder(){
  36. if (this.data.workorderName==''||this.data.workorderAddress==''||this.data.dateend==''||this.data.datestart==''||this.data.nameindex==''||this.data.deviceindex=='') {
  37. wx.showToast({
  38. title: '请填写完整工单',
  39. icon: 'none'
  40. });
  41. return
  42. }
  43. if (!this.data.switchtype) {
  44. return
  45. }
  46. this.setData({
  47. switchtype:false
  48. })
  49. let data = {
  50. workorderName:this.data.workorderName,
  51. workorderAddress:this.data.workorderAddress,
  52. workorderImg:this.data.partnerAvite.length>0?this.data.partnerAvite.toString():'',
  53. workorderContent:this.data.workorderContent,
  54. workoderPartner:this.data.namelist[this.data.nameindex].partnerId,
  55. workorderEndtime:this.data.dateend, // 开始时间
  56. workorderStarttime:this.data.datestart, // 结束时间
  57. workorderGrade:this.data.priority,
  58. type:(this.data.index*1)+1,
  59. deviceId:this.data.devicedata[this.data.deviceindex].deviceId
  60. }
  61. api.request(`/workoder/createworkorder`, 'POST',data)
  62. .then((res) => {
  63. console.log(res);
  64. if (res.code==200) {
  65. // this.requestSubscribeMessage();
  66. // this.loadMessages();
  67. this.setData({
  68. switchtype:true
  69. })
  70. wx.switchTab({
  71. url: '/pages/index/index',
  72. })
  73. }
  74. })
  75. .catch((err) => {
  76. console.error('请求失败:', err);
  77. // 在这里处理请求失败的情况
  78. this.setData({
  79. switchtype:true
  80. })
  81. });
  82. },
  83. // 用户信息
  84. getselectinformationall(){
  85. let data = {
  86. }
  87. api.request(`/partner/selectinformationall`, 'POST',data)
  88. .then((res) => {
  89. console.log(res);
  90. this.setData({
  91. namelist:res.data
  92. })
  93. })
  94. .catch((err) => {
  95. console.error('请求失败:', err);
  96. // 在这里处理请求失败的情况
  97. });
  98. },
  99. // 设备列表
  100. getselectdevicelist(){
  101. let data = {
  102. }
  103. api.request(`/device/selectdevicelist`, 'POST',data)
  104. .then((res) => {
  105. console.log(res);
  106. this.setData({
  107. devicedata:res.data
  108. })
  109. })
  110. .catch((err) => {
  111. console.error('请求失败:', err);
  112. // 在这里处理请求失败的情况
  113. });
  114. },
  115. onPeakprice(e){
  116. console.log(e.detail.value);
  117. this.setData({
  118. workorderName:e.detail.value
  119. })
  120. },
  121. onaddress(e){
  122. console.log(e.detail.value);
  123. this.setData({
  124. workorderAddress:e.detail.value
  125. })
  126. },
  127. ontextarea(e){
  128. console.log(e);
  129. this.setData({
  130. workorderContent:e.detail.value
  131. })
  132. },
  133. bindPickerChange(e){
  134. console.log('picker发送选择改变,携带值为', e.detail.value)
  135. this.setData({
  136. nameindex: e.detail.value
  137. })
  138. },
  139. binddeviceChange(e){
  140. console.log('picker发送选择改变,携带值为', e.detail.value)
  141. this.setData({
  142. deviceindex: e.detail.value,
  143. workorderAddress:this.data.devicedata[e.detail.value].devicesName
  144. })
  145. },
  146. bindeventChange(e){
  147. this.setData({
  148. index: e.detail.value
  149. })
  150. },
  151. // 开始时间
  152. bindstartChange: function(e) {
  153. console.log('picker发送选择改变,携带值为', e.detail.value)
  154. this.setData({
  155. datestart: e.detail.value
  156. })
  157. },
  158. // 结束时间
  159. bindendChange: function(e) {
  160. const selectedEnd = e.detail.value;
  161. console.log('picker发送选择改变,携带值为', e.detail.value)
  162. const { datestart } = this.data;
  163. // 检查结束时间是否早于开始时间
  164. if (datestart && selectedEnd < datestart) {
  165. wx.showToast({
  166. title: '结束时间不能早于开始时间',
  167. icon: 'none',
  168. duration: 2000
  169. });
  170. return; // 不更新结束时间
  171. }
  172. // 验证通过,更新结束时间
  173. this.setData({
  174. dateend: selectedEnd
  175. });
  176. },
  177. // 工单优先级
  178. onradio(e){
  179. console.log(e.detail.value);
  180. this.setData({
  181. priority:e.detail.value
  182. })
  183. },
  184. // 预览图片
  185. previewImage(e) {
  186. const src = e.currentTarget.dataset.src;
  187. wx.previewImage({
  188. current: src, // 当前显示图片的http链接
  189. urls: [src] // 需要预览的图片http链接列表
  190. });
  191. },
  192. bindCancel(e){
  193. console.log(e.currentTarget.dataset.index);
  194. let index = e.currentTarget.dataset.index
  195. // 使用 filter 方法创建新数组(推荐)
  196. const newPartnerAvite = this.data.partnerAvite.filter((item, i) => i !== index);
  197. this.setData({
  198. partnerAvite: newPartnerAvite
  199. });
  200. },
  201. // 上传头像--项目--文件1
  202. bindtoImage(){
  203. let _this = this
  204. // 先检查隐私授权状态
  205. wx.getPrivacySetting({
  206. success: (res) => {
  207. if (res.needAuthorization) {
  208. // 弹出隐私协议弹窗
  209. wx.requirePrivacyAuthorize({
  210. success: () => {
  211. console.log('用户已同意隐私协议');
  212. _this.choosetoImage(); // 继续执行上传
  213. },
  214. fail: () => {
  215. console.log('用户拒绝了隐私协议');
  216. wx.showToast({
  217. title: '需同意隐私协议才能使用',
  218. icon: 'none'
  219. });
  220. }
  221. });
  222. } else {
  223. _this.choosetoImage(); // 已授权,直接上传
  224. }
  225. }
  226. });
  227. },
  228. // 上传头像图片
  229. choosetoImage() {
  230. let _this = this
  231. wx.chooseMedia({
  232. count: 1,
  233. mediaType: ['image','video'],
  234. sourceType: ['album', 'camera'],
  235. success(res) {
  236. console.log(res);
  237. const tempFiles = res.tempFiles;
  238. _this.setData({
  239. imageList: tempFiles.map(file => file.tempFilePath),
  240. });
  241. _this.uploadtoImages(tempFiles);
  242. },
  243. fail(err) {
  244. console.error("选择失败:", err);
  245. }
  246. })
  247. },
  248. // 上传到服务器
  249. uploadtoImages(files) {
  250. let _this =this
  251. const token = wx.getStorageSync('token');
  252. files.forEach((file) => {
  253. wx.uploadFile({
  254. url: 'https://esos-iot.bjdexn.cn:8443/config/upload/webPost',
  255. filePath: file.tempFilePath,
  256. name: 'file',
  257. formData: {
  258. file:file.tempFilePath
  259. },
  260. header: {
  261. 'Authorization': 'Bearer ' + token // Also add to header if needed
  262. },
  263. success: (res) => {
  264. console.log(res);
  265. const obj = JSON.parse(res.data);
  266. this.data.partnerAvite.push(obj.data.partnerAvite)
  267. this.setData({
  268. partnerAvite:this.data.partnerAvite
  269. })
  270. },
  271. fail: (err) => {
  272. console.error('上传失败', err);
  273. },
  274. });
  275. });
  276. },
  277. /**
  278. * 生命周期函数--监听页面初次渲染完成
  279. */
  280. onReady() {
  281. },
  282. /**
  283. * 生命周期函数--监听页面显示
  284. */
  285. onShow() {
  286. },
  287. /**
  288. * 生命周期函数--监听页面隐藏
  289. */
  290. onHide() {
  291. },
  292. /**
  293. * 生命周期函数--监听页面卸载
  294. */
  295. onUnload() {
  296. },
  297. /**
  298. * 页面相关事件处理函数--监听用户下拉动作
  299. */
  300. onPullDownRefresh() {
  301. },
  302. /**
  303. * 页面上拉触底事件的处理函数
  304. */
  305. onReachBottom() {
  306. },
  307. /**
  308. * 用户点击右上角分享
  309. */
  310. onShareAppMessage() {
  311. }
  312. })