pad-app/pages/shipWork/patrolAdd.vue

379 lines
10 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="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>{{vvyName}}</text>
</view>
<view class="li">
<p>进出口:</p>
<text>{{shipInfo.importExportFlagName}}</text>
</view>
<view class="li">
<p>贸易类型:</p>
<text>{{shipInfo.spmTradeName}}</text>
</view>
<view class="li">
<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>{{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="urlList" fileMediatype="image" @select="select"
@delete="delUrl" title="最多选择9张图片"></uni-file-picker>
</view>
</template>
<view class="pictureLook" v-else>
<view v-for="(item,index) in urlList" :key="index">
<image :src="item.url" mode="widthFix">
</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>{{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">
<van-button type="default" @click="cancel">取消</van-button>
<van-button type="danger" v-if="obj.state == 'look'" @click="del">删除</van-button>
<van-button type="info" v-if="obj.state == 'add' || obj.state == 'edit'" @click="save">保存</van-button>
<van-button type="info" v-if="obj.state == 'look'" @click="toGo('edit')"></van-button>
</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: "",
shipInfo: {},
obj: {},
patrolRow: {},
patrolRowIndex: {},
// 航次下拉框
vvyId: "",
vvyName: "",
hcList: [],
// 类型
type: "",
// 图片
urlList: [],
ysUrl: [],
delUrlList: [],
// 描述
remark: "",
// 下拉数据
optionData: [],
}
},
onLoad(options) {
if ('params' in options) {
// 获取传递的对象参数使用decodeURIComponent解码并转为对象
this.obj = JSON.parse(decodeURIComponent(options.params))
}
},
mounted() {
that = this
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 = "新增安全巡检"
}
this.executeSql1('shipOption')
this.executeSql1("shipInfoTable")
},
methods: {
// 查
executeSql1(tableName) {
let sql = `select * from ${tableName}`
sqlite.executeSqlCeshi(sql).then((value) => {
// 在resolve时执行的回调函数
if (tableName == 'shipOption') {
this.optionData = value
this.getShip()
} else if (tableName == 'shipInfoTable') {
this.shipInfo = value[0]
}
}).catch((error) => {
// 在reject时执行的回调函数
console.error(error);
});
},
executeSql2(tableName) {
let sql = `select * from ${tableName} WHERE contactId = '${this.patrolRow.webId}'`
sqlite.executeSqlCeshi(sql).then((value) => {
// 在resolve时执行的回调函数
this.urlList = value
}).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() {
this.patrolRow = uni.getStorageSync('patrolRow');
this.patrolRowIndex = uni.getStorageSync('patrolRowIndex');
this.executeSql2('safetyInspectionRespUrlList')
this.vvyId = this.patrolRow.vvyId
this.vvyName = this.patrolRow.vvyName
this.type = this.patrolRow.type
this.remark = this.patrolRow.remark
},
// 航次下拉
hcChange(e) {
this.vvyId = e;
this.hcList.forEach(v => {
if (v.value == e) {
this.vvyName = v.text
}
})
},
// 图片上传
select(e) {
pathToBase64(e.tempFiles[0].path)
.then(base64 => {
compressImgBySize(base64, 1200).then(baseImg => {
// 输出图片base64
that.ysUrl.push(baseImg)
})
})
.catch(error => {
console.error(error)
})
},
// 移除图片
delUrl(e) {
if (this.obj.state == 'edit') {
this.delUrlList.push(e.tempFile.webId)
}
pathToBase64(e.tempFile.path)
.then(base64 => {
compressImgBySize(base64, 1200).then(baseImg => {
// 输出图片base64
this.ysUrl.forEach((v, index) => {
if (v == base64) {
this.ysUrl.splice(index, 1)
}
})
})
})
.catch(error => {
console.error(error)
})
},
// 取消
cancel() {
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
},
// 弹框删除
delConfirm() {
for (var i = 0; i < this.urlList.length; i++) {
let delSql = `DELETE FROM safetyInspectionRespUrlList WHERE webId = '${this.urlList[i].webId}';`
this.executeSql(delSql)
}
let sql = `DELETE FROM safetyInspectionRespList WHERE webId = '${this.patrolRow.webId}';`
this.executeSql(sql)
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
},
// 删除
del() {
this.$refs.popup.open()
},
// 保存
save() {
let date = new Date().getTime()
let webId = uuidv4()
let webStatus = 0
let webDate = api.getDate(date)
if (this.obj.state == "edit") {
let sql =
`UPDATE safetyInspectionRespList SET vvyId = '${this.vvyId}', vvyName = '${this.vvyName}',
type = '${this.type}',remark = '${this.remark}', webStatus = '${webStatus}',
webDate = '${webDate}' WHERE webId = '${this.patrolRow.webId}';`
this.executeSql(sql)
if (this.delUrlList.length > 0) {
for (var i = 0; i < this.delUrlList.length; i++) {
let delSql = `DELETE FROM safetyInspectionRespUrlList WHERE webId = '${this.delUrlList[i]}';`
this.executeSql(delSql)
}
}
for (var i = 0; i < this.ysUrl.length; i++) {
let webId2 = uuidv4()
let sql2 = `insert into safetyInspectionRespUrlList values('${webId2}','${this.patrolRow.webId}','${this.ysUrl[i]}',
'${webStatus}','${webDate}')`
this.executeSql(sql2)
}
} else if (this.obj.state == "add") {
let sql = `insert into safetyInspectionRespList values('${webId}','${this.vvyId}','${this.vvyName}',
'${this.type}','${this.remark}','${this.shipInfo.tradeTypeName}','${this.shipInfo.importExportFlagName}',
'${this.shipInfo.spmName}','${webStatus}','${webDate}')`
this.executeSql(sql)
for (var i = 0; i < this.ysUrl.length; i++) {
let webId2 = uuidv4()
let sql2 = `insert into safetyInspectionRespUrlList values('${webId2}','${webId}','${this.ysUrl[i]}',
'${webStatus}','${webDate}')`
this.executeSql(sql2)
}
}
uni.navigateTo({
url: '/pages/shipWork/patrol'
})
},
// 编辑
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;
.ul {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
.wLi {
width: 100% !important;
}
.tpLi {
width: 100% !important;
display: block !important;
p {
text-align: left !important;
}
}
.li {
width: 44%;
border-top: 1px solid #ccc;
border-bottom: 1px solid #ccc;
display: flex;
padding: 10px 20px;
line-height: 35px;
margin-bottom: 20px;
.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;
}
}
.pictureLook {
display: flex;
flex-wrap: wrap;
image {
width: 120px;
height: 120px;
margin: 10px;
}
}
}
}
.btnList {
display: flex;
justify-content: center;
/deep/ .van-button {
margin: 30px 20px;
width: 120px;
height: 50px;
}
}
}
}
</style>