index.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. <template>
  2. <!-- 自充值 -->
  3. <div class="pageUniPay flex-col">
  4. <s-header :name="$t('uniPay.selfRecharging')" :noback="false"></s-header>
  5. <div class="box1 flex-col">
  6. <van-field v-model="deviceValue" is-link readonly :label="$t('uniPay.selfRecharging')"
  7. :placeholder="$t('uniPay.pleaseSelectAMachine')" @click="deviceShow = true" />
  8. <van-popup v-model:show="deviceShow" round closeable position="bottom">
  9. <van-cascader v-model="deviceId" :title="$t('uniPay.pleaseSelectAMachine')" :options="deviceOptions"
  10. @close="show = false" @finish="onDeviceFinish" />
  11. </van-popup>
  12. <van-field v-model="productValue" is-link readonly :label="$t('uniPay.pattern')"
  13. :placeholder="$t('uniPay.pleaseSelectAPattern')" @click="productShow = true" />
  14. <van-popup v-model:show="productShow" round closeable position="bottom">
  15. <van-cascader v-model="productId" :title="$t('uniPay.pleaseSelectAPattern')" :options="productOptions"
  16. @close="show = false" @finish="onProductFinish">
  17. <template #option="{ option }">
  18. <div class="cascader-item">
  19. <van-image :src="option.imgUrl" width="50px" height="50px"></van-image>
  20. <div class="cascader-label">{{ option.value }}</div>
  21. </div>
  22. </template>
  23. </van-cascader>
  24. </van-popup>
  25. <div class="van-cell van-field">
  26. <div class="van-cell__title van-field__label"><span>{{ $t('uniPay.paymentMethod') }}:</span></div>
  27. <div class="van-cell__value van-field__value radioBox">
  28. <van-radio-group v-model="payType" direction="horizontal">
  29. <van-radio name="WEIXIN_NATIVE" icon-size="18px">{{ $t('uniPay.weChat') }}</van-radio>
  30. <van-radio name="ALIPAY_NATIVE" icon-size="18px">{{ $t('uniPay.alipay') }}</van-radio>
  31. </van-radio-group>
  32. </div>
  33. </div>
  34. <van-button round type="primary" class="volumeChangeButton" @click="submitForm">{{ $t('uniPay.placeOrder')
  35. }}</van-button>
  36. <van-popup v-model:show="uniPayShow" position="center" :style="{ width: '90%', 'text-align': 'center' }">
  37. <p>{{ $t('uniPay.orderNumber') }}: {{ uniPayObj.sn }}</p>
  38. <img :src="uniPayObj.rd_Pic" style="max-width: 100%; height: auto;" />
  39. </van-popup>
  40. </div>
  41. </div>
  42. </template>
  43. <script>
  44. import { onMounted, ref } from 'vue';
  45. import sHeader from "@/components/SimpleHeader";
  46. import { getListEquipment, selectProducts } from '@/service/device';
  47. import { uniPayAjax } from '@/service/uniPay';
  48. import { showFailToast } from 'vant';
  49. import { getLoginUser } from '@/common/js/utils';
  50. import { useI18n } from 'vue-i18n';
  51. import { styleUrl } from '../../common/js/utils';
  52. export default {
  53. setup() {
  54. // 引入语言
  55. const { t } = useI18n();
  56. const user = getLoginUser();
  57. const deviceId = ref('');
  58. const deviceValue = ref('');
  59. const deviceShow = ref(false);
  60. const deviceOptions = ref([]);
  61. const onDeviceFinish = ({ selectedOptions }) => {
  62. deviceShow.value = false;
  63. deviceValue.value = selectedOptions[0].text;
  64. getProduct();
  65. }
  66. const productId = ref('');
  67. const productValue = ref('');
  68. const productShow = ref(false);
  69. const productOptions = ref([]);
  70. const onProductFinish = ({ selectedOptions }) => {
  71. productShow.value = false;
  72. productValue.value = selectedOptions[0].text;
  73. }
  74. const payType = ref('WEIXIN_NATIVE');
  75. const uniPayObj = ref({});
  76. const uniPayShow = ref(false);
  77. // 初始化页面获取列表
  78. onMounted(async () => {
  79. // 加载样式
  80. styleUrl('uniPay');
  81. getDeviceOptionFun();
  82. });
  83. // 获取机器下拉
  84. const getDeviceOptionFun = async () => {
  85. const { data } = await getListEquipment({ adminId: user.id });
  86. if (data.code === '00000') {
  87. deviceOptions.value = data.data.map(item => {
  88. return {
  89. text: item.name,
  90. value: item.id,
  91. clientId: item.clientId,
  92. };
  93. });
  94. } else { showFailToast(data.message); }
  95. }
  96. const showSugarPhoto = (no) => {
  97. return require(`../../assets/order/spunSugar/goods/${no}.png`);
  98. };
  99. // 获取花形下拉列表
  100. const getProduct = async () => {
  101. const { data } = await selectProducts({ equipmentId: deviceId.value });
  102. if (data.code) {
  103. productOptions.value = data.data.map(item => {
  104. // console.log(item.no);
  105. return {
  106. text: item.productName,
  107. value: item.productName,
  108. imgUrl: showSugarPhoto(item.no),
  109. };
  110. })
  111. } else { showFailToast(data.message); }
  112. }
  113. // 提交表单
  114. const submitForm = async () => {
  115. if (deviceId.value === '') { showFailToast(t('uniPay.pleaseSelectAMachine')); return; }
  116. if (productValue.value === '') { showFailToast(t('uniPay.pleaseSelectAPattern')); return; }
  117. const device = deviceOptions.value.filter(v => v.value === deviceId.value);
  118. const { data } = await uniPayAjax({ clientId: device[0].clientId, frpCode: payType.value, productName: productValue.value });
  119. if (data.code === 0) {
  120. uniPayObj.value = JSON.parse(data.data);
  121. uniPayShow.value = true;
  122. } else {
  123. showFailToast(data.errmsg);
  124. }
  125. };
  126. return {
  127. deviceId,
  128. deviceValue,
  129. deviceShow,
  130. deviceOptions,
  131. onDeviceFinish,
  132. productId,
  133. productValue,
  134. productShow,
  135. productOptions,
  136. onProductFinish,
  137. payType,
  138. submitForm,
  139. uniPayObj,
  140. uniPayShow,
  141. showSugarPhoto,
  142. };
  143. },
  144. components: { sHeader },
  145. };
  146. </script>
  147. <style lang="less" scoped>
  148. @import "../../common/style/common";
  149. </style>