add.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. <template>
  2. <view class="add-apply-page">
  3. <view class="form-item has-arrow">
  4. <view class="label">到达日期</view>
  5. <view class="content">
  6. <picker
  7. class="picker-box"
  8. mode="date"
  9. :value="formData.arriveDate"
  10. :start="startDate"
  11. :end="endDate"
  12. @change="arriveDateChange"
  13. >
  14. <view :class="['text',formData.arriveDate?'':'placeholde-text']">{{formData.arriveDate||'请选择日期'}}</view>
  15. </picker>
  16. </view>
  17. </view>
  18. <view class="form-item has-arrow">
  19. <view class="label">返程日期</view>
  20. <view class="content">
  21. <picker
  22. class="picker-box"
  23. mode="date"
  24. :value="formData.backDate"
  25. :start="startDate"
  26. :end="endDate"
  27. @change="backDateChange"
  28. >
  29. <view :class="['text',formData.backDate?'':'placeholde-text']">{{formData.backDate||'请选择日期'}}</view>
  30. </picker>
  31. </view>
  32. </view>
  33. <view class="form-item has-arrow">
  34. <view class="label">目的地</view>
  35. <view class="content" @click="showDestination=true">
  36. <view :class="['text',formData.destination.length?'':'placeholde-text']">{{formData.destination.join('')||'请选择目的地'}}</view>
  37. </view>
  38. </view>
  39. <view class="form-item has-arrow">
  40. <view class="label">出差事由</view>
  41. <view class="content" @click="showReason=true">
  42. <view :class="['text',formData.reason?'':'placeholde-text']">{{formData.reason||'请选择出差事由'}}</view>
  43. </view>
  44. </view>
  45. <view class="form-item has-arrow">
  46. <view class="label">交通工具</view>
  47. <view class="content" @click="showVehicle=true">
  48. <view :class="['text',formData.vehicle?'':'placeholde-text']">{{formData.vehicle||'请选择交通工具'}}</view>
  49. </view>
  50. </view>
  51. <view class="form-item" v-if="formData.vehicle=='其他'">
  52. <view class="label">其他工具</view>
  53. <view class="content">
  54. <input v-model="formData.otherVehicle" style="width:100%;height:100%" type="text" placeholder="请输入交通工具">
  55. </view>
  56. </view>
  57. <view class="partner-box" style="margin-top:20rpx">
  58. <view class="form-item" v-for="(item,index) in formData.partner" :key="item.AdminId">
  59. <view class="label">同行人</view>
  60. <view class="content">{{item.RealName}}</view>
  61. <image class="del-icon" src="../static/del.png" mode="aspectFill" @click="handleDelPartner(index)"/>
  62. </view>
  63. <view class="add-partner-box" @click="showPartner=true">
  64. <image class="del-icon" src="../static/add.png" mode="aspectFill"/>
  65. <text>同行人</text>
  66. </view>
  67. </view>
  68. <view class="fix-bottom-wrap btns-wrap flex">
  69. <button class="refuse-btn" @click="handleRefuse">取消</button>
  70. <button class="pass-btn" @click="handleApply">确定</button>
  71. </view>
  72. <!-- 选择目的地弹窗 -->
  73. <van-popup :show="showDestination" @close="showDestination=false" position="bottom">
  74. <van-area
  75. :value="formData.destination"
  76. :area-list="areaList"
  77. :columns-num="2"
  78. @confirm="confrimDestination"
  79. @cancel="showDestination = false"
  80. />
  81. </van-popup>
  82. <!-- 出差事由 -->
  83. <van-popup :show="showReason" @close="showReason=false" position="bottom">
  84. <van-picker
  85. show-toolbar
  86. title="出差事由"
  87. :columns="reasonOpt"
  88. @confirm="onReasonChange"
  89. @cancel="showReason=false"
  90. />
  91. </van-popup>
  92. <!-- 交通工具 -->
  93. <van-popup :show="showVehicle" @close="showVehicle=false" position="bottom">
  94. <van-picker
  95. show-toolbar
  96. title="交通工具"
  97. :columns="vehicleOpts"
  98. @confirm="onvehicleChange"
  99. @cancel="showVehicle=false"
  100. />
  101. </van-popup>
  102. <!-- 选择同行人 -->
  103. <van-popup :show="showPartner" @close="showPartner=false" position="bottom">
  104. <van-cascader
  105. v-if="showPartner"
  106. title="请选择同行人"
  107. :options="systemUserList"
  108. :field-names="systemUserListOpt"
  109. @close="showPartner=false"
  110. @finish="onSelectPartnerFinish"
  111. />
  112. </van-popup>
  113. </view>
  114. </template>
  115. <script>
  116. import { areaList } from '@/utils/area.js';
  117. import {apiSystemUsers} from '@/api/common'
  118. import {apiAddApply,apiEditApply,apiBusinessTripDetail} from '@/api/businessTrip/index'
  119. export default {
  120. computed: {
  121. startDate() {
  122. return this.getDate('start');
  123. },
  124. endDate() {
  125. return this.getDate('end');
  126. }
  127. },
  128. data() {
  129. const currentDate = this.getDate()
  130. return {
  131. id:0,
  132. formData:{
  133. arriveDate:'',
  134. backDate:'',
  135. destination:[],
  136. reason:'',
  137. vehicle:'',
  138. otherVehicle:'',
  139. partner:[]
  140. },
  141. areaList,
  142. showDestination:false,
  143. showReason:false,
  144. reasonOpt:['路演','调研','培训','会议'],
  145. showVehicle:false,
  146. vehicleOpts:['飞机','火车','汽车','其他'],
  147. showPartner:false,
  148. systemUserList:[],
  149. systemUserListOpt:{
  150. text: 'RealName',
  151. value: 'AdminId',
  152. children: 'ChildrenList',
  153. }
  154. }
  155. },
  156. onLoad(opt){
  157. this.id=opt.id
  158. if(opt.id){
  159. this.getDetail()
  160. }
  161. this.getSystemUsers()
  162. },
  163. methods: {
  164. async handleApply(){
  165. const pids=[],pnames=[];
  166. this.formData.partner.forEach(item => {
  167. pids.push(item.AdminId)
  168. pnames.push(item.RealName)
  169. });
  170. let params={
  171. ArriveDate:this.formData.arriveDate,
  172. ReturnDate:this.formData.backDate,
  173. Province:this.formData.destination[0],
  174. City:this.formData.destination[1],
  175. Reason:this.formData.reason,
  176. Transportation:this.formData.otherVehicle?`${this.formData.vehicle}-${this.formData.otherVehicle}`:this.formData.vehicle,
  177. PeerPeopleId:pids.join(','),
  178. PeerPeopleName:pnames.join(',')
  179. }
  180. if(!params.ArriveDate){
  181. uni.showToast({
  182. title:'请选择到达日期',
  183. icon:'none'
  184. })
  185. return
  186. }
  187. if(!params.ReturnDate){
  188. uni.showToast({
  189. title:'请选择返程日期',
  190. icon:'none'
  191. })
  192. return
  193. }
  194. if(!params.City){
  195. uni.showToast({
  196. title:'请选择目的地',
  197. icon:'none'
  198. })
  199. return
  200. }
  201. if(!params.Reason){
  202. uni.showToast({
  203. title:'请选择出差事由',
  204. icon:'none'
  205. })
  206. return
  207. }
  208. if(!params.Transportation){
  209. uni.showToast({
  210. title:'请选择交通工具',
  211. icon:'none'
  212. })
  213. return
  214. }
  215. const res=this.id?await apiEditApply({...params,BusinessApplyId:Number(this.id)}):await apiAddApply(params)
  216. if(res.code===200){
  217. uni.showToast({
  218. title:"提交成功",
  219. icon:'success'
  220. })
  221. uni.$emit('businessApproveListUpdate')
  222. setTimeout(()=>{
  223. this.handleRefuse()
  224. },1500)
  225. }
  226. },
  227. handleRefuse(){
  228. uni.navigateBack({
  229. delta:1
  230. })
  231. },
  232. getDate(type) {
  233. const date = new Date();
  234. let year = date.getFullYear();
  235. let month = date.getMonth() + 1;
  236. let day = date.getDate();
  237. if (type === 'start') {
  238. year = year - 60;
  239. } else if (type === 'end') {
  240. year = year + 2;
  241. }
  242. month = month > 9 ? month : '0' + month;
  243. day = day > 9 ? day : '0' + day;
  244. return `${year}-${month}-${day}`;
  245. },
  246. arriveDateChange(e){
  247. this.formData.arriveDate=e.detail.value
  248. },
  249. backDateChange(e){
  250. this.formData.backDate=e.detail.value
  251. },
  252. confrimDestination(e){
  253. this.formData.destination=[e.detail.values[0].name,e.detail.values[1].name]
  254. this.showDestination=false
  255. },
  256. onReasonChange(e){
  257. this.formData.reason=e.detail.value
  258. this.showReason=false
  259. },
  260. onvehicleChange(e){
  261. this.formData.vehicle=e.detail.value
  262. this.showVehicle=false
  263. },
  264. // 选择同行人
  265. onSelectPartnerFinish(e){
  266. // console.log(e);
  267. const item=e.detail.selectedOptions[e.detail.selectedOptions.length-1]
  268. this.formData.partner.push(item)
  269. this.showPartner=false
  270. },
  271. handleDelPartner(index){
  272. this.formData.partner.splice(index,1)
  273. },
  274. getSystemUsers(){
  275. apiSystemUsers().then(res=>{
  276. if(res.code===200){
  277. this.systemUserList=res.data.List||[]
  278. }
  279. })
  280. },
  281. // 获取详情
  282. getDetail(){
  283. apiBusinessTripDetail({BusinessApplyId:this.id}).then(res=>{
  284. if(res.code===200){
  285. this.formData.arriveDate=res.data.ArriveDate
  286. this.formData.backDate=res.data.ReturnDate
  287. this.formData.destination=[res.data.Province,res.data.City]
  288. this.formData.reason=res.data.Reason
  289. this.formData.vehicle=res.data.Transportation.split('-')[0]
  290. this.formData.otherVehicle=res.data.Transportation.split('-')[1]?res.data.Transportation.split('-')[1]:''
  291. const temPartnerName=res.data.PeerPeopleName.split(',')
  292. const temPartnerId=res.data.PeerPeopleId.split(',')
  293. temPartnerName.forEach((item,index)=>{
  294. this.formData.partner.push({
  295. AdminId:temPartnerId[index],
  296. RealName:item
  297. })
  298. })
  299. }
  300. })
  301. }
  302. },
  303. }
  304. </script>
  305. <style lang="scss" scoped>
  306. .add-apply-page{
  307. padding-top: 10rpx;
  308. padding-bottom: calc(150rpx + constant(safe-area-inset-bottom));
  309. padding-bottom: calc(150rpx + env(safe-area-inset-bottom));
  310. .form-item{
  311. display: flex;
  312. align-items: center;
  313. border-bottom: 1px solid #f5f5f5;
  314. padding: 20rpx 34rpx;
  315. position: relative;
  316. background-color: #fff;
  317. font-size: 32rpx;
  318. .label{
  319. width: 130rpx;
  320. flex-shrink: 0;
  321. text-align: right;
  322. margin-right: 30rpx;
  323. }
  324. .content{
  325. flex: 1;
  326. min-height: 40rpx;
  327. .picker-box{
  328. width: 100%;
  329. height: 100%;
  330. }
  331. .placeholde-text{
  332. color: #999;
  333. }
  334. }
  335. .del-icon{
  336. width: 34rpx;
  337. height: 34rpx;
  338. }
  339. }
  340. .has-arrow::after{
  341. content: '';
  342. display: block;
  343. transform:rotate(45deg);
  344. width: 18rpx;
  345. height: 18rpx;
  346. border-top: 2rpx solid #333;
  347. border-right: 2rpx solid #333;
  348. }
  349. .picker-box{
  350. height: 500rpx;
  351. .item {
  352. line-height: 100rpx;
  353. text-align: center;
  354. }
  355. }
  356. .destination-popup-top-btn{
  357. display: flex;
  358. justify-content: space-between;
  359. align-items: center;
  360. padding: 20rpx 34rpx;
  361. view:first-child{
  362. color: #999;
  363. }
  364. view:last-child{
  365. color: #3385FF;
  366. }
  367. }
  368. .add-partner-box{
  369. display: flex;
  370. padding: 20rpx 34rpx;
  371. align-items: center;
  372. font-size: 32rpx;
  373. color: #3385FF;
  374. background-color: #fff;
  375. image{
  376. width: 34rpx;
  377. height: 34rpx;
  378. margin-right: 20rpx;
  379. display: block;
  380. }
  381. }
  382. .btns-wrap {
  383. justify-content: center;
  384. button {
  385. width: 260rpx;
  386. height: 70rpx;
  387. border-radius: 28px;
  388. border: none;
  389. margin: 0 15px;
  390. font-size: 15px;
  391. color: #fff;
  392. line-height: 70rpx;
  393. }
  394. .pass-btn {
  395. background-color: #3385FF;
  396. }
  397. .refuse-btn {
  398. background-color: #fff;
  399. color: #3385FF;
  400. border: 1px solid #3385FF;
  401. }
  402. }
  403. }
  404. </style>