|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223 |
- // package_A/page/TaskDetail/index.js
- import {statusList, baseRules, orderRules, pointStyle} from '../../../utils/data.js'
- import {getEquipments, getCloudBox, getMounts, confirmOrder, beginFly, endFly} from '../../../api/task.js'
-
- Page({
-
- /**
- * 页面的初始数据
- */
- data: {
- taskIsLive: null, // 任务状态
- pointList: [], // 坐标数组
- dataSource: {},
- statusList,
- messageList: [
- {label: '任务执行时间', value: "taskStartTime", icon: "handletime"},
- {label: '任务地点', value: "patrolLocation", icon: "location"},
- {label: '任务发起人', value: "sponsorName", icon: "user"},
- {label: '租户名称', value: "tenantName", icon: "tenant"},
- {label: '需要直播', value: "isLive", icon: "islive"},
- {label: '备注', value: "remark", icon: "notes"}
- ],
- form: {},
- formRules: {},
- formOptions: {
- equipmentId: {current: -1, list: [], key:'name'},
- equipmentMountId: {current: -1, list: [], key:'name'},
- photographyWay: {current: -1, list: [{id: 1, label: '普通巡检'},
- {id: 2, label: '正射影像'}, {id: 3, label: '倾斜摄影'}], key:'label'},
- cloudBoxId: {current: -1, list: [], key:'boxName'}
- },
- disabled: false
- },
-
- /**
- * 生命周期函数--监听页面加载
- */
- onLoad(options) {
- if(options.data) {
- let dataSource = this.data.dataSource
- dataSource = JSON.parse(options.data)
- if(dataSource.photographyWay) {
- this.getCurrentById('photographyWay',dataSource.photographyWay)
- }
- // form默认数据
- let form = this.data.form
- form.id = dataSource.id
- form.equipmentId = dataSource.equipmentId
- form.equipmentMountId = dataSource.equipmentMountId
- form.photographyWay = dataSource.photographyWay
- // 地图坐标展示
- let pointList = this.data.pointList
- let point1 = Object.assign({id: 1,latitude: parseFloat(dataSource.startLatitude), longitude: parseFloat(dataSource.startLongitude)}, pointStyle)
- let point2 = Object.assign({id: 2,latitude: parseFloat(dataSource.endLatitude), longitude: parseFloat(dataSource.endLongitude)}, pointStyle)
- pointList.push(point1)
- pointList.push(point2)
- this.setData({pointList})
- // 表单动态展示
- let formRules = this.data.formRules
- if(dataSource.isLive === 2) {
- formRules = Object.assign({}, baseRules)
- } else {
- form.cloudBoxId = dataSource.cloudBoxId
- formRules = Object.assign({}, baseRules, orderRules)
- }
- if(dataSource.status > 15) {
- this.setData({disabled: true})
- }
- this.setData({dataSource, taskIsLive: dataSource.isLive, formRules, form})
- }
- },
- onShow() {
- this.getEquipmentsList()
- this.getCloudBoxList()
- this.getMountsList()
- },
-
- // 数据回显
- getCurrentById(value, id) {
- let formOptions = this.data.formOptions
- let list = formOptions[value].list
- list.forEach((item, index)=> {
- if(item.id === id) {
- formOptions[value].current = index
- this.setData({formOptions})
- }
- })
- },
-
- /**
- * 获取无人机列表
- * @param {*} e
- */
- getEquipmentsList() {
- getEquipments().then(res=> {
- if(res.code === 0) {
- let dataList = res.data
- let formOptions = this.data.formOptions
- formOptions.equipmentId.list = dataList
- this.setData({formOptions})
- if(this.data.dataSource.equipmentId) {
- let id = this.data.dataSource.equipmentId
- this.getCurrentById('equipmentId', id)
- }
- }
- })
- },
- // 获取云盒列表
- getCloudBoxList() {
- getCloudBox().then(res=> {
- if(res.code === 0) {
- let dataList = res.data
- let formOptions = this.data.formOptions
- formOptions.cloudBoxId.list = dataList
- this.setData({formOptions})
- if(this.data.dataSource.cloudBoxId) {
- let id = this.data.dataSource.cloudBoxId
- this.getCurrentById('cloudBoxId', id)
- }
- }
- })
- },
- // 获取挂载列表
- getMountsList() {
- getMounts().then(res=> {
- if(res.code === 0) {
- let dataList = res.data
- let formOptions = this.data.formOptions
- formOptions.equipmentMountId.list = dataList
- this.setData({formOptions})
- if(this.data.dataSource.equipmentMountId) {
- let id = this.data.dataSource.equipmentMountId
- this.getCurrentById('equipmentMountId', id)
- }
- }
- })
- },
- /**
- * 选择
- * @param {*} e
- */
- updateChange(e) {
- let index = e.currentTarget.dataset.index
- let current = parseInt(e.detail.value)
- let value = this.data.formOptions[index].list[current].id
- let form = this.data.form
- form[index] = value
- let formOptions = this.data.formOptions
- formOptions[index].current = current
- this.setData({formOptions, form})
- this.validate(index)
- },
- validate(name) {
- let formRules = this.data.formRules;
- let validator = formRules[name].validator
- let result = validator ? !validator(this.data.form[name]) : false;
- formRules[name].warning = result
- this.setData({
- formRules
- })
- return result
- },
- validateForm() {
- return new Promise((resolve, reject) => {
- try {
- let formRules = this.data.formRules;
- let result = false;
- for (let key in formRules) {
- let temp = this.validate(key)
- if (temp) {
- result = temp
- }
- }
- resolve(!result)
- } catch (e) {
- reject(e)
- }
- })
- },
- // 接单
- reciveOrder() {
- this.validateForm().then(res => {
- if (res) {
- let params = this.data.form
- confirmOrder(params).then(res=> {
- if(res.code === 0) {
- wx.switchTab({
- url: '/pages/task/task',
- })
- }
- })
- }
- })
- },
- // 开始飞行
- beginFlight() {
- this.validateForm().then(res => {
- if (res) {
- let params = this.data.form
- beginFly(params).then(res=> {
- if(res.code === 0) {
- wx.switchTab({
- url: '/pages/task/task',
- })
- }
- })
- }
- })
- },
- // 结束飞行
- finishFlight() {
- let form = this.data.form
- let params = {}
- params.id = form.id
- endFly(params).then(res=> {
- if(res.code === 0) {
- wx.switchTab({
- url: '/pages/task/task',
- })
- }
- })
- }
- })
|