form.vue 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. <template>
  2. <view class="page">
  3. <view class="content">
  4. <view class="head">
  5. <span class="title">写日志</span>
  6. </view>
  7. <view class="forms">
  8. <view class="title2">{{ userName }}的金科环境项目日志</view>
  9. <view class="title-sub">日志详情</view>
  10. <uni-forms label-position="left" class="form" ref="form" :rules="rules">
  11. <view class="box" v-for="item in formData" :key="item.key">
  12. <view
  13. v-show="formData.length > 1"
  14. class="btn-remove"
  15. @click="removeFormData(item.key)"
  16. >-</view
  17. >
  18. <uni-forms-item
  19. required
  20. label="项目名称"
  21. name="project_name"
  22. class="formItem"
  23. >
  24. <template v-if="!project_id">
  25. <picker
  26. @change="(e) => selectProject(item.key, e)"
  27. :range="projectList"
  28. range-key="project_name"
  29. >
  30. <view class="proNameEdit" v-if="item.project_name">
  31. {{ item.project_name }}
  32. </view>
  33. <view class="selectPlaceholder" v-else>请选择项目</view>
  34. </picker>
  35. </template>
  36. <view class="proName" v-else>
  37. {{ getProjectName(project_id) }}
  38. </view>
  39. </uni-forms-item>
  40. <uni-forms-item
  41. required
  42. label="日志概述"
  43. name="title"
  44. class="formItem"
  45. >
  46. <input
  47. v-model="item.title"
  48. class="input"
  49. placeholder="请输入日志概述"
  50. />
  51. </uni-forms-item>
  52. <uni-forms-item
  53. required
  54. label="日志详情"
  55. name="content"
  56. class="formItem"
  57. >
  58. <textarea
  59. v-model="item.content"
  60. class="textarea"
  61. placeholder="请输入日志详情"
  62. />
  63. </uni-forms-item>
  64. </view>
  65. </uni-forms>
  66. <view class="btn-row">
  67. <view class="btn-add" @click="addFormData">+ 新增</view>
  68. <view class="btn-add" @click="deleteLog" v-if="log_id">删除</view>
  69. </view>
  70. </view>
  71. <view class="button" @click="submit">提 交</view>
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. import {
  77. createDaily,
  78. approvalLogDaily,
  79. approvalDelLog,
  80. approvalEditLog,
  81. } from "@/services/daily";
  82. import { mapState, mapActions } from "vuex";
  83. export default {
  84. data() {
  85. return {
  86. scrollTop: 0,
  87. // projectList: [],
  88. project_id: "",
  89. log_id: "",
  90. formData: [
  91. {
  92. key: +new Date(),
  93. project_name: "",
  94. code_id: "",
  95. title: "",
  96. content: "",
  97. },
  98. ],
  99. rules: {
  100. project_name: {
  101. rules: [
  102. {
  103. required: true,
  104. errorMessage: "请选择项目名称",
  105. },
  106. ],
  107. },
  108. },
  109. };
  110. },
  111. onLoad(options) {
  112. this.queryProjectList();
  113. if (options.id) {
  114. this.initDate(options.id);
  115. this.log_id = options.id;
  116. }
  117. if (options.project_id) {
  118. this.project_id = Number(options.project_id);
  119. }
  120. },
  121. computed: {
  122. ...mapState(["projectList"]),
  123. userName() {
  124. if (this.log_id) {
  125. return this.formData[0].author_name;
  126. }
  127. const user = uni.getStorageSync("user");
  128. return user.CName;
  129. },
  130. },
  131. methods: {
  132. ...mapActions(["queryProjectList"]),
  133. getProjectName(id) {
  134. const item = this.projectList.find((item) => item.id == id);
  135. return item ? item.project_name : "-";
  136. },
  137. selectProject(key, e) {
  138. const select = this.projectList[e.target.value];
  139. const item = this.formData.find((item) => item.key == key);
  140. item.code_id = select.id;
  141. item.project_name = select.project_name;
  142. // this.formData = [...this.formData];
  143. },
  144. addFormData() {
  145. this.formData.push({
  146. key: +new Date(),
  147. project_name: "",
  148. });
  149. },
  150. removeFormData(key) {
  151. let index = this.formData.findIndex((item) => item.key == key);
  152. this.formData.splice(index, 1);
  153. },
  154. async submit() {
  155. //编辑
  156. if (this.log_id) {
  157. this.editLog();
  158. return;
  159. }
  160. // 从项目列表页进入的日志界面无须选择项目
  161. if (this.project_id) {
  162. this.formData.forEach((item) => (item.code_id = this.project_id));
  163. }
  164. await createDaily(this.formData);
  165. uni.showToast({
  166. title: "添加成功",
  167. });
  168. setTimeout(() => {
  169. uni.hideToast();
  170. uni.navigateBack();
  171. }, 1800);
  172. },
  173. async initDate(id) {
  174. const res = await approvalLogDaily({ id });
  175. if (res.data) {
  176. this.formData = res.data;
  177. }
  178. },
  179. async deleteLog() {
  180. await approvalDelLog(this.log_id);
  181. uni.showToast({
  182. title: "删除成功",
  183. });
  184. setTimeout(() => {
  185. uni.hideToast();
  186. uni.navigateBack();
  187. }, 1800);
  188. },
  189. async editLog() {
  190. await approvalEditLog({ log_id: this.log_id, formData: this.formData });
  191. uni.showToast({
  192. title: "编辑成功",
  193. duration: 1800,
  194. });
  195. },
  196. },
  197. };
  198. </script>
  199. <style lang="less" scoped>
  200. .head {
  201. width: calc(100% - 60rpx);
  202. padding: 40rpx;
  203. position: fixed;
  204. background: url("~@/static/app-plus/menu-title-bg.png") no-repeat center;
  205. background-size: 100% 100%;
  206. background-color: #fff;
  207. display: flex;
  208. justify-content: space-between;
  209. align-items: center;
  210. z-index: 1;
  211. .title {
  212. font: 18px bold;
  213. color: #fff;
  214. }
  215. }
  216. .forms {
  217. padding: 40rpx 34rpx;
  218. padding-top: 168rpx;
  219. .titleContent {
  220. display: flex;
  221. justify-content: space-between;
  222. }
  223. .title2 {
  224. font-size: 28rpx;
  225. font-weight: 400;
  226. color: #4a90e2;
  227. line-height: 40rpx;
  228. padding-bottom: 18rpx;
  229. border-bottom: 1px solid #e8e8e8;
  230. }
  231. .title-sub {
  232. font-size: 28rpx;
  233. font-weight: 400;
  234. color: #4a4a4a;
  235. line-height: 40rpx;
  236. margin-top: 20rpx;
  237. margin-bottom: 20rpx;
  238. }
  239. .formItem {
  240. }
  241. .proNameEdit,
  242. .input,
  243. .textarea,
  244. .selectPlaceholder {
  245. font-size: 28rpx;
  246. padding-left: 24rpx;
  247. border: 1rpx solid #c0c0c0;
  248. }
  249. .proName,
  250. .proNameEdit,
  251. .input,
  252. .selectPlaceholder {
  253. line-height: 72rpx;
  254. height: 72rpx;
  255. }
  256. .textarea {
  257. padding-top: 10rpx;
  258. width: 400rpx;
  259. height: 200rpx;
  260. }
  261. .proName,
  262. .proNameEdit {
  263. width: 400rpx;
  264. white-space: nowrap;
  265. text-overflow: ellipsis;
  266. overflow: hidden;
  267. }
  268. }
  269. .form {
  270. margin: 0 20px;
  271. }
  272. .button {
  273. position: fixed;
  274. bottom: 0;
  275. left: 0;
  276. width: 100%;
  277. height: 100rpx;
  278. background: url("~@/static/btn-bg.png") no-repeat center;
  279. background-size: 100% 100%;
  280. font-size: 38rpx;
  281. font-weight: 500;
  282. color: #ffffff;
  283. line-height: 100rpx;
  284. text-align: center;
  285. }
  286. .btn-row {
  287. display: flex;
  288. justify-content: space-between;
  289. }
  290. .btn-add {
  291. width: 140rpx;
  292. height: 50rpx;
  293. border: 1rpx solid #329bfe;
  294. color: #329bfe;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. margin-left: 48rpx;
  299. }
  300. .box {
  301. position: relative;
  302. }
  303. .btn-remove {
  304. position: absolute;
  305. right: -10px;
  306. top: -12px;
  307. width: 12px;
  308. height: 12px;
  309. background: #f54444;
  310. border-radius: 50%;
  311. line-height: 20rpx;
  312. text-align: center;
  313. color: #fff;
  314. font-weight: bold;
  315. }
  316. .forms {
  317. padding-bottom: 140rpx;
  318. }
  319. </style>