index.vue 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <template>
  2. <view class="page">
  3. <view class="periodDate">
  4. <text>服务日期:{{periodDate.label}}</text>
  5. </view>
  6. <view class="flex-col group" v-if="serviceObjectList.length>1">
  7. <view class="serob"><text>服务对象</text></view>
  8. <u-grid :border="false" col="4">
  9. <u-grid-item v-for="(item,index) in serviceObjectList" :key="index">
  10. <view class="serobItem flex-col" >
  11. <view class="serobImgView" @click="selectServiceObject(item)">
  12. <image class="serobImg" mode="aspectFill" :src="item.facePhotoUrl || '/static/me/ud4.png'"></image>
  13. </view>
  14. <text class="serobName">{{item.nickName || '未填写'}}</text>
  15. <view class="serobV" v-if="item.select === true">
  16. <image class="serobVicon" src="/static/order/ud20.png"></image>
  17. </view>
  18. </view>
  19. </u-grid-item>
  20. </u-grid>
  21. <!-- <view class="serobReminder">-->
  22. <!-- <text>请注意,一人一号</text>-->
  23. <!-- </view>-->
  24. </view>
  25. <view class="flex-col group " v-for="(item, index) in orderParam.childService">
  26. <view class="flex-row " v-if="serviceObjectList.length>1">
  27. <image class="selectSerobImg" mode="aspectFill" :src="item.facePhotoUrl || '/static/me/ud4.png'"></image>
  28. <text class="selectSerobName">{{item.nickName || '未填写'}}</text>
  29. </view>
  30. <view class="serob">
  31. <text>服务人员</text>
  32. </view>
  33. <view>
  34. <u-grid col="4">
  35. <u-grid-item v-for="(item1,index1) in item.serviceTeacherList" :key="index1">
  36. <view class="serobItem flex-col" @click="selectServiceTeach(item.serviceTeacherList,index,index1)">
  37. <view class="serobImgView">
  38. <image class="serobImg" mode="aspectFill" :src="item1.facePhotoUrl || '/static/me/ud4.png'"></image>
  39. </view>
  40. <text class="serobName ">{{item1.personName || '未填写'}}</text>
  41. <view class="flex-row justify-center ">
  42. <u-icon name="rmb-circle" size="14"></u-icon>
  43. <text class="teachPrice">¥{{item1.fee}}</text>
  44. </view>
  45. <view class="serobV " v-if="item1.select">
  46. <image class="serobVicon" src="/static/order/ud20.png"></image>
  47. </view>
  48. </view>
  49. </u-grid-item>
  50. </u-grid>
  51. </view>
  52. <view class="serob" :style="{'marginTop':'32rpx'}">
  53. <text>服务时段</text>
  54. </view>
  55. <view>
  56. <u-grid :border="false" col="5">
  57. <u-grid-item v-if="item2.total > 0" v-for="(item2,index2) in item.serviceTimeList" :key="index2">
  58. <view class="flex-col justify-center timeItem " :class="{selectBack: item2.select}" @click="selectServiceTime(item.serviceTimeList,index,index2)">
  59. <view class="flex-row justify-center">
  60. <text class="time">{{item2.label}}</text>
  61. </view>
  62. <view class="flex-row justify-center">
  63. <text class="price">¥{{item2.price}}</text>
  64. </view>
  65. </view>
  66. </u-grid-item>
  67. </u-grid>
  68. </view>
  69. </view>
  70. <view class="flex-col group ">
  71. <view class="groupItemKey">
  72. <text>取号规则</text>
  73. </view>
  74. <view class="textareaView ">
  75. <!-- <textarea v-model="orderParam.remark" placeholder-style="color:#999999;fontSize:28rpx"-->
  76. <!-- placeholder="如有其它特殊需求,请在此输入您的需求" />-->
  77. <view class="serobReminder">
  78. <text>请注意,一人一号</text>
  79. </view>
  80. </view>
  81. </view>
  82. <view :style="{'height':'236rpx'}"></view>
  83. <view class="flex-col group2 ">
  84. <view class="btnTitle flex-row">
  85. <u-icon v-if="selectIcon" name="checkmark-circle-fill" color="#FFE52C" size="18"
  86. @click="selectChange"></u-icon>
  87. <u-icon v-else name="/static/order/ud9.png" color="#FFE52C" size="18" @click="selectChange"></u-icon>
  88. <text :style="{'margin-left':'10rpx'}">请阅读并同意</text>
  89. <text :style="{'color':'red'}" @click="goTermsOfService">《预约需知》</text>
  90. </view>
  91. <view class="btn flex-row justify-between">
  92. <view>
  93. <text class="title">待支付</text>
  94. <text class="num">¥{{price}}</text>
  95. </view>
  96. <view class="btnRight" @click="commitOrder">
  97. <text>提交</text>
  98. </view>
  99. </view>
  100. </view>
  101. <myPay ref="myPay" :blPay="false" :orderNo="subOrderNo" @payResult="payResult"></myPay>
  102. </view>
  103. </template>
  104. <script>
  105. import myPay from '../../components/pay/pay';
  106. export default {
  107. components: {
  108. myPay
  109. },
  110. data() {
  111. return {
  112. //服务对象列表
  113. serviceObjectList:[],
  114. //服务人员列表
  115. serviceTeacherList:[],
  116. userInfo: {},
  117. //服务门店
  118. store: {},
  119. //默认服务时间
  120. periodDate: [],
  121. //预约费用
  122. price: '0',
  123. //订单编号
  124. subOrderNo:'',
  125. selectIcon: true,
  126. orderParam:{
  127. orderType: 1,
  128. serviceAttribute: 2,
  129. serviceStoreId: '',
  130. remark: '',
  131. serviceDate:'',
  132. childService:[
  133. // {
  134. // serviceObjectId: '',
  135. // facePhotoUrl:'', //回显需要,不做参数
  136. // nickName:'', //回显需要,不做参数
  137. // serviceUserId: '',
  138. // personName:'',//回显需要,不做参数
  139. // fee:'',//回显需要,不做参数
  140. // serviceStartTime: '',
  141. // serviceTeacherList:[],//服务人员列表,回显需要,不做参数
  142. // serviceTimeList:[]//服务时段列表,回显需要,不做参数
  143. // }
  144. ]
  145. }
  146. }
  147. },
  148. onLoad() {
  149. this.store = uni.getStorageSync('storeInfo')
  150. this.userInfo = uni.getStorageSync('userInfo')
  151. this.orderParam.serviceStoreId = this.store.storeId
  152. //获取排班日期
  153. this.selectDate()
  154. },
  155. onShow() {
  156. },
  157. mounted(){
  158. },
  159. methods: {
  160. //获取排班日期
  161. selectDate() {
  162. console.log(this.store)
  163. this.$api.selectDate({
  164. organization: this.store.storeId
  165. }).then(res => {
  166. this.periodDate = res.data.data[0]
  167. this.orderParam.serviceDate=this.periodDate.label
  168. this.getServicePerson(this.periodDate.label)
  169. })
  170. },
  171. // 查询服务工作人员列表
  172. getServicePerson(date) {
  173. this.$api.getServicePerson({
  174. storeId:this.store.storeId,
  175. date:date
  176. }).then((res) => {
  177. this.serviceTeacherList = res.data.data;
  178. this.serviceTeacherList[0].select = true
  179. this.getServicePersonUrl(this.serviceTeacherList);
  180. this.listServiceObject()
  181. })
  182. },
  183. getServicePersonUrl(items){
  184. for (let i = 0; i < items.length; i++) {
  185. if (items[i].facePhoto) {
  186. this.$api.getImgUrlByOssId({
  187. ossId: items[i].facePhoto
  188. }).then(res => {
  189. items[i].facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  190. this.$set(this.serviceTeacherList, i, items[i])
  191. })
  192. }
  193. }
  194. },
  195. // 查询服务对象信息列表
  196. listServiceObject() {
  197. this.$api.listServiceObject(this.reqParm).then((res) => {
  198. console.log(res)
  199. this.serviceObjectList = res.data.data
  200. this.getServiceObjectUrl(this.serviceObjectList);
  201. })
  202. },
  203. // 获取图片
  204. getServiceObjectUrl(items) {
  205. for (let i = 0; i < items.length; i++) {
  206. if (items[i].facePhoto) {
  207. this.$api.getImgUrlByOssId({
  208. ossId: items[i].facePhoto
  209. }).then(res => {
  210. items[i].facePhotoUrl = res.data.data[0].url.replace(/^http:/, "https:")
  211. this.$set(this.serviceObjectList, i, items[i])
  212. })
  213. }
  214. if (i === 0){
  215. this.selectServiceObject(items[i])
  216. }
  217. }
  218. },
  219. selectServiceObject(item) {
  220. if (!this.serviceTeacherList || this.serviceTeacherList.length==0){
  221. uni.showToast({
  222. icon: 'none',
  223. duration: 2000,
  224. title: '暂无可预约排班'
  225. });
  226. return
  227. }
  228. if (item.select) {
  229. this.orderParam.childService = this.orderParam.childService.filter(selectServiceObject =>
  230. selectServiceObject.serviceObjectId !== item.id)
  231. item.select = !item.select
  232. } else {
  233. this.$api.getServicePersonTime({
  234. personId: this.serviceTeacherList[0].personId,
  235. date: this.periodDate.label,
  236. storeId:this.store.storeId
  237. }).then(res => {
  238. if (!res.data.data || res.data.data.length==0){
  239. uni.showToast({
  240. icon: 'none',
  241. duration: 2000,
  242. title: '暂无可预约排班'
  243. });
  244. return
  245. }
  246. item.select = !item.select
  247. let periodTimeList = res.data.data
  248. let selectServiceObjectList = this.orderParam.childService
  249. //选择服务对象时,获取的排班时间为全部技师的排班时间,所以只要某个时段被选过,那么这个时段的数量-1
  250. selectServiceObjectList.forEach(selectServiceObject =>{
  251. periodTimeList.forEach(periodTime =>{
  252. if (selectServiceObject.serviceStartTime === periodTime.label ){
  253. periodTime.total = periodTime.total - 1
  254. }
  255. })
  256. })
  257. let date = null //系统为当前服务对象分配的时间
  258. for (const time of periodTimeList) {
  259. if (time.total>0){
  260. time.select = true
  261. date = time
  262. //为当前服务对象分配时间段成功时,需要将以前的服务对象的可选择的时间段的total -1
  263. selectServiceObjectList.forEach(selectServiceObject =>{
  264. if (selectServiceObject.serviceUserId === -1){
  265. //如果子订单没有指定技师,则对应的时段-1
  266. selectServiceObject.serviceTimeList.forEach(t=>{
  267. if (t.label == date.label){
  268. t.total = t.total -1
  269. }
  270. })
  271. }else {
  272. selectServiceObject.serviceTimeList.forEach(t=>{
  273. //如果子订单指定技师,且该技师的服务时段未被选中,则对应的时段-1
  274. if (t.label == date.label && !t.select){
  275. t.total = t.total -1
  276. }
  277. })
  278. }
  279. })
  280. break
  281. }
  282. }
  283. console.log(periodTimeList)
  284. //这里只为了断开技师列表的应用关系
  285. let serviceTeacherListStr = JSON.stringify(this.serviceTeacherList)
  286. let serviceTeacherList = JSON.parse(serviceTeacherListStr)
  287. //创建子订单项
  288. let childService ={
  289. serviceObjectId: item.id,
  290. facePhotoUrl:item.facePhotoUrl, //回显需要,不做参数
  291. nickName:item.nickName, //回显需要,不做参数
  292. serviceUserId: serviceTeacherList[0].personId,
  293. fee:serviceTeacherList[0].fee,//回显需要,不做参数
  294. serviceStartTime: date.label,
  295. serviceTeacherList:serviceTeacherList,//服务人员列表,回显需要,不做参数
  296. serviceTimeList:periodTimeList//服务时段列表,回显需要,不做参数
  297. }
  298. this.orderParam.childService.push(childService)
  299. })
  300. }
  301. this.price = 0
  302. for (let childService of this.orderParam.childService) {
  303. this.price = this.price * 1 + childService.fee * 1
  304. this.price = this.price.toFixed(2)
  305. }
  306. },
  307. selectServiceTeach(items,index,index1){
  308. items.forEach(e=>{
  309. e.select=false
  310. })
  311. items[index1].select =true
  312. this.orderParam.childService[index].fee = items[index1].fee
  313. this.orderParam.childService[index].serviceUserId = items[index1].personId
  314. this.$api.getServicePersonTime({
  315. personId: items[index1].personId,
  316. date: this.periodDate.label,
  317. storeId:this.store.storeId
  318. }).then(res => {
  319. let serviceTimeList = res.data.data
  320. let selectServiceObjectList = this.orderParam.childService.filter(selectServiceObject =>
  321. (selectServiceObject.serviceUserId === items[index1].personId
  322. && selectServiceObject.serviceObjectId !== this.orderParam.childService[index].serviceObjectId)
  323. || selectServiceObject.serviceUserId === -1
  324. )
  325. selectServiceObjectList.forEach(selectServiceObject =>{
  326. serviceTimeList.forEach(periodTime =>{
  327. if (selectServiceObject.serviceStartTime === periodTime.label ){
  328. if (selectServiceObject.serviceUserId === -1){
  329. selectServiceObject.serviceTimeList.forEach(t=>{
  330. if (t.label == periodTime.label && t.total === 1){
  331. periodTime.total = periodTime.total - 1
  332. }
  333. })
  334. }else {
  335. periodTime.total = periodTime.total - 1
  336. }
  337. }
  338. })
  339. })
  340. for (const time of serviceTimeList) {
  341. if (time.total>0){
  342. time.select = true
  343. break
  344. }
  345. }
  346. serviceTimeList[0].select = true
  347. this.orderParam.childService[index].serviceStartTime= serviceTimeList[0].label,
  348. this.orderParam.childService[index].serviceTimeList= serviceTimeList
  349. })
  350. this.price = 0
  351. for (let childService of this.orderParam.childService) {
  352. this.price = this.price * 1 + childService.fee * 1
  353. this.price = this.price.toFixed(2)
  354. }
  355. console.log(this.price)
  356. this.$forceUpdate()
  357. },
  358. selectServiceTime(items,index,index2){
  359. console.log(items,index,index2)
  360. items.forEach(e=>{
  361. e.select=false
  362. })
  363. items[index2].select =true // 新选中的时间
  364. // let selectServiceObject = this.orderParam.childService[index] //旧的时间
  365. // this.orderParam.childService.forEach(i=>{
  366. // if (selectServiceObject.serviceUserId === -1){
  367. // i.serviceTimeList.forEach(t=>{
  368. // if (t.label == selectServiceObject.serviceStartTime && !t.select ){
  369. // console.log('-1----------加1')
  370. // t.total +=1
  371. // }
  372. // if (t.label == items[index2].serviceStartTime && i.serviceObjectId != selectServiceObject.serviceObjectId){
  373. // console.log('-1----------减1')
  374. // t.total -=1
  375. // }
  376. // })
  377. // }else {
  378. // if (selectServiceObject.serviceUserId == i.serviceUserId){
  379. // i.serviceTimeList.forEach(t=>{
  380. // if (t.label == selectServiceObject.serviceStartTime && !t.select ){
  381. // t.total +=1
  382. // }
  383. // if (t.label == items[index2].serviceStartTime && i.serviceObjectId != selectServiceObject.serviceObjectId){
  384. // t.total -=1
  385. // }
  386. // })
  387. // }
  388. // }
  389. // })
  390. this.orderParam.childService[index].serviceStartTime = items[index2].label
  391. this.$forceUpdate()
  392. },
  393. selectChange() {
  394. this.selectIcon = !this.selectIcon
  395. },
  396. goTermsOfService() {
  397. uni.navigateTo({
  398. url: '/myPages/TermsOfService/index?name=' + '预约需知' + '&type=' + 5
  399. })
  400. },
  401. //支付组件回调
  402. payResult(e){
  403. console.log(e)
  404. if(e.payResult){
  405. uni.showToast({
  406. title: '支付成功!'
  407. });
  408. }else {
  409. uni.showToast({
  410. title: '支付失败',
  411. icon: 'error'
  412. });
  413. }
  414. setTimeout(()=>{
  415. uni.switchTab({
  416. url: '/pages/order/index'
  417. })
  418. },1000)
  419. },
  420. //提交订单
  421. commitOrder() {
  422. if (this.subOrderNo){
  423. this.$refs.myPay.openPopup()
  424. }else {
  425. if (!this.selectIcon) {
  426. uni.$u.toast('请阅读并同意《预约需知》')
  427. return;
  428. }
  429. if (this.orderParam.childService.length === 0) {
  430. uni.$u.toast('请选择服务对象')
  431. return;
  432. }
  433. if (this.requestStatus) {
  434. return;
  435. }
  436. this.requestStatus = true
  437. this.$api.commonGeneralOrder(this.orderParam).then(res => {
  438. console.log('++++++++++++++++++订单提交+++++++++++', res)
  439. if (res.data.data.subOrderNo) {
  440. this.subOrderNo = res.data.data.subOrderNo
  441. this.$refs.myPay.openPopup()
  442. } else {
  443. uni.$u.toast('预约成功')
  444. setTimeout(() => {
  445. uni.switchTab({
  446. url: '/pages/order/index'
  447. })
  448. }, 1000)
  449. }
  450. this.requestStatus = false
  451. }).catch(err => {
  452. this.requestStatus = false
  453. })
  454. }
  455. },
  456. }
  457. }
  458. </script>
  459. <style scoped lang="scss">
  460. @import './index.rpx.scss';
  461. </style>