拓恒飞手平台小程序
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.

index.js 7.5KB

1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. // package_A/page/TaskDetail/index.js
  2. import {statusList, baseRules, orderRules, pointStyle} from '../../../utils/data.js'
  3. import {getEquipments, getCloudBox, getMounts, confirmOrder, beginFly, endFly} from '../../../api/task.js'
  4. Page({
  5. /**
  6. * 页面的初始数据
  7. */
  8. data: {
  9. taskIsLive: null, // 任务状态
  10. pointList: [], // 坐标数组
  11. dataSource: {},
  12. statusList,
  13. messageList: [
  14. {label: '任务执行时间', value: "taskStartTime", icon: "handletime"},
  15. {label: '任务地点', value: "patrolLocation", icon: "location"},
  16. {label: '任务发起人', value: "sponsorName", icon: "user"},
  17. {label: '租户名称', value: "tenantName", icon: "tenant"},
  18. {label: '需要直播', value: "isLive", icon: "islive"},
  19. {label: '备注', value: "remark", icon: "notes"}
  20. ],
  21. form: {},
  22. formRules: {},
  23. formOptions: {
  24. equipmentId: {current: -1, list: [], key:'name'},
  25. equipmentMountId: {current: -1, list: [], key:'name'},
  26. photographyWay: {current: -1, list: [{id: 1, label: '普通巡检'},
  27. {id: 2, label: '正射影像'}, {id: 3, label: '倾斜摄影'}], key:'label'},
  28. cloudBoxId: {current: -1, list: [], key:'boxName'}
  29. },
  30. disabled: false
  31. },
  32. /**
  33. * 生命周期函数--监听页面加载
  34. */
  35. onLoad(options) {
  36. if(options.data) {
  37. let dataSource = this.data.dataSource
  38. dataSource = JSON.parse(options.data)
  39. if(dataSource.photographyWay) {
  40. this.getCurrentById('photographyWay',dataSource.photographyWay)
  41. }
  42. // form默认数据
  43. let form = this.data.form
  44. form.id = dataSource.id
  45. form.equipmentId = dataSource.equipmentId
  46. form.equipmentMountId = dataSource.equipmentMountId
  47. form.photographyWay = dataSource.photographyWay
  48. // 地图坐标展示
  49. let pointList = this.data.pointList
  50. let point1 = Object.assign({id: 1,latitude: parseFloat(dataSource.startLatitude), longitude: parseFloat(dataSource.startLongitude)}, pointStyle)
  51. let point2 = Object.assign({id: 2,latitude: parseFloat(dataSource.endLatitude), longitude: parseFloat(dataSource.endLongitude)}, pointStyle)
  52. pointList.push(point1)
  53. pointList.push(point2)
  54. this.setData({pointList})
  55. // 表单动态展示
  56. let formRules = this.data.formRules
  57. if(dataSource.isLive === 2) {
  58. formRules = Object.assign({}, baseRules)
  59. } else {
  60. form.cloudBoxId = dataSource.cloudBoxId
  61. formRules = Object.assign({}, baseRules, orderRules)
  62. }
  63. if(dataSource.status > 15) {
  64. this.setData({disabled: true})
  65. }
  66. this.setData({dataSource, taskIsLive: dataSource.isLive, formRules, form})
  67. }
  68. },
  69. onShow() {
  70. this.getEquipmentsList()
  71. this.getCloudBoxList()
  72. this.getMountsList()
  73. },
  74. // 数据回显
  75. getCurrentById(value, id) {
  76. let formOptions = this.data.formOptions
  77. let list = formOptions[value].list
  78. list.forEach((item, index)=> {
  79. if(item.id === id) {
  80. formOptions[value].current = index
  81. this.setData({formOptions})
  82. }
  83. })
  84. },
  85. /**
  86. * 获取无人机列表
  87. * @param {*} e
  88. */
  89. getEquipmentsList() {
  90. getEquipments().then(res=> {
  91. if(res.code === 0) {
  92. let dataList = res.data
  93. let formOptions = this.data.formOptions
  94. formOptions.equipmentId.list = dataList
  95. this.setData({formOptions})
  96. if(this.data.dataSource.equipmentId) {
  97. let id = this.data.dataSource.equipmentId
  98. this.getCurrentById('equipmentId', id)
  99. }
  100. }
  101. })
  102. },
  103. // 获取云盒列表
  104. getCloudBoxList() {
  105. getCloudBox().then(res=> {
  106. if(res.code === 0) {
  107. let dataList = res.data
  108. let formOptions = this.data.formOptions
  109. formOptions.cloudBoxId.list = dataList
  110. this.setData({formOptions})
  111. if(this.data.dataSource.cloudBoxId) {
  112. let id = this.data.dataSource.cloudBoxId
  113. this.getCurrentById('cloudBoxId', id)
  114. }
  115. }
  116. })
  117. },
  118. // 获取挂载列表
  119. getMountsList() {
  120. getMounts().then(res=> {
  121. if(res.code === 0) {
  122. let dataList = res.data
  123. let formOptions = this.data.formOptions
  124. formOptions.equipmentMountId.list = dataList
  125. this.setData({formOptions})
  126. if(this.data.dataSource.equipmentMountId) {
  127. let id = this.data.dataSource.equipmentMountId
  128. this.getCurrentById('equipmentMountId', id)
  129. }
  130. }
  131. })
  132. },
  133. /**
  134. * 选择
  135. * @param {*} e
  136. */
  137. updateChange(e) {
  138. let index = e.currentTarget.dataset.index
  139. let current = parseInt(e.detail.value)
  140. let value = this.data.formOptions[index].list[current].id
  141. let form = this.data.form
  142. form[index] = value
  143. let formOptions = this.data.formOptions
  144. formOptions[index].current = current
  145. this.setData({formOptions, form})
  146. this.validate(index)
  147. },
  148. validate(name) {
  149. let formRules = this.data.formRules;
  150. let validator = formRules[name].validator
  151. let result = validator ? !validator(this.data.form[name]) : false;
  152. formRules[name].warning = result
  153. this.setData({
  154. formRules
  155. })
  156. return result
  157. },
  158. validateForm() {
  159. return new Promise((resolve, reject) => {
  160. try {
  161. let formRules = this.data.formRules;
  162. let result = false;
  163. for (let key in formRules) {
  164. let temp = this.validate(key)
  165. if (temp) {
  166. result = temp
  167. }
  168. }
  169. resolve(!result)
  170. } catch (e) {
  171. reject(e)
  172. }
  173. })
  174. },
  175. // 接单
  176. reciveOrder() {
  177. this.validateForm().then(res => {
  178. if (res) {
  179. let params = this.data.form
  180. confirmOrder(params).then(res=> {
  181. if(res.code === 0) {
  182. wx.switchTab({
  183. url: '/pages/task/task',
  184. })
  185. }
  186. })
  187. }
  188. })
  189. },
  190. // 开始飞行
  191. beginFlight() {
  192. this.validateForm().then(res => {
  193. if (res) {
  194. let params = this.data.form
  195. beginFly(params).then(res=> {
  196. if(res.code === 0) {
  197. wx.switchTab({
  198. url: '/pages/task/task',
  199. })
  200. }
  201. })
  202. }
  203. })
  204. },
  205. // 结束飞行
  206. finishFlight() {
  207. let form = this.data.form
  208. let params = {}
  209. params.id = form.id
  210. endFly(params).then(res=> {
  211. if(res.code === 0) {
  212. wx.switchTab({
  213. url: '/pages/task/task',
  214. })
  215. }
  216. })
  217. }
  218. })