entrustForm.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  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 style="right: 0;position: absolute;top: 25%;" @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. if (!this.entrustForm.entrustDurationTime) {
  112. this.$refs.uTips.show({
  113. title: '请输入委托时长',
  114. type: 'warning',
  115. })
  116. return
  117. }
  118. console.log('委托时长',this.entrustForm.entrustDurationTime)
  119. NET.request(API.submitEvaluate, {
  120. // 会员
  121. mid: this.userData.userId,
  122. nickname: this.userData.userName,
  123. // 数据
  124. ...this.entrustForm,
  125. entrustDurationTime: JSON.stringify(this.entrustForm.entrustDurationTime),
  126. payAomount: this.price * Number(this.entrustForm.entrustDurationTime),
  127. orderId: Number(this.orderId),
  128. // #ifdef APP-PLUS
  129. channel: 2
  130. //#endif
  131. }, 'POST').then(res => {
  132. if (res.isSuccess) {
  133. if (res.data) {
  134. this.orderId = res.data.orderId
  135. // #ifdef MP-WEIXIN
  136. uni.requestPayment({
  137. provider: 'wxpay',
  138. timeStamp: res.data.timeStamp,
  139. nonceStr: res.data.nonceStr,
  140. package: res.data.packageValue,
  141. signType: res.data.signType,
  142. paySign: res.data.paySign,
  143. success: (payRes) => {
  144. this.$refs.uTips.show({
  145. title: '支付成功',
  146. type: 'success',
  147. })
  148. // setTimeout(() => {
  149. // uni.reLaunch({
  150. // url: '/pagesMain/paySuccess?orderId=' + this.orderId
  151. // });
  152. // }, 1000)
  153. uni.navigateBack(-1);
  154. },
  155. fail: (error) => {
  156. this.$refs.uTips.show({
  157. title: '支付失败',
  158. type: 'warning',
  159. })
  160. }
  161. })
  162. //#endif
  163. // #ifdef APP-PLUS
  164. uni.requestPayment({
  165. provider: 'wxpay',
  166. orderInfo:{
  167. "package": res.data.packageValue,
  168. "appid": res.data.appId,
  169. "sign": res.data.sign,
  170. "partnerid": res.data.partnerId,
  171. "prepayid": res.data.prepayId,
  172. "noncestr": res.data.nonceStr,
  173. "timestamp": res.data.timeStamp,
  174. },
  175. success: (payRes) => {
  176. this.$refs.uTips.show({
  177. title: '支付成功',
  178. type: 'success',
  179. })
  180. uni.navigateBack(-1);
  181. },
  182. fail: (error) => {
  183. this.$refs.uTips.show({
  184. title: '支付失败',
  185. type: 'warning',
  186. })
  187. }
  188. })
  189. //#endif
  190. }
  191. } else {
  192. this.$refs.uTips.show({
  193. title: res.msg,
  194. type: 'warning',
  195. })
  196. }
  197. }).catch(error => {
  198. this.$refs.uTips.show({
  199. title: '支付未成功',
  200. type: 'warning',
  201. })
  202. })
  203. },
  204. },
  205. }
  206. </script>
  207. <style>
  208. page {
  209. width: 100%;
  210. height: 100%;
  211. background-color: #f7f7f7;
  212. }
  213. </style>
  214. <style lang="less" scoped>
  215. .container {
  216. width: 100%;
  217. height: 100%;
  218. float: left;
  219. box-sizing: border-box;
  220. background-color: #f7f7f7;
  221. padding-bottom: 70px;
  222. overflow-y: auto;
  223. .entrust-form {
  224. width: 100%;
  225. float: left;
  226. box-sizing: border-box;
  227. padding: 0 15px;
  228. background-color: #ffffff;
  229. /deep/.u-field {
  230. padding-left: 0px;
  231. padding-right: 0px;
  232. }
  233. /deep/.u-cell {
  234. padding-left: 0px;
  235. padding-right: 0px;
  236. }
  237. /deep/.u-cell_title {
  238. color: #999999;
  239. }
  240. /deep/.u-label-text {
  241. color: #999999;
  242. }
  243. }
  244. .entrust-handle {
  245. width: calc(100% - 30px);
  246. height: 40px;
  247. position: fixed;
  248. bottom: 20px;
  249. left: 15px;
  250. .handle-custom {
  251. background-color: #56a83a;
  252. /deep/button {
  253. background-color: #56a83a;
  254. }
  255. /deep/.u-btn--success--disabled {
  256. background-color: #74bd60 !important;
  257. }
  258. }
  259. }
  260. }
  261. </style>