index.vue 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  1. <template>
  2. <!-- <ws-dropdown
  3. trigger="click"
  4. placement="bottom-start"
  5. style="width: 100%;"
  6. :hide-on-click="false"
  7. >
  8. &lt;!&ndash; 选择框 &ndash;&gt;
  9. <ws-button class="selectClass">
  10. <span class="textClass">{{ pleaseChoose.length>0?pleaseChoose:getPleaseChoose }}</span>
  11. <i class="el-icon-arrow-down el-icon&#45;&#45;right" style="float:right"></i>
  12. </ws-button>
  13. &lt;!&ndash; 下拉框 &ndash;&gt;
  14. <ws-dropdown-menu
  15. slot="dropdown"
  16. class="kuangClass"
  17. :data-stopPropagation="true"
  18. >
  19. &lt;!&ndash; 已有内容 &ndash;&gt;
  20. <ws-dropdown-item
  21. v-for="(item, index) in unitList"
  22. :key="index"
  23. :command="item.constKey"
  24. >
  25. <div style="display:flex;width:172px" v-if="item.flag != 'add'">
  26. &lt;!&ndash; 已有显示 &ndash;&gt;
  27. <span
  28. style="width:170px"
  29. v-if="item.flag == 'delete'"
  30. @click="selectContract(item, index)"
  31. >{{
  32. getLanguage === 'en' &&
  33. item.constValueEn &&
  34. item.constValueEn.length > 0
  35. ? item.constValueEn
  36. : item.constValue
  37. }}</span
  38. >
  39. &lt;!&ndash; 新增文本框 &ndash;&gt;
  40. <span style="width:160px" v-if="item.flag == 'check'">
  41. <ws-input
  42. v-model="item.constValue"
  43. clearable
  44. maxlength="10"
  45. style="height:24px;width:125px"
  46. ></ws-input>
  47. </span>
  48. &lt;!&ndash; 对号 &ndash;&gt;
  49. <i
  50. class="el-icon-check"
  51. style="line-height: 29px;margin-left:10px"
  52. v-if="item.flag == 'check'"
  53. @click="saveClick(item, index)"
  54. ></i>
  55. &lt;!&ndash; 编辑 &ndash;&gt;
  56. <i
  57. class="el-icon-edit"
  58. style="line-height: 29px;margin-left:10px"
  59. v-if="item.flag == 'delete'"
  60. @click="editClick(item, index)"
  61. ></i>
  62. &lt;!&ndash; 删除 &ndash;&gt;
  63. <i
  64. class="el-icon-delete"
  65. style="line-height: 29px;"
  66. @click="deleteClick(item, index)"
  67. ></i>
  68. </div>
  69. </ws-dropdown-item>
  70. &lt;!&ndash; 新增按钮 &ndash;&gt;
  71. <ws-dropdown-item>
  72. <div class="butClass">
  73. <ws-button type="primary" @click="addClick()" class="addbutton">{{
  74. $t('button.add')
  75. }}</ws-button>
  76. </div>
  77. </ws-dropdown-item>
  78. </ws-dropdown-menu>
  79. </ws-dropdown>-->
  80. <el-select v-model="pleaseChoose"
  81. :placeholder="getPleaseChoose"
  82. style="width: 100%;"
  83. filterable
  84. clearable
  85. @change="selectContract">
  86. <el-option v-for="(item,index) in unitList"
  87. :key="item.constValue"
  88. :label="getLanguage !== 'en' ? item.constValue : item.constValueEn"
  89. :value="item.constValue">
  90. <span class="unit-left"
  91. style="float: left">
  92. <span v-if="item.flag == 'delete'"> {{ item.constValue }}</span>
  93. <!-- 新增文本框 -->
  94. <div style="width:160px"
  95. v-if="item.flag !== 'delete'"
  96. @click.stop>
  97. <ws-input v-model="item.constValue"
  98. clearable
  99. maxlength="10"
  100. style="width:100%;"></ws-input>
  101. </div>
  102. </span>
  103. <span style="float: right; color: #8492a6; font-size: 13px">
  104. <!-- 对号 -->
  105. <i class="el-icon-check"
  106. style="line-height: 29px;margin-left:10px"
  107. v-if="item.flag !== 'delete'"
  108. @click.stop="saveClick(item, index)"></i>
  109. <!-- 编辑 -->
  110. <i class="el-icon-edit"
  111. style="line-height: 29px;margin-left:10px"
  112. v-if="item.flag == 'delete'"
  113. @click.stop="editClick(item, index)"></i>
  114. <!-- 删除 -->
  115. <i class="el-icon-delete"
  116. style="line-height: 29px;"
  117. @click.stop="deleteClick(item, index)"></i>
  118. </span>
  119. </el-option>
  120. <!-- 新增按钮 -->
  121. <el-option value=""
  122. label="">
  123. <div style="text-align: center">
  124. <ws-button type="primary"
  125. @click.stop="addClick">{{$t('button.add')}}</ws-button>
  126. </div>
  127. </el-option>
  128. </el-select>
  129. </template>
  130. <script>
  131. import {
  132. add,
  133. edit,
  134. saveDelete,
  135. customDropDown
  136. } from '@/model/indexRx'
  137. export default {
  138. props: [
  139. 'setlanguage', // 当前语言
  140. 'vModel', // 数据绑定
  141. 'vModelType', // 数据绑定类型 id 或者key 默认key
  142. 'type', // 查询类别参数
  143. 'setShowType', // 显示类型
  144. 'row' // 当前行数据
  145. ],
  146. data () {
  147. return {
  148. unitList: [],
  149. showName: '',
  150. showType: true,
  151. pleaseChoose: '',
  152. //编辑后的单位
  153. trainingMethods: {
  154. constCode: this.type ? this.type : 'MATERIAL_MEASUREMENT_UNIT',
  155. constKey: '',
  156. constValue: '',
  157. id: '',
  158. compId: localStorage.getItem('ws-pf_compId')
  159. }
  160. }
  161. },
  162. computed: {
  163. getLanguage () {
  164. let language = this.$store.state.app.language
  165. return language
  166. },
  167. getPleaseChoose () {
  168. return this.$t('common.selected')
  169. }
  170. },
  171. watch: {
  172. vModel () {
  173. this.getUnitList()
  174. }
  175. },
  176. mounted () {
  177. this.getUnitList()
  178. },
  179. methods: {
  180. getUnitList () {
  181. customDropDown({
  182. compId: localStorage.getItem('ws-pf_compId'),
  183. constCode: this.type
  184. }).toPromise().then(response => {
  185. this.unitList = response
  186. let currItem
  187. this.unitList.forEach((item, index, arr) => {
  188. item.flag = 'delete'
  189. if (this.vModel == item.constKey) {
  190. currItem = item
  191. }
  192. })
  193. //
  194. if (currItem) {
  195. this.selectContract(currItem.constValue)
  196. }
  197. })
  198. },
  199. // =============================================== 可编辑单位增删改查方法区 ===============================================
  200. // 选中
  201. selectContract (val) {
  202. let key = this.unitList.find(item => item.constValue === val).constKey
  203. this.$emit('update:vModel', key)
  204. this.pleaseChoose = val
  205. this.$emit('selectValue', val)
  206. },
  207. // 保存
  208. saveClick (item, index) {
  209. if (Object.is(item.id, 1)) {
  210. return
  211. }
  212. if (Object.is(this.unitList[index].flag, 'delete')) {
  213. this.$set(this.unitList, index, { flag: 'check' })
  214. } else {
  215. this.$set(this.unitList, index, { flag: 'delete' })
  216. }
  217. if (!item.constKey) {
  218. if (!item.constValue) {
  219. this.unitList.splice(index, 1)
  220. return
  221. }
  222. this.trainingMethods.constValue = item.constValue
  223. add(this.trainingMethods).toPromise().then(response => {
  224. this.getUnitList()
  225. })
  226. } else {
  227. this.trainingMethods.constValue = item.constValue
  228. this.trainingMethods.id = item.id
  229. this.trainingMethods.constKey = item.constKey
  230. edit(this.trainingMethods).toPromise().then(response => {
  231. this.getUnitList()
  232. })
  233. }
  234. },
  235. // 编辑
  236. editClick (item, index) {
  237. const map = JSON.parse(JSON.stringify(item))
  238. if (Object.is(item.id, 1)) {
  239. return
  240. }
  241. if (Object.is(this.unitList[index].flag, 'delete')) {
  242. map.flag = 'check'
  243. this.$set(this.unitList, index, map)
  244. } else {
  245. map.flag = 'delete'
  246. this.$set(this.unitList, index, map)
  247. }
  248. },
  249. // 删除
  250. deleteClick (item, index) {
  251. if (Object.is(item.constKey, 1)) {
  252. return
  253. }
  254. if (!item.constValue) {
  255. this.unitList.splice(index, 1)
  256. return
  257. }
  258. saveDelete({ id: this.unitList[index].id }).toPromise().then(response => {
  259. this.getUnitList()
  260. this.pleaseChoose = ''
  261. })
  262. },
  263. // 新增按钮
  264. addClick () {
  265. // let [flag, constValue, constKey] = ['check', '', '']
  266. // let obj = { flag, constValue, constKey }
  267. // let objAdd = { flag: 'add', constValue: '新增项目', constKey: '' }
  268. // let result = this.unitList.filter((item, val, arr) => {
  269. // return item.id != '1'
  270. // })
  271. // result.push(obj)
  272. // result.push(objAdd)
  273. // this.unitList = result
  274. this.unitList.push({
  275. flag: 'add',
  276. constValue: '',
  277. constKey: ''
  278. })
  279. }
  280. // =============================================== 可编辑单位增删改查方法区 ===============================================
  281. }
  282. }
  283. </script>
  284. <style lang="scss" scoped>
  285. .unit-left {
  286. /deep/ .el-input--small .el-input__inner {
  287. height: 24px;
  288. line-height: 24px;
  289. }
  290. }
  291. .selectClass {
  292. width: 100%;
  293. height: 32px;
  294. margin-top: 7px;
  295. }
  296. .textClass {
  297. float: left;
  298. line-height: 10px;
  299. margin-left: -8px;
  300. margin-top: 2px;
  301. }
  302. .kuangClass {
  303. width: 200px;
  304. transform-origin: center top;
  305. z-index: 2010;
  306. position: fixed;
  307. top: 293px;
  308. left: 458px;
  309. }
  310. /deep/ .el-dropdown-menu__item {
  311. margin: 5px 0px;
  312. }
  313. .butClass {
  314. /deep/ .el-button--small {
  315. width: 167px;
  316. }
  317. }
  318. /deep/.el-input--medium {
  319. width: 100% !important;
  320. }
  321. </style>