procedureManage.vue 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. <!--
  2. * @Description: create
  3. * @Version: 1.0
  4. * @Autor: XuTongZhang
  5. * @Date: 2020-07-28 16:00:46
  6. * @LastEditors: XuTongZhang
  7. * @LastEditTime: 2020-08-11 13:00:39
  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. ></v-table>
  21. <!-- :prop="'questionList.' + index + '.questionName'" -->
  22. <v-pager @page="callPage" :total="totalrecords"></v-pager>
  23. <el-dialog :visible.sync="dialogFormVisible" width="660px" :before-close="close" :close-on-click-modal="false">
  24. <el-form :model="form" ref="form" label-width="140px" label-position="left">
  25. <el-form-item label="流程名称" prop="processName" :rules="{
  26. required: true, message: '问题不能为空', trigger: 'blur'
  27. }">
  28. <el-input v-model.trim="form.processName" placeholder="请输入流程名称" v-if="state!=2" autocomplete="off"></el-input>
  29. <div v-else>{{form.processName}}</div>
  30. </el-form-item>
  31. <el-form-item
  32. v-for="(item, index) in form.questionList"
  33. :label="'面试问题' + (index + 1)"
  34. :key="item.key"
  35. :prop="'questionList.' + index"
  36. :rules="{
  37. required: true, validator: validatePass, trigger: 'change'
  38. }"
  39. >
  40. <div v-if="state!=2">
  41. <div class="flex">
  42. <el-input v-model.trim="item.questionName" placeholder="请输入面试问题"></el-input>
  43. <el-button type="danger" @click.prevent="index === 0 || removeDomain(item)">删除</el-button>
  44. </div>
  45. <el-select
  46. v-model="item.videoIdList"
  47. multiple
  48. filterable
  49. :disabled="state === 2"
  50. default-first-option
  51. placeholder="请选择面试视频">
  52. <el-option
  53. v-for="item in downList"
  54. :key="item.key || item.id"
  55. :label="item.videoName"
  56. :value="item.id">
  57. </el-option>
  58. </el-select>
  59. </div>
  60. <div v-else>
  61. <div>
  62. {{item.questionName}}
  63. </div>
  64. <video width="100%" v-if="item.videoIdList && item.videoIdList.length" :src="downList.some(i => i.id === item.videoIdList[item.active]) ? $img + downList.find(i => i.id === item.videoIdList[item.active]).videoPath : ''" controls></video>
  65. <div class="flex">
  66. <div v-for="(i, j) in item.videoIdList" :key="i" class="active" @click="updateActive(item, index, j)" :class="item.active === j ? 'is-active' : ''">{{downList.some(k => k.id === i) ? downList.find(k => k.id === i).videoName : '无数据'}}</div>
  67. </div>
  68. </div>
  69. </el-form-item>
  70. </el-form>
  71. <div slot="footer" class="dialog-footer">
  72. <el-button @click="close">取 消</el-button>
  73. <el-button v-if="state!==2" @click="addDomain" type="success">新增</el-button>
  74. <el-button type="primary" v-if="state!==2" @click="branch">确 定</el-button>
  75. </div>
  76. </el-dialog>
  77. </div>
  78. </template>
  79. <script>
  80. export default {
  81. data () {
  82. let validatePass = function (rule, value, callback) {
  83. if (!value.questionName || !value.questionName.length) {
  84. callback(new Error('请输入面试问题'))
  85. } else {
  86. if (!value.videoIdList || !value.videoIdList.length) {
  87. callback(new Error('请选择面试视频'))
  88. }
  89. callback()
  90. }
  91. }
  92. return {
  93. tableList: [],
  94. dialogFormVisible: false,
  95. page: 1,
  96. totalrecords: 0,
  97. form: {
  98. questionList: [
  99. { key: 1 }
  100. ]
  101. },
  102. state: 0,
  103. active: 0,
  104. activeId: '',
  105. downList: [],
  106. pickList: [],
  107. list: [],
  108. delId: [],
  109. btn: [
  110. {
  111. name: '添加',
  112. type: 'success',
  113. method: 'add'
  114. }
  115. ],
  116. table: {
  117. column: [
  118. {
  119. label: '编号',
  120. props: 'id'
  121. },
  122. {
  123. label: '流程名称',
  124. props: 'processName'
  125. }
  126. ],
  127. handle: [
  128. {
  129. title: '查看',
  130. method: 'details',
  131. type: 'info'
  132. },
  133. {
  134. title: '编辑',
  135. method: 'editor',
  136. type: 'warning'
  137. },
  138. {
  139. title: '删除',
  140. method: 'del',
  141. type: 'danger'
  142. }
  143. ]
  144. },
  145. validatePass
  146. }
  147. },
  148. created () {
  149. this.queryData()
  150. this.queryDownList()
  151. },
  152. methods: {
  153. queryData (form = {}) {
  154. let page = this.page
  155. let reqdata = form
  156. this.$api
  157. .post('/process/queryProcessList', {
  158. reqdata,
  159. page
  160. })
  161. .then((res) => {
  162. this.totalrecords = res.totalrecords
  163. this.tableList = res.list
  164. })
  165. },
  166. queryDownList () {
  167. this.$api
  168. .post('/video/queryVideoList', {
  169. reqdata: {}
  170. })
  171. .then((res) => {
  172. this.downList = res.list
  173. })
  174. },
  175. updateActive (item, index, j) {
  176. console.log(item, index, j)
  177. // this.form.questionList[index].active = j
  178. item.active = j
  179. this.$set(this.form.questionList, index, item)
  180. console.log(this.form.questionList[index].active)
  181. },
  182. add () {
  183. this.open()
  184. this.state = 0
  185. },
  186. getDetails (row) {
  187. let reqdata = { id: row.id }
  188. this.$api
  189. .post('/process/queryProcessDetail', {
  190. reqdata
  191. })
  192. .then((res) => {
  193. this.open()
  194. this.form = JSON.parse(JSON.stringify(res.object))
  195. this.form.questionList = this.form.questionList.map(item => {
  196. item.active = 0
  197. return item
  198. })
  199. console.log(this.form)
  200. })
  201. },
  202. details (row) {
  203. this.getDetails(row)
  204. this.state = 2
  205. },
  206. editor (row) {
  207. this.getDetails(row)
  208. this.state = 1
  209. },
  210. del (row) {
  211. this.$confirm('此操作将永久删除该数据, 是否继续?', '提示', {
  212. confirmButtonText: '确定',
  213. cancelButtonText: '取消',
  214. type: 'warning'
  215. }).then(() => {
  216. let reqdata = { id: row.id }
  217. this.$api
  218. .post('/process/deleteProcess', {
  219. reqdata
  220. })
  221. .then((res) => {
  222. this.$message({
  223. message: '删除成功',
  224. type: 'success'
  225. })
  226. this.queryData()
  227. })
  228. }).catch(() => {
  229. this.$message({
  230. type: 'info',
  231. message: '已取消删除'
  232. })
  233. })
  234. },
  235. branch () {
  236. if (this.state) {
  237. this.uploadQuestion()
  238. } else {
  239. this.determine()
  240. }
  241. },
  242. uploadQuestion () {
  243. let a
  244. this.$refs['form'].validate((valid) => {
  245. a = valid
  246. })
  247. if (!a) return
  248. let list = this.form.questionList.filter(item => !item.id)
  249. let b = 0
  250. list.length
  251. ? list.forEach(item => {
  252. let reqdata = item
  253. reqdata.processId = this.form.id
  254. this.$api
  255. .post('/question/saveQuestion', {
  256. reqdata
  257. })
  258. .then((res) => {
  259. b++
  260. item.id = res.object.id
  261. // this.form.questionList[this.form.questionList.length - index - 1].id = res.object.id
  262. console.log(this.form)
  263. // console.log(b, num)
  264. if (b === list.length) {
  265. this.determine()
  266. }
  267. })
  268. })
  269. : this.determine()
  270. },
  271. determine () {
  272. let a
  273. this.$refs['form'].validate((valid) => {
  274. a = valid
  275. })
  276. if (!a) return
  277. let url = this.state ? '/process/updateProcess' : '/process/saveProcess'
  278. let reqdata = JSON.parse(JSON.stringify(this.form))
  279. if (this.state) {
  280. reqdata.questionList.map(item => {
  281. item.questionId = item.id
  282. return item
  283. })
  284. // this.delId.forEach(item => {
  285. // reqdata.questionList.push({ questionId: item })
  286. // })
  287. }
  288. this.$api
  289. .post(url, {
  290. reqdata
  291. })
  292. .then((res) => {
  293. this.close()
  294. this.queryData()
  295. this.delId = []
  296. })
  297. },
  298. removeDomain (item) {
  299. var index = this.form.questionList.indexOf(item)
  300. if (index !== -1) {
  301. this.delId.push(this.form.questionList[index].id)
  302. this.form.questionList.splice(index, 1)
  303. }
  304. },
  305. open () {
  306. this.dialogFormVisible = true
  307. },
  308. close () {
  309. this.dialogFormVisible = false
  310. this.form = { processName: '', questionList: [] }
  311. this.form.questionList.push({ key: 1, questionName: '' })
  312. this.$forceUpdate()
  313. console.log(this.form)
  314. },
  315. addDomain () {
  316. this.form.questionList.push({
  317. key: Date.now()
  318. })
  319. },
  320. callPage (val) {
  321. this.page = val
  322. this.queryData()
  323. }
  324. },
  325. watch: {
  326. dialogFormVisible: function (val, oldVla) {
  327. if (this.$refs['form'] !== undefined) {
  328. this.$refs['form'].resetFields()
  329. }
  330. }
  331. }
  332. }
  333. </script>
  334. <style lang="scss" scoped>
  335. .dialog-footer {
  336. display: flex;
  337. justify-content: center;
  338. align-items: center;
  339. }
  340. .flex {
  341. margin-bottom: 5px;
  342. display: flex;
  343. .active {
  344. cursor: pointer;
  345. color: rgb(42, 117, 216);
  346. margin: 5px;
  347. }
  348. .is-active {
  349. color: #000;
  350. font-size: 16px;
  351. }
  352. }
  353. </style>