tansferDuration.vue 11 KB

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