pad-app/pages/shipWork/patrolAdd.vue

589 lines
14 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<template>
<view class="patrolAdd">
<head-view :title="title" url="/pages/shipWork/patrol"></head-view>
<view class="container contentFixed">
<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'"> -->
<template>
<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>
</view> -->
</view>
<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>
</view>
<uni-popup ref="popup" type="dialog">
<uni-popup-dialog type="error" confirmText="确定" title="通知" content="是否删除此条数据"
@confirm="delConfirm"></uni-popup-dialog>
</uni-popup>
<view class="btnList">
<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>
</view>
</view>
</view>
</view>
</template>
<script>
import sqlite from "../../common/sqlite.js"
import api from "../../common/api.js";
import {
pathToBase64,
base64ToPath
} from '../../js_sdk/mmmm-image-tools/index.js'
import {
compressImgBySize
} from '@/common/compressImg'
import {
v4 as uuidv4
} from 'uuid';
let that;
export default {
data() {
return {
title: "",
vtpId: "",
portObj: {},
loginObj: {},
shipInfo: {},
obj: {},
importExportName: "",
spmTradeName: "",
patrolRow: {},
// 航次下拉框
vvyId: "",
vvyName: "",
hcList: [],
// 类型
type: "",
// 图片
urlList: [],
urlList2: [],
delUrlList: [],
// 描述
remark: "",
// 下拉数据
optionData: [],
spmId: ''
}
},
onLoad(options) {
if ('params' in options) {
// 获取传递的对象参数使用decodeURIComponent解码并转为对象
this.obj = JSON.parse(decodeURIComponent(options.params))
}
},
mounted() {
that = this
this.portObj = uni.getStorageSync('portObj')
this.loginObj = uni.getStorageSync('loginObj')
this.vtpId = uni.getStorageSync('vtpId')
this.executeSql1('shipOption')
this.executeSql1("shipInfoTable")
this.executeSql1("voyageScheduleDataDetailRespDTOList")
if (this.obj.state == 'edit' || this.obj.state == 'look') {
this.getRow();
}
if (this.obj.state == "edit") {
this.title = "编辑安全巡检"
} else if (this.obj.state == "look") {
this.title = "查看安全巡检"
} else {
this.title = "新增安全巡检"
}
},
methods: {
// 查
executeSql1(tableName) {
let sql = `select * from ${tableName} WHERE vtpId = '${this.vtpId}'`
sqlite.executeSqlCeshi(sql).then((value) => {
// 在resolve时执行的回调函数
if (tableName == 'shipOption') {
this.optionData = value
this.getShip()
} else if (tableName == 'shipInfoTable') {
this.shipInfo = value[0]
this.spmId = this.shipInfo.spmId
} else if (tableName == 'voyageScheduleDataDetailRespDTOList') {
this.vvyInfo = value
this.hcList = []
value.forEach((v, index) => {
this.hcList.push({
text: v.vvyName,
value: v.vvyId
})
})
}
}).catch((error) => {
// 在reject时执行的回调函数
console.error(error);
});
},
// 获取船只信息
getShip() {
// this.shipInfo = uni.getStorageSync('shipInfo')
// 航次下拉数据
let hcOption = []
this.optionData.forEach((v, index) => {
if (v.dictionariesName == 'vvyList') {
hcOption.push(v)
}
})
hcOption.forEach((v, index) => {
this.hcList.push({
text: v.ptrDesc,
value: v.ptrCode
})
})
},
// 获取当前行信息
getRow() {
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({
url:res.data
})
}
}
})
},
// 航次下拉
hcChange(e) {
this.vvyId = e;
this.hcList.forEach(v => {
if (v.value == e) {
this.vvyName = v.text
}
})
this.vvyInfo.forEach(v => {
if (v.vvyId == e) {
this.importExportName = v.importExportFlagName
this.spmTradeName = v.tradeTypeName
}
})
},
// 图片上传
select(e) {
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
})
}
})
})
},
// 移除图片
delUrl(e) {
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,
})
},
// 取消
cancel() {
uni.showModal({
title: '提示',
content: '将退出编辑,所有内容不保留',
success: function (res) {
if (res.confirm) {
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
} else if (res.cancel) {
console.log('用户点击取消');
}
}
});
},
// 弹框删除
delConfirm() {
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: () => {}
})
},
// 删除
del() {
this.$refs.popup.open()
},
// 保存
save() {
if (this.vvyId == "") {
uni.showModal({
title: '提示',
showCancel: false,
content: '请输入航次!'
})
return
}
if (this.type == "") {
uni.showModal({
title: '提示',
showCancel: false,
content: '请输入类型!'
})
return
}
if (!this.urlList2.length) {
uni.showModal({
title: '提示',
showCancel: false,
content: '请上传图片!'
})
return
}
if (this.remark == "") {
uni.showModal({
title: '提示',
showCancel: false,
content: '请输入描述!'
})
return
}
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,
"spmId": this.spmId,
"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)
}
})
} 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)
}
})
}
},
// 编辑
toGo(state) {
this.obj.state = state;
const params = encodeURIComponent(JSON.stringify(this.obj));
uni.navigateTo({
url: `/pages/shipWork/patrolAdd?params=${params}`
})
},
executeSql(sql) {
sqlite.executeSqlCeshi(sql).then((value) => {
// 在resolve时执行的回调函数
// console.log(value);
}).catch((error) => {
// 在reject时执行的回调函数
console.error(error);
});
},
}
}
</script>
<style lang="less" scoped>
.patrolAdd {
.container {
padding: 30px 20px;
.info {
background-color: #fff;
}
.ul {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
.li {
width: 49%;
display: flex;
justify-content: space-between;
border-bottom: 1px solid #EEEEEE;
padding: 0 16px;
height: 56px;
line-height: 56px;
/deep/.uni-stat__select {
flex: none;
width: 30%;
}
/deep/.uni-select {
border: none;
}
/deep/.uni-select__input-text {
text-align: right;
padding-right: 10px;
}
.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;
}
/deep/.is-add {
background: url(../../static/images/xjpz.png) no-repeat;
background-size: 100% 100%;
border: 1px solid transparent !important;
.is-add {
display: none;
}
}
}
.pictureLook {
display: flex;
flex-wrap: wrap;
image {
width: 120px;
height: 120px;
margin: 10px;
}
}
}
.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;
}
}
}
.btnList {
position: fixed;
bottom: 0;
left: 0;
right: 0;
height: 80px;
background-color: #fff;
display: flex;
justify-content: center;
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;
}
.bc {
color: #fff;
background: #0067CF;
}
}
}
}
</style>