form.vue 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  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(options) {
  107. this.queryProjectList();
  108. if (options.id) {
  109. this.initDate(options.id);
  110. }
  111. if (options.project_id) {
  112. this.project_id = options.project_id;
  113. }
  114. this.log_id = options.id;
  115. },
  116. computed: {
  117. ...mapState(["projectList"]),
  118. },
  119. methods: {
  120. ...mapActions(["queryProjectList"]),
  121. getProjectName(id) {
  122. const item = this.projectList.find((item) => item.id == id);
  123. return item ? item.project_name : "-";
  124. },
  125. selectProject(key, e) {
  126. const select = this.projectList[e.target.value];
  127. const item = this.formData.find((item) => item.key == key);
  128. item.code_id = select.id;
  129. item.project_name = select.project_name;
  130. console.log(this.formData);
  131. // this.formData = [...this.formData];
  132. },
  133. addFormData() {
  134. this.formData.push({
  135. key: +new Date(),
  136. project_name: "",
  137. });
  138. },
  139. removeFormData(key) {
  140. let index = this.formData.findIndex((item) => item.key == key);
  141. this.formData.splice(index, 1);
  142. },
  143. async submit() {
  144. // 从项目列表页进入的日志界面无须选择项目
  145. if (this.project_id) {
  146. this.formData.forEach((item) => (item.code_id = this.project_id));
  147. }
  148. await createDaily(this.formData);
  149. uni.showToast({
  150. title: "添加成功",
  151. });
  152. setTimeout(() => {
  153. uni.hideToast();
  154. uni.navigateBack();
  155. }, 1800);
  156. },
  157. async initDate(id) {
  158. //测试代码 详情接口有问题
  159. // this.formData = [
  160. // {
  161. // project_name: "11111",
  162. // code_id: "11111",
  163. // title: "11111",
  164. // content: "11111",
  165. // },
  166. // {
  167. // project_name: "3333",
  168. // code_id: "22222",
  169. // title: "22222",
  170. // content: "22222",
  171. // },
  172. // {
  173. // project_name: "45",
  174. // code_id: "111511",
  175. // title: "111161",
  176. // content: "111811",
  177. // },
  178. // {
  179. // project_name: "110111",
  180. // code_id: "111911",
  181. // title: "111119",
  182. // content: "119111",
  183. // },
  184. // ];
  185. const res = await approvalLogDaily({ id });
  186. console.log(res);
  187. },
  188. async deleteLog() {
  189. await approvalDelLog(this.log_id);
  190. uni.showToast({
  191. title: "删除成功",
  192. });
  193. setTimeout(() => {
  194. uni.hideToast();
  195. uni.navigateBack();
  196. }, 1800);
  197. },
  198. async editLog() {
  199. await approvalEditLog({ log_id: this.log_id, formData: this.formData });
  200. uni.showToast({
  201. title: "编辑成功",
  202. });
  203. setTimeout(() => {
  204. uni.hideToast();
  205. uni.navigateBack();
  206. }, 1800);
  207. },
  208. },
  209. };
  210. </script>
  211. <style lang="less" scoped>
  212. .head {
  213. width: calc(100% - 60rpx);
  214. padding: 40rpx;
  215. position: fixed;
  216. background: url("~@/static/app-plus/menu-title-bg.png") no-repeat center;
  217. background-size: 100% 100%;
  218. background-color: #fff;
  219. display: flex;
  220. justify-content: space-between;
  221. align-items: center;
  222. z-index: 1;
  223. .title {
  224. font: 18px bold;
  225. color: #fff;
  226. }
  227. }
  228. .forms {
  229. padding: 40rpx 34rpx;
  230. padding-top: 168rpx;
  231. .titleContent {
  232. display: flex;
  233. justify-content: space-between;
  234. }
  235. .title2 {
  236. font-size: 28rpx;
  237. font-weight: 400;
  238. color: #4a90e2;
  239. line-height: 40rpx;
  240. padding-bottom: 18rpx;
  241. border-bottom: 1px solid #e8e8e8;
  242. }
  243. .title-sub {
  244. font-size: 28rpx;
  245. font-weight: 400;
  246. color: #4a4a4a;
  247. line-height: 40rpx;
  248. margin-top: 20rpx;
  249. margin-bottom: 20rpx;
  250. }
  251. .formItem {
  252. }
  253. .proName,
  254. .input,
  255. .textarea,
  256. .selectPlaceholder {
  257. font-size: 28rpx;
  258. padding-left: 24rpx;
  259. border: 1rpx solid #c0c0c0;
  260. }
  261. .proName,
  262. .input,
  263. .selectPlaceholder {
  264. line-height: 72rpx;
  265. height: 72rpx;
  266. }
  267. .textarea {
  268. padding-top: 10rpx;
  269. width: 400rpx;
  270. height: 200rpx;
  271. }
  272. .proName {
  273. width: 400rpx;
  274. white-space: nowrap;
  275. text-overflow: ellipsis;
  276. overflow: hidden;
  277. }
  278. }
  279. .form {
  280. margin: 0 20px;
  281. }
  282. .button {
  283. position: fixed;
  284. bottom: 0;
  285. left: 0;
  286. width: 100%;
  287. height: 100rpx;
  288. background: url("~@/static/btn-bg.png") no-repeat center;
  289. background-size: 100% 100%;
  290. font-size: 38rpx;
  291. font-weight: 500;
  292. color: #ffffff;
  293. line-height: 100rpx;
  294. text-align: center;
  295. }
  296. .btn-row {
  297. display: flex;
  298. justify-content: space-between;
  299. }
  300. .btn-add {
  301. width: 140rpx;
  302. height: 50rpx;
  303. border: 1rpx solid #329bfe;
  304. color: #329bfe;
  305. display: flex;
  306. justify-content: center;
  307. align-items: center;
  308. margin-left: 48rpx;
  309. }
  310. .box {
  311. position: relative;
  312. }
  313. .btn-remove {
  314. position: absolute;
  315. right: -10px;
  316. top: -12px;
  317. width: 12px;
  318. height: 12px;
  319. background: #f54444;
  320. border-radius: 50%;
  321. line-height: 20rpx;
  322. text-align: center;
  323. color: #fff;
  324. font-weight: bold;
  325. }
  326. .forms {
  327. padding-bottom: 140rpx;
  328. }
  329. </style>