entrustForm.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. <template>
  2. <view class="container">
  3. <view class="entrust-form">
  4. <u-cell-group :border="false">
  5. <u-cell-item title="委托金额" title-width="180" :arrow="false" :value="price">
  6. <!-- <u-number-box digit :positive-integer="false" :min="0" v-model="entrustForm.payAomount" bg-color="#51A539" color="#ffffff"></u-number-box> -->
  7. </u-cell-item>
  8. <u-cell-item title="委托时长(小时)" title-width="190" :arrow="false">
  9. <!-- <u-number-box digit :min="1" v-model="entrustForm.entrustDurationTime" bg-color="#51A539" color="#ffffff"></u-number-box> -->
  10. <CnumberBox @getNum="getNum" minNum="1" :isInt="false"></CnumberBox>
  11. </u-cell-item>
  12. <u-cell-item title="委托开始时间" title-width="180" @click="dateShow = true">
  13. <text class="">{{entrustForm.entrustStartTime}}</text>
  14. </u-cell-item>
  15. <u-field type="textarea" placeholder="请输入备注" v-model="entrustForm.remarks" label-width="0"></u-field>
  16. </u-cell-group>
  17. </view>
  18. <view class="entrust-handle">
  19. <u-button type="success" shape="circle" :ripple="true" @click="toPay()" class="handle-custom">支付</u-button>
  20. </view>
  21. <u-picker mode="time" v-model="dateShow" :start-year="startYear" :params="params" @confirm="setDate"></u-picker>
  22. <u-top-tips ref="uTips"></u-top-tips>
  23. </view>
  24. </template>
  25. <script>
  26. const NET = require('@/utils/request')
  27. const API = require('@/config/api')
  28. import CnumberBox from '@/components/CnumberBox.vue'
  29. export default {
  30. components: {
  31. CnumberBox
  32. },
  33. data() {
  34. return {
  35. price: 0,
  36. userData: {},
  37. entrustForm: {
  38. productId: '',
  39. productName: '',
  40. tenantCode: '',
  41. areaSize: '',
  42. payAomount: 1,
  43. entrustDurationTime: 1,
  44. entrustStartTime: '',
  45. remarks: '',
  46. },
  47. dateShow: false,
  48. params: {
  49. year: true,
  50. month: true,
  51. day: true,
  52. hour: true,
  53. minute: true,
  54. second: true
  55. },
  56. startYear: '',
  57. orderId: ''
  58. }
  59. },
  60. onLoad(options) {
  61. this.userData = uni.getStorageSync("userData")
  62. this.startYear = new Date().getFullYear()
  63. this.entrustForm.productId = options.productId
  64. this.entrustForm.productName = options.productName
  65. this.entrustForm.tenantCode = options.tenantCode
  66. this.entrustForm.areaSize = options.areaSize
  67. this.getPrice()
  68. this.orderId = options.orderId
  69. },
  70. methods: {
  71. // 获取子组件的购买数量
  72. getNum(num) {
  73. this.entrustForm.entrustDurationTime = num
  74. },
  75. // 设置时间
  76. setDate(data) {
  77. this.entrustForm.entrustStartTime = data.year + '-' + data.month + '-' + data.day + ' ' + data.hour + ':' + data.minute +
  78. ':' + data.second
  79. },
  80. // 获取委托金额
  81. getPrice() {
  82. NET.request(API.getShareTaskPric, {}, 'GET').then(res => {
  83. if (res.isSuccess) {
  84. if (res.data) {
  85. this.price = res.data
  86. }
  87. } else {
  88. this.$refs.uTips.show({
  89. title: res.msg,
  90. type: 'warning',
  91. })
  92. }
  93. })
  94. },
  95. // 支付
  96. toPay() {
  97. if (!this.entrustForm.remarks) {
  98. this.$refs.uTips.show({
  99. title: '请填写备注信息',
  100. type: 'warning',
  101. })
  102. return
  103. }
  104. if (!this.entrustForm.entrustStartTime) {
  105. this.$refs.uTips.show({
  106. title: '请选择开始时间',
  107. type: 'warning',
  108. })
  109. return
  110. }
  111. NET.request(API.submitEvaluate, {
  112. // 会员
  113. mid: this.userData.userId,
  114. nickname: this.userData.userName,
  115. // 数据
  116. ...this.entrustForm,
  117. entrustDurationTime: JSON.stringify(this.entrustForm.entrustDurationTime),
  118. payAomount: this.price * Number(this.entrustForm.entrustDurationTime),
  119. orderId: Number(this.orderId),
  120. // #ifdef APP-PLUS
  121. channel: 2
  122. //#endif
  123. }, 'POST').then(res => {
  124. if (res.isSuccess) {
  125. if (res.data) {
  126. this.orderId = res.data.orderId
  127. // #ifdef MP-WEIXIN
  128. uni.requestPayment({
  129. provider: 'wxpay',
  130. timeStamp: res.data.timeStamp,
  131. nonceStr: res.data.nonceStr,
  132. package: res.data.packageValue,
  133. signType: res.data.signType,
  134. paySign: res.data.paySign,
  135. success: (payRes) => {
  136. this.$refs.uTips.show({
  137. title: '支付成功',
  138. type: 'success',
  139. })
  140. // setTimeout(() => {
  141. // uni.reLaunch({
  142. // url: '/pagesMain/paySuccess?orderId=' + this.orderId
  143. // });
  144. // }, 1000)
  145. uni.navigateBack(-1);
  146. },
  147. fail: (error) => {
  148. this.$refs.uTips.show({
  149. title: '支付失败',
  150. type: 'warning',
  151. })
  152. }
  153. })
  154. //#endif
  155. // #ifdef APP-PLUS
  156. uni.requestPayment({
  157. provider: 'wxpay',
  158. orderInfo:{
  159. "package": res.data.packageValue,
  160. "appid": res.data.appId,
  161. "sign": res.data.sign,
  162. "partnerid": res.data.partnerId,
  163. "prepayid": res.data.prepayId,
  164. "noncestr": res.data.nonceStr,
  165. "timestamp": res.data.timeStamp,
  166. },
  167. success: (payRes) => {
  168. this.$refs.uTips.show({
  169. title: '支付成功',
  170. type: 'success',
  171. })
  172. uni.navigateBack(-1);
  173. },
  174. fail: (error) => {
  175. this.$refs.uTips.show({
  176. title: '支付失败',
  177. type: 'warning',
  178. })
  179. }
  180. })
  181. //#endif
  182. }
  183. } else {
  184. this.$refs.uTips.show({
  185. title: res.msg,
  186. type: 'warning',
  187. })
  188. }
  189. }).catch(error => {
  190. this.$refs.uTips.show({
  191. title: '支付未成功',
  192. type: 'warning',
  193. })
  194. })
  195. },
  196. },
  197. }
  198. </script>
  199. <style>
  200. page {
  201. width: 100%;
  202. height: 100%;
  203. background-color: #f7f7f7;
  204. }
  205. </style>
  206. <style lang="less" scoped>
  207. .container {
  208. width: 100%;
  209. height: 100%;
  210. float: left;
  211. box-sizing: border-box;
  212. background-color: #f7f7f7;
  213. padding-bottom: 70px;
  214. overflow-y: auto;
  215. .entrust-form {
  216. width: 100%;
  217. float: left;
  218. box-sizing: border-box;
  219. padding: 0 15px;
  220. background-color: #ffffff;
  221. /deep/.u-field {
  222. padding-left: 0px;
  223. padding-right: 0px;
  224. }
  225. /deep/.u-cell {
  226. padding-left: 0px;
  227. padding-right: 0px;
  228. }
  229. /deep/.u-cell_title {
  230. color: #999999;
  231. }
  232. /deep/.u-label-text {
  233. color: #999999;
  234. }
  235. }
  236. .entrust-handle {
  237. width: calc(100% - 30px);
  238. height: 40px;
  239. position: fixed;
  240. bottom: 20px;
  241. left: 15px;
  242. .handle-custom {
  243. background-color: #56a83a;
  244. /deep/button {
  245. background-color: #56a83a;
  246. }
  247. /deep/.u-btn--success--disabled {
  248. background-color: #74bd60 !important;
  249. }
  250. }
  251. }
  252. }
  253. </style>