123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324 |
- <template>
- <view class="page">
- <view class="content">
- <view class="head">
- <span class="title">写日志</span>
- </view>
- <view class="forms">
- <view class="title2">张三的金科环境项目日志</view>
- <view class="title-sub">日志详情</view>
- <uni-forms label-position="left" class="form" ref="form" :rules="rules">
- <view class="box" v-for="item in formData" :key="item.key">
- <view
- v-show="formData.length > 1"
- class="btn-remove"
- @click="removeFormData(item.key)"
- >-</view
- >
- <uni-forms-item
- required
- label="项目名称"
- name="project_name"
- class="formItem"
- >
- <template v-if="!project_id">
- <picker
- @change="(e) => selectProject(item.key, e)"
- :range="projectList"
- range-key="Name"
- >
- <view class="select" v-if="item.project_name">
- {{ item.project_name }}
- </view>
- <view class="selectPlaceholder" v-else>请选择项目</view>
- </picker>
- </template>
- <view class="select" v-else>
- {{ getProjectName(project_id) }}
- </view>
- </uni-forms-item>
- <uni-forms-item
- required
- label="日志概述"
- name="title"
- class="formItem"
- >
- <input
- v-model="item.title"
- class="input"
- placeholder="请输入日志概述"
- />
- </uni-forms-item>
- <uni-forms-item
- required
- label="日志详情"
- name="content"
- class="formItem"
- >
- <textarea
- v-model="item.content"
- class="textarea"
- placeholder="请输入日志详情"
- />
- </uni-forms-item>
- </view>
- </uni-forms>
- <view class="btn-row">
- <view class="btn-add" @click="addFormData">+ 新增</view>
- <view class="btn-add" @click="deleteLog">删除</view>
- </view>
- </view>
- <view class="button" @click="submit">提 交</view>
- </view>
- </view>
- </template>
- <script>
- import {
- createDaily,
- approvalLogDaily,
- approvalDelLog,
- } from "@/services/daily";
- import { mapState, mapActions } from "vuex";
- export default {
- data() {
- return {
- scrollTop: 0,
- // projectList: [],
- project_id: "",
- log_id: "",
- formData: [
- {
- key: +new Date(),
- project_name: "",
- code_id: "",
- title: "",
- content: "",
- },
- ],
- rules: {
- project_name: {
- rules: [
- {
- required: true,
- errorMessage: "请选择项目名称",
- },
- ],
- },
- },
- };
- },
- onLoad() {
- },
- onLoad(options) {
- this.queryProjectList();
- if (options.id) {
- this.initDate(options.id);
- }
- if (options.project_id) {
- this.project_id = options.project_id;
- // this.formData[0].code_id = options.project_id
- }
- this.log_id = options.id;
- },
- computed: {
- ...mapState(["projectList"]),
- },
- methods: {
- ...mapActions(["queryProjectList"]),
- getProjectName(id) {
- const item = this.projectList.find(item => item.ID == id)
- return item ? item.Name : '-'
- },
- selectProject(key, e) {
- const select = this.projectList[e.target.value];
- const idx = this.formData.findIndex((item) => item.key == key);
- const item = this.formData[idx];
- const resultData = JSON.parse(JSON.stringify(this.formData));
- resultData[idx] = {
- ...item,
- code_id: select.ID,
- project_name: select.Name,
- };
- this.formData = resultData;
- },
- addFormData() {
- this.formData.push({
- key: +new Date(),
- project_name: "",
- });
- },
- removeFormData(key) {
- let index = this.formData.findIndex((item) => item.key == key);
- this.formData.splice(index, 1);
- },
- async submit() {
- await createDaily(this.formData);
- uni.showToast({
- title: "添加成功",
- });
- setTimeout(() => {
- uni.hideToast();
- uni.navigateBack();
- }, 1800);
- },
- async initDate(id) {
- this.formData = [
- {
- project_name: "11111",
- code_id: "11111",
- title: "11111",
- content: "11111",
- },
- {
- project_name: "3333",
- code_id: "22222",
- title: "22222",
- content: "22222",
- },
- {
- project_name: "45",
- code_id: "111511",
- title: "111161",
- content: "111811",
- },
- {
- project_name: "110111",
- code_id: "111911",
- title: "111119",
- content: "119111",
- },
- ];
- // const res = await approvalLogDaily({ id });
- // console.log(res);
- },
- async deleteLog() {
- await approvalDelLog(this.log_id);
- uni.showToast({
- title: "删除成功",
- });
- setTimeout(() => {
- uni.hideToast();
- uni.navigateBack();
- }, 1800);
- },
- },
- };
- </script>
- <style lang="less" scoped>
- .head {
- width: calc(100% - 60rpx);
- padding: 40rpx;
- position: fixed;
- background: url("~@/static/app-plus/menu-title-bg.png") no-repeat center;
- background-size: 100% 100%;
- background-color: #fff;
- display: flex;
- justify-content: space-between;
- align-items: center;
- z-index: 1;
- .title {
- font: 18px bold;
- color: #fff;
- }
- }
- .forms {
- padding: 40rpx 34rpx;
- padding-top: 168rpx;
- .titleContent {
- display: flex;
- justify-content: space-between;
- }
- .title2 {
- font-size: 28rpx;
- font-weight: 400;
- color: #4a90e2;
- line-height: 40rpx;
- padding-bottom: 18rpx;
- border-bottom: 1px solid #e8e8e8;
- }
- .title-sub {
- font-size: 28rpx;
- font-weight: 400;
- color: #4a4a4a;
- line-height: 40rpx;
- margin-top: 20rpx;
- margin-bottom: 20rpx;
- }
- .formItem {
- }
- .input,
- .textarea,
- .selectPlaceholder {
- font-size: 28rpx;
- padding-left: 24rpx;
- border: 1rpx solid #c0c0c0;
- }
- .input,
- .selectPlaceholder {
- line-height: 72rpx;
- height: 72rpx;
- }
- .textarea {
- padding-top: 10rpx;
- width: 400rpx;
- height: 200rpx;
- }
- }
- .form {
- margin: 0 20px;
- }
- .button {
- position: fixed;
- bottom: 0;
- left: 0;
- width: 100%;
- height: 100rpx;
- background: url("~@/static/btn-bg.png") no-repeat center;
- background-size: 100% 100%;
- font-size: 38rpx;
- font-weight: 500;
- color: #ffffff;
- line-height: 100rpx;
- text-align: center;
- }
- .btn-row {
- display: flex;
- justify-content: space-between;
- }
- .btn-add {
- width: 140rpx;
- height: 50rpx;
- border: 1rpx solid #329bfe;
- color: #329bfe;
- display: flex;
- justify-content: center;
- align-items: center;
- margin-left: 48rpx;
- }
- .box {
- position: relative;
- }
- .btn-remove {
- position: absolute;
- right: -10px;
- top: -12px;
- width: 12px;
- height: 12px;
- background: #f54444;
- border-radius: 50%;
- line-height: 20rpx;
- text-align: center;
- color: #fff;
- font-weight: bold;
- }
- .forms {
- padding-bottom: 140rpx;
- }
- </style>
|