item-list-layer.vue 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <template>
  2. <el-dialog title="选择花材" :visible.sync="selDialog" :close-on-click-modal="false" :append-to-body="true" @close="$emit('update:show', false)" width="950px">
  3. <div class="recharge-modal-content">
  4. <el-checkbox-group v-model="checkList" class="radio-wrap" >
  5. <x-crud class="liu-crud-wrap" @load="onLoad">
  6. <template #table-column-radio="{scope}">
  7. <div>
  8. <el-checkbox v-if="scope.row.select == 2" disabled :label="scope.row" >{{scope.row.id}}</el-checkbox>
  9. <el-checkbox v-else :label="scope.row" @click.stop.native="stop" >{{scope.row.id}}</el-checkbox>
  10. </div>
  11. </template>
  12. <template #table-column-select="{scope}">
  13. <span v-if="scope.row.select == 2">✔</span>
  14. <span v-else></span>
  15. </template>
  16. <template #table-column-stockWarning="{scope}">
  17. <el-input v-model="scope.row.stockWarning" @click.stop.native="stop" placeholder="库存预警值" size="small"></el-input>
  18. </template>
  19. <template #table-column-cost="{scope}">
  20. <el-input v-model="scope.row.cost" placeholder="成本价" @click.stop.native="stop" size="small" ></el-input>
  21. </template>
  22. <template #table-column-addPrice="{scope}">
  23. <el-input v-model="scope.row.addPrice" placeholder="加价" @click.stop.native="stop" size="small"></el-input>
  24. </template>
  25. <template #table-column-cover="{scope}">
  26. <div>
  27. <cl-avatar shape="square" :size="40" :src="scope.row.cover | default_avatar" :style="{ margin: 'auto' }" ></cl-avatar>
  28. </div>
  29. </template>
  30. </x-crud>
  31. </el-checkbox-group>
  32. <div>
  33. <span>花材分类:</span>
  34. <el-select style="width:300px;" v-model="sonClassName" size="small" placeholder="请选择分类" @change="selClassFn">
  35. <el-option v-for="(item, index) in itemClassList" :key="index" :value="item.name">{{ item.name }}</el-option>
  36. </el-select>
  37. </div>
  38. </div>
  39. <div slot="footer" class="dialog-footer">
  40. <el-button size="small" @click="resetForm" >取 消</el-button>
  41. <el-button type="primary" size="small" @click="confirmFn">确定</el-button>
  42. </div>
  43. </el-dialog>
  44. </template>
  45. <script>
  46. export default {
  47. name: 'sj-list-layer',
  48. props: {
  49. show: {
  50. type: Boolean,
  51. default: false
  52. },
  53. classId: {
  54. type: Number,
  55. default: 0
  56. },
  57. multi: {
  58. type: Boolean,
  59. default: false
  60. },
  61. className:{
  62. type: String,
  63. default:''
  64. }
  65. },
  66. data () {
  67. return {
  68. selDialog: false,
  69. ruleForm: {},
  70. checkList: [],
  71. list: [],
  72. //分类列表
  73. itemClassList: [],
  74. sonClassId:0,
  75. sonClassName:''
  76. };
  77. },
  78. computed: {
  79. },
  80. watch: {
  81. show () {
  82. this.selDialog = this.show;
  83. }
  84. },
  85. created () { },
  86. methods: {
  87. stop(){},
  88. selClassFn(val){
  89. let index = this.itemClassList.findIndex((e) => e.name == val)
  90. this.sonClassId = this.itemClassList[index].id
  91. },
  92. getAllClass() {
  93. if (!this.$util.isEmpty(this.itemClassList)) {
  94. return this.itemClassList
  95. }
  96. this.$service.itemClass.getAllClass().then((res) => {
  97. this.itemClassList = res.list
  98. })
  99. },
  100. confirmFn () {
  101. if (this.checkList.length == 0) {
  102. this.$message.warning('请选择花材')
  103. return false
  104. }
  105. if(this.sonClassId == 0){
  106. this.$message.warning('请选择分类')
  107. return false
  108. }
  109. this.$emit('confirm', {list:this.checkList,classId:this.sonClassId})
  110. },
  111. resetForm () {
  112. this.$emit('cancel');
  113. },
  114. selectItem(row){
  115. console.log(row)
  116. //已经选过
  117. if(row.select == 2){
  118. return false
  119. }
  120. let index = this.checkList.findIndex(e => e.id == row.id)
  121. if(index === -1){
  122. this.checkList = [row,...this.checkList]
  123. }else{
  124.         this.checkList.splice(index,1)
  125. }
  126. },
  127. onLoad ({ ctx, app }) {
  128. this.sonClassId = this.classId
  129. this.sonClassName = this.className
  130. //分类列表
  131. this.getAllClass()
  132. this.app = app;
  133. ctx.service(this.$service.ptItem)
  134. .set('table', {
  135. columns: [
  136. {
  137. prop: 'radio',
  138. label: '选择',
  139. align: 'center',
  140. width: 110
  141. },
  142. {
  143. prop: 'cover',
  144. label: '图片',
  145. align: 'center',
  146. width: 120
  147. },
  148. {
  149. prop: 'name',
  150. label: '名称',
  151. align: 'center'
  152. },
  153. {
  154. prop: 'stockWarning',
  155. label: '库存预警值',
  156. align: 'center'
  157. },
  158. {
  159. prop: 'cost',
  160. label: '成本价',
  161. align: 'center'
  162. },
  163. {
  164. prop: 'addPrice',
  165. label: '加价',
  166. align: 'center'
  167. },
  168. {
  169. prop: 'weight',
  170. label: '重量',
  171. align: 'center'
  172. },
  173. {
  174. prop: 'select',
  175. label: '已添加',
  176. align: 'center'
  177. }
  178. ],
  179. on: {
  180. 'row-click': (row, column) => {
  181. this.selectItem(row)
  182. }
  183. },
  184. // 操作列
  185. op: {
  186. visible: false // 是否显示
  187. }
  188. })
  189. .set('dict', {
  190. search: {
  191. keyWord: 'name'
  192. }
  193. })
  194. .set('search', {
  195. key: {
  196. placeholder: '花材名称,支持拼音首字母搜索'
  197. }
  198. })
  199. .set('layout', [
  200. ['slot-tabs'],
  201. ['search-key', 'flex1', 'refresh-btn'],
  202. ['data-table'],
  203. ['flex1', 'pagination']
  204. ])
  205. .on('refresh', async (params, { next, render }) => {
  206. // 继续执行刷新
  207. let { list } = await next(params);
  208. list.map((e, index) => {
  209. e.index = index;
  210. });
  211. this.list = list;
  212. render(list);
  213. })
  214. .done();
  215. app.refresh({ type: this.tabIndex });
  216. }
  217. }
  218. };
  219. </script>
  220. <style lang="scss">
  221. // 列表
  222. .radio-wrap {
  223. display: block;
  224. }
  225. .el-dialog{
  226. margin: 10px auto 10px !important;
  227. }
  228. </style>