templateManage.vue 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. <!--
  2. * @Description: create
  3. * @Version: 1.0
  4. * @Autor: XuTongZhang
  5. * @Date: 2020-07-28 16:28:13
  6. * @LastEditors: XuTongZhang
  7. * @LastEditTime: 2020-08-17 17:38:04
  8. -->
  9. <template>
  10. <div class="indexPage">
  11. <v-input :btn="btn" :list="list" @add="add"></v-input>
  12. <v-table
  13. :table="table"
  14. :tableList="tableList"
  15. :sortType="true"
  16. :queryData="queryData"
  17. @details="details"
  18. @editor="editor"
  19. @del="del"
  20. @qrCode="qrCode"
  21. ></v-table>
  22. <v-pager @page="callPage" :total="totalrecords"></v-pager>
  23. <el-dialog :visible.sync="dialogFormVisible" :before-close="close" width="650px" :close-on-click-modal="false">
  24. <el-form :model="form" ref="form" label-width="140px" :rules="rule" label-position="left">
  25. <el-form-item label="模板名称" prop="templateName">
  26. <el-input v-if="state !== 2" v-model="form.templateName" placeholder="请输入模板名称" autocomplete="off"></el-input>
  27. <div v-else>{{form.templateName}}</div>
  28. </el-form-item>
  29. <el-form-item label="模板内容" prop="templateIntroduce">
  30. <el-input
  31. v-if="state !== 2"
  32. type="textarea"
  33. :rows="4"
  34. resize="none"
  35. placeholder="请输入模板内容"
  36. v-model="form.templateIntroduce"
  37. ></el-input>
  38. <div v-else>{{form.templateIntroduce}}</div>
  39. </el-form-item>
  40. <el-form-item label="关联场景" prop="sceneId">
  41. <el-select v-if="state !== 2" clearable v-model="form.sceneId" placeholder="请选择关联场景">
  42. <el-option
  43. v-for="item in downList0"
  44. :key="item.id"
  45. :label="item.sceneName"
  46. :value="item.id"
  47. ></el-option>
  48. </el-select>
  49. <div v-else>{{this.downList0.some(i => i.id === form.sceneId) ? this.downList0.find(i => i.id === form.sceneId).sceneName : ''}}</div>
  50. </el-form-item>
  51. <el-form-item label="关联流程" prop="processId">
  52. <el-select v-if="state !== 2" v-model="form.processId" placeholder="请选择关联流程">
  53. <el-option
  54. v-for="item in downList1"
  55. :key="item.id"
  56. :label="item.processName"
  57. :value="item.id"
  58. ></el-option>
  59. </el-select>
  60. <div v-else>{{this.downList1.some(i => i.id === form.processId) ? this.downList1.find(i => i.id === form.processId).processName : ''}}</div>
  61. </el-form-item>
  62. <el-form-item label="关联表单" prop="formId">
  63. <el-select v-if="state !== 2" v-model="form.formId" placeholder="请选择关联表单">
  64. <el-option
  65. v-for="item in downList2"
  66. :key="item.id"
  67. :label="item.formName"
  68. :value="item.id"
  69. ></el-option>
  70. </el-select>
  71. <div v-else>{{this.downList2.some(i => i.id === form.formId) ? this.downList2.find(i => i.id === form.formId).formName : ''}}</div>
  72. </el-form-item>
  73. </el-form>
  74. <div slot="footer" class="dialog-footer">
  75. <el-button @click="close">取 消</el-button>
  76. <el-button type="primary" v-if="state!==2" @click="determine">确 定</el-button>
  77. </div>
  78. </el-dialog>
  79. <el-dialog :visible.sync="dialogVisible" width="650px" :before-close="closeDia" :close-on-click-modal="false">
  80. <el-form :model="codeForm" ref="codeForm" label-width="200px" :rules="rules" label-position="left">
  81. <el-form-item label="二维码名称" prop="qrcodeName">
  82. <el-input v-model="codeForm.qrcodeName" placeholder="请输入二维码名称" autocomplete="off"></el-input>
  83. </el-form-item>
  84. <el-form-item label="二维码有效期" prop="time">
  85. <el-date-picker
  86. v-model="codeForm.time"
  87. type="daterange"
  88. align="right"
  89. unlink-panels
  90. range-separator="至"
  91. start-placeholder="开始日期"
  92. end-placeholder="结束日期"
  93. :picker-options="pickerOptions">
  94. </el-date-picker>
  95. </el-form-item>
  96. <el-form-item label="二维码状态" prop="status">
  97. <el-radio-group v-model="codeForm.status">
  98. <el-radio :label="0">启用中</el-radio>
  99. <el-radio :label="1">禁用中</el-radio>
  100. </el-radio-group>
  101. </el-form-item>
  102. <div class="flex">
  103. <el-button @click="createQrCoed">{{codeForm.qrcodePath ? '修改二维码' : '生成二维码'}}</el-button>
  104. </div>
  105. <el-image
  106. class="img"
  107. :src="codeForm.qrcodePath ? $img + codeForm.qrcodePath : ''"
  108. :preview-src-list="[$img + codeForm.qrcodePath]">
  109. </el-image>
  110. <div class="flex">
  111. <el-button @click="downLoad">下载</el-button>
  112. </div>
  113. </el-form>
  114. </el-dialog>
  115. </div>
  116. </template>
  117. <script>
  118. export default {
  119. data () {
  120. return {
  121. tableList: [],
  122. page: 1,
  123. totalrecords: 0,
  124. dialogVisible: false,
  125. dialogFormVisible: false,
  126. state: 0,
  127. form: {},
  128. url: '',
  129. codeForm: {},
  130. pickList: [],
  131. downList0: [],
  132. downList1: [],
  133. downList2: [],
  134. rule: {
  135. templateName: [{ required: true, message: '请输入模板名称', trigger: 'blur' }],
  136. templateIntroduce: [{ required: true, message: '请输入模板内容', trigger: 'blur' }]
  137. },
  138. rules: {
  139. qrcodeName: [{ required: true, message: '请输入二维码名称', trigger: 'blur' }],
  140. time: [{ required: true, message: '请输入时间区间', trigger: 'blur' }],
  141. status: [{ required: true, message: '请选择二维码状态', trigger: 'blur' }]
  142. },
  143. list: [],
  144. btn: [
  145. {
  146. name: '添加',
  147. type: 'success',
  148. method: 'add'
  149. }
  150. ],
  151. table: {
  152. column: [
  153. {
  154. label: '编号',
  155. props: 'id'
  156. },
  157. {
  158. label: '模板名称',
  159. props: 'templateName'
  160. },
  161. {
  162. label: '关联场景',
  163. props: 'sceneName'
  164. },
  165. {
  166. label: '关联流程',
  167. props: 'processName'
  168. },
  169. {
  170. label: '关联表单',
  171. props: 'formName'
  172. }
  173. ],
  174. width: 400,
  175. handle: [
  176. {
  177. title: '查看',
  178. method: 'details',
  179. type: 'info'
  180. },
  181. {
  182. title: '修改',
  183. method: 'editor',
  184. type: 'warning'
  185. },
  186. {
  187. title: '删除',
  188. method: 'del',
  189. type: 'danger'
  190. },
  191. {
  192. title: '二维码',
  193. method: 'qrCode',
  194. type: 'info',
  195. props: 'type',
  196. key: false
  197. }
  198. ]
  199. },
  200. pickerOptions: {
  201. shortcuts: [{
  202. text: '最近一周',
  203. onClick (picker) {
  204. const end = new Date()
  205. const start = new Date()
  206. end.setTime(end.getTime() + 3600 * 1000 * 24 * 7)
  207. picker.$emit('pick', [start, end])
  208. }
  209. }, {
  210. text: '最近一个月',
  211. onClick (picker) {
  212. const end = new Date()
  213. const start = new Date()
  214. end.setTime(end.getTime() + 3600 * 1000 * 24 * 30)
  215. picker.$emit('pick', [start, end])
  216. }
  217. }, {
  218. text: '最近三个月',
  219. onClick (picker) {
  220. const end = new Date()
  221. const start = new Date()
  222. end.setTime(end.getTime() + 3600 * 1000 * 24 * 90)
  223. picker.$emit('pick', [start, end])
  224. }
  225. }]
  226. }
  227. }
  228. },
  229. created () {
  230. this.queryDownList()
  231. },
  232. methods: {
  233. queryData (form = {}) {
  234. let page = this.page
  235. let reqdata = form
  236. this.$api
  237. .post('/template/queryTemplateList', {
  238. reqdata,
  239. page
  240. })
  241. .then((res) => {
  242. this.totalrecords = res.totalrecords
  243. this.tableList = res.list.map(item => {
  244. item.sceneName = this.downList0.some(i => i.id === item.sceneId) ? this.downList0.find(i => i.id === item.sceneId).sceneName : ''
  245. item.processName = this.downList1.some(i => i.id === item.processId) ? this.downList1.find(i => i.id === item.processId).processName : ''
  246. item.formName = this.downList2.some(i => i.id === item.formId) ? this.downList2.find(i => i.id === item.formId).formName : ''
  247. item.type = !(item.processId && item.sceneId)
  248. return item
  249. })
  250. })
  251. },
  252. queryDownList () {
  253. let reqdata = {}
  254. let num = 0
  255. let urlArray = ['/scene/querySceneList', '/process/queryProcessList', '/form/queryFormList']
  256. urlArray.forEach((item, index) => {
  257. this.$api
  258. .post(item, {
  259. reqdata
  260. })
  261. .then((res) => {
  262. num++
  263. this['downList' + index] = res.list
  264. console.log(this['downList' + index])
  265. num === 3 && this.queryData()
  266. })
  267. })
  268. },
  269. add () {
  270. this.open()
  271. this.form = {}
  272. this.state = 0
  273. },
  274. getDetails (row) {
  275. let reqdata = { id: row.id }
  276. this.$api
  277. .post('/template/queryTemplateDetail', {
  278. reqdata
  279. })
  280. .then((res) => {
  281. this.open()
  282. this.form = res.object
  283. this.form.sceneId = this.form.sceneId || null
  284. this.form.processId = this.form.processId || null
  285. this.form.formId = this.form.formId || null
  286. })
  287. },
  288. details (row) {
  289. this.getDetails(row)
  290. this.state = 2
  291. },
  292. editor (row) {
  293. this.getDetails(row)
  294. this.state = 1
  295. },
  296. del (row) {
  297. let reqdata = { id: row.id }
  298. this.$api
  299. .post('/template/deleteTemplate', {
  300. reqdata
  301. })
  302. .then((res) => {
  303. this.queryData()
  304. })
  305. },
  306. determine () {
  307. let a
  308. this.$refs['form'].validate((valid) => {
  309. a = valid
  310. })
  311. if (!a) return
  312. let url = this.state
  313. ? '/template/updateTemplate'
  314. : '/template/saveTemplate'
  315. let reqdata = this.form
  316. this.$api
  317. .post(url, {
  318. reqdata
  319. })
  320. .then((res) => {
  321. this.close()
  322. this.queryData()
  323. })
  324. },
  325. qrCode (row) {
  326. console.log(row)
  327. this.codeForm.templateId = row.id
  328. this.openDia()
  329. this.$api
  330. .post('/qrCode/checkQrCode', {
  331. reqdata: {
  332. templateId: row.id
  333. }
  334. })
  335. .then((res) => {
  336. this.$api
  337. .post('/qrCode/queryQrCodeDetail', {
  338. reqdata: {
  339. templateId: row.id
  340. }
  341. })
  342. .then((res) => {
  343. this.codeForm = res.object
  344. this.$set(this.codeForm, 'time', [res.object.startTime, res.object.endTime])
  345. })
  346. })
  347. },
  348. createQrCoed () {
  349. let a
  350. this.$refs['codeForm'].validate((valid) => {
  351. a = valid
  352. })
  353. if (!a) return
  354. let { templateId, time, qrcodeName, id } = this.codeForm
  355. let url = this.codeForm.qrcodePath ? '/qrCode/updateQrCodeInfo' : '/qrCode/createQrCodeByTemplate'
  356. this.$api
  357. .post(url, {
  358. reqdata: {
  359. qrcodeName,
  360. templateId,
  361. id: id,
  362. startTime: new Date(time[0]).valueOf(),
  363. endTime: new Date(time[1]).valueOf()
  364. }
  365. })
  366. .then((res) => {
  367. this.$api
  368. .post('/qrCode/queryQrCodeDetail', {
  369. reqdata: {
  370. templateId
  371. }
  372. })
  373. .then((res) => {
  374. this.codeForm = res.object
  375. this.$set(this.codeForm, 'time', [res.object.startTime, res.object.endTime])
  376. })
  377. })
  378. },
  379. downLoad () {
  380. this.codeForm.qrcodePath ? window.open(this.$img + this.codeForm.qrcodePath) : this.$message({
  381. message: '暂无二维码',
  382. type: 'error'
  383. })
  384. },
  385. open () {
  386. this.dialogFormVisible = true
  387. },
  388. close () {
  389. this.dialogFormVisible = false
  390. this.form = {}
  391. },
  392. openDia () {
  393. this.dialogVisible = true
  394. },
  395. closeDia () {
  396. this.dialogVisible = false
  397. this.codeForm = {}
  398. },
  399. callPage (val) {
  400. this.page = val
  401. this.queryData()
  402. }
  403. },
  404. watch: {
  405. dialogFormVisible: function (val, oldVla) {
  406. if (this.state === 2) {
  407. if (this.$refs['form'] !== undefined) {
  408. this.$refs['form'].resetFields()
  409. }
  410. }
  411. }
  412. }
  413. }
  414. </script>
  415. <style lang="scss" scoped>
  416. .dialog-footer {
  417. display: flex;
  418. justify-content: center;
  419. align-items: center;
  420. }
  421. .flex {
  422. display: flex;
  423. justify-content: center;
  424. }
  425. .img {
  426. width: 350px;
  427. height: 350px;
  428. margin-top: 30px;
  429. margin-left:150px;
  430. margin-bottom: 10px;
  431. }
  432. </style>