TraceTimeLineEdit.vue 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. <!--
  2. 作者:yangzhijie1488@163.com
  3. 时间:2017-12-12
  4. 描述:创建追踪单时间节点
  5. 输入参数:从localstorage中输入参数
  6. {
  7. "canDelete": 是否可删除数据
  8. "canSave": 是否可保存数据
  9. "trace": 追踪单
  10. "traceTimeLine": 追踪单时间节点
  11. }
  12. -->
  13. <template>
  14. <div>
  15. <div>
  16. <Navbar title="时间节点" :is-go-back="true" />
  17. <div>
  18. <div class="form-group">
  19. <label for="exampleInputEmail2">添加检查项</label>
  20. <textarea
  21. id="hcqk"
  22. v-model="traceTimeLine.content"
  23. style="width: 100%"
  24. class="form-control"
  25. rows="5"
  26. />
  27. </div>
  28. <div class="form-group">
  29. <label for="exampleInputEmail2">负责人</label>
  30. <a-select
  31. v-model:value="traceTimeLine.userName"
  32. style="width: 100%; height: 30px"
  33. :options="allUsers"
  34. @change="getUser"
  35. />
  36. </div>
  37. <div class="form-group">
  38. <label for="exampleInputEmail2">截止时间</label>
  39. <a-config-provider :locale="locale">
  40. <a-date-picker
  41. v-model:value="planFinishedDate"
  42. style="width: 100%"
  43. show-time
  44. format="YYYY-MM-DD HH:mm:ss"
  45. :show-now="false"
  46. placeholder="请选择日期"
  47. />
  48. </a-config-provider>
  49. <!-- <Date v-model="traceTimeLine.endDate" style="width: 100%" /> -->
  50. </div>
  51. <div style="margin-top: 10px">
  52. <button
  53. type="text"
  54. class="btn btn-default"
  55. @click="saveTraceTimeLine()"
  56. >
  57. 确认
  58. </button>
  59. <button type="text" class="btn btn-default" @click="returnBack()">
  60. 取消
  61. </button>
  62. <button type="text" class="btn btn-default" @click="deleteById()">
  63. 删除
  64. </button>
  65. </div>
  66. </div>
  67. </div>
  68. <Loading v-if="loading" />
  69. </div>
  70. </template>
  71. <script>
  72. import { Notify } from 'pc-component-v3';
  73. import Common from '../common/Common.js';
  74. import zhCN from 'ant-design-vue/es/locale/zh_CN';
  75. import dayjs from 'dayjs';
  76. import 'dayjs/locale/zh-cn';
  77. import weekday from 'dayjs/plugin/weekday';
  78. import localeData from 'dayjs/plugin/localeData';
  79. dayjs.extend(weekday);
  80. dayjs.extend(localeData);
  81. dayjs.locale('zh-cn');
  82. export default {
  83. components: {},
  84. data: function () {
  85. return {
  86. traceTimeLineId: '', // 追踪单(输入参数)
  87. projectId: '', // 项目Id
  88. traceTimeLine: {
  89. trackId: undefined,
  90. userId: undefined,
  91. userName: undefined,
  92. content: undefined,
  93. endDate: undefined,
  94. }, // 追踪单时间节点(输入参数)
  95. loading: false,
  96. allUsers: [],
  97. locale: zhCN,
  98. planFinishedDate: '',
  99. };
  100. },
  101. mounted: function () {
  102. $('.input-tan').focus(function () {
  103. document.activeElement.blur();
  104. });
  105. this.initData();
  106. },
  107. methods: {
  108. /**
  109. * 初始化数据
  110. */
  111. initData: function () {
  112. var _self = this;
  113. this.traceTimeLineId = Number(this.$route.params.traceTimeLineId);
  114. this.projectId = Number(this.$route.query.projectId);
  115. this.loadTraceTimeLine();
  116. },
  117. // 获取负责人信息
  118. getUser: function (_, val) {
  119. this.traceTimeLine.userId = val.userId;
  120. this.traceTimeLine.userName = val.userName;
  121. },
  122. /**
  123. * 加载时间节点Id
  124. */
  125. loadTraceTimeLine: function () {
  126. var _self = this;
  127. $.ajax({
  128. url: Common.getApiURL('TraceTimeLineResource/uniqueTraceTimeLineDto'),
  129. type: 'get',
  130. contentType: 'application/json',
  131. beforeSend: function (request) {
  132. Common.addTokenToRequest(request);
  133. },
  134. data: {
  135. traceTimeLineId: _self.traceTimeLineId,
  136. },
  137. success: function (data) {
  138. _self.traceTimeLine = data;
  139. if(data.endDate !== '' && data.endDate){
  140. _self.planFinishedDate = dayjs(data.endDate,'YYYY-MM-DD HH:mm:ss');
  141. }
  142. _self.loadSelectUserName();
  143. _self.loading = false;
  144. },
  145. error: function (XMLHttpRequest, textStatus, errorThrown) {
  146. _self.loading = false;
  147. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  148. },
  149. });
  150. },
  151. /**@argument
  152. * 保存当前时间节点数据
  153. */
  154. saveTraceTimeLine: function () {
  155. var _self = this;
  156. _self.traceTimeLine.traceId = _self.traceId;
  157. var content = _self.traceTimeLine.content;
  158. _self.traceTimeLine.endDate = _self.dateConvert(_self.planFinishedDate);
  159. var dates = _self.traceTimeLine.endDate;
  160. if (
  161. content != null &&
  162. content != '' &&
  163. dates != null &&
  164. dates != undefined &&
  165. dates != ''
  166. ) {
  167. _self.loading = true;
  168. $.ajax({
  169. url: Common.getApiURL('TraceTimeLineResource/saveTraceTimeLine'),
  170. type: 'post',
  171. contentType: 'application/json',
  172. beforeSend: function (request) {
  173. Common.addTokenToRequest(request);
  174. },
  175. data: JSON.stringify(_self.traceTimeLine),
  176. success: function (data) {
  177. _self.loading = false;
  178. _self.returnBack();
  179. },
  180. error: function (XMLHttpRequest, textStatus, errorThrown) {
  181. _self.loading = false;
  182. Common.processException(XMLHttpRequest, textStatus, errorThrown);
  183. },
  184. });
  185. } else {
  186. _self.loading = false;
  187. Notify.error('提示', '请将界面内容填写完整!');
  188. }
  189. },
  190. /**@argument
  191. * 根据时间节点ID删除时间节点信息
  192. */
  193. deleteById: function () {
  194. var _self = this;
  195. _self.loading = true;
  196. $.ajax({
  197. url: Common.getApiURL('TraceTimeLineResource/deleteById'),
  198. type: 'get',
  199. data: {
  200. traceTimeLineId: _self.traceTimeLine.id,
  201. },
  202. beforeSend: function (request) {
  203. Common.addTokenToRequest(request);
  204. },
  205. success: function (data) {
  206. _self.loading = false;
  207. _self.returnBack();
  208. },
  209. error: function (xmlHttpRequest, textStatus, errorThrown) {
  210. _self.loading = false;
  211. Common.processException(xmlHttpRequest, textStatus, errorThrown);
  212. },
  213. });
  214. },
  215. /**@argument
  216. * 返回上一界面
  217. */
  218. returnBack: function () {
  219. history.back();
  220. },
  221. /**
  222. * 加载用户
  223. */
  224. loadSelectUserName: function () {
  225. var _self = this;
  226. $.ajax({
  227. url: Common.getApiURL(
  228. 'ProjectItemUserResource/listByProjectItemId?projectItemId=' +
  229. _self.projectId,
  230. ),
  231. type: 'get',
  232. dataType: 'json',
  233. beforeSend: function (request) {
  234. Common.addTokenToRequest(request);
  235. },
  236. success: function (data) {
  237. data.forEach(item => {
  238. item.value = item.userId;
  239. item.label = item.userName;
  240. });
  241. _self.allUsers = data;
  242. },
  243. error: function (errorData) {
  244. Common.processException(errorData);
  245. },
  246. });
  247. },
  248. // 日期处理函数
  249. plusZero: function (n) {
  250. return n >= 10 ? n : '0' + n;
  251. },
  252. dateConvert: function (dateStr) {
  253. const date = new Date(dateStr);
  254. const year = date.getFullYear();
  255. const month = date.getMonth() + 1;
  256. const day = date.getDate();
  257. const hour = date.getHours();
  258. const minute = date.getMinutes();
  259. const second = date.getSeconds();
  260. return (
  261. year +
  262. '-' +
  263. this.plusZero(month) +
  264. '-' +
  265. this.plusZero(day) +
  266. ' ' +
  267. this.plusZero(hour) +
  268. ':' +
  269. this.plusZero(minute) +
  270. ':' +
  271. this.plusZero(second)
  272. );
  273. },
  274. },
  275. };
  276. </script>
  277. <style scoped>
  278. </style>