form.vue 7.8 KB

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