index.vue 15 KB

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