index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  1. <template>
  2. <view class="addactiyity-container">
  3. <van-form>
  4. <van-field
  5. :value="formatterLabelTime(formData.startTime)"
  6. is-link
  7. readonly
  8. clickable
  9. name="datetimePicker"
  10. label="开始时间"
  11. placeholder="选择开始时间"
  12. @click.native="clickTimeChoose('start')"
  13. />
  14. <van-field
  15. :value="formatterLabelTime(formData.endTime)"
  16. is-link
  17. readonly
  18. clickable
  19. name="datetimePicker"
  20. label="结束时间"
  21. placeholder="选择结束时间"
  22. @click.native="clickTimeChoose('end')"
  23. />
  24. <van-field
  25. :value="formData.matterContent"
  26. clickable
  27. label="事项内容"
  28. type="textarea"
  29. rows="1"
  30. autosize
  31. placeholder="请输入事项内容"
  32. @change="bindInputHandle('matterContent',$event)"
  33. />
  34. <!-- <van-field
  35. v-if="edit_matter_id"
  36. :value="formData.EditReason"
  37. clickable
  38. label="修改原因"
  39. type="textarea"
  40. rows="1"
  41. autosize
  42. placeholder="请输入修改原因"
  43. @change="bindInputHandle('EditReason',$event)"
  44. /> -->
  45. </van-form>
  46. <div class="submit-bot">
  47. <van-button type="primary" plain color="#3385FF" size="small" class="btn" block round @click="cancelHandle">取消</van-button>
  48. <van-button type="primary" color="#3385FF" size="small" class="btn" block round @click="submitHandle">确定</van-button>
  49. </div>
  50. <!-- 选择时间 -->
  51. <van-popup :show="isTimePicker" position="bottom">
  52. <van-datetime-picker
  53. :value="pickerForm.time"
  54. type="datetime"
  55. :formatter="formatterPickerTime"
  56. @confirm="confirmTime"
  57. @cancel="() => {isTimePicker = false;pickerForm.time=''}"
  58. />
  59. </van-popup>
  60. </view>
  61. </template>
  62. <script>
  63. import {
  64. getDefaultOption
  65. } from '../addActivity/common.js';
  66. import { validateForm } from '../utils/validate.js';
  67. import { addMatter,editMatter } from '@/api/roadshow/index.js';
  68. const moment = require('../utils/_moment.js');
  69. export default {
  70. data() {
  71. return {
  72. edit_matter_id:'',
  73. isTimePicker: false,
  74. select_type: '',
  75. pickerForm: {
  76. time: ''
  77. },
  78. formData: {
  79. startTime: '',
  80. endTime: '',
  81. matterContent: "",
  82. EditReason:''
  83. },
  84. weekMap: new Map([
  85. ['1','周一'],
  86. ['2','周二'],
  87. ['3','周三'],
  88. ['4','周四'],
  89. ['5','周五'],
  90. ['6','周六'],
  91. ['7','周日']
  92. ]),
  93. };
  94. },
  95. methods: {
  96. /* 取消 */
  97. cancelHandle() {
  98. uni.navigateBack({
  99. delta:1
  100. })
  101. },
  102. /* 提交表单 */
  103. async submitHandle() {
  104. let isCheck = validateForm('事项',this.formData);
  105. console.log(isCheck)
  106. if(!isCheck) return
  107. let params = {
  108. MatterContent: this.formData.matterContent,
  109. StartDate: moment(this.formData.startTime).format('YYYY-MM-DD'),
  110. EndDate: moment(this.formData.endTime).format('YYYY-MM-DD'),
  111. StartTime: moment(this.formData.startTime).format('HH:mm:ss'),
  112. EndTime: moment(this.formData.endTime).format('HH:mm:ss'),
  113. StartWeek: moment(this.formData.startTime
  114. ).format('ddd'),
  115. EndWeek: moment(this.formData.endTime
  116. ).format('ddd'),
  117. }
  118. // 发送请求
  119. const { code } = this.edit_matter_id ? await editMatter({
  120. RsMattersId: Number(this.edit_matter_id),
  121. EditReason:this.formData.EditReason,
  122. ...params
  123. }) : await addMatter(params);
  124. if(code !== 200) return;
  125. uni.showToast({
  126. title: this.edit_matter_id ? '提交成功' : '添加成功',
  127. icon: 'success',
  128. })
  129. setTimeout(() => {
  130. this.cancelHandle();
  131. },1800)
  132. },
  133. /* 点击选择时间 */
  134. clickTimeChoose(type) {
  135. this.pickerForm.time = type === 'start' ? this.formData.startTime : this.formData.endTime;
  136. this.select_type = type;
  137. setTimeout(() => {
  138. this.isTimePicker = true;
  139. })
  140. },
  141. /* 选择时间 */
  142. confirmTime({detail}) {
  143. // console.log(val)
  144. if (this.select_type === 'start') {
  145. this.formData.startTime = detail;
  146. } else {
  147. this.formData.endTime = detail;
  148. }
  149. this.isTimePicker = false;
  150. this.pickerForm.time = '';
  151. },
  152. /* 绑定input输入value */
  153. bindInputHandle(key,{detail}) {
  154. this.formData[key] = detail;
  155. },
  156. /* 格式化时间显示 */
  157. formatterLabelTime(val) {
  158. if(!val) return '';
  159. const date = moment(val).format('MM.DD(ddd) HH:mm');
  160. return date;
  161. },
  162. /* 格式化弹窗时间显示 */
  163. formatterPickerTime(type, val) {
  164. switch (type) {
  165. case 'year':
  166. return val + '年';
  167. case 'month':
  168. return val + '月';
  169. case 'day':
  170. return val + '日';
  171. case 'hour':
  172. return val + '时';
  173. case 'minute':
  174. return val + '分';
  175. }
  176. },
  177. /* 设置默认状态 */
  178. initSetState(options) {
  179. const {
  180. RoleTypeCode
  181. } = JSON.parse(uni.getStorageSync('userInfo')) || null;
  182. const {
  183. startTime,
  184. endTime
  185. } = getDefaultOption(RoleTypeCode, 2);
  186. this.formData = {
  187. startTime: startTime,
  188. endTime: endTime,
  189. matterContent: '',
  190. };
  191. /* 编辑时回显表单 */
  192. if(options.edit_matter_id) {
  193. const { form,edit_matter_id } = options;
  194. this.formData = {...this.formData,...JSON.parse(form),EditReason:''};
  195. this.edit_matter_id = Number(edit_matter_id);
  196. }
  197. // console.log(this.formData)
  198. uni.setNavigationBarTitle({
  199. title: this.edit_matter_id ? '修改事项' : '添加事项'
  200. })
  201. }
  202. },
  203. onLoad(options) {
  204. this.initSetState(options);
  205. this.getOpenerEventChannel().on('emitBackData', (data)=> {
  206. this.initSetState(data);
  207. })
  208. },
  209. onShow() {
  210. }
  211. }
  212. </script>
  213. <style lang="scss" scoped>
  214. .addactiyity-container {
  215. padding-bottom: 200rpx;
  216. .submit-bot {
  217. position: fixed;
  218. left: 0;
  219. right: 0;
  220. bottom: 0;
  221. z-index: 99;
  222. height: 140rpx;
  223. padding: 0 150rpx;
  224. background-color: #fff;
  225. display: flex;
  226. align-items: center;
  227. padding-bottom: constant(safe-area-inset-bottom);
  228. padding-bottom: env(safe-area-inset-bottom);
  229. box-shadow: 0px -2px 6px rgba(110, 119, 141, 0.07);
  230. .btn {
  231. width: 220rpx;
  232. height: 60rpx;
  233. margin-right: 30rpx;
  234. }
  235. }
  236. }
  237. </style>
  238. <style lang="scss">
  239. .van-tree-select {
  240. .van-tree-select__item--active {
  241. color: #1989fa !important;
  242. }
  243. .van-sidebar-item--selected {
  244. border-color: #1989fa !important;
  245. }
  246. }
  247. </style>