index.vue 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279
  1. <template>
  2. <view>
  3. <u-modal :show="showModal" ref="uModal" :asyncClose="false" showCancelButton @cancel="closeDialog"
  4. cancelColor="#909399" :confirmText="'确定'" confirmColor="#2979ff" @confirm="confirm" @close="closeDialog"
  5. :closeOnClickOverlay="false">
  6. <view class="title_wrap">
  7. <view class="title">
  8. {{ title }}
  9. </view>
  10. <view class="modal_wrap">
  11. <text @click="handleBrandClick" class="item"
  12. :class="info.dictLabel ? 'brand' : 'brand placeholder'">{{ info.dictLabel || '品牌' }}</text>
  13. <text class="divider">|</text>
  14. <u--input placeholder="型号" class="item" border="none" v-model="info.model" clearable></u--input>
  15. <text class="divider">|</text>
  16. <u--input class="code-input item" placeholder="编码" border="none" v-model="info.code"
  17. clearable></u--input>
  18. </view>
  19. </view>
  20. <view class="img_wrap">
  21. <imgs-row-scroll v-if="info.imgsUrl.length > 0" :isShowDeleteIcon="true"
  22. @deleteImgInfo="getDeleteImgInfo" imgMode="aspectFill" :totalWidth="400" :images="info.imgsUrl"
  23. :previewEnabled="true" :imageWidth="150" :imageHeight="150"></imgs-row-scroll>
  24. <u-upload @afterRead="afterRead" name="3" multiple :maxCount="10"></u-upload>
  25. </view>
  26. <u--input v-if="editOrAdd === 'edit'" class="price" placeholder="价格" border="bottom" v-model="info.price"
  27. clearable></u--input>
  28. <qiun-data-charts v-if="isShowChart" type="column" :chartData="chartData" canvasId="priceChart" :opts="opts" :ontouch="true"
  29. width="700rpx" height="600rpx" backgroundColor="#fff" />
  30. </u-modal>
  31. <brandList ref="brandListRef" @selectedBrand="handleSelectedBrand"></brandList>
  32. </view>
  33. </template>
  34. <script>
  35. import imgsRowScroll from '@/components/imgs-row-scroll/index.vue'
  36. import brandList from '@/components/brand-list/index.vue'
  37. export default {
  38. name: 'AddInquiryDialog',
  39. components: {
  40. imgsRowScroll,
  41. brandList
  42. },
  43. props: {
  44. clueId: {
  45. type: String,
  46. default: ''
  47. },
  48. show: {
  49. type: Boolean,
  50. default: false
  51. },
  52. editOrAdd: {
  53. type: String,
  54. default: ''// edit 编辑(有价格), editForm 编辑询价单(无价格), add 新增询价单, receptFormAdd 新增接收询价单 线索页面:第一次点击是新增(不需要回显),status传1,第二次点击是无价格编辑status传1;接单中心:第一次点击是新增(需要回显)status传1,第二次点击是无价格编辑status传1;只有edit是有价格编辑status传2
  55. },
  56. editInfo: {
  57. type: Object,
  58. default: () => { }
  59. },
  60. type: {
  61. type: Number,
  62. default: 1
  63. },
  64. isClue: {
  65. type: Boolean,
  66. default: false
  67. },
  68. title: {
  69. type: String,
  70. default: ''
  71. },
  72. isShowChart: {
  73. type: Boolean,
  74. default: false
  75. }
  76. },
  77. emits: ['submitSuccess'],
  78. inject: {
  79. refreshData: {
  80. default: null
  81. }
  82. },
  83. data() {
  84. return {
  85. showModal: false,
  86. info: {
  87. model: '',
  88. code: '',
  89. id: '',
  90. price: '',
  91. dictLabel: '',
  92. dictValue: '',
  93. imgsUrl: []
  94. },
  95. rules: {
  96. brand: [
  97. { required: true, message: '请输入品牌', trigger: 'blur' }
  98. ]
  99. },
  100. opts: {
  101. color: [this.getRandomColor()],
  102. padding: [15, 15, 0, 5],
  103. touchMoveLimit: 24,
  104. enableScroll: true,
  105. legend: {},
  106. xAxis: {
  107. disableGrid: true,
  108. scrollShow: true,
  109. itemCount: 4
  110. },
  111. yAxis: {
  112. data: [
  113. {
  114. min: 0
  115. }
  116. ]
  117. },
  118. extra: {
  119. column: {
  120. type: "group",
  121. width: 30,
  122. activeBgColor: "#000000",
  123. activeBgOpacity: 0.08,
  124. seriesGap: 5,
  125. barBorderRadius: [6,6,6,6]
  126. }
  127. }
  128. },
  129. chartData:{}
  130. }
  131. },
  132. watch: {
  133. show: {
  134. handler(newVal) {
  135. this.showModal = newVal;
  136. },
  137. immediate: true
  138. }
  139. },
  140. methods: {
  141. getRandomColor() {
  142. var letters = '0123456789ABCDEF';
  143. var color = '#';
  144. for (var i = 0; i < 6; i++) {
  145. color += letters[Math.floor(Math.random() * 16)];
  146. }
  147. return color;
  148. },
  149. // 编辑回显
  150. initData() {
  151. this.$nextTick(() => {
  152. this.info = JSON.parse(JSON.stringify(this.editInfo))
  153. console.log(this.info)
  154. if(this.isShowChart){
  155. this.chartData = {
  156. categories: this.info.priceChart.map((item, index) => item.userName),
  157. series: [
  158. {
  159. name: "价格",
  160. data: this.info.priceChart.map(item => item.price)
  161. }
  162. ]
  163. };
  164. }
  165. this.showModal = true;
  166. })
  167. },
  168. // 获取删除图片信息
  169. getDeleteImgInfo(info) {
  170. this.info.imgsUrl = info.newImages
  171. },
  172. handleBrandClick() {
  173. this.$refs.brandListRef.showBrandList();
  174. },
  175. handleSelectedBrand(info) {
  176. this.info.dictLabel = info.dictLabel
  177. this.info.dictValue = info.dictValue
  178. },
  179. // 上传图片
  180. afterRead(info) {
  181. info.file.forEach(item => {
  182. uni.$u.api.uploadFile(item.url).then((res) => {
  183. this.info.imgsUrl.push(res.data.url);
  184. uni.$u.toast("文件上传成功");
  185. }).catch(() => {
  186. uni.$u.toast("上传文件失败");
  187. })
  188. })
  189. },
  190. // 确认添加
  191. confirm() {
  192. if (!this.info.dictLabel || !this.info.dictValue) {
  193. uni.showToast({
  194. title: '请选择品牌',
  195. icon: 'none'
  196. })
  197. return
  198. }
  199. if (!this.info.model) {
  200. uni.showToast({
  201. title: '请输入型号',
  202. icon: 'none'
  203. })
  204. return
  205. }
  206. if (!this.info.code) {
  207. uni.showToast({
  208. title: '请输入编码',
  209. icon: 'none'
  210. })
  211. return
  212. }
  213. if (this.info.imgsUrl.length == 0) {
  214. uni.showToast({
  215. title: '请上传图片',
  216. icon: 'none'
  217. })
  218. return
  219. }
  220. if (this.editOrAdd === 'edit' && !this.info.price) {
  221. uni.showToast({
  222. title: '请输入价格',
  223. icon: 'none'
  224. })
  225. return
  226. }
  227. const data = {
  228. clueId: this.clueId,
  229. dictValue: this.info.dictValue,
  230. dictLabel: this.info.dictLabel,
  231. model: this.info.model,
  232. code: this.info.code,
  233. id: (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm') ? this.info.id : '',
  234. price: this.editOrAdd === 'edit' ? this.info.price : '',
  235. imgsUrl: this.info.imgsUrl,
  236. status: this.editOrAdd === 'edit' ? '2' : '1',
  237. type: this.type
  238. }
  239. uni.$u.api.addInquiry(data).then(res => {
  240. uni.$u.toast('保存成功')
  241. this.closeDialog()
  242. this.$emit('submitSuccess')
  243. if (this.isClue && this.refreshData) this.refreshData.resetData(); //线索公海页面需要刷新列表
  244. }).catch((err) => {
  245. uni.$u.toast(err)
  246. })
  247. },
  248. showDialog() {
  249. if (this.editOrAdd === 'edit' || this.editOrAdd === 'editForm' || this.editOrAdd === 'receptFormAdd') {
  250. this.initData();
  251. } else if (this.editOrAdd === 'add') {
  252. this.clearForm()
  253. this.showModal = true;
  254. }
  255. },
  256. clearForm() {
  257. this.info = {
  258. dictLabel: '',
  259. dictValue: '',
  260. model: '',
  261. code: '',
  262. id: '',
  263. price: '',
  264. imgsUrl: []
  265. }
  266. },
  267. closeDialog() {
  268. this.showModal = false;
  269. },
  270. }
  271. };
  272. </script>
  273. <style lang="scss" scoped>
  274. @import './index.scss'
  275. </style>