edit.vue 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. <template>
  2. <view class="page">
  3. <view class="form">
  4. <u-form :model="form" ref="uForm">
  5. <u-form-item label-width="150" label="标题" prop="contract_name">
  6. <u-input placeholder="请输入您的合同标题" v-model="form.contract_name" type="text"></u-input>
  7. </u-form-item>
  8. <u-form-item label-width="150" label="金额" prop="contract_amount">
  9. <u-input placeholder="请输入合同金额" v-model="form.contract_amount" type="text"></u-input>
  10. <template v-slot:right>
  11. 万元
  12. </template>
  13. </u-form-item>
  14. <u-form-item label-width="150" label="到期日期" prop="info1" @click.native="openinfo1Popoup">
  15. <view class="scoped-input-floor" @click.native="openinfo1Popoup"></view>
  16. <u-input placeholder="请选择到期日期" v-model="form.end_at" disabled type="text"></u-input>
  17. </u-form-item>
  18. <u-form-item label-position="top" label-width="150" label="电子合同PDF" prop="contract_pdf">
  19. <view class="scoped-more-img">
  20. <view class="si-op" v-if="form.contract_pdf" @click="linkWebView">
  21. <u-image src="/static/icon_bg_pdf.png" mode="heightFix" height="150rpx" class="img"></u-image>
  22. <u-image src="/static/icon_g_close.png" class="i" height="40rpx" @click="delPdf()"></u-image>
  23. </view>
  24. <view class="si-op" @click="uploadPDF" v-else>
  25. <u-image src="/static/icon_upload_pdf.png" mode="heightFix" height="150rpx" class="img"></u-image>
  26. </view>
  27. </view>
  28. </u-form-item>
  29. <!-- <view class="sp-op">
  30. <u-image src="/static/icon_upload_pdf.png" mode="heightFix" height="150rpx" class="img"></u-image>
  31. </view> -->
  32. </u-form>
  33. <u-gap height="60"></u-gap>
  34. <u-button type="primary" @click="submitHandle">提交</u-button>
  35. </view>
  36. <!-- mask -->
  37. <u-mask :show="maskShow" @click="maskShow = false">
  38. <view class="warp">
  39. <!-- <u-image src="https://zdcdn.2bwin.cn/uploads/20220513/90abe6fe85d6c17f6bdc069955fbb878.png" mode="widthFix" width="400rpx" border-radius="20rpx"></u-image> -->
  40. <u-gap></u-gap>
  41. <u-button size="medium" type="primary" @click="maskShow = false">确定</u-button>
  42. </view>
  43. </u-mask>
  44. <!-- utoast -->
  45. <u-toast ref="uToast" />
  46. <u-select mode="single-column" :list="groupTypeSelectList" v-model="groupTypeSelectShow" @confirm="groupTypeSelectConfirm"></u-select>
  47. <u-calendar v-model="info1Show" mode="date" :max-date="'2099-5-20'" @change="info1Change"></u-calendar>
  48. </view>
  49. </template>
  50. <script>
  51. var that;
  52. export default {
  53. data() {
  54. return {
  55. groupTypeSelectShow: false,
  56. groupTypeSelectList: [],
  57. maskShow: false,
  58. form: {
  59. contract_name: null,
  60. start_at: '',
  61. end_at: '',
  62. contract_amount: '',
  63. contract_pdf: '',
  64. },
  65. cObj: {},
  66. submitButtonDisabled: false,
  67. rules: {
  68. contract_name: [
  69. {
  70. required: true,
  71. message: '合同名称不得为空',
  72. trigger: ['change', 'blur']
  73. },
  74. ],
  75. contract_amount: [
  76. {
  77. required: true,
  78. message: '合同金额不得为空',
  79. trigger: ['change', 'blur']
  80. },
  81. ],
  82. contract_pdf: [
  83. {
  84. required: true,
  85. message: 'pdf合同不得为空',
  86. trigger: ['change', 'blur']
  87. }
  88. ],
  89. },
  90. info1Show: false,
  91. submitModalShow: false,
  92. curId: '',
  93. contractCurPdf: '',
  94. };
  95. },
  96. onLoad(params) {
  97. if (params.id) {
  98. this.curId = params.id
  99. uni.setNavigationBarTitle({
  100. title: '编辑电子合同'
  101. })
  102. this.getData()
  103. } else {
  104. uni.setNavigationBarTitle({
  105. title: '添加电子合同'
  106. })
  107. }
  108. },
  109. // 必须要在onReady生命周期,因为onLoad生命周期组件可能尚未创建完毕
  110. onReady() {
  111. this.$refs.uForm.setRules(this.rules);
  112. },
  113. methods: {
  114. openinfo1Popoup () {
  115. this.info1Show = true
  116. },
  117. info1Change (e) {
  118. this.form.end_at = e.result || ''
  119. },
  120. linkWebView () {
  121. let params = {
  122. id: this.curId,
  123. url: this.contractCurPdf,
  124. tname: this.form.contract_name
  125. }
  126. uni.setStorageSync('MD_contractObj', params)
  127. uni.navigateTo({
  128. url: `/pages/user/contract/dtl?id=${this.curId}`
  129. })
  130. },
  131. getData () {
  132. uni.api.base.apicontractdetail({
  133. id: this.curId
  134. }).then(res => {
  135. // console.log(res)
  136. const cObj = res || {}
  137. if (cObj.id) {
  138. this.contractCurPdf = cObj.contract_pdf_pub
  139. let f = {
  140. contract_name: cObj.contract_name,
  141. start_at: cObj.start_at,
  142. end_at: cObj.end_at,
  143. contract_amount: cObj.contract_amount,
  144. contract_pdf: cObj.contract_pdf,
  145. }
  146. this.form = {...f}
  147. this.cObj = {...cObj}
  148. }
  149. })
  150. },
  151. delPdf () {
  152. this.form.contract_pdf = ''
  153. },
  154. // 上传 PDF 文件
  155. uploadPDF() {
  156. const that = this
  157. uni.showLoading({
  158. mask: true,
  159. title: '加载中..'
  160. })
  161. // 选择文件
  162. wx.chooseMessageFile({
  163. count: 1, // 一次只能选择一个文件
  164. type: 'file', // 文件类型
  165. success: (res) => {
  166. const filePath = res.tempFiles[0].path; // 获取文件路径
  167. const fileName = res.tempFiles[0].name; // 获取文件名
  168. // pathToBase64(filePath).then(hh => {
  169. // console.log(hh)
  170. // })
  171. console.log(filePath)
  172. // 上传文件
  173. let token = uni.getStorageSync('MD_token') || ''
  174. uni.uploadFile({
  175. url: uni.baseUrl + 'api/upload/cloudpiv',
  176. filePath,
  177. name: 'upload',
  178. formData: {
  179. 'token': token
  180. },
  181. success: (f) => {
  182. const cData = JSON.parse(f.data)
  183. if (cData.errno === 0) {
  184. // console.log(cData.data)
  185. that.form.contract_pdf = cData.data ? cData.data.url : ''
  186. // console.log(that.form)
  187. // that.form.contract_pdf = cData.data ? cData.data.url : ''
  188. that.contractCurPdf = cData.data.pub_url
  189. uni.hideLoading()
  190. } else {
  191. uni.$msg(cData.errmsg || `未知错误-${cData.errno}`)
  192. uni.hideLoading()
  193. }
  194. },
  195. fail: (err) => {
  196. console.error('上传失败', err);
  197. // 处理上传失败后的逻辑
  198. uni.showToast({
  199. title: '上传失败',
  200. icon: 'none',
  201. });
  202. uni.hideLoading()
  203. },
  204. });
  205. },
  206. fail: (err) => {
  207. console.error('选择文件失败', err);
  208. uni.showToast({
  209. title: '选择文件失败'+ err.errMsg,
  210. icon: 'none',
  211. });
  212. uni.hideLoading()
  213. },
  214. });
  215. },
  216. submitHandle() {
  217. const that = this
  218. // if (this.form.group_type == 3) {
  219. // uni.$msg('请选择认证的角色')
  220. // return
  221. // }
  222. this.$refs.uForm.validate(valid => {
  223. if (valid) {
  224. let params = {
  225. ...that.form
  226. }
  227. let apiStr = 'apicontractadd'
  228. if (this.curId) {
  229. params.id = this.curId
  230. apiStr = 'apicontractedit'
  231. }
  232. uni.api.base[apiStr](params).then(res => {
  233. uni.$msgConfirm('操作成功', () => {
  234. uni.reLaunch({
  235. url: '/pages/user/contract/list'
  236. })
  237. }, () => {
  238. uni.reLaunch({
  239. url: '/pages/user/contract/list'
  240. })
  241. })
  242. })
  243. }
  244. });
  245. },
  246. pageTo(path) {
  247. if (path === 'dev') {
  248. uni.$msg('开发中~')
  249. return
  250. }
  251. uni.navigateTo({
  252. url: path
  253. })
  254. },
  255. // 以下是工具函数
  256. // 格式化日期的月份或天数的显示(小于10,在前面增加0)
  257. getFormatDate(value) {
  258. if (value == undefined || value == '') {
  259. return '';
  260. }
  261. var str = value;
  262. if (parseInt(value) < 10) {
  263. str = '0' + value;
  264. }
  265. return str;
  266. }
  267. }
  268. };
  269. </script>
  270. <style lang="scss">
  271. .page {
  272. background-color: #ffffff;
  273. }
  274. .form {
  275. border-radius: 10rpx;
  276. padding: 0 40rpx;
  277. }
  278. .popup-body {
  279. .tips-title {
  280. font-size: $u-p;
  281. margin-bottom: 20rpx;
  282. }
  283. .tips-content {
  284. font-size: $u-p2;
  285. color: $u-tips-color;
  286. margin-bottom: 60rpx;
  287. }
  288. }
  289. .id_card {
  290. color: #606266;
  291. width: 100%;
  292. height: 350rpx;
  293. display: flex;
  294. flex-direction: column;
  295. align-items: center;
  296. justify-content: center;
  297. background-color: #f4f5f6;
  298. font-size: $u-p2;
  299. border-radius: 10rpx;
  300. image {
  301. border-radius: 10rpx;
  302. }
  303. }
  304. .footer {
  305. position: relative;
  306. text-align: center;
  307. font-size: $u-p2;
  308. left: 0;
  309. bottom: 20rpx;
  310. .agreement {
  311. color: $u-theme-color;
  312. }
  313. }
  314. .slot-content {
  315. font-size: 28rpx;
  316. color: $u-content-color;
  317. padding: 20rpx;
  318. }
  319. .warp {
  320. display: flex;
  321. flex-direction: column;
  322. align-items: center;
  323. justify-content: center;
  324. height: 100%;
  325. }
  326. .scoped-more-img {
  327. padding-top: 30rpx;
  328. .si-op {
  329. display: inline-block;
  330. vertical-align: middle;
  331. width: 150rpx;
  332. height: 150rpx;
  333. margin-right: 30rpx;
  334. margin-bottom: 30rpx;
  335. position: relative;
  336. border: 1PX solid #f2f2f2;
  337. .img {
  338. width: 150rpx;
  339. height: 150rpx;
  340. }
  341. .i {
  342. position: absolute;
  343. top: -20rpx;
  344. right: -20rpx;
  345. width: 40rpx;
  346. height: 40rpx;
  347. z-index: 9;
  348. }
  349. }
  350. }
  351. .scoped-input-floor {
  352. position: absolute;
  353. left: 0;
  354. top: 0;
  355. width: 100%;
  356. height: 100%;
  357. background: transparent;
  358. z-index: 9;
  359. }
  360. </style>