add.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <!--
  2. * @Author: liuzhenlin 461480418@qq.ocm
  3. * @Date: 2023-01-16 10:11:35
  4. * @LastEditors: liuzhenlin
  5. * @LastEditTime: 2023-03-06 13:52:55
  6. * @schContentription: file content
  7. * @FilePath: \oms\pages\schedule\components\add.vue
  8. -->
  9. <template>
  10. <view>
  11. <u-popup :show="addVisible" :round="10" mode="bottom" duration="0" @close="closeAdd">
  12. <view class="add-container">
  13. <u-form :model="addForm" :rules="rules" ref="addForm" labelWidth="0">
  14. <u-form-item prop="schTitle">
  15. <view class="header flex flex-middle">
  16. <view class="tit-input">
  17. <u-input placeholder="准备做什么?" v-model="addForm.schTitle" border="none" clearable></u-input>
  18. </view>
  19. <view class="add" @click="handleAdd">添加</view>
  20. </view>
  21. </u-form-item>
  22. <u-form-item prop="schContent">
  23. <view class="schContent flex">
  24. <view class="flex_1">
  25. <u-input placeholder="添加描述" v-model="addForm.schContent" border="none" clearable></u-input>
  26. </view>
  27. </view>
  28. </u-form-item>
  29. </u-form>
  30. <view class="date flex">
  31. <view
  32. v-for="(item, index) in tagList"
  33. :key="index"
  34. class="date-tag"
  35. :class="{ actived: item.type == dateType }"
  36. @click="selectDateType(item)">
  37. {{ item.val }}
  38. <view class="date-select" v-if="item.type == 3">
  39. <u-icon name="arrow-down" :color="dateType === 3 ? '#fff' : '#646464'" size="12"></u-icon>
  40. </view>
  41. </view>
  42. </view>
  43. <!-- <view class="schContent flex">
  44. <view class="flex_1">
  45. <u-input placeholder="添加子任务" border="none" clearable></u-input>
  46. </view>
  47. </view> -->
  48. </view>
  49. </u-popup>
  50. <u-calendar
  51. :show="showCalendar"
  52. monthNum="12"
  53. showLunar
  54. @confirm="confirmCalendar"
  55. :max-date="maxDate"
  56. @close="showCalendar = false"></u-calendar>
  57. <u-toast ref="uToast"></u-toast>
  58. </view>
  59. </template>
  60. <script>
  61. import to from 'await-to-js'
  62. import scheduleApi from '../../../api/schedule'
  63. export default {
  64. name: 'omsAdd',
  65. props: {
  66. addVisible: {
  67. type: Boolean,
  68. default: () => false,
  69. },
  70. },
  71. data() {
  72. return {
  73. tagList: [
  74. {
  75. val: '今天',
  76. type: 1,
  77. },
  78. {
  79. val: '明天',
  80. type: 2,
  81. },
  82. {
  83. val: this.parseTime(new Date(), '{m}-{d}'),
  84. type: 3,
  85. },
  86. ],
  87. addForm: {
  88. schTitle: '', //标题
  89. schContent: '', //描述
  90. schDate: this.getNowDate(),
  91. },
  92. rules: {
  93. schTitle: {
  94. type: 'string',
  95. required: true,
  96. message: '请填写任务标题',
  97. trigger: ['blur'],
  98. },
  99. schContent: {
  100. type: 'string',
  101. required: true,
  102. message: '请填写描述',
  103. trigger: ['blur'],
  104. },
  105. },
  106. showCalendar: false, //显示选择日历
  107. dateType: 1, //日期类型
  108. }
  109. },
  110. computed: {
  111. maxDate() {
  112. const nextYear = new Date().getFullYear() + 1
  113. return `${nextYear}-01-01`
  114. },
  115. },
  116. onReady() {
  117. //onReady 为uni-app支持的生命周期之一
  118. // this.$refs.addForm.setRules(this.rules)
  119. },
  120. mounted() {},
  121. methods: {
  122. handleAdd() {
  123. this.$refs.addForm
  124. .validate()
  125. .then(async () => {
  126. let params = this.addForm
  127. const [err, res] = await to(scheduleApi.create(params))
  128. if (err) return
  129. if (res && res.code == 200) {
  130. this.$refs.uToast.show({
  131. type: 'success',
  132. message: '添加成功',
  133. complete: () => {
  134. this.closeAdd()
  135. },
  136. })
  137. }
  138. })
  139. .catch(() => {})
  140. },
  141. // 选择日期类型
  142. selectDateType(item) {
  143. this.dateType = item.type
  144. if (this.dateType == 1) {
  145. this.addForm.schDate = this.getNowDate()
  146. } else if (this.dateType == 2) {
  147. this.addForm.schDate = this.getTomorrowDate()
  148. } else if (this.dateType == 3) {
  149. this.showCalendar = true
  150. }
  151. },
  152. // 确认选择日期
  153. confirmCalendar(item) {
  154. this.addForm.schDate = item[0]
  155. this.tagList[2].val = this.parseTime(item[0], '{m}-{d}')
  156. this.showCalendar = false
  157. },
  158. closeAdd() {
  159. this.addForm = {
  160. schTitle: '', //标题
  161. schContent: '', //描述
  162. }
  163. this.$refs.addForm.clearValidate()
  164. this.$emit('update:addVisible', false)
  165. },
  166. getNowDate() {
  167. var day = new Date()
  168. day.setTime(day.getTime())
  169. var date = day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate()
  170. return date
  171. },
  172. getTomorrowDate() {
  173. let day = new Date()
  174. day.setTime(day.getTime() + 24 * 60 * 60 * 1000)
  175. let date = day.getFullYear() + '-' + (day.getMonth() + 1) + '-' + day.getDate()
  176. return date
  177. },
  178. },
  179. }
  180. </script>
  181. <style lang="scss" scoped>
  182. .add-container {
  183. padding: 42rpx 28rpx 0 34rpx;
  184. .header {
  185. .tit-input {
  186. flex: 1;
  187. }
  188. .add {
  189. padding-left: 30rpx;
  190. font-size: 32rpx;
  191. font-weight: bold;
  192. color: #3e7ef8;
  193. }
  194. }
  195. .schContent {
  196. padding-top: 28rpx;
  197. border-bottom: 1px solid #cdcdcd;
  198. padding-bottom: 14rpx;
  199. }
  200. .date {
  201. padding: 28rpx 0 36rpx;
  202. border-bottom: 1px solid #cdcdcd;
  203. .date-tag {
  204. width: 115rpx;
  205. height: 62rpx;
  206. display: flex;
  207. align-items: center;
  208. justify-content: center;
  209. background: #ebf2ff;
  210. border-radius: 31rpx;
  211. font-size: 24rpx;
  212. color: #646464;
  213. margin-right: 24rpx;
  214. .date-select {
  215. padding-left: 6rpx;
  216. }
  217. &.actived {
  218. background: #3e7ef8;
  219. color: #fff;
  220. }
  221. }
  222. }
  223. }
  224. </style>