zhengyiming
11 小时以前 c3055eba8943341f7efed0d6ad77d7bbac208879
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
<template>
  <LoadingLayout :loading="isLoading" :error="isError" :loadError="refetch">
    <ContentScrollView hasPaddingTop>
      <ServiceDetailAddressCard
        :name="selectedAddress?.name ?? ''"
        :contactPhoneNumber="selectedAddress?.contactPhoneNumber ?? ''"
        :addressDetail="selectedAddress?.addressDetail ?? ''"
        showArrow
        @click="goSelectAddress"
      />
      <ServiceDetailGoodCard
        :name="detail?.name"
        :price="spec?.price"
        :specName="spec?.name"
        :specNumber="specNumber"
        :imgUrl="detail?.files?.[0]"
      />
      <!-- <List>
        <ListItem title="服务时间">
          <template #extra>
            <div class="mine-service-detail-view-list-item">{{ '请选择' }}</div>
          </template>
        </ListItem>
        <ListItem title="服务机构">
          <template #extra>
            <div class="mine-service-detail-view-list-item">{{ '请选择' }}</div>
          </template>
        </ListItem>
      </List> -->
      <nut-form :model-value="form" ref="formRef" :rules="rules" class="addStandardOrder-form">
        <nut-form-item
          label="服务开始时间:"
          class="bole-form-item"
          prop="beginTime"
          label-width="90px"
        >
          <ChooseInputWithDatePicker
            v-model="form.beginTime"
            :minDate="nowDate"
            placeholder="请选择"
            type="datetime"
            format="YYYY-MM-DD HH:mm:ss"
          ></ChooseInputWithDatePicker>
        </nut-form-item>
        <nut-form-item
          label="服务结束时间:"
          class="bole-form-item"
          prop="endTime"
          label-width="90px"
        >
          <ChooseInputWithDatePicker
            v-model="form.endTime"
            :minDate="endMinTime"
            :maxDate="endMaxTime"
            placeholder="请选择"
            type="datetime"
            format="YYYY-MM-DD HH:mm:ss"
          ></ChooseInputWithDatePicker>
        </nut-form-item>
        <nut-form-item
          label="服务机构:"
          class="bole-form-item"
          prop="enterpriseEmployeeId"
          label-width="90px"
        >
          <ChooseInputWithSuppliers
            v-model:supplierEnterpriseId="form.supplierEnterpriseId"
            placeholder="请选择"
            :serviceId="id"
            :beginTime="form.beginTime"
            :endTime="form.endTime"
            v-model:enterpriseEmployeeId="form.enterpriseEmployeeId"
            v-model:enterpriseEmployeeName="form.enterpriseEmployeeName"
          ></ChooseInputWithSuppliers>
        </nut-form-item>
        <nut-form-item
          label="备注:"
          class="bole-form-item alignTop"
          prop="remark"
          label-width="90px"
        >
          <nut-textarea
            v-model="form.remark"
            class="bole-input-textarea"
            rows="4"
            placeholder="请填写备注信息"
          >
          </nut-textarea>
        </nut-form-item>
      </nut-form>
    </ContentScrollView>
    <PageFooter>
      <div class="addStandardOrder-price-wrapper">
        <div class="addStandardOrder-price-text">支付:</div>
        <nut-price :price="totlePrice" size="large" />
      </div>
      <PageFooterBtn type="primary" class="business-card-btn" @click="goConfirm"
        >立即下单</PageFooterBtn
      >
    </PageFooter>
    <nut-address
      v-model:visible="form.selectAddressVisible"
      v-model:value="form.addressId"
      type="exist"
      :exist-address="existAddress"
      :is-show-custom-address="false"
      @selected="selected"
      exist-address-title="选择地址"
    ></nut-address>
  </LoadingLayout>
</template>
 
<script setup lang="ts">
import {
  ServiceDetailAddressCard,
  ServiceDetailGoodCard,
  List,
  ListItem,
  ChooseInputWithDatePicker,
} from '@12333/components';
import Taro from '@tarojs/taro';
import { RouterPath } from '@/constants';
import { useStandardServiceDetail } from '@12333/hooks';
import * as standardOrderServices from '@12333/services/apiV2/standardOrder';
import { FormRules } from '@nutui/nutui-taro/dist/types/__VUE/form/types';
import dayjs from 'dayjs';
import { EnumUserBankCardAccess } from '@12333/constants';
import { Message } from '@12333/utils';
 
defineOptions({
  name: 'InnerPage',
});
 
const route = Taro.useRouter();
const id = route.params?.id ?? '';
const specId = route.params?.specId ?? '';
const specNumber = Number(route.params?.specNumber);
 
const form = reactive({
  addressId: '',
  selectAddressVisible: false,
  beginTime: '',
  endTime: '',
  supplierEnterpriseId: '',
  enterpriseEmployeeId: '',
  enterpriseEmployeeName: '',
  remark: '',
});
 
