add.vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  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="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. uni.setNavigationBarTitle({
  161. title: '重新申请',
  162. success: (result) => {},
  163. fail: () => {},
  164. complete: () => {}
  165. });
  166. }
  167. this.getSystemUsers()
  168. },
  169. methods: {
  170. async handleApply(){
  171. const pids=[],pnames=[];
  172. this.formData.partner.forEach(item => {
  173. pids.push(item.AdminId)
  174. pnames.push(item.RealName)
  175. });
  176. let params={
  177. ArriveDate:this.formData.arriveDate,
  178. ReturnDate:this.formData.backDate,
  179. Province:this.formData.destination[0],
  180. City:this.formData.destination[1],
  181. Reason:this.formData.reason,
  182. Transportation:this.formData.otherVehicle?`${this.formData.vehicle}-${this.formData.otherVehicle}`:this.formData.vehicle,
  183. PeerPeopleId:pids.join(','),
  184. PeerPeopleName:pnames.join(',')
  185. }
  186. if(!params.ArriveDate){
  187. uni.showToast({
  188. title:'请选择到达日期',
  189. icon:'none'
  190. })
  191. return
  192. }
  193. if(!params.ReturnDate){
  194. uni.showToast({
  195. title:'请选择返程日期',
  196. icon:'none'
  197. })
  198. return
  199. }
  200. if(!params.City){
  201. uni.showToast({
  202. title:'请选择目的地',
  203. icon:'none'
  204. })
  205. return
  206. }
  207. if(!params.Reason){
  208. uni.showToast({
  209. title:'请选择出差事由',
  210. icon:'none'
  211. })
  212. return
  213. }
  214. if(!params.Transportation){
  215. uni.showToast({
  216. title:'请选择交通工具',
  217. icon:'none'
  218. })
  219. return
  220. }
  221. const res=this.id?await apiEditApply({...params,BusinessApplyId:Number(this.id)}):await apiAddApply(params)
  222. if(res.code===200){
  223. setTimeout(() => {
  224. uni.showToast({
  225. title:"提交成功",
  226. icon:'success'
  227. })
  228. }, 200);
  229. uni.$emit('businessApproveListUpdate')
  230. setTimeout(()=>{
  231. this.handleRefuse()
  232. },1800)
  233. }
  234. },
  235. handleRefuse(){
  236. uni.navigateBack({
  237. delta:1
  238. })
  239. },
  240. getDate(type) {
  241. const date = new Date();
  242. let year = date.getFullYear();
  243. let month = date.getMonth() + 1;
  244. let day = date.getDate();
  245. if (type === 'start') {
  246. year = year - 60;
  247. } else if (type === 'end') {
  248. year = year + 2;
  249. }
  250. month = month > 9 ? month : '0' + month;
  251. day = day > 9 ? day : '0' + day;
  252. return `${year}-${month}-${day}`;
  253. },
  254. arriveDateChange(e){
  255. this.formData.arriveDate=e.detail.value
  256. },
  257. backDateChange(e){
  258. this.formData.backDate=e.detail.value
  259. },
  260. confrimDestination(e){
  261. this.formData.destination=[e.detail.values[0].name,e.detail.values[1].name]
  262. this.showDestination=false
  263. },
  264. onReasonChange(e){
  265. this.formData.reason=e.detail.value
  266. this.showReason=false
  267. },
  268. onvehicleChange(e){
  269. this.formData.vehicle=e.detail.value
  270. this.showVehicle=false
  271. },
  272. // 选择同行人
  273. onSelectPartnerFinish(e){
  274. // console.log(e);
  275. const item=e.detail.selectedOptions[e.detail.selectedOptions.length-1]
  276. this.formData.partner.push(item)
  277. this.showPartner=false
  278. },
  279. handleDelPartner(index){
  280. this.formData.partner.splice(index,1)
  281. },
  282. getSystemUsers(){
  283. apiSystemUsers().then(res=>{
  284. if(res.code===200){
  285. this.systemUserList=res.data.List||[]
  286. }
  287. })
  288. },
  289. // 获取详情
  290. getDetail(){
  291. apiBusinessTripDetail({BusinessApplyId:this.id}).then(res=>{
  292. if(res.code===200){
  293. this.formData.arriveDate=res.data.ArriveDate
  294. this.formData.backDate=res.data.ReturnDate
  295. this.formData.destination=[res.data.Province,res.data.City]
  296. this.formData.reason=res.data.Reason
  297. this.formData.vehicle=res.data.Transportation.split('-')[0]
  298. this.formData.otherVehicle=res.data.Transportation.split('-')[1]?res.data.Transportation.split('-')[1]:''
  299. if(res.data.PeerPeopleName){
  300. const temPartnerName=res.data.PeerPeopleName.split(',')
  301. const temPartnerId=res.data.PeerPeopleId.split(',')
  302. console.log(temPartnerName);
  303. temPartnerName.forEach((item,index)=>{
  304. this.formData.partner.push({
  305. AdminId:temPartnerId[index],
  306. RealName:item
  307. })
  308. })
  309. }
  310. }
  311. })
  312. }
  313. },
  314. }
  315. </script>
  316. <style lang="scss" scoped>
  317. .add-apply-page{
  318. padding-top: 10rpx;
  319. padding-bottom: calc(150rpx + constant(safe-area-inset-bottom));
  320. padding-bottom: calc(150rpx + env(safe-area-inset-bottom));
  321. .form-item{
  322. display: flex;
  323. align-items: center;
  324. border-bottom: 1px solid #f5f5f5;
  325. padding: 20rpx 34rpx;
  326. position: relative;
  327. background-color: #fff;
  328. font-size: 32rpx;
  329. .label{
  330. width: 130rpx;
  331. flex-shrink: 0;
  332. text-align: right;
  333. margin-right: 30rpx;
  334. }
  335. .content{
  336. flex: 1;
  337. min-height: 40rpx;
  338. .picker-box{
  339. width: 100%;
  340. height: 100%;
  341. }
  342. .placeholde-text{
  343. color: #999;
  344. }
  345. }
  346. .del-icon{
  347. width: 34rpx;
  348. height: 34rpx;
  349. }
  350. }
  351. .has-arrow::after{
  352. content: '';
  353. display: block;
  354. transform:rotate(45deg);
  355. width: 18rpx;
  356. height: 18rpx;
  357. border-top: 2rpx solid #333;
  358. border-right: 2rpx solid #333;
  359. }
  360. .picker-box{
  361. height: 500rpx;
  362. .item {
  363. line-height: 100rpx;
  364. text-align: center;
  365. }
  366. }
  367. .destination-popup-top-btn{
  368. display: flex;
  369. justify-content: space-between;
  370. align-items: center;
  371. padding: 20rpx 34rpx;
  372. view:first-child{
  373. color: #999;
  374. }
  375. view:last-child{
  376. color: #3385FF;
  377. }
  378. }
  379. .add-partner-box{
  380. display: flex;
  381. padding: 20rpx 34rpx;
  382. align-items: center;
  383. font-size: 32rpx;
  384. color: #3385FF;
  385. background-color: #fff;
  386. image{
  387. width: 34rpx;
  388. height: 34rpx;
  389. margin-right: 20rpx;
  390. display: block;
  391. }
  392. }
  393. .btns-wrap {
  394. justify-content: center;
  395. button {
  396. width: 260rpx;
  397. height: 70rpx;
  398. border-radius: 28px;
  399. border: none;
  400. margin: 0 15px;
  401. font-size: 15px;
  402. color: #fff;
  403. line-height: 70rpx;
  404. }
  405. .pass-btn {
  406. background-color: #3385FF;
  407. }
  408. .refuse-btn {
  409. background-color: #fff;
  410. color: #3385FF;
  411. border: 1px solid #3385FF;
  412. }
  413. }
  414. }
  415. </style>