form.vue 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324
  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 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="Name"
  29. >
  30. <view class="select" 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="select" 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">删除</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. } from "@/services/daily";
  81. import { mapState, mapActions } from "vuex";
  82. export default {
  83. data() {
  84. return {
  85. scrollTop: 0,
  86. // projectList: [],
  87. project_id: "",
  88. log_id: "",
  89. formData: [
  90. {
  91. key: +new Date(),
  92. project_name: "",
  93. code_id: "",
  94. title: "",
  95. content: "",
  96. },
  97. ],
  98. rules: {
  99. project_name: {
  100. rules: [
  101. {
  102. required: true,
  103. errorMessage: "请选择项目名称",
  104. },
  105. ],
  106. },
  107. },
  108. };
  109. },
  110. onLoad() {
  111. },
  112. onLoad(options) {
  113. this.queryProjectList();
  114. if (options.id) {
  115. this.initDate(options.id);
  116. }
  117. if (options.project_id) {
  118. this.project_id = options.project_id;
  119. // this.formData[0].code_id = options.project_id
  120. }
  121. this.log_id = options.id;
  122. },
  123. computed: {
  124. ...mapState(["projectList"]),
  125. },
  126. methods: {
  127. ...mapActions(["queryProjectList"]),
  128. getProjectName(id) {
  129. const item = this.projectList.find(item => item.ID == id)
  130. return item ? item.Name : '-'
  131. },
  132. selectProject(key, e) {
  133. const select = this.projectList[e.target.value];
  134. const idx = this.formData.findIndex((item) => item.key == key);
  135. const item = this.formData[idx];
  136. const resultData = JSON.parse(JSON.stringify(this.formData));
  137. resultData[idx] = {
  138. ...item,
  139. code_id: select.ID,
  140. project_name: select.Name,
  141. };
  142. this.formData = resultData;
  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. await createDaily(this.formData);
  156. uni.showToast({
  157. title: "添加成功",
  158. });
  159. setTimeout(() => {
  160. uni.hideToast();
  161. uni.navigateBack();
  162. }, 1800);
  163. },
  164. async initDate(id) {
  165. this.formData = [
  166. {
  167. project_name: "11111",
  168. code_id: "11111",
  169. title: "11111",
  170. content: "11111",
  171. },
  172. {
  173. project_name: "3333",
  174. code_id: "22222",
  175. title: "22222",
  176. content: "22222",
  177. },
  178. {
  179. project_name: "45",
  180. code_id: "111511",
  181. title: "111161",
  182. content: "111811",
  183. },
  184. {
  185. project_name: "110111",
  186. code_id: "111911",
  187. title: "111119",
  188. content: "119111",
  189. },
  190. ];
  191. // const res = await approvalLogDaily({ id });
  192. // console.log(res);
  193. },
  194. async deleteLog() {
  195. await approvalDelLog(this.log_id);
  196. uni.showToast({
  197. title: "删除成功",
  198. });
  199. setTimeout(() => {
  200. uni.hideToast();
  201. uni.navigateBack();
  202. }, 1800);
  203. },
  204. },
  205. };
  206. </script>
  207. <style lang="less" scoped>
  208. .head {
  209. width: calc(100% - 60rpx);
  210. padding: 40rpx;
  211. position: fixed;
  212. background: url("~@/static/app-plus/menu-title-bg.png") no-repeat center;
  213. background-size: 100% 100%;
  214. background-color: #fff;
  215. display: flex;
  216. justify-content: space-between;
  217. align-items: center;
  218. z-index: 1;
  219. .title {
  220. font: 18px bold;
  221. color: #fff;
  222. }
  223. }
  224. .forms {
  225. padding: 40rpx 34rpx;
  226. padding-top: 168rpx;
  227. .titleContent {
  228. display: flex;
  229. justify-content: space-between;
  230. }
  231. .title2 {
  232. font-size: 28rpx;
  233. font-weight: 400;
  234. color: #4a90e2;
  235. line-height: 40rpx;
  236. padding-bottom: 18rpx;
  237. border-bottom: 1px solid #e8e8e8;
  238. }
  239. .title-sub {
  240. font-size: 28rpx;
  241. font-weight: 400;
  242. color: #4a4a4a;
  243. line-height: 40rpx;
  244. margin-top: 20rpx;
  245. margin-bottom: 20rpx;
  246. }
  247. .formItem {
  248. }
  249. .input,
  250. .textarea,
  251. .selectPlaceholder {
  252. font-size: 28rpx;
  253. padding-left: 24rpx;
  254. border: 1rpx solid #c0c0c0;
  255. }
  256. .input,
  257. .selectPlaceholder {
  258. line-height: 72rpx;
  259. height: 72rpx;
  260. }
  261. .textarea {
  262. padding-top: 10rpx;
  263. width: 400rpx;
  264. height: 200rpx;
  265. }
  266. }
  267. .form {
  268. margin: 0 20px;
  269. }
  270. .button {
  271. position: fixed;
  272. bottom: 0;
  273. left: 0;
  274. width: 100%;
  275. height: 100rpx;
  276. background: url("~@/static/btn-bg.png") no-repeat center;
  277. background-size: 100% 100%;
  278. font-size: 38rpx;
  279. font-weight: 500;
  280. color: #ffffff;
  281. line-height: 100rpx;
  282. text-align: center;
  283. }
  284. .btn-row {
  285. display: flex;
  286. justify-content: space-between;
  287. }
  288. .btn-add {
  289. width: 140rpx;
  290. height: 50rpx;
  291. border: 1rpx solid #329bfe;
  292. color: #329bfe;
  293. display: flex;
  294. justify-content: center;
  295. align-items: center;
  296. margin-left: 48rpx;
  297. }
  298. .box {
  299. position: relative;
  300. }
  301. .btn-remove {
  302. position: absolute;
  303. right: -10px;
  304. top: -12px;
  305. width: 12px;
  306. height: 12px;
  307. background: #f54444;
  308. border-radius: 50%;
  309. line-height: 20rpx;
  310. text-align: center;
  311. color: #fff;
  312. font-weight: bold;
  313. }
  314. .forms {
  315. padding-bottom: 140rpx;
  316. }
  317. </style>