赞
踩
- <template>
- <view class="content">
- <view class="wrap">
- <timeWeek></timeWeek>
- <view class="data_info">
- <view class="list">
- <text style="color: #666666;">{{dataFrom.checkUserName}}</text>
- </view>
- <view class="foods" v-if="details">
- <view class="foods_img">
- <view class="text">
- <text>菜谱图片</text>
- </view>
- <view class="img" @click="previewImage">
- <image :src="supplyPicture[0]" v-if="details"></image>
- <image v-else></image>
- </view>
- </view>
- <view class="foods_text">
- <view class="text">
- <text>菜谱内容</text>
- </view>
- <view class="foods_list">
- <text v-for="(item,index) in supplyMenu" :key="index" v-if="supplyMenu">{{item}}</text>
- </view>
- </view>
- </view>
- <view class="list">
- <text>菜品数量:</text>
- <view class="checkbox">
- <radio-group>
- <label v-for="(item,index) in scoreList" :key="index" @click="number_change(index)">
- <radio color="#007aff" :value="item.id + ''" :checked="item.id==numberCurrent" />
- <text>{{item.text}}</text>
- </label>
- </radio-group>
- </view>
- </view>
- <view class="list">
- <text>菜品味道:</text>
- <view class="checkbox">
- <radio-group>
- <label v-for="(item,index) in scoreList" :key="index" @click="taste_change(index)">
- <radio color="#007aff" :value="item.id + ''" :checked="item.id==tasteCurrent" />
- <text>{{item.text}}</text>
- </label>
- </radio-group>
- </view>
- </view>
- <view class="feedback">
- <text>意见留言</text>
- <textarea placeholder-style="color:#999999" placeholder="请填写意见留言" v-model="dataFrom.suggestion" />
- </view>
- <view class="add_image">
- <text>添加图片</text>
- <view class="upload">
- <uni-file-picker limit="9" @select="select" @delete='del_img' v-model="fileLists">
- <view class="add">
- <image src="@/static/images/imgAdd.png" mode="widthFix"></image>
- </view>
- </uni-file-picker>
- </view>
- </view>
- </view>
- <view class="btn" @click="submit" v-if="!stateFlag">
- <button type="primary">提交</button>
- </view>
- <view class="btn" @click="modification" v-if="stateFlag">
- <button type="primary">修改</button>
- </view>
- </view>
- </view>
- </template>
- <script>
- import timeWeek from "@/common/time-week/index.vue"
- import uniFilePicker from "@/components/uni-file-picker/uni-file-picker.vue"
- import urlConfig from "@/utils/config.js"
- import {
- foodSafetyMenuDetailByTime,
- foodSafetyParentCheckAdd,
- foodSafetyParentCheckDetail,
- foodSafetyParentCheckEdit
- } from "@/api/food_safety.js"
- import upload from "@/api/upload.js"
- export default {
- components: {
- timeWeek
- },
- data() {
- return {
- scoreList: [{ //评分标准
- text: '优',
- id: 1
- },
- {
- text: '中',
- id: 2
- }, {
- text: '差',
- id: 3
- }
- ],
- id: null,
- timer: null,
- numberCurrent: null, //菜品数量状态
- tasteCurrent: null, //菜品味道状态
- dataFrom: {
- checkType: null, //检查类型
- checkUserCode: null, //检查者
- checkUserName: null, //检查者姓名
- pictures: null, //检查记录图片
- suggestion: null, //意见建议
- tasteEvaluate: null, //菜品味道评价
- quantityEvaluate: null //菜品数量评价
- },
- details: "", //详情
- supplyMenu: [], //菜谱列表
- supplyPicture: [], //菜谱图片列表
- fileImg: [], //上传图片列表
- fileLists: [],
- stateFlag: false
- }
- },
- created() {
- this.get_details() //获取数据详情
- this.get_detaisl_same() //查询当天是否有检查记录
- },
- methods: {
- number_change(index) { //菜品数量
- if (this.numberCurrent == this.scoreList[index].id) {
- this.numberCurrent = null
- this.dataFrom.quantityEvaluate = null
- } else {
- this.numberCurrent = this.scoreList[index].id
- this.dataFrom.quantityEvaluate = this.scoreList[index].id
- }
- },
- taste_change(index) { //菜品味道
- if (this.tasteCurrent == this.scoreList[index].id) {
- this.tasteCurrent = null
- this.dataFrom.tasteEvaluate = null
- } else {
- this.tasteCurrent = this.scoreList[index].id
- this.dataFrom.tasteEvaluate = this.scoreList[index].id
- }
- },
- get_detaisl_same() { //查询当天是否有检查记录
- var time = new Date();
- var year = time.getFullYear(); //年
- var month = (time.getMonth() + 1 + "").padStart(2, "0"); //月
- var date = (time.getDate() + "").padStart(2, "0"); //日
- this.timer = `${year}-${month}-${date}`
- var data = {
- createTime: this.timer,
- checkType: 0
- }
- foodSafetyParentCheckDetail(data).then(res => {
- if (res.data) {
- this.stateFlag = true
- this.dataFrom.checkUserName = res.data.checkUserName //获取新的检测员
- this.dataFrom.suggestion = res.data.suggestion //获取新的意见留言
- this.numberCurrent = res.data.quantityEvaluate //获取新的菜品数量状态
- this.tasteCurrent = res.data.tasteEvaluate //获取新的菜品数量状态
- this.dataFrom.tasteEvaluate = res.data.tasteEvaluate //获取新的菜品数量
- this.dataFrom.quantityEvaluate = res.data.quantityEvaluate //获取新的菜品数量
- this.dataFrom.checkType = res.data.checkTyp //获取新的检查类型
- this.id = res.data.id //获取id
- this.imgDetailsList = res.data.pictures //获取返回的图片
- this.fileLists = []
- if (res.data.pictures) {
- var arrImg = res.data.pictures.split(',')
- for (var i = 0; i < arrImg.length; i++) {
- var url = urlConfig +
- '/sysFileInfo/previewByObjectName?fileBucket=defaultBucket&fileObjectName=' +
- arrImg[i]
- var mydata = {
- "url": url,
- "fileID": arrImg[i]
- }
- this.fileLists.push(mydata);
- }
- }
- } else {
- this.stateFlag = false
- }
- })
- },
- get_details() { //获取数据详情
- this.dataFrom.checkUserName = uni.getStorageSync('Admin-Account'); //获取用户
- var time = new Date();
- var year = time.getFullYear(); //年
- var month = (time.getMonth() + 1 + "").padStart(2, "0"); //月
- var date = (time.getDate() + "").padStart(2, "0"); //日
- this.timer = `${year}-${month}-${date}`
- var data = {
- supplyTime: this.timer
- }
- foodSafetyMenuDetailByTime(data).then(res => { //获取详情
- if (res.data) {
- this.details = res.data
- this.dataFrom.checkUserCode = this.details.supplyCode; //检查者
- this.supplyMenu = this.details.supplyMenu.split(/,| |,/)
- if (this.details.supplyPicture) {
- var imgList = this.details.supplyPicture.split(',')
- imgList.forEach(item => {
- this.supplyPicture.push(urlConfig +
- '/sysFileInfo/previewByObjectName?fileBucket=defaultBucket&fileObjectName=' +
- item);
- })
- }
- }
- })
- },
- submit() { //提交
- var arrImg = [];
- for (var i = 0; i < this.fileImg.length; i++) {
- arrImg.push(this.fileImg[i].fileObjectName)
- }
- this.dataFrom.pictures = arrImg.join(','); //检查记录图片
- this.dataFrom.checkType = 0 //检查类型
- if (this.dataFrom.quantityEvaluate == null) {
- uni.showToast({
- icon: 'none',
- title: '请评价菜品数量',
- duration: 2000
- })
- } else if (this.dataFrom.tasteEvaluate == null) {
- uni.showToast({
- icon: 'none',
- title: '请评价菜品味道',
- duration: 2000
- })
- } else if (this.dataFrom.suggestion == null) {
- uni.showToast({
- icon: 'none',
- title: '请输入意见留言',
- duration: 2000
- })
- } else if (this.dataFrom.pictures == "") {
- uni.showToast({
- icon: 'none',
- title: '请添加图片',
- duration: 2000
- })
- } else {
- foodSafetyParentCheckAdd(this.dataFrom).then(res => {
- if (res.code == "00000") {
- uni.showToast({
- title: '提交成功',
- duration: 2000
- })
- this.dataFrom = {
- pictures: null, //检查记录图片
- suggestion: null, //意见建议
- tasteEvaluate: null, //菜品味道评价
- quantityEvaluate: null //菜品数量评价
- }
- this.fileImg = []
- this.fileLists = []
- this.numberCurrent = null //菜品数量状态
- this.tasteCurrent = null //菜品味道状态
- this.get_details()
- this.get_detaisl_same()
- }
- })
- }
- },
- modification() { //修改
- this.dataFrom.id = this.id //获取修改id
- var oldList = null
- var arr = []
- if (this.fileLists && this.fileLists.length > 0) {
- oldList = this.fileLists.map(item => item.fileID).join(',')
- }
- //检查记录图片
- if (this.fileImg != null && this.fileImg.length > 0) {
- this.fileImg.forEach(item => {
- arr.push(item.fileObjectName)
- })
- if (oldList) {
- this.dataFrom.pictures = oldList + ',' + arr.join(',')
- this.fileImg = []
- } else {
- this.dataFrom.pictures = arr.join(',')
- this.fileImg = []
- }
- } else {
- if (oldList) {
- this.dataFrom.pictures = oldList
- } else {
- this.dataFrom.pictures = arr.join(',')
- }
- }
-
-
- // this.dataFrom.pictures = ""
- foodSafetyParentCheckEdit(this.dataFrom).then(res => {
- if (res.code == "00000") {
- uni.showToast({
- title: '修改成功',
- duration: 2000
- })
- this.get_detaisl_same() //查询当天是否有检查记录
- }
- })
- },
- select(e) { //上传图片
- let that = this
- uni.showLoading({
- title: "上传中"
- });
- const tempFilePaths = e.tempFilePaths;
- for (var i = 0; i < tempFilePaths.length; i++) {
- const tempFile = e.tempFiles[i];
- uni.uploadFile({
- url: urlConfig + '/sysFileInfo/upload',
- header: {
- 'Authorization': uni.getStorageSync('Admin-Token')
- },
- formData: {
- secretFlag: 'N',
- fileLocation: 5
- },
- filePath: tempFilePaths[i],
- name: 'file',
- success: (uploadFileRes) => {
- uni.hideLoading();
- const back = JSON.parse(uploadFileRes.data);
- if (uploadFileRes.statusCode == 200) {
- that.$set(back.data, "uuid", tempFile.uuid)
- that.$set(back.data, "path", tempFile.path)
- that.$set(back.data, "url", tempFile.url)
- that.fileImg.push(back.data);
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast("上传失败,请联系开发!")
- },
- complete: function() {
- uni.hideLoading();
- }
- });
- }
- },
- del_img(e) { //删除图片
- this.fileImg.map((item, index) => {
- if (item.url == e.tempFile.url) {
- this.fileImg.splice(index, 1)
- }
- })
- this.fileLists.map((item, index) => {
- if (item.fileID == e.tempFile.fileID) {
- this.fileLists.splice(index, 1)
- }
- })
- },
- previewImage() { //预览图片
- uni.previewImage({
- current: 0,
- urls: this.supplyPicture
- })
- }
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .content {
-
- .title {
- background-color: #F5F5F5;
- margin-bottom: 24rpx;
- margin-top: 24rpx;
- display: flex;
- align-items: center;
-
- text {
- display: block;
- padding: 20rpx 0;
-
- &:last-child {
- padding-left: 10rpx;
- }
-
- &:first-child {
- padding-right: 10rpx;
- padding-left: 20rpx;
- }
- }
- }
-
- .wrap {
- width: 95%;
- margin: 0 auto;
- }
-
-
- .data_info {
- .list {
- display: flex;
- align-items: center;
- margin-bottom: 24rpx;
- background-color: #F5F5F5;
- padding: 20rpx;
- box-sizing: border-box;
-
- text {
- display: inline-block;
-
- &:last-child {
- color: #999999;
- flex: 3;
- }
- }
-
- .checkbox {
- display: flex;
- align-items: center;
-
- label {
- padding-right: 20rpx;
- }
-
- radio {
- transform: scale(.8)
- }
- }
- }
-
- .foods {
- padding-bottom: 24rpx;
-
- text {
- font-size: 28rpx;
- color: #666666;
- display: block;
- text-align: center;
- }
-
- .foods_img {
- display: flex;
- align-items: center;
- justify-content: space-between;
- border: 1px solid #EEEEEE;
-
- .text {
- flex: 1;
- width: 50%;
- }
-
- .img {
- flex: 1;
- width: 50%;
- box-sizing: border-box;
- border-left: 1px solid #EEEEEE;
-
- image {
- width: 80%;
- height: 180rpx;
- display: block;
- margin: 24rpx auto;
- }
- }
- }
-
- .foods_text {
- border: 1px solid #EEEEEE;
- border-top: none;
- display: flex;
- align-items: center;
- justify-content: space-between;
-
- .text {
- flex: 1;
- width: 50%;
- }
-
- .foods_list {
- border-left: 1px solid #EEEEEE;
- flex: 1;
- width: 50%;
- padding: 24rpx 0;
-
- text {
- line-height: 40rpx;
- }
- }
- }
- }
-
- .feedback {
- padding-bottom: 24rpx;
-
- text {
- display: block;
- background-color: #F5F5F5;
- padding: 20rpx;
- }
- }
-
- .add_image {
- padding-bottom: 24rpx;
-
- text {
- display: block;
- background-color: #F5F5F5;
- padding: 20rpx;
- }
-
- .upload {
- .add {
-
- image {
- width: 100rpx;
- }
- }
- }
- }
- }
- }
- </style>
-
- <template>
- <view class="file">
- <uni-file-picker file-mediatype="all" @select="select" @delete='del' v-model="showDetalistFile">
- <view class="text_img">
- <image src="@/static/images/upload.png" mode=""></image>
- <text>添加附件</text>
- </view>
- </uni-file-picker>
- </view>
- </template>
-
- <script>
- import uniFilePicker from "@/components/uni-file-picker/uni-file-picker.vue"
- import {
- courseActivityTeacheractivityCode
- } from "@/api/course_activity.js"
- import urlConfig from "@/utils/config.js"
- export default {
- data() {
- return {
- submitFrom: {
- activityCode: null, //activityCode
- experience: null, //心得体会
- coursewares: null //上传文档
- },
- fileUrl: [],
- dataDetails: {},
- detalistFile: [],
- showDetalistFile: []
- }
- },
-
- async mounted() {
- await this.get_details()
- },
- components: {
- uniFilePicker
- },
- methods: {
- get_details() { //获取详情数据
- courseActivityTeacherDetail(this.code).then(res => {
- if (res.data.courseActivityTeacher) {
- this.dataDetails = res.data.courseActivityTeacher
- this.submitFrom.experience = this.dataDetails.experience
- }
- if (res.data.fileinfos) {
- this.detalistFile = res.data.fileinfos
- for (var i = 0; i < this.detalistFile.length; i++) {
- var mydata = {
- "name": this.detalistFile[i].fileOriginName,
- "extname": this.detalistFile[i].fileSuffix,
- "url": "",
- "fileId": this.detalistFile[i].fileId,
- }
- this.showDetalistFile.push(mydata);
- }
- }
- if (res.data.courseActivityTeacher) {
- this.stateFlag = res.data.courseActivityTeacher.statusFlag
- } else {
- this.stateFlag = null
- }
- })
- },
- submit() { //点击提交
- var coursewares = [];
- for (var i = 0; i < this.detalistFile.length; i++) {
- coursewares.push(this.detalistFile[i].fileId)
- }
- this.submitFrom.coursewares = coursewares.join(',');
- courseActivityTeacheraddExperience(this.submitFrom).then(res => {
- if (res.code == "00000") {
- this.submitFrom = null
- uni.redirectTo({
- url: "/pages/course_activity/course_activity_manager/activity-list"
- })
- uni.showToast({
- title: '提交成功',
- duration: 2000
- })
- }
- })
- },
- select(e) {
- let that = this
- uni.showLoading({
- title: "上传中"
- });
- const tempFilePaths = e.tempFilePaths;
- for (var i = 0; i < tempFilePaths.length; i++) {
- const tempFile = e.tempFiles[i];
- uni.uploadFile({
- url: urlConfig + '/sysFileInfo/upload',
- header: {
- 'Authorization': uni.getStorageSync('Admin-Token')
- },
- formData: {
- secretFlag: 'N',
- fileLocation: 5
- },
- filePath: tempFilePaths[i],
- name: 'file',
- success: (uploadFileRes) => {
- uni.hideLoading();
- const back = JSON.parse(uploadFileRes.data);
- if (uploadFileRes.statusCode == 200) {
- that.$set(back.data, "uuid", tempFile.uuid)
- that.detalistFile.push(back.data);
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast("上传失败,请联系开发!")
- },
- complete: function() {
- uni.hideLoading();
- }
- });
- }
- },
- del(e) { //删除
- this.detalistFile.map((item, index) => {
- if (item.uuid) {
- if (item.uuid == e.tempFile.uuid) {
- this.detalistFile.splice(index, 1)
- }
- } else {
- if (item.fileId == e.tempFile.fileId) {
- this.detalistFile.splice(index, 1)
- }
- }
- })
- }
- }
- }
- </script>
- <template>
- <view class="content">
- <view class="wrap">
-
- <!-- 活动通知开始 -->
- <view class="activity_inform">
- <view class="list">
- <text>教研活动主题:</text>
- <text>{{details.name}}</text>
- </view>
- <view class="list">
- <text>教研活动时间:</text>
- <text>{{details.updateTime}} 至 {{details.endTime}}</text>
- </view>
- <view class="list">
- <text>教研活动地点:</text>
- <text>{{details.place}}</text>
- </view>
- <view class="list">
- <text>参加活动成员:</text>
- <text>{{details.teacherGrades}}</text>
- </view>
- </view>
- <!-- 活动通知结束 -->
-
- <!-- 心得体会开始 -->
- <view class="activity_experience" v-if="stateFlag == 1">
- <view class="textarea">
- <textarea placeholder-style="color:#999999" placeholder="请填写心得体会" v-model="submitFrom.experience" />
- </view>
- <view class="file">
- <uni-file-picker file-mediatype="all" @select="select" @delete='del' v-model="showDetalistFile">
- <view class="text_img">
- <image src="@/static/images/upload.png" mode=""></image>
- <text>添加附件</text>
- </view>
- </uni-file-picker>
- </view>
- </view>
- <!-- 心得体会结束 -->
-
- <!-- 按钮开始 -->
- <view class="btn" v-if="stateFlag == null">
- <button type="primary" @click="join_activities">参加活动</button>
- <button type="default" @click="go_back">返回</button>
- </view>
- <view class="btn" v-if="stateFlag == 0">
- <button type="primary" @click="sign_in">签到</button>
- </view>
- <view class="btn" v-if="stateFlag == 1">
- <button type="default">签到成功</button>
- <button type="primary" @click="submit">提交</button>
- </view>
- <!-- 按钮结束 -->
-
- </view>
- </view>
- </template>
-
- <script>
- import uniFilePicker from "@/components/uni-file-picker/uni-file-picker.vue"
- import {
- courseActivityTeacherDetail,
- courseActivityTeacherAdd,
- courseActivityTeacheraddExperience,
- courseActivityTeacheractivityCode
- } from "@/api/course_activity.js"
- import upload from "@/api/upload.js"
- export default {
- data() {
- return {
- details: null, //详情
- stateFlag: null, //状态
- code: null,
- dataFrom: {
- activityCode: null //活动code
- },
- submitFrom: {
- activityCode: null, //activityCode
- experience: null, //心得体会
- coursewares: null //上传文档
- },
- fileUrl: [],
- dataDetails: {},
- detalistFile: [],
- showDetalistFile: []
- }
- },
- onLoad(option) {
- this.details = JSON.parse(decodeURIComponent(option.item))
- this.code = this.details.code
- this.dataFrom.activityCode = this.details.code
- this.submitFrom.activityCode = this.details.code
- },
- async mounted() {
- await this.get_details()
- },
- components: {
- uniFilePicker
- },
- methods: {
- get_details() { //获取详情数据
- courseActivityTeacherDetail(this.code).then(res => {
- if (res.data.courseActivityTeacher) {
- this.dataDetails = res.data.courseActivityTeacher
- this.submitFrom.experience = this.dataDetails.experience
- }
- if (res.data.fileinfos) {
- this.detalistFile = res.data.fileinfos
- for (var i = 0; i < this.detalistFile.length; i++) {
- var mydata = {
- "name": this.detalistFile[i].fileOriginName,
- "extname": this.detalistFile[i].fileSuffix,
- "url": this.detalistFile[i].fileId,
- "fileId": this.detalistFile[i].fileId,
- }
- this.showDetalistFile.push(mydata);
- }
- }
- if (res.data.courseActivityTeacher) {
- this.stateFlag = res.data.courseActivityTeacher.statusFlag
- } else {
- this.stateFlag = null
- }
- })
- },
- join_activities() { //点击参加活动
- courseActivityTeacherAdd(this.dataFrom).then(res => {
- this.get_details()
- })
- },
- go_back() { //点击返回
- uni.navigateTo({
- url: "/pages/course_activity/course_activity_manager/activity-list"
- })
- },
- sign_in() { //点击签到
- courseActivityTeacheractivityCode(this.dataFrom).then(res => {
- this.get_details()
- })
- },
- submit() { //点击提交
- if (this.submitFrom.experience == null) {
- uni.showToast({
- icon: 'none',
- title: '请填写心得体会',
- duration: 2000
- })
- } else {
- var coursewares = [];
- for (var i = 0; i < this.detalistFile.length; i++) {
- coursewares.push(this.detalistFile[i].fileId)
- }
- this.submitFrom.coursewares = coursewares.join(',');
- courseActivityTeacheraddExperience(this.submitFrom).then(res => {
- if (res.code == "00000") {
- this.submitFrom = null
- uni.redirectTo({
- url: "/pages/course_activity/course_activity_manager/activity-list"
- })
- uni.showToast({
- title: '提交成功',
- duration: 2000
- })
- }
- })
- }
- },
- select(e) {
- let that = this
- uni.showLoading({
- title: "上传中"
- });
- const tempFilePaths = e.tempFilePaths;
- for (var i = 0; i < tempFilePaths.length; i++) {
- const tempFile = e.tempFiles[i];
- uni.uploadFile({
- url: upload,
- header: {
- 'Authorization': uni.getStorageSync('Admin-Token')
- },
- filePath: tempFilePaths[i],
- name: 'file',
- success: (uploadFileRes) => {
- uni.hideLoading();
- const back = JSON.parse(uploadFileRes.data);
- if (uploadFileRes.statusCode == 200) {
- that.$set(back.data, "uuid", tempFile.uuid)
- that.$set(back.data, "path", tempFile.path)
- that.$set(back.data, "url", tempFile.url)
- that.detalistFile.push(back.data);
- }
- },
- fail: () => {
- uni.hideLoading();
- uni.showToast("上传失败,请联系开发!")
- },
- complete: function() {
- uni.hideLoading();
- }
- });
- }
- },
- del(e) { //删除
- this.detalistFile.map((item, index) => {
- if (e.tempFile.uuid) {
- if (item.uuid == e.tempFile.uuid) {
- this.detalistFile.splice(index, 1)
- }
- } else {
- if (item.url == e.tempFile.fileId || item.fileId == e.tempFile.fileId) {
- this.detalistFile.splice(index, 1)
- }
- }
- })
-
- }
- }
- }
- </script>
-
- <style lang="scss" scoped>
- .content {
-
- .wrap {
- width: 95%;
- margin: 0 auto;
- }
-
- .activity_inform {
- .list {
- margin-top: 24rpx;
- background-color: #F5F5F5;
- padding: 20rpx;
- border-radius: 8rpx;
- box-sizing: border-box;
- display: flex;
- align-items: center;
-
- &:nth-child(2) {
- display: block;
-
- text:last-child {
- display: block;
- padding-top: 10rpx;
- }
- }
-
- text {
- color: #333333;
-
- &:last-child {
- color: #999999;
- flex: 3;
- }
- }
- }
- }
-
- .activity_experience {
- .textarea {
- padding-top: 24rpx;
- }
-
- .file {
- padding-top: 24rpx;
-
- text {
- display: block;
- }
-
- .text_img {
- display: flex;
- align-items: center;
-
- image {
- width: 40rpx;
- height: 40rpx;
- padding-right: 10rpx;
- }
- }
- }
-
- }
-
- .btn {
- padding-top: 24rpx;
- }
- }
- </style>
- <template>
-
- <view class="center">
-
- <!-- 上传图片 -->
- <view class="uploadcontainer">
- <view class="uploadBox" v-for="(item, i) in imgList" :key="i.id">
- <view class="uploadCenter">
- <image :src="item.url" width='aspectFill' @click="viewImage(i)">
- </image>
- <uni-icons color='#fff' type="closeempty" class="closeClass" size="20" @click="delImg(i)">
- </uni-icons>
- </view>
- </view>
- <view class="uploadAdd" @tap="upload" v-if="imgList.length < 9">
- <view class="uploadAddImg">
- <image src="../../static/imgAdd.png" mode="aspectFill"></image>
- </view>
- </view>
- </view>
-
-
- <button type="default" @click="submit" :disabled="cannotFlag">提交</button>
- </view>
- </template>
-
-
-
- <script>
- export default {
- data() {
- return {
- imgList: [],
- imgUrl: '/sysFileInfo/previewByObjectName?fileBucket=defaultBucket&fileObjectName=',
- urlConfig: "http://192.168.10.109:8080",
- cannotFlag: false
- }
- },
- methods: {
- submit() {
- var arrList = []
- arrList = (this.imgList.map(item => item.id)).join(',')
- console.log(arrList)
- },
- upload() {
- var that = this;
- uni.chooseImage({
- count: 10,
- sizeType: ['compressed'], //可以指定是原图还是压缩图,默认二者都有
- sourceType: ['album', 'camera'], //从相册、相机选择
- success: function(res) {
- that.cannotFlag = true
- var countupload = 0;
- for (var i = 0; i < res.tempFiles.length; i++) {
- if (res.tempFiles[i].size / 1024 / 1024 > 5) {
- uni.showToast({
- icon: 'none',
- title: '图片过大,请重新上传',
- duration: 3000
- })
- return
- }
- var imageType = res.tempFiles[i].type == "image/jpeg" || res.tempFiles[i].type ==
- "image/jpg" || res.tempFiles[i].type == "image/png" || res.tempFiles[i].type ==
- "image/gif"
- if (!imageType) {
- uni.showToast({
- icon: 'none',
- title: '图片类型不正确,请重新上传',
- duration: 3000
- })
- return
- }
- if (res.tempFiles.length > 9) {
- uni.showToast({
- icon: 'none',
- title: '一次最多只能添加9张图片',
- duration: 3000
- })
- that.cannotFlag = false;
- return
- }
- if (that.imgList.length + res.tempFiles.length > 10) {
- uni.showToast({
- icon: 'none',
- title: '最多只能上传10张',
- duration: 3000
- })
- that.cannotFlag = false;
- return
- }
- const tempFilePaths = res.tempFiles[i].path;
- // 图片传
- uni.showLoading({
- title: "上传中"
- });
- const uploadTask = uni.uploadFile({
- url: 'http://192.168.10.109:8080/sysFileInfo/upload?secretFlag=N', // post请求地址
- filePath: tempFilePaths,
- name: 'file', // 待确认
- header: {
- 'Authorization': 'eyJhbGciOiJIUzUxMiJ9.eyJ1c2VySWQiOjE1NTQwMzAxMjU2MTEzMjMzOTQsImFjY291bnQiOiJ6Y3dsIiwidXVpZCI6ImY1NDRkYTBjLWE2ZmEtNGJmMy1hNjAzLTY0M2JmNTAwZWZlNCIsInJlbWVtYmVyTWUiOmZhbHNlLCJleHBpcmF0aW9uRGF0ZSI6MTY2MjAwMTg2NDA4MiwiY2FUb2tlbiI6ImVlNzY1Yzk5NGM0NzZhNjYxODlkNzNkODJjYjQyNTNiIiwib3RoZXJzIjpudWxsLCJzdWIiOiIxNTU0MDMwMTI1NjExMzIzMzk0IiwiaWF0IjoxNjYxMzk3MDY0LCJleHAiOjE2NjIwMDE4NjR9.lIgZSZeuMZBiCZcgnJ-CfEdWHsXUo9v3997ZNU-lzR6YHhjnYgry8E-dK0zt-qAaGL3w6khA_9-033wKqMe8Xw'
- },
- success: function(uploadFileRes) {
- var arrList = []
- arrList.push(JSON.parse(uploadFileRes.data).data);
- arrList.forEach(item => {
- that.imgList.push({
- url: `${that.urlConfig}${that.imgUrl}${item.fileObjectName}`,
- id: item.fileObjectName
- })
- })
- uni.hideLoading();
- },
- fail: function(uploadFileFail) {
- uni.hideLoading();
- },
- complete: (e) => {
- countupload++;
- if (countupload == res.tempFiles.length) {
- that.cannotFlag = false;
- }
- uni.hideLoading();
- }
- });
- }
- },
- error: function(e) {
- console.log(e);
- }
- });
- },
- delImg(i) {
- this.imgList.splice(i, 1);
- },
- viewImage(i) {
- var arrList = []
- arrList = this.imgList.map(item => item.url)
- uni.previewImage({
- current: i,
- urls: arrList
- });
- }
- }
- }
- </script>
-
-
- <style>
- .center {
- margin: 20rpx;
- }
-
- .uploadcontainer {
- display: flex;
- box-sizing: border-box;
- flex-wrap: wrap;
- margin: -10rpx
- }
-
- .uploadBox {
- width: 33.3%;
- padding-top: 33.33%;
- height: 0%;
- position: relative;
- }
-
- .uploadAdd {
- width: 33.3%;
- padding-top: 33.3%;
- height: 0%;
- position: relative;
- }
-
-
- .closeClass {
- position: absolute;
- top: 3px;
- right: 3px;
- height: 26px;
- line-height: 26px;
- width: 26px;
- border-radius: 50%;
- background-color: rgba(0, 0, 0, 0.5);
- }
-
- .uploadCenter {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- margin: 5px;
- border: 1px #eee solid;
- border-radius: 5px;
- overflow: hidden;
- }
-
- .uploadCenter image {
- width: 100%;
- height: 100%;
- }
-
- .uploadAddImg {
- position: absolute;
- top: 0;
- right: 0;
- bottom: 0;
- left: 0;
- margin: 5px;
- border: 1px #ccc solid;
- border-radius: 5px;
- overflow: hidden;
- }
-
- .uploadAddImg image {
- width: 100%;
- height: 100%;
- padding: 25px;
- box-sizing: border-box;
- }
- </style>
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。