const nowDate = dayjs().toDate();
const endMinTime = computed(() => {
  if (form.beginTime) {
    return dayjs(form.beginTime).add(1, 'minute').toDate();
  } else {
    return dayjs().toDate();
  }
});
const endMaxTime = computed(() => {
  if (form.beginTime) {
    return dayjs(dayjs(form.beginTime).format('YYYY-MM-DD 23:59:59')).toDate();
  } else {
    return undefined;
  }
});
 
const rules = reactive<FormRules>({
  beginTime: [{ required: true, message: '请选择服务开始时间' }],
  endTime: [{ required: true, message: '请选择服务结束时间' }],
  enterpriseEmployeeId: [{ required: true, message: '请选择服务机构' }],
});
 
const { isLoading, isError, detail, refetch } = useStandardServiceDetail({
  id,
});
 
const spec = computed(() => {
  if (detail.value.specs?.length > 0) {
    return detail.value.specs.find((x) => x.id === specId);
  }
  return null;
});
 
const { infiniteLoadingProps } = useEnterpriseAddresses({
  rows: 100,
  onSuccess(res) {
    const data = res.pages[0].data;
    const address = data.find((item) => item.isDefault);
    if (address) {
      form.addressId = address.id;
    } else {
      form.addressId = data[0].id;
    }
  },
});
 
const existAddress = computed(() => {
  return infiniteLoadingProps.value.flattenListData.map((x) => ({
    id: x.id,
    addressDetail: x.addressDetail,
    cityName: '',
    countyName: '',
    provinceName: '',
    selectedAddress: x.id === form.addressId,
    townName: '',
    name: x.name,
    phone: x.contactPhoneNumber,
  }));
});
 
const selectedAddress = computed(() => {
  const address = infiniteLoadingProps.value.flattenListData.find(
    (item) => item.id === form.addressId
  );
  return address || infiniteLoadingProps.value.flattenListData[0];
});
 
function goSelectAddress() {
  // Taro.navigateTo({
  //   url: `${RouterPath.addressManange}?mode=select`,
  // });
  form.selectAddressVisible = true;
}
 
const selected = (prevExistAdd, nowExistAdd, arr) => {
  form.addressId = nowExistAdd.id;
};
 
const totlePrice = computed(() => {
  return (spec.value?.price ?? 0) * specNumber;
});
 
const formRef = ref<any>(null);
function goConfirm() {
  if (!formRef.value) return;
  formRef.value.validate().then(({ valid, errors }: any) => {
    if (valid) {
      addStandardOrder();
    }
  });
}
 
async function addStandardOrder() {
  try {
    let params: API.AddStandardOrderCommand = {
      serviceId: detail.value.id,
      serviceName: detail.value.name,
      serviceCode: detail.value.code,
      specId: spec.value.id,
      specName: spec.value.name,
      specPrice: spec.value.price ?? 0,
      specNumber: specNumber,
      addressId: form.addressId,
      name: detail.value.name,
      contactPhoneNumber: selectedAddress.value.contactPhoneNumber,
      provinceCode: selectedAddress.value.provinceCode,
      provinceContent: selectedAddress.value.provinceContent,
      cityCode: selectedAddress.value.cityCode,
      cityContent: selectedAddress.value.cityContent,
      areaCode: selectedAddress.value.areaCode,
      areaContent: selectedAddress.value.areaContent,
      addressName: selectedAddress.value.addressName,
      addressDetail: selectedAddress.value.addressDetail,
      longitude: selectedAddress.value.longitude,
      latitude: selectedAddress.value.latitude,
      beginTime: dayjs(form.beginTime).format('YYYY-MM-DD HH:mm'),
      endTime: dayjs(form.endTime).format('YYYY-MM-DD HH:mm'),
      supplierEnterpriseId: form.supplierEnterpriseId,
      enterpriseEmployeeIds: [form.enterpriseEmployeeId],
      remark: form.remark,
      payAccess: EnumUserBankCardAccess.WeChatPay,
    };
    let res = await standardOrderServices.addStandardOrder(params);
    if (res) {
      pay(res);
    }
  } catch (error) {}
}
 
async function pay(orderId: string) {
  try {
    let params: API.PayStandardOrderCommand = {
      id: orderId,
    };
    let res = await standardOrderServices.payStandardOrder(params);
    if (res) {
      await Taro.requestPayment({
        timeStamp: res.timestamp,
        nonceStr: res.nonceStr,
        package: res.package,
        signType: res.signType as any,
        paySign: res.paySign,
      });
      Message.success('支付成功');
      Taro.redirectTo({
        url: `${RouterPath.mineOrderDetail}?id=${orderId}`,
      });
    }
  } catch (error) {}
}
</script>
 
<style lang="scss">
@import '@/styles/common.scss';
 
.addStandardOrder-page-wrapper {
  .addStandardOrder-form {
    .nut-cell-group__wrap {
      box-shadow: none;
 
      .input-text,
      .h5-textarea {
        text-align: right !important;
      }
    }
  }
 
  .addStandardOrder-price-wrapper {
    display: flex;
    flex: 2;
    min-width: 0;
    align-items: center;
    padding-left: 28px;
 
    .addStandardOrder-price-text {
      font-size: 32px;
      color: boleGetCssVar('text-color', 'primary');
    }
  }
}
</style>