allocationPerson.vue 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263
  1. <template>
  2. <view class="allocationPerson-page">
  3. <scroll-view class="scroll-y" scroll-y="true">
  4. <template v-if="title === '指派查核人员'">
  5. <tm-radio-group
  6. :list="empList"
  7. :defaultValue='details.empId'
  8. :setting="{
  9. value: 'employeeId',
  10. name: 'employeeName'
  11. }"
  12. :openkeys="[0]"
  13. @change="changeDetails"
  14. />
  15. </template>
  16. <template v-else>
  17. <div class="date-view">
  18. <view class="row">
  19. <text class="label">开始时间</text>
  20. <view class="date-box">
  21. <date-time-picker
  22. :height="100"
  23. :start="details.planStartDate"
  24. :end="details.planEndDate"
  25. :defaultValue="details.startDate"
  26. placeholder="请选择起始时间"
  27. pickType="startDate"
  28. @change="changeDateTime"
  29. />
  30. </view>
  31. </view>
  32. <view class="row">
  33. <text class="label">结束时间</text>
  34. <view class="date-box">
  35. <date-time-picker
  36. :height="100"
  37. :start="details.planStartDate"
  38. :end="details.planEndDate"
  39. :defaultValue="details.endDate"
  40. placeholder="请选择结束时间"
  41. pickType="endDate"
  42. @change="changeDateTime"
  43. />
  44. </view>
  45. </view>
  46. </div>
  47. </template>
  48. </scroll-view>
  49. <view class="fixed-buttom-btn" @click="sure">
  50. <text class="btn-text">确定</text>
  51. </view>
  52. </view>
  53. </template>
  54. <script>
  55. // 查核列表编辑 查核人和计划时间
  56. import { mapState } from "vuex";
  57. import moment from 'moment';
  58. export default {
  59. computed: {
  60. ...mapState({
  61. checkList: state => state.editCheckList.checkList
  62. })
  63. },
  64. data(){
  65. return {
  66. title: '', // 导航标题
  67. // 查核组员列表
  68. empList: [],
  69. // 组件信息
  70. details: {},
  71. // 服务器时间
  72. dateStr: '',
  73. timer: null,
  74. // 点击确定按钮是否直接保存
  75. isSubmit: false
  76. }
  77. },
  78. onLoad({ details }){
  79. const _details = details ? JSON.parse(details) : {};
  80. // 强制刷新返回查核列表页面
  81. if(getCurrentPages().length === 1){
  82. const {situationId, checkId, checkGroupId, planStartDate, planEndDate} = _details;
  83. uni.redirectTo({
  84. url: `/pages/editCheckList/editCheckList?situationId=${situationId}&checkId=${checkId}&checkGroupId=${checkGroupId}&startDate=${planStartDate}&endDate=${planEndDate}`
  85. });
  86. }
  87. this.getComponentInfo(_details);
  88. },
  89. watch: {
  90. title(newVal, oldVal){
  91. if(newVal === '设置查核时间'){
  92. this.getDateStr();
  93. !this.timer && (this.timer = setInterval(() => {
  94. this.getDateStr();
  95. }, 10000));
  96. }else {
  97. this.clearTimer();
  98. }
  99. }
  100. },
  101. destroyed() {
  102. this.clearTimer();
  103. },
  104. methods: {
  105. getComponentInfo(details) {
  106. this.setNavigationBarTitle(details.title);
  107. this.details = details;
  108. this.getEmpDeptTree(details.checkGroupId);
  109. },
  110. // 查询部门人员树
  111. getEmpDeptTree(checkGroupId) {
  112. this.$store.dispatch({
  113. type: 'allocationPerson/commActions',
  114. key: "getGroupEmpList",
  115. data: {checkGroupId}
  116. }).then(data => {
  117. if(data) {
  118. this.empList = data || [];
  119. }
  120. });
  121. },
  122. // 指派查核人员改变
  123. changeDetails(selectVal, selectData, index) {
  124. this.details = {
  125. ...this.details,
  126. empId: selectData.employeeId,
  127. empName: selectData.employeeName
  128. }
  129. },
  130. // 时间变化
  131. changeDateTime(dateObj, pickType) {
  132. if(pickType === 'startDate'){ // 开始时间变化
  133. this.diffDateTime(dateObj.f3, this.details.endDate);
  134. }else {
  135. this.diffDateTime(this.details.startDate, dateObj.f3);
  136. }
  137. this.details = {
  138. ...this.details,
  139. [pickType]: dateObj.f3
  140. };
  141. },
  142. // 开始时间和结束时间对比
  143. diffDateTime(startTime, endTime){
  144. if (moment(startTime).valueOf() > moment(endTime).valueOf()) {
  145. this.showModal('开始时间不能大于结束时间');
  146. }
  147. },
  148. // 点击确定
  149. sure() {
  150. const { empId, startDate, endDate} = this.details;
  151. if(this.isSubmit === true) {
  152. return this.changeCheckList(this.checkList);
  153. }
  154. if(this.title === '指派查核人员'){
  155. if(!empId){
  156. return this.showModal('请选择查核人');
  157. }
  158. this.setNavigationBarTitle('设置查核时间');
  159. }else {
  160. if(!startDate){
  161. return this.showModal('请选择开始时间');
  162. }
  163. if(!endDate){
  164. return this.showModal('请选择结束时间');
  165. }
  166. if(!empId){
  167. this.setNavigationBarTitle('指派查核人员');
  168. this.isSubmit = true;
  169. }else {
  170. this.changeCheckList(this.checkList);
  171. }
  172. }
  173. },
  174. // 更改查核列表数据
  175. changeCheckList(data) {
  176. const { situationId, checkId, checkGroupId } = this.details;
  177. let checkList = this.checkList.map((item, i) => {
  178. if(this.details.index === i) {
  179. return {
  180. ...item,
  181. ...this.details
  182. }
  183. }else {
  184. return item;
  185. }
  186. });
  187. this.$store.commit({
  188. type: 'editCheckList/comChangeState',
  189. key: 'checkList',
  190. data: checkList
  191. });
  192. // 关闭当前页面,返回上一页面
  193. uni.navigateBack({delta: 1});
  194. },
  195. // 修改导航名称
  196. setNavigationBarTitle(title) {
  197. this.title = title;
  198. uni.setNavigationBarTitle({
  199. title
  200. });
  201. },
  202. // 获取当前时间
  203. getDateStr() {
  204. this.$store.dispatch({
  205. type: "commActions",
  206. key: "getDateStr" ,
  207. }).then((data) => {
  208. if (data) {
  209. this.dateStr = data;
  210. }
  211. });
  212. },
  213. showModal(content) {
  214. uni.showModal({
  215. content,
  216. showCancel: false
  217. });
  218. },
  219. // 清除定时器
  220. clearTimer(){
  221. if(this.timer){
  222. clearInterval(this.timer);
  223. this.timer = null;
  224. }
  225. }
  226. },
  227. }
  228. </script>
  229. <style lang="less">
  230. .allocationPerson-page {
  231. height: 100%;
  232. .scroll-y {
  233. height: calc(100% - 87.5rpx);
  234. padding-top: 15rpx;
  235. .date-view {
  236. padding: 0 25rpx;
  237. background: #fff;
  238. .row {
  239. display: flex;
  240. align-items: center;
  241. height: 62.5rpx;
  242. border-top: 0.62rpx solid #DADEE6;
  243. .label {
  244. width: 112.5rpx;
  245. font-size: 22.5rpx;
  246. color: #292C33;
  247. }
  248. .date-box {
  249. padding-left: 25rpx;
  250. flex: 1;
  251. }
  252. }
  253. }
  254. }
  255. }
  256. </style>