add.vue 15 KB

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