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