tansferDuration.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <template>
  2. <div class="transfer">
  3. <div style="flex: 1;overflow-y: auto;padding: 0 16px;" class="transfer-box">
  4. <div>
  5. <div>减少时长的云机</div>
  6. <div>
  7. <comoros :key="transferUserCardKey" :dayTime="countObj.transferMinDay"
  8. :transferPhoneList="transferPhoneList" v-model="params.transferUserCardId"
  9. :name.sync="transferUserCardName" @confirm="comorosConfirm" />
  10. </div>
  11. </div>
  12. <div class="transfer-item">
  13. <div>增加时长的云机</div>
  14. <div>
  15. <comoros :key="acceptUserCardKey" :disabledId="params.transferUserCardId"
  16. :transferPhoneList="transferPhoneList" :buyVipType="buyVipType" v-model="params.acceptUserCardId"
  17. :name.sync="acceptUserCardName" :androidVersion="androidVersion" distinguishBool />
  18. </div>
  19. </div>
  20. <div class="transfer-item">
  21. <div>转移的时间</div>
  22. <div class="transfer-item-input">
  23. <van-field placeholder="请输入转移的时间" v-model="params.transferTime"
  24. @input="params.transferTime = params.transferTime.replace(/\D/g, '')" />
  25. </div>
  26. </div>
  27. <span style="font-size: 12px;font-weight: 400;color: #3B7FFF;line-height: 16px;margin-top: 5px;"
  28. @click="(params.transferTime && Object.keys(countObj).length) && serviceCount()"
  29. :class="{ opacity: !params.transferTime || !Object.keys(countObj).length }">{{ countLoading ? '正在计算中...' :
  30. '服务费计算'
  31. }}</span>
  32. <div class="transfer-tip">
  33. <div>
  34. 温馨提示:
  35. </div>
  36. <div class="transfer-tip-content">
  37. <div v-html="html"></div>
  38. </div>
  39. </div>
  40. </div>
  41. <div class="transfer-btn" v-show="btnVisible">
  42. <van-button type="info" block
  43. :disabled="!params.transferUserCardId || !params.acceptUserCardId || !params.transferTime"
  44. :loading="allocateLoading" @click="changePopUpType(0)" loading-text="正在分配时间中...">
  45. 分配时间
  46. </van-button>
  47. </div>
  48. <van-dialog v-model="visible" :title="clickType ? '服务费计算' : ''" confirmButtonColor="#3B7FFF" className="dialog"
  49. showCancelButton cancelButtonColor="#999999" @confirm="!clickType && confirm()"
  50. @close="allocateLoading = false">
  51. <div style="padding: 16px;font-weight: 100;">
  52. <template v-if="clickType">
  53. <div style="display: flex; justify-content: space-between;">
  54. <div>转移天数:</div>
  55. <div style="color: #F9F9F9;">{{ params.transferTime }}天</div>
  56. </div>
  57. <div style="display: flex; justify-content: space-between;">
  58. <div>服务费:</div>
  59. <div style="color: #F9F9F9;">{{ serviceCharge }}天</div>
  60. </div>
  61. </template>
  62. <template v-else>
  63. <div style="line-height: 30px;">
  64. <div style="text-align: center;font-weight:bold;">
  65. 确定要将【{{ transferUserCardName }}】
  66. </div>
  67. <div style="text-align: center;">
  68. 时间分配给【{{ acceptUserCardName }}】
  69. </div>
  70. <div style="text-align: center;margin-top: 10px">
  71. 服务费:{{ serviceCharge }}天
  72. </div>
  73. </div>
  74. </template>
  75. </div>
  76. </van-dialog>
  77. </div>
  78. </template>
  79. <script>
  80. import {
  81. sha256
  82. } from 'js-sha256';
  83. import BigNumber from "bignumber.js";
  84. import { Toast } from 'vant'
  85. const comoros = () => import('./comoros.vue')
  86. export default {
  87. name: 'tansferDuration',
  88. components: {
  89. comoros
  90. },
  91. props: {
  92. token: {
  93. type: String,
  94. default: ''
  95. }
  96. },
  97. data() {
  98. return {
  99. visible: false,// 显示弹窗
  100. transferPhoneList: [], // 云机列表
  101. buyVipType: '', // 当前选中的云机类型
  102. params: {},
  103. acceptUserCardKey: +new Date(),
  104. transferUserCardKey: +new Date(),
  105. acceptUserCardName: '',
  106. transferUserCardName: '',
  107. // 点击类型 0 是确认转移、1是计算手续费
  108. clickType: 0,
  109. // 计算loading
  110. countLoading: false,
  111. // 计算服务费的对象
  112. countObj: {},
  113. // 服务费
  114. serviceCharge: '',
  115. // 分配时间loading
  116. allocateLoading: false,
  117. html: '',
  118. androidVersion: '',
  119. btnVisible: true
  120. };
  121. },
  122. mounted() {
  123. this.init()
  124. this.getFeeRatio()
  125. this.getRule()
  126. const userAgent = navigator.userAgent
  127. if (userAgent.includes("Android")) {
  128. window.onresize = this.monitoringDevices
  129. }
  130. },
  131. beforeDestroy() {
  132. window.onresize = null
  133. },
  134. methods: {
  135. init() {
  136. this.params = {
  137. acceptUserCardId: '', // 接受设备ID
  138. transferUserCardId: '', // 转移设备ID
  139. transferTime: '' // 转移天数
  140. }
  141. this.acceptUserCardKey = +new Date()
  142. this.transferUserCardKey = +new Date()
  143. this.buyVipType = ''
  144. this.serviceCharge = ''
  145. this.getTransferPhoneList()
  146. },
  147. // 获取云机列表
  148. getTransferPhoneList() {
  149. this.$axios.$get('resources/v5/time/transfer/getTransferPhoneList', { header: { token: this.token, versionName: '5.9.0' } }).then(res => {
  150. if (res.success) {
  151. this.transferPhoneList = res.data
  152. }
  153. })
  154. },
  155. // 确认框
  156. comorosConfirm(data) {
  157. this.buyVipType = data.buyVipType
  158. this.buyVipType === 'SVIP' && (this.androidVersion = data.androidVersion);
  159. this.acceptUserCardKey = +new Date()
  160. this.params.acceptUserCardId = ''
  161. },
  162. // 获取手续费比例
  163. getFeeRatio() {
  164. this.$axios.$get('resources/v5/time/transfer/getFeeRatio', { headers: { Authorization: this.token, versionName: '5.9.0' } }).then(res => {
  165. if (res.success) {
  166. res.data.transferMinDay = res.data.transferMinDay * 24 * 60
  167. this.countObj = res.data
  168. }
  169. }).catch(err => {
  170. Toast.fail(err.message)
  171. })
  172. },
  173. // 确定提交
  174. async confirm() {
  175. // 获取服务器时间
  176. let requestTime = await this.$axios.$get('pay/v1/order/getSystemTime', { headers: { Authorization: this.token, versionName: '5.9.0' } })
  177. requestTime = new Date(requestTime.data * 1000).$formatTime()
  178. const requestTimeSign = sha256("Register_SZX_2023:" + requestTime)
  179. this.$axios.$post('resources/v5/time/transfer/transferDurationOperation', {
  180. ...this.params,
  181. requestTime
  182. }, { headers: { Authorization: this.token, versionName: '5.9.0', requestTimeSign } }).then(res => {
  183. if (res.success) {
  184. this.init()
  185. Toast.success(res.msg)
  186. }
  187. }).catch(err => {
  188. Toast.fail(err.message)
  189. }).finally(() => {
  190. this.allocateLoading = false
  191. })
  192. },
  193. // 服务费计算
  194. serviceCount(bool = true) {
  195. if (this.countLoading) return
  196. if (bool) this.countLoading = true
  197. const arr = this.countObj.list.sort((a, b) => {
  198. return a.timeConsumingEnd - b.timeConsumingEnd
  199. })
  200. let commission = null
  201. for (const i of arr) {
  202. if (+this.params.transferTime <= i.timeConsumingEnd) {
  203. commission = i.commission
  204. break
  205. }
  206. }
  207. if (!commission) commission = this.countObj.commissionSet
  208. const serviceCharge = +new BigNumber(this.params.transferTime).times(new BigNumber(commission).div(100))
  209. this.serviceCharge = serviceCharge < 1 ? 1 : serviceCharge
  210. this.countLoading = false
  211. if (bool) this.changePopUpType(1)
  212. },
  213. changePopUpType(e) {
  214. if (!Object.keys(this.countObj).length) {
  215. Toast.fail('活动已结束')
  216. return
  217. }
  218. if (!e) {
  219. this.serviceCount(false)
  220. this.allocateLoading = true
  221. }
  222. this.visible = true
  223. this.clickType = e
  224. },
  225. // 获取规则
  226. getRule() {
  227. this.$axios.$get('/public/v4/agreement/content', {
  228. params: {
  229. agreementCoding: 'YJSBSJZY2024'
  230. }, headers: { Authorization: this.token, versionName: '5.9.0' }
  231. }).then(res => {
  232. const html = res.data.content;
  233. const rx = /<body[^>]*>([\s\S]+?)<\/body>/i;
  234. let m = rx.exec(html);
  235. if (m) {
  236. m = m[1]
  237. };
  238. this.html = m
  239. })
  240. },
  241. monitoringDevices() {
  242. this.btnVisible = !this.btnVisible
  243. }
  244. },
  245. };
  246. </script>
  247. <style lang="scss" scoped>
  248. .transfer {
  249. padding: 0 0 30px;
  250. display: flex;
  251. flex-direction: column;
  252. height: 100%;
  253. .transfer-item {
  254. margin-top: 16px;
  255. }
  256. .transfer-tip {
  257. margin-top: 24px;
  258. }
  259. .transfer-item-input {
  260. margin-top: 8px;
  261. display: flex;
  262. align-items: center;
  263. }
  264. .transfer-tip-content {
  265. margin-top: 8px;
  266. }
  267. .transfer-tip-content {
  268. font-size: 12px;
  269. font-family: PingFangSC, PingFang SC;
  270. font-weight: 400;
  271. color: #959799;
  272. line-height: 17px;
  273. }
  274. .transfer-btn {
  275. padding: 0 16px;
  276. height: 48px;
  277. margin-top: 20px;
  278. .van-button {
  279. height: 100%;
  280. border-radius: 5px;
  281. }
  282. }
  283. .van-field {
  284. background: #2C2C2D;
  285. margin-right: 12px;
  286. border-radius: 5px;
  287. height: 52px !important;
  288. font-weight: 500 !important;
  289. align-items: center;
  290. ::v-deep .van-field__control {
  291. color: #fff;
  292. }
  293. ::v-deep .van-field__control::-webkit-input-placeholder {
  294. color: #999999 !important;
  295. }
  296. }
  297. }
  298. .dialog {
  299. color: #CFD1D4;
  300. ::v-deep [class*=van-hairline]::after {
  301. border-color: rgba(72, 72, 72, 0.5);
  302. }
  303. &,
  304. ::v-deep .van-button__content {
  305. background: #2C2C2D;
  306. }
  307. }
  308. .opacity {
  309. opacity: .4;
  310. }
  311. .transfer-tip-content {
  312. ::v-deep ol {
  313. list-style-type: decimal;
  314. }
  315. ::v-deep ul {
  316. list-style-type: disc;
  317. }
  318. }
  319. </style>