pad-app/pages/shipWork/patrolAdd.vue

541 lines
13 KiB
Vue
Raw Normal View History

2023-07-12 17:46:47 +08:00
<template>
<view class="patrolAdd">
2023-08-24 17:06:35 +08:00
<head-view :title="title" url="/pages/shipWork/patrol"></head-view>
2023-11-01 18:40:05 +08:00
<view class="container contentFixed">
2023-12-14 17:02:53 +08:00
<view class="info">
<view class="ul">
<view class="li">
<p>船名</p>
<text>{{shipInfo.vslCnname}}</text>
</view>
<view class="li">
<p><text class="required" v-if="obj.state != 'look'">*</text></p>
<uni-data-select v-model="vvyId" :localdata="hcList" @change="hcChange"
v-if="obj.state != 'look'"></uni-data-select>
<text v-else>{{patrolRow.vvyName}}</text>
</view>
<view class="li">
<p>进出口</p>
<text>{{importExportName}}</text>
</view>
<view class="li">
<p>贸易类型</p>
<text>{{spmTradeName}}</text>
</view>
<view class="li inputLi">
<p><text class="required" v-if="obj.state != 'look'">*</text></p>
<uni-easyinput v-if="obj.state != 'look'" v-model="type" placeholder="请输入"></uni-easyinput>
<text v-else>{{patrolRow.type}}</text>
</view>
<view class="li tpLi">
<p><text class="required" v-if="obj.state != 'look'">*</text></p>
<template v-if="obj.state != 'look'">
<view class="picture">
<uni-file-picker limit="9" v-model="urlList2" fileMediatype="image" @select="select"
@delete="delUrl" title="最多选择9张图片"></uni-file-picker>
</view>
</template>
<view class="pictureLook" v-else>
<view v-for="(item,index) in urlList2" :key="index">
<image :src="item.url" mode="widthFix" @click="clickImg(urlList2,index)">
</view>
2023-07-20 17:16:08 +08:00
</view>
2023-07-12 17:46:47 +08:00
</view>
2023-12-14 17:02:53 +08:00
<view class="li wLi">
<p><text class="required" v-if="obj.state != 'look'">*</text></p>
<uni-easyinput type="textarea" autoHeight v-model="remark" placeholder="请输入任务描述(200字以内)"
maxlength="200" v-if="obj.state != 'look'"></uni-easyinput>
<text v-else>{{patrolRow.remark}}</text>
</view>
2023-07-20 17:16:08 +08:00
</view>
2023-12-14 17:02:53 +08:00
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog type="error" confirmText="确定" title="通知" content="是否删除此条数据"
@confirm="delConfirm"></uni-popup-dialog>
</uni-popup>
<view class="btnList">
2023-12-22 17:48:52 +08:00
<view class="btn qx" @click="cancel"></view>
<view class="btn sc" v-if="obj.state == 'look'" @click="del"></view>
<view class="btn bc" v-if="obj.state == 'add' || obj.state == 'edit'" @click="save"></view>
<view class="btn bc" v-if="obj.state == 'look'" @click="toGo('edit')"></view>
2023-07-20 17:16:08 +08:00
</view>
</view>
2023-07-12 17:46:47 +08:00
</view>
</view>
</template>
<script>
2023-08-01 09:32:45 +08:00
import sqlite from "../../common/sqlite.js"
2023-08-01 14:35:05 +08:00
import api from "../../common/api.js";
2023-09-23 20:16:54 +08:00
import {
pathToBase64,
base64ToPath
} from '../../js_sdk/mmmm-image-tools/index.js'
import {
compressImgBySize
} from '@/common/compressImg'
2023-08-01 16:50:18 +08:00
import {
v4 as uuidv4
} from 'uuid';
2023-09-23 20:16:54 +08:00
let that;
2023-07-12 17:46:47 +08:00
export default {
data() {
return {
2023-08-24 16:22:29 +08:00
title: "",
2023-11-21 17:43:02 +08:00
vtpId: "",
portObj: {},
loginObj: {},
2023-08-23 17:42:44 +08:00
shipInfo: {},
2023-07-12 17:46:47 +08:00
obj: {},
2023-11-21 17:43:02 +08:00
importExportName: "",
spmTradeName: "",
2023-07-20 17:16:08 +08:00
patrolRow: {},
2023-07-12 17:46:47 +08:00
// 航次下拉框
2023-07-20 17:16:08 +08:00
vvyId: "",
vvyName: "",
hcList: [],
2023-07-12 17:46:47 +08:00
// 类型
2023-07-20 17:16:08 +08:00
type: "",
// 图片
2023-09-23 20:16:54 +08:00
urlList: [],
2023-11-21 17:43:02 +08:00
urlList2: [],
2023-09-23 20:16:54 +08:00
delUrlList: [],
2023-07-12 17:46:47 +08:00
// 描述
2023-07-20 17:16:08 +08:00
remark: "",
2023-08-18 17:28:11 +08:00
2023-08-03 15:36:23 +08:00
// 下拉数据
optionData: [],
2023-07-12 17:46:47 +08:00
}
},
onLoad(options) {
if ('params' in options) {
// 获取传递的对象参数使用decodeURIComponent解码并转为对象
this.obj = JSON.parse(decodeURIComponent(options.params))
}
2023-07-20 17:16:08 +08:00
},
mounted() {
2023-09-23 20:16:54 +08:00
that = this
2023-11-21 17:43:02 +08:00
this.portObj = uni.getStorageSync('portObj')
this.loginObj = uni.getStorageSync('loginObj')
this.vtpId = uni.getStorageSync('vtpId')
this.executeSql1('shipOption')
this.executeSql1("shipInfoTable")
this.executeSql1("voyageScheduleDataDetailRespDTOList")
2023-07-20 17:16:08 +08:00
if (this.obj.state == 'edit' || this.obj.state == 'look') {
this.getRow();
}
2023-08-24 16:22:29 +08:00
if (this.obj.state == "edit") {
this.title = "编辑安全巡检"
} else if (this.obj.state == "look") {
this.title = "查看安全巡检"
} else {
this.title = "新增安全巡检"
}
2023-07-12 17:46:47 +08:00
},
methods: {
2023-08-03 15:36:23 +08:00
// 查
executeSql1(tableName) {
2023-11-21 17:43:02 +08:00
let sql = `select * from ${tableName} WHERE vtpId = '${this.vtpId}'`
2023-08-03 15:36:23 +08:00
sqlite.executeSqlCeshi(sql).then((value) => {
// 在resolve时执行的回调函数
2023-08-23 17:42:44 +08:00
if (tableName == 'shipOption') {
this.optionData = value
this.getShip()
} else if (tableName == 'shipInfoTable') {
this.shipInfo = value[0]
2023-11-21 17:43:02 +08:00
} else if (tableName == 'voyageScheduleDataDetailRespDTOList') {
this.vvyInfo = value
this.hcList = []
value.forEach((v, index) => {
this.hcList.push({
text: v.vvyName,
value: v.vvyId
})
})
2023-08-23 17:42:44 +08:00
}
2023-08-03 15:36:23 +08:00
}).catch((error) => {
// 在reject时执行的回调函数
console.error(error);
});
},
2023-07-20 17:16:08 +08:00
// 获取船只信息
getShip() {
2023-08-23 17:42:44 +08:00
// this.shipInfo = uni.getStorageSync('shipInfo')
2023-08-03 15:36:23 +08:00
// 航次下拉数据
let hcOption = []
this.optionData.forEach((v, index) => {
if (v.dictionariesName == 'vvyList') {
hcOption.push(v)
}
})
hcOption.forEach((v, index) => {
2023-07-20 17:16:08 +08:00
this.hcList.push({
2023-08-03 15:36:23 +08:00
text: v.ptrDesc,
value: v.ptrCode
2023-07-20 17:16:08 +08:00
})
})
},
// 获取当前行信息
getRow() {
2023-11-21 17:43:02 +08:00
uni.request({
url: `${this.$local}/api/safetyInspection/details/${this.obj.id}`,
header: {
'Content-Type': 'application/json', //自定义请求头信息
'Authorization': `Bearer ${this.loginObj.access_token}`
},
method: 'GET', //请求方式,必须为大写
success: (res) => {
this.patrolRow = res.data.data
this.vvyId = this.patrolRow.vvyId
this.vvyName = this.patrolRow.vvyName
this.importExportName = this.patrolRow.importExportName
this.spmTradeName = this.patrolRow.tradeTypeName
this.type = this.patrolRow.type
this.remark = this.patrolRow.remark
if (this.patrolRow.url != null) {
this.urlList = this.patrolRow.url
} else {
this.urlList = []
}
if (this.patrolRow.url.length > 0 || this.patrolRow.url != null) {
this.patrolRow.url.forEach(v => {
this.initImg(v)
})
}
},
fail: (error) => {}
})
},
initImg(fileName) {
uni.request({
url: `${this.$local}/api/file/url/?fileName=${fileName}`,
header: {
'Content-Type': 'application/json', //自定义请求头信息
'Authorization': `Bearer ${this.loginObj.access_token}`
},
method: 'GET', //请求方式,必须为大写
success: (res) => {
if (res.statusCode == 200) {
this.urlList2.push(res.data)
}
}
})
2023-07-20 17:16:08 +08:00
},
2023-07-12 17:46:47 +08:00
// 航次下拉
hcChange(e) {
2023-07-20 17:16:08 +08:00
this.vvyId = e;
this.hcList.forEach(v => {
if (v.value == e) {
this.vvyName = v.text
}
})
2023-11-21 17:43:02 +08:00
this.vvyInfo.forEach(v => {
if (v.vvyId == e) {
this.importExportName = v.importExportFlagName
this.spmTradeName = v.tradeTypeName
}
})
2023-07-20 17:16:08 +08:00
},
// 图片上传
select(e) {
2023-12-27 17:57:26 +08:00
e.tempFiles.forEach(v => {
uni.uploadFile({
url: `${this.$local}/api/file/upload`, //上传图片api
header: {
'Authorization': `Bearer ${this.loginObj.access_token}`
},
filePath: v.path,
name: 'file',
success: (res) => {
this.urlList2.push(v)
let data = JSON.parse(res.data).data
this.urlList.push(data.filePath)
},
fail(e) {
uni.showToast({
title: `${e.errMsg}`,
icon: 'none',
duration: 2000
})
}
})
2023-11-21 17:43:02 +08:00
})
2023-08-18 17:28:11 +08:00
},
2023-09-23 20:16:54 +08:00
// 移除图片
delUrl(e) {
2023-11-21 17:43:02 +08:00
let delIndex = 0
this.urlList2.forEach((v, index) => {
if (v.uuid == e.tempFile.uuid) {
delIndex = index
}
})
this.urlList.splice(delIndex, 1)
this.urlList2.splice(delIndex, 1)
},
// 点击图片放大
clickImg(urlList, index) {
uni.previewImage({
current: index,
urls: urlList,
})
2023-07-12 17:46:47 +08:00
},
// 取消
cancel() {
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
},
// 弹框删除
delConfirm() {
2023-11-21 17:43:02 +08:00
uni.request({
url: `${this.$local}/api/safetyInspection/${this.obj.id}`,
header: {
'Content-Type': 'application/json', //自定义请求头信息
'Authorization': `Bearer ${this.loginObj.access_token}`
},
method: 'DELETE', //请求方式,必须为大写
success: (res) => {
console.log(res)
if (res.statusCode == 200) {
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
}
},
fail: () => {}
2023-07-20 17:16:08 +08:00
})
},
// 删除
del() {
this.$refs.popup.open()
},
2023-07-12 17:46:47 +08:00
// 保存
save() {
2023-11-21 17:43:02 +08:00
let spmTradeName = ""
if (this.spmTradeName == "内贸") {
spmTradeName = "N"
} else {
spmTradeName = "W"
}
let importExportName = ""
if (this.importExportName == "进口") {
importExportName = "I"
} else {
importExportName = "E"
}
let dto = {
"importExport": importExportName,
"remark": this.remark,
"spmId": this.vtpId,
"tradeType": spmTradeName,
"type": this.type,
"uploadStatus": "",
"url": this.urlList,
"vsiId": this.obj.id,
"vvyId": this.vvyId
}
if (this.obj.state == "add") {
uni.request({
url: `${this.$local}/api/safetyInspection`,
data: dto,
header: {
'Content-Type': 'application/json', //自定义请求头信息
'Authorization': `Bearer ${this.loginObj.access_token}`
},
method: 'POST', //请求方式,必须为大写
success: (res) => {
if (res.statusCode == 200) {
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
}
},
fail: (e) => {
console.log(e)
2023-09-23 20:16:54 +08:00
}
2023-11-21 17:43:02 +08:00
})
} else if (this.obj.state == 'edit') {
uni.request({
url: `${this.$local}/api/safetyInspection/${this.obj.id}`,
data: dto,
header: {
'Content-Type': 'application/json', //自定义请求头信息
'Authorization': `Bearer ${this.loginObj.access_token}`
},
method: 'PUT', //请求方式,必须为大写
success: (res) => {
if (res.statusCode == 200) {
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
}
},
fail: (e) => {
console.log(e)
}
})
2023-07-20 17:16:08 +08:00
}
2023-07-12 17:46:47 +08:00
},
// 编辑
toGo(state) {
this.obj.state = state;
const params = encodeURIComponent(JSON.stringify(this.obj));
uni.navigateTo({
url: `/pages/shipWork/patrolAdd?params=${params}`
})
2023-08-01 09:32:45 +08:00
},
executeSql(sql) {
sqlite.executeSqlCeshi(sql).then((value) => {
// 在resolve时执行的回调函数
2023-08-18 17:28:11 +08:00
// console.log(value);
2023-08-01 09:32:45 +08:00
}).catch((error) => {
// 在reject时执行的回调函数
console.error(error);
});
},
2023-07-12 17:46:47 +08:00
}
}
</script>
<style lang="less" scoped>
.patrolAdd {
.container {
padding: 30px 20px;
2023-12-14 17:02:53 +08:00
.info {
background-color: #fff;
}
2023-07-20 17:16:08 +08:00
.ul {
2023-07-12 17:46:47 +08:00
display: flex;
flex-wrap: wrap;
justify-content: space-between;
2023-12-14 17:02:53 +08:00
.li {
width: 49%;
display: flex;
justify-content: space-between;
border-bottom: 1px solid #EEEEEE;
padding: 0 16px;
height: 56px;
line-height: 56px;
2023-07-12 17:46:47 +08:00
2023-12-14 17:02:53 +08:00
/deep/.uni-stat__select {
flex: none;
width: 30%;
}
2023-07-12 17:46:47 +08:00
2023-12-14 17:02:53 +08:00
/deep/.uni-select {
border: none;
2023-07-12 17:46:47 +08:00
}
2023-12-14 17:02:53 +08:00
/deep/.uni-select__input-text {
text-align: right;
padding-right: 10px;
}
2023-07-12 17:46:47 +08:00
.required {
color: red;
margin-right: 5px;
}
p {
min-width: 85px;
text-align: right;
}
.picture {
/deep/.file-picker__box {
width: 120px !important;
height: 120px !important;
padding-top: 0;
}
2023-12-22 17:48:52 +08:00
/deep/.is-add {
background: url(../../static/images/xjpz.png) no-repeat;
background-size: 100% 100%;
border: 1px solid transparent !important;
.is-add {
display: none;
}
}
2023-07-12 17:46:47 +08:00
}
.pictureLook {
display: flex;
flex-wrap: wrap;
2023-07-20 17:16:08 +08:00
image {
2023-07-12 17:46:47 +08:00
width: 120px;
height: 120px;
margin: 10px;
}
}
}
2023-12-14 17:02:53 +08:00
.inputLi {
/deep/.is-input-border {
height: 40px;
margin-top: 8px;
}
}
.wLi {
width: 100% !important;
height: 200px;
justify-content: flex-start;
/deep/.is-input-border {
margin-top: 16px;
}
}
.tpLi {
width: 100% !important;
display: block !important;
height: 260px;
p {
text-align: left !important;
}
}
2023-07-12 17:46:47 +08:00
}
.btnList {
2023-12-14 17:02:53 +08:00
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 80px;
background-color: #fff;
2023-07-12 17:46:47 +08:00
display: flex;
justify-content: center;
2023-12-22 17:48:52 +08:00
box-shadow: 0 -3px 7px 0 rgba(0, 0, 0, 0.10);
.btn {
margin: 15.5px 17px;
width: 200px;
height: 49px;
border-radius: 2px;
font-size: 18px;
text-align: center;
line-height: 49px;
}
.qx {
background-color: #eee;
}
.sc {
background-color: #E50101;
color: #fff;
}
2023-07-12 17:46:47 +08:00
2023-12-22 17:48:52 +08:00
.bc {
color: #fff;
background: #0067CF;
2023-07-12 17:46:47 +08:00
}
}
}
}
</style>