add.vue 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. <template>
  2. <view class="box">
  3. <view class="address-box" v-if="defaultOrg == 0 || (defaultOrg > 0 && type == 1)">
  4. <view class="address-box-list">
  5. <view class="address-box-label">
  6. 项目名称
  7. </view>
  8. <view class="address-box-input">
  9. <picker v-if="orgs.length > 0" disabled="true" @change="bindPickerChange" :value="orgIndex" :range="orgs" range-key="name">
  10. <text class="address-box-input-text">{{orgs[orgIndex].name}}</text>
  11. <image class="address-box-input-icon" src="../../images/xiangyou.png"></image>
  12. </picker>
  13. </view>
  14. </view>
  15. <view class="address-box-list">
  16. <view class="address-box-label">
  17. 项目服务
  18. </view>
  19. <view class="address-box-input">
  20. <picker v-if="serves.length > 0" @change="bindPickerServeChange" :value="serveIndex" :range="serves" range-key="title">
  21. <text class="address-box-input-text">{{serves[serveIndex].title}}</text>
  22. <image class="address-box-input-icon" src="../../images/xiangyou.png"></image>
  23. </picker>
  24. </view>
  25. </view>
  26. <view class="address-box-list">
  27. <view class="address-box-label">
  28. 预约日期
  29. </view>
  30. <view class="address-box-input">
  31. <picker mode="date" :value="date" :start="startDate" :end="endDate" @change="bindDateChange">
  32. <text class="address-box-input-text">{{date}}</text>
  33. <image class="address-box-input-icon" src="../../images/xiangyou.png"></image>
  34. </picker>
  35. </view>
  36. </view>
  37. <view class="address-box-list">
  38. <view class="address-box-label">
  39. 预约时间段
  40. </view>
  41. <view class="address-box-input">
  42. <picker v-if="times.length > 0" @change="bindPickerTimeChange" :value="timeIndex" :range="times" range-key="name">
  43. <text class="address-box-input-text">{{times[timeIndex].name}}</text>
  44. <image class="address-box-input-icon" src="../../images/xiangyou.png"></image>
  45. </picker>
  46. </view>
  47. </view>
  48. </view>
  49. <view class="address-box">
  50. <view class="address-box-list">
  51. <view class="address-box-label">
  52. 预约人姓名
  53. </view>
  54. <view class="address-box-input">
  55. <input v-model="name" placeholder="请输入" type="text">
  56. </view>
  57. </view>
  58. <view class="address-box-list">
  59. <view class="address-box-label">
  60. 手机号码
  61. </view>
  62. <view class="address-box-input">
  63. <input v-model="phone" placeholder="请输入" type="tel">
  64. </view>
  65. </view>
  66. </view>
  67. <view class="address-btn" @click="saveBtn">
  68. 提 交
  69. </view>
  70. <view class="address-btn2" @click="saveBtn2">
  71. 我的记录
  72. </view>
  73. </view>
  74. </template>
  75. <script>
  76. var app = getApp();
  77. function getDate(type) {
  78. const date = new Date();
  79. let year = date.getFullYear();
  80. let month = date.getMonth() + 1;
  81. let day = date.getDate();
  82. if (type === 'start') {
  83. year = year - 60;
  84. } else if (type === 'end') {
  85. year = year + 2;
  86. }
  87. month = month > 9 ? month : '0' + month;;
  88. day = day > 9 ? day : '0' + day;
  89. return `${year}-${month}-${day}`;
  90. }
  91. export default {
  92. data() {
  93. return {
  94. id: 0,
  95. defaultOrg: 0,
  96. type: 0,
  97. orgs: [],
  98. orgIndex: 0,
  99. serves: [],
  100. serveIndex: 0,
  101. date: getDate({
  102. format: true
  103. }),
  104. startDate:getDate('start'),
  105. endDate:getDate('end'),
  106. times: [],
  107. timeIndex: 0,
  108. name: '',
  109. phone: ''
  110. }
  111. },
  112. onLoad(option) {
  113. app.checkLogin();
  114. this.defaultOrg = option.orgId ? option.orgId : 0;
  115. this.type = option.type ? option.type : 0;
  116. console.log(this.defaultOrg,this.type);
  117. if(!this.defaultOrg){
  118. this.getOrgs();
  119. }else{
  120. if(this.type == 1){ //预约
  121. this.getOrgs();
  122. }else{//现场登记
  123. uni.setNavigationBarTitle({
  124. title: '现场登记'
  125. });
  126. uni.setStorageSync(app.globalData.storagePre+'orgId', this.defaultOrg);
  127. }
  128. }
  129. },
  130. onShow() {
  131. var that = this;
  132. app.ajaxReadyCallback = res => { //各个接口统一回调方法
  133. var apiname = res.data.apiname;
  134. console.log(res);
  135. if(apiname == 'org'){
  136. that.orgs = res.data.data;
  137. if(that.defaultOrg && that.type == 1){
  138. if(that.orgs.length > 0){
  139. that.orgs.forEach((item,index) => {
  140. if(item.id.toString() == that.defaultOrg.toString()){
  141. that.orgIndex = index;
  142. }
  143. })
  144. }
  145. }else{
  146. that.orgIndex = 0;
  147. }
  148. if(that.orgs.length > 0){
  149. that.getService();
  150. }
  151. } else if(apiname == 'service'){
  152. that.serves = res.data.data;
  153. that.serveIndex = 0;
  154. if(that.serves.length > 0){
  155. that.getServiceTime();
  156. }
  157. } else if(apiname == 'serviceTime'){
  158. that.times = [];
  159. that.timeIndex = 0;
  160. res.data.data.forEach((item) => {
  161. that.times.push({
  162. id: item.id,
  163. name: item.start + '~' + item.end
  164. });
  165. })
  166. } else if(apiname == 'order'){
  167. uni.showToast({
  168. title: '提交成功',
  169. icon: 'none',
  170. duration: 2000
  171. });
  172. setTimeout(function(){
  173. uni.navigateTo({
  174. url: '/pages/index/index'
  175. });
  176. },1000);
  177. }
  178. }
  179. },
  180. methods: {
  181. getUrlCode (name) {
  182. return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.href) || [, ''])[1].replace(/\+/g, '%20')) || null
  183. },
  184. bindPickerChange: function(e) {
  185. console.log('picker发送选择改变,携带值为:' + e.detail.value)
  186. this.orgIndex = e.detail.value;
  187. this.getService();
  188. },
  189. bindPickerServeChange: function(e) {
  190. console.log('bindPickerServeChange发送选择改变,携带值为:' + e.detail.value)
  191. this.serveIndex = e.detail.value;
  192. this.getServiceTime();
  193. },
  194. bindPickerTimeChange: function(e) {
  195. console.log('bindPickerTimeChange发送选择改变,携带值为:' + e.detail.value)
  196. this.timeIndex = e.detail.value;
  197. },
  198. bindDateChange: function(e) {
  199. console.log('bindDateChange发送选择改变,携带值为:' + e.detail.value)
  200. this.date = e.detail.value;
  201. this.getServiceTime();
  202. },
  203. getOrgs(){
  204. this.serves = [];
  205. this.serveIndex = 0;
  206. this.times = [];
  207. this.timeIndex = 0;
  208. app.ajax({
  209. url: app.globalData.serverUrl + 'org/lists',
  210. type: 'POST',
  211. apiname: 'org'
  212. });
  213. },
  214. getService(){
  215. this.times = [];
  216. this.timeIndex = 0;
  217. const orgId = this.orgs[this.orgIndex].id;
  218. app.ajax({
  219. url: app.globalData.serverUrl + 'service/list',
  220. type: 'POST',
  221. apiname: 'service',
  222. data: {
  223. orgId: orgId
  224. }
  225. });
  226. },
  227. getServiceTime(){
  228. const serviceId = this.serves[this.serveIndex].id;
  229. const orgId = this.orgs[this.orgIndex].id;
  230. app.ajax({
  231. url: app.globalData.serverUrl + 'service/times',
  232. type: 'POST',
  233. apiname: 'serviceTime',
  234. data: {
  235. serviceId: serviceId,
  236. day: this.date,
  237. orgId: orgId
  238. }
  239. });
  240. },
  241. saveBtn(){
  242. let serviceTimeId = 0;
  243. if(this.times[this.timeIndex]){
  244. serviceTimeId = this.times[this.timeIndex].id;
  245. }
  246. let orgId = 0;
  247. if(this.orgs[this.orgIndex]){
  248. orgId = this.orgs[this.orgIndex].id;
  249. }
  250. let param = {
  251. type: this.defaultOrg==0?1:2,
  252. serviceTimeId: serviceTimeId,
  253. name: this.name,
  254. phone: this.phone,
  255. orgId: orgId
  256. }
  257. if(this.defaultOrg){
  258. param.orgId = this.defaultOrg;
  259. }
  260. if(!this.name){
  261. uni.showToast({
  262. title: '请输入姓名',
  263. icon: 'none',
  264. duration: 2000
  265. })
  266. return;
  267. }
  268. if(!this.phone){
  269. uni.showToast({
  270. title: '请输入手机号',
  271. icon: 'none',
  272. duration: 2000
  273. })
  274. return;
  275. }
  276. app.ajax({
  277. url: app.globalData.serverUrl + 'visitorOrder/order',
  278. type: 'POST',
  279. apiname: 'order',
  280. data: param
  281. });
  282. },
  283. saveBtn2(){
  284. uni.reLaunch({ //关闭所有页面,跳转到闪屏页
  285. url: '/pages/index/index'
  286. })
  287. }
  288. }
  289. }
  290. </script>
  291. <style lang="scss" scoped>
  292. .box{
  293. padding: 20rpx;
  294. }
  295. .address-box{
  296. // padding: 0 20rpx;
  297. margin-bottom: 20rpx;
  298. }
  299. .address-box-list{
  300. height: 100rpx;
  301. line-height: 100rpx;
  302. border-bottom: 1rpx solid #f2f2f2;
  303. padding: 0 20rpx;
  304. border-radius: 8rpx;
  305. background-color: #FFFFFF;
  306. }
  307. .address-box-list:last-child{
  308. border: 0;
  309. }
  310. .address-box-label{
  311. display: inline-block;
  312. width: 200rpx;
  313. height: 100%;
  314. float: left;
  315. }
  316. .address-box-input{
  317. display: inline-block;
  318. width: 460rpx;
  319. height: 100%;
  320. float: right;
  321. text-align: right;
  322. }
  323. .address-box-input input{
  324. height: 80rpx;
  325. line-height: 80rpx;
  326. margin-top: 10rpx;
  327. font-size: 28rpx;
  328. vertical-align: middle;
  329. }
  330. .address-box-input-text{
  331. display: inline-block;
  332. width: 430rpx;
  333. line-height: 100%;
  334. vertical-align: middle;
  335. color: #949494;
  336. padding-right: 18rpx;
  337. font-size: 28rpx;
  338. }
  339. .address-box-input-icon{
  340. width: 12rpx;
  341. height: 22rpx;
  342. vertical-align: middle;
  343. }
  344. .address-btn{
  345. width: 700rpx;
  346. height: 70rpx;
  347. line-height: 70rpx;
  348. color: #FFFFFF;
  349. background-color: $theme-color;
  350. border-radius: 10rpx;
  351. margin: 50rpx auto 20rpx auto;
  352. text-align: center;
  353. }
  354. .address-btn2{
  355. width: 700rpx;
  356. height: 70rpx;
  357. line-height: 70rpx;
  358. color: $theme-color;
  359. background-color: #FFFFFF;
  360. border-radius: 10rpx;
  361. margin: 20rpx auto;
  362. text-align: center;
  363. }
  364. .address-btn-del{
  365. width: 700rpx;
  366. height: 70rpx;
  367. line-height: 70rpx;
  368. color: $theme-color;
  369. background-color: #FFFFFF;
  370. border: 1rpx solid $theme-color;
  371. border-radius: 10rpx;
  372. margin: 10rpx auto;
  373. text-align: center;
  374. }
  375. </style>