a.html 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport"
  6. content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" />
  7. <link rel="stylesheet" href="./resource/vantIndex.css" />
  8. <link rel="stylesheet" href="./vue-form-making/index.css">
  9. </head>
  10. <body>
  11. <style>
  12. :root:root {
  13. --van-nav-bar-background: rgb(21, 122, 44);
  14. --van-nav-bar-title-text-color: rgb(255, 255, 255);
  15. --van-nav-bar-icon-color: rgb(255, 255, 255);
  16. }
  17. .blank_adopzrdd {
  18. display: flex;
  19. align-items: center;
  20. margin-bottom: 10px;
  21. }
  22. .blank_adopzrdd>span {
  23. display: inline-block;
  24. width: 80px;
  25. }
  26. :root#app {
  27. background: #4298fd0d;
  28. }
  29. ::v-deep.fm-form-item {
  30. margin-bottom: 10px !important;
  31. }
  32. </style>
  33. <div id="app">
  34. <van-nav-bar height='100rpx;margin-top:100rpx' @click-left="onClickLeft"
  35. style="background-color: rgb(21, 122, 44);color: rgb(255, 255, 255);" :title="title" left-arrow
  36. :safe-area-inset-top='true' :placeholder='true' :fixed='true'></van-nav-bar>
  37. <fm-generate-vant-form style='height: 81vh !important;overflow: auto;background: #a3a6ad1c;margin-top:44px'
  38. v-if='isFlag' :data="jsonData" :value="form.valueJson" ref="generateForm" :edit='isEdit' @on-upload-local="handleUploadLocal">
  39. <template v-slot:blank_adopzrdd="scope">
  40. <div style="width: 100%;">
  41. <van-button type="primary" size="small" @click="addNewRow('blank_adopzrdd')"
  42. style="margin-bottom: 10px">添加报销事项</van-button>
  43. <div v-for="(item, index) in scope.model.blank_adopzrdd" :key="index" style="width: 100%;">
  44. <div class="blank_adopzrdd">
  45. <span>{{ index + 1 }}报销事项:</span>
  46. <van-field rows="1" v-model="scope.model.blank_adopzrdd[index].remark" type="textarea"
  47. autosize style="width: calc(100% - 80px)"></van-field>
  48. </div>
  49. <div class="blank_adopzrdd">
  50. <span>
  51. <van-icon @click="delNewRow('blank_adopzrdd', index)" name="delete"
  52. style="color: #f56c6c;"></van-icon>
  53. 金额:</span>
  54. <van-field v-model="scope.model.blank_adopzrdd[index].price" type="number"
  55. style="width: calc(100% - 80px)"
  56. @change="changePrice(scope.model.blank_adopzrdd)"></van-field>
  57. </div>
  58. </div>
  59. </div>
  60. </template>
  61. <template v-slot:manage_workorder="scope">
  62. <van-field v-model="scope.model.manage_workorder.code" readonly @click="addWorkOrder()"></van-field>
  63. </template>
  64. </fm-generate-vant-form>
  65. <div>
  66. <div v-if='isEdit'
  67. style="display: flex;justify-content: space-between; padding: 30px 30px; position: fixed; bottom: 0; width: 100%; height: 80px;">
  68. <van-button style="width:48%" type="primary" :loading="loading" @click="handleAudit(1)">提交
  69. </van-button>
  70. <van-button style="width:48%" type="danger" :loading="loading" @click="onClickLeft">取消
  71. </van-button>
  72. </div>
  73. </div>
  74. </div>
  75. <script src="./resource/vue.global.prod.js"></script>
  76. <script src="./resource/vant.min.js"></script>
  77. <script src="./resource/axios.min.js"></script>
  78. <script src="./resource/uni.webview.js"></script>
  79. <script src="./vue-form-making/form-making-v3.umd.js"></script>
  80. <script>
  81. let EnvObj = {}
  82. uni.getEnv(function(res) {
  83. EnvObj = res;
  84. console.log('当前环境:' + JSON.stringify(res));
  85. });
  86. Vue.createApp({
  87. data() {
  88. return {
  89. loading: false,
  90. isFlag: false,
  91. isEdit: true,
  92. title: '',
  93. jsonData: {},
  94. editData: {},
  95. form: {},
  96. headers: {},
  97. APIUrl: '',
  98. type: 'add',
  99. }
  100. },
  101. created() {
  102. let _this = this
  103. window.x_sun = (e) => {
  104. _this.setSalesServiceWork(JSON.parse(e))
  105. }
  106. // 接收文件选择后的回调
  107. window.x_selectFiles = (e) => {
  108. let data = JSON.parse(e)
  109. console.log('收到选中的文件:', data)
  110. // 更新表单数据
  111. if (data.field && _this.$refs.generateForm) {
  112. // fileupload 字段需要格式化为数组对象
  113. // let fileData = (data.files || []).map(id => ({
  114. // objectName: id,
  115. // content: ''
  116. // }))
  117. _this.$refs.generateForm.setData({
  118. [data.field]: data.files
  119. })
  120. }
  121. }
  122. this.headers = this.getQueryParams('headers');
  123. let params = this.getQueryParams('params');
  124. this.isEdit = params.isEdit || true
  125. this.type = params.type || 'add'
  126. this.APIUrl = this.headers.serverInfo || 'http://192.168.1.105:18086'
  127. axios({
  128. method: 'get',
  129. url: this.APIUrl + `/flowable/bpmcustomform/getById/${params.id}`,
  130. headers: this.headers,
  131. }).then((res) => {
  132. if (res.data.code != '-1') {
  133. this.form = res.data.data
  134. this.form.formId = res.data.data.id
  135. this.form.id = ''
  136. this.form.valueJson = {}
  137. this.title = this.form.name
  138. this.jsonData = JSON.parse(res.data.data.formJson.makingJson);
  139. this.jsonData.list.forEach(item => {
  140. item.options.headers = [{
  141. key: 'Authorization',
  142. value: this.headers.Authorization
  143. }]
  144. item.options.action = item.options.action && item.options.action.replace(
  145. '/api', this.APIUrl)
  146. if (item.type == "deptAndUserCascader") {
  147. item.type = 'cascader'
  148. }
  149. if (item.type == "deptCascader") {
  150. item.type = 'cascader'
  151. /* item.isPathValue = false */
  152. if (item.options.isDefaultLoginUser) {
  153. /* this.form.valueJson[item.model] = [1,1765997946953797633]; */
  154. this.form.valueJson[item.model] = params.userInfo.groupIdList;
  155. }
  156. }
  157. if (item.type == "userSelect") {
  158. item.type = 'select'
  159. if (item.options.isDefaultLoginUser) {
  160. this.form.valueJson[item.model] = params.userInfo.userId;
  161. }
  162. }
  163. })
  164. this.jsonData.config.dataSource && this.jsonData.config.dataSource.forEach(item => {
  165. item.headers = {
  166. Authorization: this.headers.Authorization
  167. }
  168. item.url = item.url && item.url.replace('/api', this.APIUrl)
  169. })
  170. this.isFlag = true
  171. this.$nextTick(() => {
  172. if (params.manage_workorder) {
  173. this.setSalesServiceWork(params.manage_workorder)
  174. }
  175. })
  176. }
  177. });
  178. // axios({
  179. // method: 'get',
  180. // url: this.APIUrl + `/bpm/task/list-by-process-instance-id?processInstanceId=${params.id}`,
  181. // headers: this.headers,
  182. // }).then((res) => {
  183. // console.log(res)
  184. // if (res.data.code != '-1') {
  185. // }
  186. // });
  187. },
  188. methods: {
  189. async handleUploadLocal (model) {
  190. console.log('上传本地文件按钮被点击,字段模型:', model, this.type)
  191. let data = await this.$refs.generateForm.getData(false);
  192. // 在这里处理上传本地文件的逻辑
  193. uni.postMessage({
  194. data: {
  195. type: 'selectFiles',
  196. field: model,
  197. files: data[model],
  198. isEdit: 'add'
  199. }
  200. });
  201. },
  202. addWorkOrder() {
  203. uni.postMessage({
  204. data: {
  205. type: 'selectWork',
  206. }
  207. });
  208. },
  209. async addNewRow(key) {
  210. console.log(key);
  211. let data = await this.$refs.generateForm.getData(false);
  212. data[key].push({
  213. price: '',
  214. remark: ''
  215. });
  216. this.$refs.generateForm.setData({
  217. key: data[key]
  218. });
  219. },
  220. async delNewRow(key, index) {
  221. let data = await this.$refs.generateForm.getData(false);
  222. data[key] = data[key].filter((item, index1) => index1 != index);
  223. this.$refs.generateForm.setData({
  224. [key]: data[key]
  225. });
  226. this.changePrice(data[key]);
  227. },
  228. changePrice(data) {
  229. let num = 0;
  230. data.forEach((item) => {
  231. num += Number(item.price);
  232. });
  233. this.$refs.generateForm.setData({
  234. input_jd9ouzyh: num
  235. });
  236. },
  237. setSalesServiceWork(data) {
  238. this.$refs.generateForm.setData({
  239. manage_workorder: data
  240. });
  241. this.$refs.generateForm.setRules('manage_workorder', [{
  242. required: false,
  243. message: '必须填写'
  244. }])
  245. setTimeout(() => {
  246. this.$refs.generateForm.validate(['manage_workorder'])
  247. })
  248. },
  249. getQueryParams(queryName) {
  250. const urlSearchParams = new URLSearchParams(window.location.search);
  251. const query = urlSearchParams.get(queryName);
  252. console.log(query, 'query')
  253. return JSON.parse(query);
  254. },
  255. generateFormValid(validate = true) {
  256. return this.$refs.generateForm.getData(validate).then((data) => { //清空content
  257. for (key in data) {
  258. if (key.includes('fileupload')) {
  259. data[key].forEach(item => {
  260. item['content'] = ''
  261. })
  262. }
  263. }
  264. return data;
  265. });
  266. },
  267. async handleAudit(status) {
  268. this.loading = true;
  269. try {
  270. this.form.valueJson = await this.generateFormValid();
  271. } catch (error) {
  272. this.loading = false;
  273. return;
  274. }
  275. console.log(this.form.valueJson)
  276. this.form.processType = '1';
  277. let API = this.APIUrl + '/bpm/process-instance/create'
  278. axios({
  279. method: 'post',
  280. url: API,
  281. headers: this.headers,
  282. data: {
  283. ...this.form,
  284. }
  285. }).then((res) => {
  286. this.loading = false;
  287. if (res.data.code != '-1') {
  288. vant.showNotify({
  289. type: 'success',
  290. message: `提交成功!`,
  291. duration: 1000,
  292. });
  293. setTimeout(() => {
  294. this.onClickLeft()
  295. }, 1000)
  296. } else {
  297. vant.showNotify({
  298. type: 'danger',
  299. message: `提交失败!${res.data.message}`,
  300. duration: 1000,
  301. });
  302. }
  303. }).catch((err) => {
  304. vant.showNotify({
  305. type: 'danger',
  306. message: `提交失败!${err.message}`,
  307. duration: 1000,
  308. });
  309. this.loading = false;
  310. });
  311. },
  312. onClickLeft() {
  313. uni.navigateBack({
  314. delta: 1
  315. });
  316. }
  317. }
  318. }).use(vant).use(FormMakingV3).mount('#app')
  319. </script>
  320. </body>
  321. </html>